hiddev.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /**
  2. * @file
  3. * @author chipsea
  4. * @brief
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. #ifndef HIDDEV_H
  11. #define HIDDEV_H
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif
  16. /*********************************************************************
  17. * INCLUDES
  18. */
  19. /*********************************************************************
  20. * MACROS
  21. */
  22. /*********************************************************************
  23. * CONSTANTS
  24. */
  25. // HID Device Parameters
  26. #define HIDDEV_ERASE_ALLBONDS 0 // Erase all of the bonded devices. Write Only. No Size.
  27. // HID read/write operation
  28. #define HID_DEV_OPER_WRITE 0 // Write operation
  29. #define HID_DEV_OPER_READ 1 // Read operation
  30. #define HID_DEV_OPER_ENABLE 2 // Notification enabled for report ID
  31. #define HID_DEV_OPER_DISABLE 3 // Notifications disabled for report ID
  32. // HID callback events
  33. #define HID_DEV_SUSPEND_EVT 0 // HID suspend
  34. #define HID_DEV_EXIT_SUSPEND_EVT 1 // HID exit suspend
  35. #define HID_DEV_SET_BOOT_EVT 2 // HID set boot mode
  36. #define HID_DEV_SET_REPORT_EVT 3 // HID set report mode
  37. /* HID Report type */
  38. #define HID_REPORT_TYPE_INPUT 1
  39. #define HID_REPORT_TYPE_OUTPUT 2
  40. #define HID_REPORT_TYPE_FEATURE 3
  41. /* HID information flags */
  42. #define HID_FLAGS_REMOTE_WAKE 0x01 // RemoteWake
  43. #define HID_FLAGS_NORMALLY_CONNECTABLE 0x02 // NormallyConnectable
  44. /* Control point commands */
  45. #define HID_CMD_SUSPEND 0x00 // Suspend
  46. #define HID_CMD_EXIT_SUSPEND 0x01 // Exit Suspend
  47. /* HID protocol mode values */
  48. #define HID_PROTOCOL_MODE_BOOT 0x00 // Boot Protocol Mode
  49. #define HID_PROTOCOL_MODE_REPORT 0x01 // Report Protocol Mode
  50. /* Attribute value lengths */
  51. #define HID_PROTOCOL_MODE_LEN 1 // HID Protocol Mode
  52. #define HID_INFORMATION_LEN 4 // HID Information
  53. #define HID_REPORT_REF_LEN 2 // HID Report Reference Descriptor
  54. #define HID_EXT_REPORT_REF_LEN 2 // External Report Reference Descriptor
  55. // HID Keyboard/Keypad Usage IDs (subset of the codes available in the USB HID Usage Tables spec)
  56. #define HID_KEYBOARD_RESERVED 0 // 0x00 - No event inidicated
  57. #define HID_KEYBOARD_A 4 // 0x04 - Keyboard a and A
  58. #define HID_KEYBOARD_B 5 // 0x05 - Keyboard b and B
  59. #define HID_KEYBOARD_C 6 // 0x06 - Keyboard c and C
  60. #define HID_KEYBOARD_D 7 // 0x07 - Keyboard d and D
  61. #define HID_KEYBOARD_E 8 // 0x08 - Keyboard e and E
  62. #define HID_KEYBOARD_F 9 // 0x09 - Keyboard f and F
  63. #define HID_KEYBOARD_G 10 // 0x0A - Keyboard g and G
  64. #define HID_KEYBOARD_H 11 // 0x0B - Keyboard h and H
  65. #define HID_KEYBOARD_I 12 // 0x0C - Keyboard i and I
  66. #define HID_KEYBOARD_J 13 // 0x0D - Keyboard j and J
  67. #define HID_KEYBOARD_K 14 // 0x0E - Keyboard k and K
  68. #define HID_KEYBOARD_L 15 // 0x0F - Keyboard l and L
  69. #define HID_KEYBOARD_M 16 // 0x10 - Keyboard m and M
  70. #define HID_KEYBOARD_N 17 // 0x11 - Keyboard n and N
  71. #define HID_KEYBOARD_O 18 // 0x12 - Keyboard o and O
  72. #define HID_KEYBOARD_P 19 // 0x13 - Keyboard p and p
  73. #define HID_KEYBOARD_Q 20 // 0x14 - Keyboard q and Q
  74. #define HID_KEYBOARD_R 21 // 0x15 - Keyboard r and R
  75. #define HID_KEYBOARD_S 22 // 0x16 - Keyboard s and S
  76. #define HID_KEYBOARD_T 23 // 0x17 - Keyboard t and T
  77. #define HID_KEYBOARD_U 24 // 0x18 - Keyboard u and U
  78. #define HID_KEYBOARD_V 25 // 0x19 - Keyboard v and V
  79. #define HID_KEYBOARD_W 26 // 0x1A - Keyboard w and W
  80. #define HID_KEYBOARD_X 27 // 0x1B - Keyboard x and X
  81. #define HID_KEYBOARD_Y 28 // 0x1C - Keyboard y and Y
  82. #define HID_KEYBOARD_Z 29 // 0x1D - Keyboard z and Z
  83. #define HID_KEYBOARD_1 30 // 0x1E - Keyboard 1 and !
  84. #define HID_KEYBOARD_2 31 // 0x1F - Keyboard 2 and @
  85. #define HID_KEYBOARD_3 32 // 0x20 - Keyboard 3 and #
  86. #define HID_KEYBOARD_4 33 // 0x21 - Keyboard 4 and %
  87. #define HID_KEYBOARD_5 34 // 0x22 - Keyboard 5 and %
  88. #define HID_KEYBOARD_6 35 // 0x23 - Keyboard 6 and ^
  89. #define HID_KEYBOARD_7 36 // 0x24 - Keyboard 7 and &
  90. #define HID_KEYBOARD_8 37 // 0x25 - Keyboard 8 and *
  91. #define HID_KEYBOARD_9 38 // 0x26 - Keyboard 9 and (
  92. #define HID_KEYBOARD_0 39 // 0x27 - Keyboard 0 and )
  93. #define HID_KEYBOARD_RETURN 40 // 0x28 - Keyboard Return (ENTER)
  94. #define HID_KEYBOARD_ESCAPE 41 // 0x29 - Keyboard ESCAPE
  95. #define HID_KEYBOARD_DELETE 42 // 0x2A - Keyboard DELETE (Backspace)
  96. #define HID_KEYBOARD_TAB 43 // 0x2B - Keyboard Tab
  97. #define HID_KEYBOARD_SPACEBAR 44 // 0x2C - Keyboard Spacebar
  98. #define HID_KEYBOARD_MINUS 45 // 0x2D - Keyboard - and (underscore)
  99. #define HID_KEYBOARD_EQUAL 46 // 0x2E - Keyboard = and +
  100. #define HID_KEYBOARD_LEFT_BRKT 47 // 0x2F - Keyboard [ and {
  101. #define HID_KEYBOARD_RIGHT_BRKT 48 // 0x30 - Keyboard ] and }
  102. #define HID_KEYBOARD_BACK_SLASH 49 // 0x31 - Keyboard \ and |
  103. #define HID_KEYBOARD_SEMI_COLON 51 // 0x33 - Keyboard ; and :
  104. #define HID_KEYBOARD_SGL_QUOTE 52 // 0x34 - Keyboard ' and "
  105. #define HID_KEYBOARD_GRV_ACCENT 53 // 0x35 - Keyboard Grave Accent and Tilde
  106. #define HID_KEYBOARD_COMMA 54 // 0x36 - Keyboard , and <
  107. #define HID_KEYBOARD_DOT 55 // 0x37 - Keyboard . and >
  108. #define HID_KEYBOARD_FWD_SLASH 56 // 0x38 - Keyboard / and ?
  109. #define HID_KEYBOARD_CAPS_LOCK 57 // 0x39 - Keyboard Caps Lock
  110. #define HID_KEYBOARD_F1 58 // 0x3A - Keyboard F1
  111. #define HID_KEYBOARD_F2 59 // 0x3B - Keyboard F2
  112. #define HID_KEYBOARD_F3 60 // 0x3C - Keyboard F3
  113. #define HID_KEYBOARD_F4 61 // 0x3D - Keyboard F4
  114. #define HID_KEYBOARD_F5 62 // 0x3E - Keyboard F5
  115. #define HID_KEYBOARD_F6 63 // 0x3F - Keyboard F6
  116. #define HID_KEYBOARD_F7 64 // 0x40 - Keyboard F7
  117. #define HID_KEYBOARD_F8 65 // 0x41 - Keyboard F8
  118. #define HID_KEYBOARD_F9 66 // 0x42 - Keyboard F9
  119. #define HID_KEYBOARD_F10 67 // 0x43 - Keyboard F10
  120. #define HID_KEYBOARD_F11 68 // 0x44 - Keyboard F11
  121. #define HID_KEYBOARD_F12 69 // 0x45 - Keyboard F12
  122. #define HID_KEYBOARD_PRNT_SCREEN 70 // 0x46 - Keyboard Print Screen
  123. #define HID_KEYBOARD_SCROLL_LOCK 71 // 0x47 - Keyboard Scroll Lock
  124. #define HID_KEYBOARD_PAUSE 72 // 0x48 - Keyboard Pause
  125. #define HID_KEYBOARD_INSERT 73 // 0x49 - Keyboard Insert
  126. #define HID_KEYBOARD_HOME 74 // 0x4A - Keyboard Home
  127. #define HID_KEYBOARD_PAGE_UP 75 // 0x4B - Keyboard PageUp
  128. #define HID_KEYBOARD_DELETE_FWD 76 // 0x4C - Keyboard Delete Forward
  129. #define HID_KEYBOARD_END 77 // 0x4D - Keyboard End
  130. #define HID_KEYBOARD_PAGE_DOWN 78 // 0x4E - Keyboard PageDown
  131. #define HID_KEYBOARD_RIGHT_ARROW 79 // 0x4F - Keyboard RightArrow
  132. #define HID_KEYBOARD_LEFT_ARROW 80 // 0x50 - Keyboard LeftArrow
  133. #define HID_KEYBOARD_DOWN_ARROW 81 // 0x51 - Keyboard DownArrow
  134. #define HID_KEYBOARD_UP_ARROW 82 // 0x52 - Keyboard UpArrow
  135. #define HID_KEYBPAD_NUM_LOCK 83 // 0x53 - Keypad Num Lock and Clear
  136. #define HID_KEYBPAD_DIVIDE 84 // 0x54 - Keypad /
  137. #define HID_KEYBOARD_MULTIPLY 85 // 0x55 - Keypad *
  138. #define HID_KEYBOARD_SUBTRACT 86 // 0x56 - Keypad -
  139. #define HID_KEYBPAD_ADD 87 // 0x57 - Keypad +
  140. #define HID_KEYBPAD_ENTER 88 // 0x58 - Keypad ENTER
  141. #define HID_KEYBPAD_1 89 // 0x59 - Keypad 1 and End
  142. #define HID_KEYBPAD_2 90 // 0x5A - Keypad 2 and Down Arrow
  143. #define HID_KEYBPAD_3 91 // 0x5B - Keypad 3 and PageDn
  144. #define HID_KEYBPAD_4 92 // 0x5C - Keypad 4 and Lfet Arrow
  145. #define HID_KEYBPAD_5 93 // 0x5D - Keypad 5
  146. #define HID_KEYBPAD_6 94 // 0x5E - Keypad 6 and Right Arrow
  147. #define HID_KEYBPAD_7 95 // 0x5F - Keypad 7 and Home
  148. #define HID_KEYBPAD_8 96 // 0x60 - Keypad 8 and Up Arrow
  149. #define HID_KEYBPAD_9 97 // 0x61 - Keypad 9 and PageUp
  150. #define HID_KEYBPAD_0 98 // 0x62 - Keypad 0 and Insert
  151. #define HID_KEYBPAD_DOT 99 // 0x63 - Keypad . and Delete
  152. #define HID_KEYBOARD_MUTE 127 // 0x7F - Keyboard Mute
  153. #define HID_KEYBOARD_VOLUME_UP 128 // 0x80 - Keyboard Volume up
  154. #define HID_KEYBOARD_VOLUME_DOWN 129 // 0x81 - Keyboard Volume down
  155. #define HID_KEYBOARD_LEFT_CTRL 224 // 0xE0 - Keyboard LeftContorl
  156. #define HID_KEYBOARD_LEFT_SHIFT 225 // 0xE1 - Keyboard LeftShift
  157. #define HID_KEYBOARD_LEFT_ALT 226 // 0xE2 - Keyboard LeftAlt
  158. #define HID_KEYBOARD_LEFT_GUI 227 // 0xE3 - Keyboard LeftGUI
  159. #define HID_KEYBOARD_RIGHT_CTRL 228 // 0xE4 - Keyboard LeftContorl
  160. #define HID_KEYBOARD_RIGHT_SHIFT 229 // 0xE5 - Keyboard LeftShift
  161. #define HID_KEYBOARD_RIGHT_ALT 230 // 0xE6 - Keyboard LeftAlt
  162. #define HID_KEYBOARD_RIGHT_GUI 231 // 0xE7 - Keyboard RightGUI
  163. #define HID_MOUSE_BUTTON_LEFT 253
  164. #define HID_MOUSE_BUTTON_MIDDLE 254
  165. #define HID_MOUSE_BUTTON_RIGHT 255
  166. // HID Consumer Usage IDs (subset of the codes available in the USB HID Usage Tables spec)
  167. #define HID_CONSUMER_POWER 48 // 0x30 - Power
  168. #define HID_CONSUMER_RESET 49 // 0x31 - Reset
  169. #define HID_CONSUMER_SLEEP 50 // 0x32 - Sleep
  170. #define HID_CONSUMER_MENU 64 // 0x40 - Menu
  171. #define HID_CONSUMER_SELECTION 128 // 0x80 - Selection
  172. #define HID_CONSUMER_ASSIGN_SEL 129 // 0x81 - Assign Selection
  173. #define HID_CONSUMER_MODE_STEP 130 // 0x82 - Mode Step
  174. #define HID_CONSUMER_RECALL_LAST 131 // 0x83 - Recall Last
  175. #define HID_CONSUMER_QUIT 148 // 0x94 - Quit
  176. #define HID_CONSUMER_HELP 149 // 0x95 - Help
  177. #define HID_CONSUMER_CHANNEL_UP 156 // 0x9C - Channel Increment
  178. #define HID_CONSUMER_CHANNEL_DOWN 157 // 0x9D - Channel Decrement
  179. #define HID_CONSUMER_PLAY 176 // 0xB0 - Play
  180. #define HID_CONSUMER_PAUSE 177 // 0xB1 - Pause
  181. #define HID_CONSUMER_RECORD 178 // 0xB2 - Record
  182. #define HID_CONSUMER_FAST_FORWARD 179 // 0xB3 - Fast Forward
  183. #define HID_CONSUMER_REWIND 180 // 0xB4 - Rewind
  184. #define HID_CONSUMER_SCAN_NEXT_TRK 181 // 0xB5 - Scan Next Track
  185. #define HID_CONSUMER_SCAN_PREV_TRK 182 // 0xB6 - Scan Previous Track
  186. #define HID_CONSUMER_STOP 183 // 0xB7 - Stop
  187. #define HID_CONSUMER_EJECT 184 // 0xB8 - Eject
  188. #define HID_CONSUMER_RANDOM_PLAY 185 // 0xB9 - Random Play
  189. #define HID_CONSUMER_SELECT_DISC 186 // 0xBA - Select Disk
  190. #define HID_CONSUMER_ENTER_DISC 187 // 0xBB - Enter Disc
  191. #define HID_CONSUMER_REPEAT 188 // 0xBC - Repeat
  192. #define HID_CONSUMER_STOP_EJECT 204 // 0xCC - Stop/Eject
  193. #define HID_CONSUMER_PLAY_PAUSE 205 // 0xCD - Play/Pause
  194. #define HID_CONSUMER_PLAY_SKIP 206 // 0xCE - Play/Skip
  195. #define HID_CONSUMER_VOLUME 224 // 0xE0 - Volume
  196. #define HID_CONSUMER_BALANCE 225 // 0xE1 - Balance
  197. #define HID_CONSUMER_MUTE 226 // 0xE2 - Mute
  198. #define HID_CONSUMER_BASS 227 // 0xE3 - Bass
  199. #define HID_CONSUMER_VOLUME_UP 233 // 0xE9 - Volume Increment
  200. #define HID_CONSUMER_VOLUME_DOWN 234 // 0xEA - Volume Decrement
  201. /**********my define android HID keys value*****/
  202. #define HID_ANDROID_CONSUMER_MENU 101//0x65 - adnroid menu
  203. #define HID_USER_DEFINE_CH_UP 54//0x36 - user define ch+
  204. #define HID_USER_DEFINE_CH_DOWN 55//0x37 - user define ch-
  205. /*********************************************************************
  206. * TYPEDEFS
  207. */
  208. // HID report mapping table
  209. typedef struct
  210. {
  211. uint16 handle; // Handle of report characteristic
  212. uint16 cccdHandle; // Handle of CCCD for report characteristic
  213. uint8 id; // Report ID
  214. uint8 type; // Report type
  215. uint8 mode; // Protocol mode (report or boot)
  216. } hidRptMap_t;
  217. // HID dev configuration structure
  218. typedef struct
  219. {
  220. uint32 idleTimeout; // Idle timeout in milliseconds
  221. uint8 hidFlags; // HID feature flags
  222. } hidDevCfg_t;
  223. /*********************************************************************
  224. * Global Variables
  225. */
  226. // These variables are defined in the service .c file that uses HID Dev
  227. // HID report map length
  228. extern uint16 hidReportMapLen;
  229. // HID protocol mode
  230. extern uint8 hidProtocolMode;
  231. //extern uint16 gapConnHandle;
  232. /*********************************************************************
  233. * Profile Callbacks
  234. */
  235. // HID Report callback
  236. typedef uint8 (*hidDevReportCB_t)( uint8 id, uint8 type, uint16 uuid,
  237. uint8 oper, uint16 *pLen, uint8 *pData );
  238. // HID event callback
  239. typedef void (*hidDevEvtCB_t)( uint8 evt );
  240. // HID passcode callback
  241. typedef void (*hidDevPasscodeCB_t)( uint8 *deviceAddr, uint16 connectionHandle,
  242. uint8 uiInputs, uint8 uiOutputs );
  243. typedef struct
  244. {
  245. hidDevReportCB_t reportCB;
  246. hidDevEvtCB_t evtCB;
  247. hidDevPasscodeCB_t passcodeCB;
  248. } hidDevCB_t;
  249. extern void hidDevGapStateCB( gaprole_States_t newState );
  250. extern void hidDevPairStateCB( uint16 connHandle, uint8 state, uint8 status );
  251. extern void hidDevPasscodeCB( uint8 *deviceAddr, uint16 connectionHandle,
  252. uint8 uiInputs, uint8 uiOutputs );
  253. extern void HidDev_Init( uint8 task_id );
  254. extern uint16 HidDev_ProcessEvent( uint8 task_id, uint16 events );
  255. extern void HidDev_Register( hidDevCfg_t *pCfg, hidDevCB_t *pCBs );
  256. extern void HidDev_RegisterReports( uint8 numReports, hidRptMap_t *pRpt );
  257. extern void HidDev_Report( uint8 id, uint8 type, uint8 len, uint8 *pData );
  258. extern void HidDev_Close( void );
  259. extern bStatus_t HidDev_SetParameter( uint8 param, uint8 len, void *pValue );
  260. extern bStatus_t HidDev_GetParameter( uint8 param, void *pValue );
  261. extern void HidDev_PasscodeRsp( uint8 status, uint32 passcode );
  262. extern bStatus_t HidDev_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
  263. uint8 *pValue, uint16 *pLen, uint16 offset,
  264. uint8 maxLen);
  265. extern bStatus_t HidDev_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
  266. uint8 *pValue, uint16 len, uint16 offset);
  267. /*********************************************************************
  268. *********************************************************************/
  269. #ifdef __cplusplus
  270. }
  271. #endif
  272. #endif /* HIDDEV_H */