hidkbdservice.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 HIDKBDSERVICE_H
  11. #define HIDKBDSERVICE_H
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif
  16. /*********************************************************************
  17. * INCLUDES
  18. */
  19. /*********************************************************************
  20. * CONSTANTS
  21. */
  22. #define FOLLOW_TI_MAP 1
  23. #if FOLLOW_TI_MAP
  24. // Number of HID reports defined in the service
  25. #define HID_NUM_REPORTS 5//7
  26. // HID Report IDs for the service
  27. #define HID_RPT_ID_LED_OUT 0 // LED output report ID
  28. #define HID_RPT_ID_KEY_IN 1 // Keyboard input report ID
  29. #define HID_RPT_ID_CC_IN 2 // Consumer Control input report ID
  30. #define HID_RPT_ID_VOICE_START_IN 10 // Voice Start input report ID
  31. #define HID_RPT_ID_VOICE_DATA_IN 11 // Voice Data input report ID
  32. //voice defines
  33. #define BLE_VOICE_CMD_STOP 0x00
  34. #define BLE_VOICE_CMD_START 0x04
  35. #define HID_VOICE_IN_START_LEN 5
  36. #define HID_RPT_ID_MOUSE_IN 0xFF
  37. enum
  38. {
  39. HID_SERVICE_IDX, // HID Service
  40. HID_INCLUDED_SERVICE_IDX, // Included Service (battery)
  41. HID_INFO_DECL_IDX, // HID Information characteristic declaration
  42. HID_INFO_IDX, // HID Information characteristic
  43. HID_CONTROL_POINT_DECL_IDX, // HID Control Point characteristic declaration
  44. HID_CONTROL_POINT_IDX, // HID Control Point characteristic
  45. HID_PROTOCOL_MODE_DECL_IDX, // HID Protocol Mode characteristic declaration
  46. HID_PROTOCOL_MODE_IDX, // HID Protocol Mode characteristic
  47. HID_REPORT_MAP_DECL_IDX, // HID Report Map characteristic declaration
  48. HID_REPORT_MAP_IDX, // HID Report Map characteristic
  49. HID_EXT_REPORT_REF_DESC_IDX, // HID External Report Reference Descriptor
  50. HID_REPORT_KEY_IN_DECL_IDX, // HID Report characteristic declaration, key input
  51. HID_REPORT_KEY_IN_IDX, // HID Report characteristic, key input
  52. HID_REPORT_KEY_IN_CCCD_IDX, // HID Report characteristic client characteristic configuration, key input
  53. HID_REPORT_REF_KEY_IN_IDX, // HID Report Reference characteristic descriptor, key input
  54. HID_REPORT_LED_OUT_DECL_IDX, // HID Report characteristic, LED output declaration
  55. HID_REPORT_LED_OUT_IDX, // HID Report characteristic, LED output
  56. HID_REPORT_REF_LED_OUT_IDX, // HID Report Reference characteristic descriptor, LED output
  57. HID_BOOT_KEY_IN_DECL_IDX, // HID Boot Keyboard Input Report declaration
  58. HID_BOOT_KEY_IN_IDX, // HID Boot Keyboard Input Report
  59. HID_BOOT_KEY_IN_CCCD_IDX, // HID Boot Keyboard Input Report characteristic client characteristic configuration
  60. HID_BOOT_KEY_OUT_DECL_IDX, // HID Boot Keyboard Output Report declaration
  61. HID_BOOT_KEY_OUT_IDX, // HID Boot Keyboard Output Report
  62. HID_REPORT_CC_IN_DECL_IDX, // HID Report characteristic declaration, consumer control
  63. HID_REPORT_CC_IN_IDX, // HID Report characteristic, consumer control
  64. HID_REPORT_CC_IN_CCCD_IDX, // HID Report characteristic client characteristic configuration, consumer control
  65. HID_REPORT_REF_CC_IN_IDX, // HID Report Reference characteristic descriptor, consumer control
  66. HID_VOICE_START_IN_DECL_IDX, // HID Voice Start Input Report declaration
  67. HID_VOICE_START_IN_IDX, // HID Voice Start Input Report
  68. HID_VOICE_START_IN_CCCD_IDX, // HID Voice Start Input Report characteristic client characteristic configuration
  69. HID_REPORT_REF_VOICE_START_IDX, // HID Report Reference characteristic descriptor, Voice Start
  70. HID_VOICE_DATA_IN_DECL_IDX, // HID Voice Start Input Report declaration
  71. HID_VOICE_DATA_IN_IDX, // HID Voice Start Input Report
  72. HID_VOICE_DATA_IN_CCCD_IDX, // HID Voice Start Input Report characteristic client characteristic configuration
  73. HID_REPORT_REF_VOICE_DATA_IDX, // HID Report Reference characteristic descriptor, Voice Start
  74. };
  75. #else
  76. // HID Report IDs for the service
  77. #define HID_RPT_ID_MOUSE_IN 1 // Mouse input report ID
  78. #define HID_RPT_ID_KEY_IN 2 // Keyboard input report ID
  79. #define HID_RPT_ID_CC_IN 3
  80. #define HID_RPT_ID_LED_OUT 0 // LED output report ID
  81. #define HID_RPT_ID_FEATURE 0 // Feature report ID
  82. #define EN_VOICE_MODE 1
  83. #define EN_CONSUMER_MODE 1
  84. #define EN_MOUSE_REPORT 1
  85. #if EN_VOICE_MODE
  86. #define HID_RPT_ID_VOICE_START_IN 10 // Voice Start input report ID
  87. #define HID_RPT_ID_VOICE_DATA_IN 11 // Voice Data input report ID
  88. // Number of HID reports defined in the service
  89. #define HID_NUM_REPORTS 11
  90. //voice defines
  91. #define BLE_VOICE_CMD_STOP 0x00
  92. #define BLE_VOICE_CMD_START 0x04
  93. #else
  94. // Number of HID reports defined in the service
  95. #define HID_NUM_REPORTS 7
  96. #endif
  97. // Attribute index enumeration-- these indexes match array elements above
  98. enum
  99. {
  100. HID_SERVICE_IDX, // HID Service
  101. HID_INCLUDED_SERVICE_IDX, // Included Service
  102. HID_INFO_DECL_IDX, // HID Information characteristic declaration
  103. HID_INFO_IDX, // HID Information characteristic
  104. HID_CONTROL_POINT_DECL_IDX, // HID Control Point characteristic declaration
  105. HID_CONTROL_POINT_IDX, // HID Control Point characteristic
  106. HID_PROTOCOL_MODE_DECL_IDX, // HID Protocol Mode characteristic declaration
  107. HID_PROTOCOL_MODE_IDX, // HID Protocol Mode characteristic
  108. HID_REPORT_MAP_DECL_IDX, // HID Report Map characteristic declaration
  109. HID_REPORT_MAP_IDX, // HID Report Map characteristic
  110. HID_EXT_REPORT_REF_DESC_IDX, // HID External Report Reference Descriptor
  111. #if EN_MOUSE_REPORT
  112. HID_REPORT_MOUSE_IN_DECL_IDX, // HID Report characteristic, mouse input declaration
  113. HID_REPORT_MOUSE_IN_IDX, // HID Report characteristic, mouse input
  114. HID_REPORT_MOUSE_IN_CCCD_IDX, // HID Report characteristic client characteristic configuration
  115. HID_REPORT_REF_MOUSE_IN_IDX, // HID Report Reference characteristic descriptor, mouse input
  116. #endif
  117. HID_REPORT_KEY_IN_DECL_IDX, // HID Report characteristic, key input declaration
  118. HID_REPORT_KEY_IN_IDX, // HID Report characteristic, key input
  119. HID_REPORT_KEY_IN_CCCD_IDX, // HID Report characteristic client characteristic configuration
  120. HID_REPORT_REF_KEY_IN_IDX, // HID Report Reference characteristic descriptor, key input
  121. HID_REPORT_LED_OUT_DECL_IDX, // HID Report characteristic, LED output declaration
  122. HID_REPORT_LED_OUT_IDX, // HID Report characteristic, LED output
  123. HID_REPORT_REF_LED_OUT_IDX, // HID Report Reference characteristic descriptor, LED output
  124. HID_BOOT_KEY_IN_DECL_IDX, // HID Boot Keyboard Input Report declaration
  125. HID_BOOT_KEY_IN_IDX, // HID Boot Keyboard Input Report
  126. HID_BOOT_KEY_IN_CCCD_IDX, // HID Boot Keyboard Input Report characteristic client characteristic configuration
  127. HID_BOOT_KEY_OUT_DECL_IDX, // HID Boot Keyboard Output Report declaration
  128. HID_BOOT_KEY_OUT_IDX, // HID Boot Keyboard Output Report
  129. #if EN_CONSUMER_MODE
  130. HID_REPORT_CC_IN_DECL_IDX, // HID Report characteristic declaration, consumer control
  131. HID_REPORT_CC_IN_IDX, // HID Report characteristic, consumer control
  132. HID_REPORT_CC_IN_CCCD_IDX, // HID Report characteristic client characteristic configuration, consumer control
  133. HID_REPORT_REF_CC_IN_IDX, // HID Report Reference characteristic descriptor, consumer control
  134. #endif
  135. HID_BOOT_MOUSE_IN_DECL_IDX, // HID Boot Mouse Input Report declaration
  136. HID_BOOT_MOUSE_IN_IDX, // HID Boot Mouse Input Report
  137. HID_BOOT_MOUSE_IN_CCCD_IDX, // HID Boot Mouse Input Report characteristic client characteristic configuration
  138. HID_FEATURE_DECL_IDX, // Feature Report declaration
  139. HID_FEATURE_IDX, // Feature Report
  140. HID_REPORT_REF_FEATURE_IDX // HID Report Reference characteristic descriptor, feature
  141. #if EN_VOICE_MODE
  142. ,
  143. HID_VOICE_START_IN_DECL_IDX, // HID Voice Start Input Report declaration
  144. HID_VOICE_START_IN_IDX, // HID Voice Start Input Report
  145. HID_VOICE_START_IN_CCCD_IDX, // HID Voice Start Input Report characteristic client characteristic configuration
  146. HID_REPORT_REF_VOICE_START_IDX, // HID Report Reference characteristic descriptor, Voice Start
  147. HID_VOICE_DATA_IN_DECL_IDX, // HID Voice Start Input Report declaration
  148. HID_VOICE_DATA_IN_IDX, // HID Voice Start Input Report
  149. HID_VOICE_DATA_IN_CCCD_IDX, // HID Voice Start Input Report characteristic client characteristic configuration
  150. HID_REPORT_REF_VOICE_DATA_IDX, // HID Report Reference characteristic descriptor, Voice Start
  151. #endif
  152. };
  153. #endif
  154. // HID feature flags
  155. #define HID_KBD_FLAGS HID_FLAGS_REMOTE_WAKE
  156. /*********************************************************************
  157. * TYPEDEFS
  158. */
  159. /*********************************************************************
  160. * MACROS
  161. */
  162. /*********************************************************************
  163. * Profile Callbacks
  164. */
  165. /*********************************************************************
  166. * API FUNCTIONS
  167. */
  168. /*********************************************************************
  169. * @fn HidKbd_AddService
  170. *
  171. * @brief Initializes the HID service for keyboard by registering
  172. * GATT attributes with the GATT server.
  173. *
  174. * @param none
  175. *
  176. * @return Success or Failure
  177. */
  178. extern bStatus_t HidKbd_AddService(void);
  179. /*********************************************************************
  180. * @fn HidKbd_SetParameter
  181. *
  182. * @brief Set a HID Kbd parameter.
  183. *
  184. * @param id - HID report ID.
  185. * @param type - HID report type.
  186. * @param uuid - attribute uuid.
  187. * @param len - length of data to right.
  188. * @param pValue - pointer to data to write. This is dependent on
  189. * the input parameters and WILL be cast to the appropriate
  190. * data type (example: data type of uint16 will be cast to
  191. * uint16 pointer).
  192. *
  193. * @return GATT status code.
  194. */
  195. extern uint8 HidKbd_SetParameter( uint8 id, uint8 type, uint16 uuid, uint16 len, void *pValue );
  196. /*********************************************************************
  197. * @fn HidKbd_GetParameter
  198. *
  199. * @brief Get a HID Kbd parameter.
  200. *
  201. * @param id - HID report ID.
  202. * @param type - HID report type.
  203. * @param uuid - attribute uuid.
  204. * @param pLen - length of data to be read.
  205. * @param pValue - pointer to data to get. This is dependent on
  206. * the input parameters and WILL be cast to the appropriate
  207. * data type (example: data type of uint16 will be cast to
  208. * uint16 pointer).
  209. *
  210. * @return GATT status code.
  211. */
  212. extern uint8 HidKbd_GetParameter( uint8 id, uint8 type, uint16 uuid, uint16 *pLen, void *pValue );
  213. /*********************************************************************
  214. *********************************************************************/
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif /* HIDKBDSERVICE_H */