usb_hid.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef __USB_HID_H__
  22. #define __USB_HID_H__
  23. #include "bsp_common.h"
  24. #include "usb_define.h"
  25. //Keybord keyvalue define
  26. #define HID_KEY_NULL 0x00 // NULL
  27. #define HID_KEY_A 0x04 // A
  28. #define HID_KEY_B 0x05 // B
  29. #define HID_KEY_C 0x06 // C
  30. #define HID_KEY_D 0x07 // D
  31. #define HID_KEY_E 0x08 // E
  32. #define HID_KEY_F 0x09 // F
  33. #define HID_KEY_G 0x0A // G
  34. #define HID_KEY_H 0x0B // H
  35. #define HID_KEY_I 0x0C // I
  36. #define HID_KEY_J 0x0D // J
  37. #define HID_KEY_K 0x0E // K
  38. #define HID_KEY_L 0x0F // L
  39. #define HID_KEY_M 0x10 // M
  40. #define HID_KEY_N 0x11 // N
  41. #define HID_KEY_O 0x12 // O
  42. #define HID_KEY_P 0x13 // P
  43. #define HID_KEY_Q 0x14 // Q
  44. #define HID_KEY_R 0x15 // R
  45. #define HID_KEY_S 0x16 // S
  46. #define HID_KEY_T 0x17 // T
  47. #define HID_KEY_U 0x18 // U
  48. #define HID_KEY_V 0x19 // V
  49. #define HID_KEY_W 0x1A // W
  50. #define HID_KEY_X 0x1B // X
  51. #define HID_KEY_Y 0x1C // Y
  52. #define HID_KEY_Z 0x1D // Z
  53. #define HID_KEY_1 0x1E // 1 and !
  54. #define HID_KEY_2 0x1F // 2 and @
  55. #define HID_KEY_3 0x20 // 3 and #
  56. #define HID_KEY_4 0x21 // 4 and $
  57. #define HID_KEY_5 0x22 // 5 and %
  58. #define HID_KEY_6 0x23 // 6 and ^
  59. #define HID_KEY_7 0x24 // 7 and &
  60. #define HID_KEY_8 0x25 // 8 and *
  61. #define HID_KEY_9 0x26 // 9 and (
  62. #define HID_KEY_0 0x27 // 10 and )
  63. #define HID_KEY_ENTER 0x28 // ENTER
  64. #define HID_KEY_ESC 0x29 // ESC
  65. #define HID_KEY_BACKSPACE 0x2A // BACKSPACE
  66. #define HID_KEY_TAB 0x2B // TAB
  67. #define HID_KEY_SPACE 0x2C // SPACE
  68. #define HID_KEY_SUB 0x2D // - and _
  69. #define HID_KEY_EQUAL 0x2E // = and +
  70. #define HID_KEY_LEFT_BRACKET 0x2F // [ and {
  71. #define HID_KEY_RIGHT_BRACKET 0x30 // ] and }
  72. #define HID_KEY_VERTICAL_LINE 0x31 // "\" and |
  73. #define HID_KEY_WAVE 0x32 // ` and ~
  74. #define HID_KEY_SEMICOLON 0x33 // ; and :
  75. #define HID_KEY_QUOTE 0x34 // ' and "
  76. #define HID_KEY_THROW 0x35 // ~ and `
  77. #define HID_KEY_COMMA 0x36 // , and <
  78. #define HID_KEY_DOT 0x37 // . and >
  79. #define HID_KEY_QUESTION 0x38 // / and ?
  80. #define HID_KEY_CAPS_LOCK 0x39 // CAPS
  81. #define HID_KEY_F1 0x3A
  82. #define HID_KEY_F2 0x3B
  83. #define HID_KEY_F3 0x3C
  84. #define HID_KEY_F4 0x3D
  85. #define HID_KEY_F5 0x3E
  86. #define HID_KEY_F6 0x3F
  87. #define HID_KEY_F7 0x40
  88. #define HID_KEY_F8 0x41
  89. #define HID_KEY_F9 0x42
  90. #define HID_KEY_F10 0x43
  91. #define HID_KEY_F11 0x44
  92. #define HID_KEY_F12 0x45
  93. #define HID_KEY_PRT_SCR 0x46
  94. #define HID_KEY_SCOLL_LOCK 0x47
  95. #define HID_KEY_PAUSE 0x48
  96. #define HID_KEY_INS 0x49
  97. #define HID_KEY_HOME 0x4A
  98. #define HID_KEY_PAGEUP 0x4B
  99. #define HID_KEY_DEL 0x4C
  100. #define HID_KEY_END 0x4D
  101. #define HID_KEY_PAGEDOWN 0x4E
  102. #define HID_KEY_RIGHT_ARROW 0x4F
  103. #define HID_KEY_LEFT_ARROW 0x50
  104. #define HID_KEY_DOWN_ARROW 0x51
  105. #define HID_KEY_UP_ARROW 0x52
  106. //Num Pad
  107. #define HID_KEY_PAD_NUMLOCK 0x53
  108. #define HID_KEY_PAD_DIV 0x54
  109. #define HID_KEY_PAD_MUL 0x55
  110. #define HID_KEY_PAD_SUB 0x56
  111. #define HID_KEY_PAD_ADD 0x57
  112. #define HID_KEY_PAD_ENTER 0x58
  113. #define HID_KEY_PAD_1 0x59
  114. #define HID_KEY_PAD_2 0x5A
  115. #define HID_KEY_PAD_3 0x5B
  116. #define HID_KEY_PAD_4 0x5C
  117. #define HID_KEY_PAD_5 0x5D
  118. #define HID_KEY_PAD_6 0x5E
  119. #define HID_KEY_PAD_7 0x5F
  120. #define HID_KEY_PAD_8 0x60
  121. #define HID_KEY_PAD_9 0x61
  122. #define HID_KEY_PAD_0 0x62
  123. #define HID_KEY_PAD_DOT 0x63
  124. #define HID_KEY_PRESSED 0x00
  125. #define HID_KEY_RELEASED 0x01
  126. // Control
  127. #define HID_KEY_LCTRL 0xE0 // left ctrl // #define HID_KEY_LCTRL 0x01
  128. #define HID_KEY_LALT 0xE2 // left Alt // #define HID_KEY_LALT 0x04
  129. #define HID_KEY_LSHFIT 0xE1 // left Shift // #define HID_KEY_LSHFIT 0x02
  130. #define HID_KEY_LWIN 0xE3 // left windows // #define HID_KEY_LWIN 0x08
  131. #define HID_KEY_RWIN 0xE7 // right windows // #define HID_KEY_RWIN 0x80
  132. #define HID_KEY_RSHIFT 0xE5 // right Shift // #define HID_KEY_RSHIFT 0x20
  133. #define HID_KEY_RALT 0xE6 // right Alt // #define HID_KEY_RALT 0x40
  134. #define HID_KEY_RCTRL 0xE4 // right Ctrl // #define HID_KEY_RCTRL 0x10
  135. #define HID_KEY_APP 0x65 // Application // #define HID_KEY_APP 0x65
  136. #define HID_KEY_K14 0x89 // international key
  137. #define HID_KEY_KR_L 0x91
  138. #define HID_KEY_K107 0x85
  139. #define HID_KEY_K45 0x64
  140. #define HID_KEY_K42 0x32
  141. #define HID_KEY_K131 0x8b
  142. #define HID_KEY_K132 0x8a
  143. #define HID_KEY_K133 0x88
  144. #define HID_KEY_K56 0x87
  145. #define HID_KEY_KR_R 0x90
  146. #define USB_HID_DESC_LEN 9U
  147. #define USB_HID_DESCRIPTOR_TYPE 0x21U
  148. #define USB_HID_REPORT_DESC 0x22U
  149. #define USB_HID_PHYSICAL_DESC 0x23U
  150. #define USB_HID_REQ_SET_PROTOCOL 0x0BU
  151. #define USB_HID_REQ_GET_PROTOCOL 0x03U
  152. #define USB_HID_REQ_SET_IDLE 0x0AU
  153. #define USB_HID_REQ_GET_IDLE 0x02U
  154. #define USB_HID_REQ_SET_REPORT 0x09U
  155. #define USB_HID_REQ_GET_REPORT 0x01U
  156. enum
  157. {
  158. USB_HID_NOT_READY,
  159. USB_HID_READY,
  160. USB_HID_SEND_DONE,
  161. };
  162. typedef struct
  163. {
  164. uint8_t Value;
  165. uint8_t Shift;
  166. }USB_HIDKeyValue;
  167. typedef struct {
  168. uint8_t bLength;
  169. uint8_t bDescriptorType;
  170. uint8_t bcdHID[2];
  171. uint8_t bCountryCode;
  172. uint8_t bNumDescriptors;
  173. uint8_t bReportDescriptorType;
  174. uint8_t wDescriptorLength[2];
  175. }usb_hid_descriptor_t;
  176. typedef struct
  177. {
  178. union
  179. {
  180. uint8_t SpecialKey;
  181. struct
  182. {
  183. uint8_t LeftControl:1;
  184. uint8_t LeftShift :1;
  185. uint8_t LeftAlt:1;
  186. uint8_t LeftGUI:1;
  187. uint8_t RightControl:1;
  188. uint8_t RightShift :1;
  189. uint8_t RightAlt :1;
  190. uint8_t RightGUI :1;
  191. }SPECIALHID_KEY_b;
  192. };
  193. uint8_t bZero;
  194. uint8_t PressKey[6];
  195. }USB_HIDKeyBoradKeyStruct;
  196. typedef struct
  197. {
  198. union
  199. {
  200. uint8_t Led;
  201. struct
  202. {
  203. uint8_t NumsLock:1;
  204. uint8_t CapsLock:1;
  205. uint8_t l2:1;
  206. uint8_t l3:1;
  207. uint8_t Kana:1;
  208. uint8_t zero :3;
  209. }SPECIALHID_KEY_b;
  210. };
  211. }USB_HIDKeyBoradLedStruct;
  212. USB_HIDKeyValue USB_HIDGetValueFromAscii(uint8_t ascii);
  213. #endif