Keyboard firmwares for Atmel AVR and Cortex-M
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

usb_keyboard_debug.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #ifndef usb_serial_h__
  2. #define usb_serial_h__
  3. #include <stdint.h>
  4. void usb_init(void); // initialize everything
  5. uint8_t usb_configured(void); // is the USB port configured
  6. int8_t usb_keyboard_press(uint8_t key, uint8_t modifier);
  7. int8_t usb_keyboard_send(void);
  8. extern uint8_t keyboard_modifier_keys;
  9. extern uint8_t keyboard_keys[6];
  10. extern volatile uint8_t keyboard_leds;
  11. int8_t usb_debug_putchar(uint8_t c); // transmit a character
  12. void usb_debug_flush_output(void); // immediately transmit any buffered output
  13. #define USB_DEBUG_HID
  14. #define KEY_CTRL 0x01
  15. #define KEY_SHIFT 0x02
  16. #define KEY_ALT 0x04
  17. #define KEY_GUI 0x08
  18. #define KEY_LEFT_CTRL 0x01
  19. #define KEY_LEFT_SHIFT 0x02
  20. #define KEY_LEFT_ALT 0x04
  21. #define KEY_LEFT_GUI 0x08
  22. #define KEY_RIGHT_CTRL 0x10
  23. #define KEY_RIGHT_SHIFT 0x20
  24. #define KEY_RIGHT_ALT 0x40
  25. #define KEY_RIGHT_GUI 0x80
  26. #define KEY_A 4
  27. #define KEY_B 5
  28. #define KEY_C 6
  29. #define KEY_D 7
  30. #define KEY_E 8
  31. #define KEY_F 9
  32. #define KEY_G 10
  33. #define KEY_H 11
  34. #define KEY_I 12
  35. #define KEY_J 13
  36. #define KEY_K 14
  37. #define KEY_L 15
  38. #define KEY_M 16
  39. #define KEY_N 17
  40. #define KEY_O 18
  41. #define KEY_P 19
  42. #define KEY_Q 20
  43. #define KEY_R 21
  44. #define KEY_S 22
  45. #define KEY_T 23
  46. #define KEY_U 24
  47. #define KEY_V 25
  48. #define KEY_W 26
  49. #define KEY_X 27
  50. #define KEY_Y 28
  51. #define KEY_Z 29
  52. #define KEY_1 30
  53. #define KEY_2 31
  54. #define KEY_3 32
  55. #define KEY_4 33
  56. #define KEY_5 34
  57. #define KEY_6 35
  58. #define KEY_7 36
  59. #define KEY_8 37
  60. #define KEY_9 38
  61. #define KEY_0 39
  62. #define KEY_ENTER 40
  63. #define KEY_ESC 41
  64. #define KEY_BACKSPACE 42
  65. #define KEY_TAB 43
  66. #define KEY_SPACE 44
  67. #define KEY_MINUS 45
  68. #define KEY_EQUAL 46
  69. #define KEY_LEFT_BRACE 47
  70. #define KEY_RIGHT_BRACE 48
  71. #define KEY_BACKSLASH 49
  72. #define KEY_NUMBER 50
  73. #define KEY_SEMICOLON 51
  74. #define KEY_QUOTE 52
  75. #define KEY_TILDE 53
  76. #define KEY_COMMA 54
  77. #define KEY_PERIOD 55
  78. #define KEY_SLASH 56
  79. #define KEY_CAPS_LOCK 57
  80. #define KEY_F1 58
  81. #define KEY_F2 59
  82. #define KEY_F3 60
  83. #define KEY_F4 61
  84. #define KEY_F5 62
  85. #define KEY_F6 63
  86. #define KEY_F7 64
  87. #define KEY_F8 65
  88. #define KEY_F9 66
  89. #define KEY_F10 67
  90. #define KEY_F11 68
  91. #define KEY_F12 69
  92. #define KEY_PRINTSCREEN 70
  93. #define KEY_SCROLL_LOCK 71
  94. #define KEY_PAUSE 72
  95. #define KEY_INSERT 73
  96. #define KEY_HOME 74
  97. #define KEY_PAGE_UP 75
  98. #define KEY_DELETE 76
  99. #define KEY_END 77
  100. #define KEY_PAGE_DOWN 78
  101. #define KEY_RIGHT 79
  102. #define KEY_LEFT 80
  103. #define KEY_DOWN 81
  104. #define KEY_UP 82
  105. #define KEY_NUM_LOCK 83
  106. #define KEYPAD_SLASH 84
  107. #define KEYPAD_ASTERIX 85
  108. #define KEYPAD_MINUS 86
  109. #define KEYPAD_PLUS 87
  110. #define KEYPAD_ENTER 88
  111. #define KEYPAD_1 89
  112. #define KEYPAD_2 90
  113. #define KEYPAD_3 91
  114. #define KEYPAD_4 92
  115. #define KEYPAD_5 93
  116. #define KEYPAD_6 94
  117. #define KEYPAD_7 95
  118. #define KEYPAD_8 96
  119. #define KEYPAD_9 97
  120. #define KEYPAD_0 98
  121. #define KEYPAD_PERIOD 99
  122. // Everything below this point is only intended for usb_serial.c
  123. #ifdef USB_SERIAL_PRIVATE_INCLUDE
  124. #include <avr/io.h>
  125. #include <avr/pgmspace.h>
  126. #include <avr/interrupt.h>
  127. #define EP_TYPE_CONTROL 0x00
  128. #define EP_TYPE_BULK_IN 0x81
  129. #define EP_TYPE_BULK_OUT 0x80
  130. #define EP_TYPE_INTERRUPT_IN 0xC1
  131. #define EP_TYPE_INTERRUPT_OUT 0xC0
  132. #define EP_TYPE_ISOCHRONOUS_IN 0x41
  133. #define EP_TYPE_ISOCHRONOUS_OUT 0x40
  134. #define EP_SINGLE_BUFFER 0x02
  135. #define EP_DOUBLE_BUFFER 0x06
  136. #define EP_SIZE(s) ((s) == 64 ? 0x30 : \
  137. ((s) == 32 ? 0x20 : \
  138. ((s) == 16 ? 0x10 : \
  139. 0x00)))
  140. #define MAX_ENDPOINT 4
  141. #define LSB(n) (n & 255)
  142. #define MSB(n) ((n >> 8) & 255)
  143. #if defined(__AVR_AT90USB162__)
  144. #define HW_CONFIG()
  145. #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
  146. #define USB_CONFIG() (USBCON = (1<<USBE))
  147. #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
  148. #elif defined(__AVR_ATmega32U4__)
  149. #define HW_CONFIG() (UHWCON = 0x01)
  150. #define PLL_CONFIG() (PLLCSR = 0x12)
  151. #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
  152. #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
  153. #elif defined(__AVR_AT90USB646__)
  154. #define HW_CONFIG() (UHWCON = 0x81)
  155. #define PLL_CONFIG() (PLLCSR = 0x1A)
  156. #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
  157. #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
  158. #elif defined(__AVR_AT90USB1286__)
  159. #define HW_CONFIG() (UHWCON = 0x81)
  160. #define PLL_CONFIG() (PLLCSR = 0x16)
  161. #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
  162. #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
  163. #endif
  164. // standard control endpoint request types
  165. #define GET_STATUS 0
  166. #define CLEAR_FEATURE 1
  167. #define SET_FEATURE 3
  168. #define SET_ADDRESS 5
  169. #define GET_DESCRIPTOR 6
  170. #define GET_CONFIGURATION 8
  171. #define SET_CONFIGURATION 9
  172. #define GET_INTERFACE 10
  173. #define SET_INTERFACE 11
  174. // HID (human interface device)
  175. #define HID_GET_REPORT 1
  176. #define HID_GET_IDLE 2
  177. #define HID_GET_PROTOCOL 3
  178. #define HID_SET_REPORT 9
  179. #define HID_SET_IDLE 10
  180. #define HID_SET_PROTOCOL 11
  181. // CDC (communication class device)
  182. #define CDC_SET_LINE_CODING 0x20
  183. #define CDC_GET_LINE_CODING 0x21
  184. #define CDC_SET_CONTROL_LINE_STATE 0x22
  185. #endif
  186. #endif