Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

command.c 7.0KB

13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
12 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
13 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. Copyright 2011 Jun Wako <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <util/delay.h>
  17. #include "usb_keycodes.h"
  18. #include "host.h"
  19. #include "print.h"
  20. #include "debug.h"
  21. #include "util.h"
  22. #include "timer.h"
  23. #include "keyboard.h"
  24. #include "matrix.h"
  25. #include "bootloader.h"
  26. #include "command.h"
  27. #ifdef HOST_PJRC
  28. # include "usb_keyboard.h"
  29. # ifdef EXTRAKEY_ENABLE
  30. # include "usb_extra.h"
  31. # endif
  32. #endif
  33. #ifdef HOST_VUSB
  34. # include "usbdrv.h"
  35. #endif
  36. static uint8_t command_common(void);
  37. static void help(void);
  38. static void switch_layer(uint8_t layer);
  39. static bool last_print_enable;
  40. uint8_t command_proc(void)
  41. {
  42. uint8_t processed = 0;
  43. last_print_enable = print_enable;
  44. if (!IS_COMMAND())
  45. return 0;
  46. print_enable = true;
  47. if (command_extra() || command_common()) {
  48. processed = 1;
  49. _delay_ms(500);
  50. }
  51. print_enable = last_print_enable;
  52. return processed;
  53. }
  54. /* This allows to define extra commands. return 0 when not processed. */
  55. uint8_t command_extra(void) __attribute__ ((weak));
  56. uint8_t command_extra(void)
  57. {
  58. return 0;
  59. }
  60. static uint8_t command_common(void)
  61. {
  62. switch (host_get_first_key()) {
  63. case KB_H:
  64. help();
  65. break;
  66. case KB_B:
  67. host_clear_keyboard_report();
  68. host_send_keyboard_report();
  69. print("jump to bootloader... ");
  70. _delay_ms(1000);
  71. bootloader_jump(); // not return
  72. print("not supported.\n");
  73. break;
  74. case KB_D:
  75. debug_enable = !debug_enable;
  76. if (debug_enable) {
  77. last_print_enable = true;
  78. print("debug enabled.\n");
  79. debug_matrix = true;
  80. debug_keyboard = true;
  81. debug_mouse = true;
  82. } else {
  83. print("debug disabled.\n");
  84. last_print_enable = false;
  85. debug_matrix = false;
  86. debug_keyboard = false;
  87. debug_mouse = false;
  88. }
  89. break;
  90. case KB_X: // debug matrix toggle
  91. debug_matrix = !debug_matrix;
  92. if (debug_matrix)
  93. print("debug matrix enabled.\n");
  94. else
  95. print("debug matrix disabled.\n");
  96. break;
  97. case KB_K: // debug keyboard toggle
  98. debug_keyboard = !debug_keyboard;
  99. if (debug_keyboard)
  100. print("debug keyboard enabled.\n");
  101. else
  102. print("debug keyboard disabled.\n");
  103. break;
  104. case KB_M: // debug mouse toggle
  105. debug_mouse = !debug_mouse;
  106. if (debug_mouse)
  107. print("debug mouse enabled.\n");
  108. else
  109. print("debug mouse disabled.\n");
  110. break;
  111. case KB_V: // print version & information
  112. print(STR(DESCRIPTION) "\n");
  113. break;
  114. case KB_T: // print timer
  115. print("timer: "); phex16(timer_count); print("\n");
  116. break;
  117. case KB_P: // print toggle
  118. if (last_print_enable) {
  119. print("print disabled.\n");
  120. last_print_enable = false;
  121. } else {
  122. last_print_enable = true;
  123. print("print enabled.\n");
  124. }
  125. break;
  126. case KB_S:
  127. print("host_keyboard_leds:"); phex(host_keyboard_leds()); print("\n");
  128. #ifdef HOST_PJRC
  129. print("UDCON: "); phex(UDCON); print("\n");
  130. print("UDIEN: "); phex(UDIEN); print("\n");
  131. print("UDINT: "); phex(UDINT); print("\n");
  132. print("usb_keyboard_leds:"); phex(usb_keyboard_leds); print("\n");
  133. print("usb_keyboard_protocol: "); phex(usb_keyboard_protocol); print("\n");
  134. print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n");
  135. print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n");
  136. #endif
  137. #ifdef HOST_VUSB
  138. # if USB_COUNT_SOF
  139. print("usbSofCount: "); phex(usbSofCount); print("\n");
  140. # endif
  141. #endif
  142. break;
  143. #ifdef NKRO_ENABLE
  144. case KB_N:
  145. // send empty report before change
  146. host_clear_keyboard_report();
  147. host_send_keyboard_report();
  148. keyboard_nkro = !keyboard_nkro;
  149. if (keyboard_nkro)
  150. print("NKRO: enabled\n");
  151. else
  152. print("NKRO: disabled\n");
  153. break;
  154. #endif
  155. #ifdef EXTRAKEY_ENABLE
  156. case KB_ESC:
  157. host_clear_keyboard_report();
  158. host_send_keyboard_report();
  159. #ifdef HOST_PJRC
  160. if (suspend && remote_wakeup) {
  161. usb_remote_wakeup();
  162. } else {
  163. host_system_send(SYSTEM_POWER_DOWN);
  164. host_system_send(0);
  165. _delay_ms(500);
  166. }
  167. #else
  168. host_system_send(SYSTEM_POWER_DOWN);
  169. host_system_send(0);
  170. _delay_ms(500);
  171. #endif
  172. break;
  173. #endif
  174. case KB_BSPC:
  175. matrix_init();
  176. print("clear matrix\n");
  177. break;
  178. case KB_0:
  179. switch_layer(0);
  180. break;
  181. case KB_1:
  182. switch_layer(1);
  183. break;
  184. case KB_2:
  185. switch_layer(2);
  186. break;
  187. case KB_3:
  188. switch_layer(3);
  189. break;
  190. case KB_4:
  191. switch_layer(4);
  192. break;
  193. default:
  194. return 0;
  195. }
  196. return 1;
  197. }
  198. static void help(void)
  199. {
  200. print("b: jump to bootloader\n");
  201. print("d: toggle debug enable\n");
  202. print("x: toggle matrix debug\n");
  203. print("k: toggle keyboard debug\n");
  204. print("m: toggle mouse debug\n");
  205. print("p: toggle print enable\n");
  206. print("v: print version\n");
  207. print("t: print timer count\n");
  208. print("s: print status\n");
  209. #ifdef NKRO_ENABLE
  210. print("n: toggle NKRO\n");
  211. #endif
  212. print("Backspace: clear matrix\n");
  213. print("ESC: power down/wake up\n");
  214. print("0: switch to Layer0 \n");
  215. print("1: switch to Layer1 \n");
  216. print("2: switch to Layer2 \n");
  217. print("3: switch to Layer3 \n");
  218. print("4: switch to Layer4 \n");
  219. }
  220. static void switch_layer(uint8_t layer)
  221. {
  222. print("current_layer: "); phex(current_layer); print("\n");
  223. print("default_layer: "); phex(default_layer); print("\n");
  224. current_layer = layer;
  225. default_layer = layer;
  226. print("switch to Layer: "); phex(layer); print("\n");
  227. }