A USB foot pedal for turning pages of PDF piano sheet music
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

usb_keyboard.h 4.9KB

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