app_usbd_hid.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /**
  2. * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef APP_USBD_HID_H__
  41. #define APP_USBD_HID_H__
  42. #include <stdint.h>
  43. #include <stdbool.h>
  44. #include "sdk_common.h"
  45. #include "nrf_atomic.h"
  46. #include "app_usbd_hid_types.h"
  47. #include "app_usbd.h"
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. /**
  52. * @defgroup app_usbd_hid USB HID class
  53. * @ingroup app_usbd
  54. *
  55. * @brief @tagAPI52840 Module with generic HID event data processing.
  56. * @{
  57. */
  58. #define APP_USBD_HID_IFACE_IDX 0 /**< @brief HID instance interface index. */
  59. #define APP_USBD_HID_EPIN_IDX 0 /**< @brief HID instance endpoint IN index. */
  60. #define APP_USBD_HID_EPOUT_IDX 1 /**< @brief HID instance endpoint OUT index.*/
  61. /**
  62. * @brief HID context state flags.
  63. *
  64. * Bit numbers in @ref app_usbd_hid_ctx_t::state_flags.
  65. */
  66. typedef enum {
  67. APP_USBD_HID_STATE_FLAG_APPENDED = 0, /**< State flag APPENDED. */
  68. APP_USBD_HID_STATE_FLAG_STARTED = 1, /**< State flag STARTED. */
  69. APP_USBD_HID_STATE_FLAG_SUSPENDED = 2, /**< State flag SUSPENDED. */
  70. APP_USBD_HID_STATE_FLAG_TRANS_IN_PROGRESS = 3, /**< State flag TRANS_IN_PROGRESS. */
  71. } app_usbd_hid_state_flag_t;
  72. /**
  73. * @brief Events passed to user event handler.
  74. *
  75. * @note Example prototype of user event handler:
  76. @code
  77. void hid_user_ev_handler(app_usbd_class_inst_t const * p_inst,
  78. app_usbd_hid_mouse_user_event_t event);
  79. @endcode
  80. */
  81. typedef enum {
  82. APP_USBD_HID_USER_EVT_SET_BOOT_PROTO, /**< Event SET_BOOT_PROTOCOL. */
  83. APP_USBD_HID_USER_EVT_SET_REPORT_PROTO, /**< Event SET_REPORT_PROTOCOL. */
  84. APP_USBD_HID_USER_EVT_OUT_REPORT_READY, /**< Event OUT_REPORT_READY. */
  85. APP_USBD_HID_USER_EVT_IN_REPORT_DONE, /**< Event IN_REPORT_DONE. */
  86. APP_USBD_HID_USER_EVT_FEATURE_REPORT_READY, /**< Event FEATURE_REPORT_READY. */
  87. } app_usbd_hid_user_event_t;
  88. /**
  89. * @brief User event handler.
  90. *
  91. * @param[in] p_inst Class instance.
  92. * @param[in] event User event.
  93. */
  94. typedef void (*app_usbd_hid_user_ev_handler_t)(app_usbd_class_inst_t const * p_inst,
  95. app_usbd_hid_user_event_t event);
  96. /**
  97. * @brief Idle report handler.
  98. *
  99. * @param[in] p_inst Class instance.
  100. * @param[in] report_id Number of report ID that needs idle transfer.
  101. */
  102. typedef ret_code_t (*app_usbd_hid_idle_handler_t)(app_usbd_class_inst_t const * p_inst,
  103. uint8_t report_id);
  104. /**
  105. * @brief HID unified interface
  106. * */
  107. typedef struct {
  108. /**
  109. * @brief Function called on HID specific, GetReport request.
  110. *
  111. * This function should trigger data write to control pipe.
  112. *
  113. * @param[in] p_inst Class instance.
  114. * @param[in] p_setup_ev Setup event.
  115. *
  116. * @return Standard error code.
  117. */
  118. ret_code_t (*on_get_report)(app_usbd_class_inst_t const * p_inst,
  119. app_usbd_setup_evt_t const * p_setup_ev);
  120. /**
  121. * @brief Function called on HID specific, SetReport request.
  122. *
  123. * This function should trigger data read from control pipe. This function is not required and
  124. * NULL could be pinned to this handler when output report is not defined in report descriptor.
  125. *
  126. * @param[in] p_inst Class instance.
  127. * @param[in] p_setup_ev Setup event.
  128. *
  129. * @return Standard error code.
  130. */
  131. ret_code_t (*on_set_report)(app_usbd_class_inst_t const * p_inst,
  132. app_usbd_setup_evt_t const * p_setup_ev);
  133. /**
  134. * @brief Function called on IN endpoint transfer.
  135. *
  136. * This function should trigger next endpoint IN transfer if required.
  137. *
  138. * @param[in] p_inst Class instance.
  139. *
  140. * @return Standard error code.
  141. */
  142. ret_code_t (*ep_transfer_in)(app_usbd_class_inst_t const * p_inst);
  143. /**
  144. * @brief Function called on OUT endpoint transfer.
  145. *
  146. * This function should should read data from OUT endpoint. This function is not required and
  147. * NULL could be pinned to this handler when class doesn't have OUT endpoint.
  148. *
  149. * @param[in] p_inst Class instance.
  150. *
  151. * @return Standard error code.
  152. */
  153. ret_code_t (*ep_transfer_out)(app_usbd_class_inst_t const * p_inst);
  154. /**
  155. * @brief Function returns subclass descriptor count.
  156. *
  157. * @param[in] p_inst Class instance.
  158. *
  159. * @return Count of descriptors
  160. */
  161. uint8_t (*subclass_count)(app_usbd_class_inst_t const * p_inst);
  162. /**
  163. * @brief Function returns subclass descriptor size.
  164. *
  165. * @param[in] p_inst Class instance.
  166. * @param[in] desc_num Index of the subclass descriptor
  167. *
  168. * @return Size of descriptor
  169. */
  170. size_t (*subclass_length)(app_usbd_class_inst_t const * p_inst,
  171. uint8_t desc_num);
  172. /**
  173. * @brief Function returns pointer to subclass descriptor data.
  174. *
  175. * @param[in] p_inst Class instance.
  176. * @param[in] desc_num Index of the subclass descriptor
  177. * @param[in] cur_byte Index of required byte
  178. *
  179. * @return Pointer to requested byte in subclass descriptor
  180. */
  181. const uint8_t * (*subclass_data)(app_usbd_class_inst_t const * p_inst,
  182. uint8_t desc_num,
  183. uint32_t cur_byte);
  184. /**
  185. * @brief Function called on idle transfer
  186. *
  187. * This function should trigger next idle transfer.
  188. *
  189. * @param[in,out] p_inst Instance of the class.
  190. * @param[in] report_id Number of report ID that needs idle transfer.
  191. *
  192. * @return Standard error code.
  193. */
  194. ret_code_t (*on_idle)(app_usbd_class_inst_t const * p_inst, uint8_t report_id);
  195. ret_code_t (*set_idle_handler)(app_usbd_class_inst_t const * p_inst,
  196. app_usbd_hid_idle_handler_t handler);
  197. } app_usbd_hid_methods_t;
  198. /**
  199. * @brief HID report buffers.
  200. */
  201. typedef struct {
  202. uint8_t * p_buff;
  203. size_t size;
  204. } app_usbd_hid_report_buffer_t;
  205. /**
  206. * @brief Define OUT report buffer structure @ref app_usbd_hid_report_buffer_t.
  207. *
  208. * @param name Instance name.
  209. * @param rep_size Output report size.
  210. */
  211. #define APP_USBD_HID_GENERIC_GLOBAL_OUT_REP_DEF(name, rep_size) \
  212. static uint8_t CONCAT_2(name, _buf)[(rep_size)]; \
  213. const app_usbd_hid_report_buffer_t name = { \
  214. .p_buff = CONCAT_2(name, _buf), \
  215. .size = sizeof(CONCAT_2(name, _buf)), \
  216. }
  217. /**
  218. * @brief Define FEATURE report buffer structure @ref app_usbd_hid_report_buffer_t.
  219. *
  220. * @param name Instance name.
  221. * @param rep_size Feature report size.
  222. */
  223. #define APP_USBD_HID_GENERIC_GLOBAL_FEATURE_REP_DEF(name, rep_size) \
  224. static uint8_t CONCAT_2(name, _feature_buf)[(rep_size)]; \
  225. const app_usbd_hid_report_buffer_t name = { \
  226. .p_buff = CONCAT_2(name, _feature_buf), \
  227. .size = sizeof(CONCAT_2(name, _feature_buf)), \
  228. }
  229. /**
  230. * @brief HID subclass descriptor.
  231. */
  232. typedef struct {
  233. size_t size;
  234. app_usbd_descriptor_t type;
  235. uint8_t const * const p_data;
  236. } app_usbd_hid_subclass_desc_t;
  237. /**
  238. * @brief Initializer of HID report descriptor
  239. *
  240. * @param name Report descriptor name
  241. * @param ... Report descriptor data
  242. */
  243. #define APP_USBD_HID_GENERIC_SUBCLASS_REPORT_DESC(name, ...) \
  244. static uint8_t const CONCAT_2(name, _data)[] = \
  245. __VA_ARGS__ \
  246. ; \
  247. static const app_usbd_hid_subclass_desc_t name = \
  248. { \
  249. sizeof(CONCAT_2(name, _data)), \
  250. APP_USBD_DESCRIPTOR_REPORT, \
  251. CONCAT_2(name,_data) \
  252. }
  253. /**
  254. * @brief Initializer of HID physical descriptor
  255. *
  256. * @param name Physical descriptor name
  257. * @param ... Physical descriptor data
  258. */
  259. #define APP_USBD_HID_GENERIC_SUBCLASS_PHYSICAL_DESC(name, ...) \
  260. static uint8_t const CONCAT_2(name, _data)[] = \
  261. __VA_ARGS__ \
  262. ; \
  263. static const app_usbd_hid_subclass_desc_t name = \
  264. { \
  265. sizeof(CONCAT_2(name, _data)), \
  266. APP_USBD_DESCRIPTOR_PHYSICAL, \
  267. CONCAT_2(name,_data) \
  268. }
  269. /**
  270. * @brief USB HID instance.
  271. */
  272. typedef struct {
  273. app_usbd_hid_subclass_desc_t const ** const p_subclass_desc; //!< HID subclass descriptors array.
  274. size_t subclass_desc_count; //!< HID subclass descriptors count.
  275. app_usbd_hid_subclass_t subclass_boot; //!< Boot device (see HID definition).
  276. app_usbd_hid_protocol_t protocol; //!< HID protocol (see HID definition).
  277. app_usbd_hid_report_buffer_t * p_rep_buffer_in; //!< Report buffer IN.
  278. app_usbd_hid_report_buffer_t const * p_rep_buffer_out; //!< Report buffer OUT (only one instance).
  279. app_usbd_hid_report_buffer_t const * p_rep_buffer_feature; //!< Report buffer FEATURE.
  280. app_usbd_hid_methods_t const * p_hid_methods; //!< Hid interface methods.
  281. app_usbd_hid_user_ev_handler_t user_event_handler; //!< User event handler.
  282. uint8_t * p_ep_interval; //!< Endpoint intervals.
  283. } app_usbd_hid_inst_t;
  284. /**
  285. * @brief USB HID instance initializer @ref app_usbd_hid_inst_t.
  286. *
  287. * @param subclass_dsc HID subclass descriptors.
  288. * @param sub_boot Subclass boot. (@ref app_usbd_hid_subclass_t)
  289. * @param protocl HID protocol. (@ref app_usbd_hid_protocol_t)
  290. * @param report_buff_in Input report buffer list.
  291. * @param report_buff_out Output report buffer.
  292. * @param report_buff_feature Feature report buffer.
  293. * @param user_ev_handler @ref app_usbd_hid_user_ev_handler_t.
  294. * @param hid_methods @ref app_usbd_hid_methods_t.
  295. * @param ep_list List of endpoints and intervals
  296. * */
  297. #define APP_USBD_HID_INST_CONFIG(subclass_dsc, \
  298. sub_boot, \
  299. protocl, \
  300. report_buff_in, \
  301. report_buff_out, \
  302. report_buff_feature, \
  303. user_ev_handler, \
  304. hid_methods, \
  305. ep_list) \
  306. { \
  307. .p_subclass_desc = subclass_dsc, \
  308. .subclass_desc_count = ARRAY_SIZE(subclass_dsc), \
  309. .p_rep_buffer_in = report_buff_in, \
  310. .p_rep_buffer_out = report_buff_out, \
  311. .p_rep_buffer_feature = report_buff_feature, \
  312. .user_event_handler = user_ev_handler, \
  313. .p_hid_methods = hid_methods, \
  314. .subclass_boot = sub_boot, \
  315. .protocol = protocl, \
  316. .p_ep_interval = ep_list \
  317. }
  318. /**
  319. * @brief HID internal context.
  320. * */
  321. typedef struct {
  322. nrf_atomic_u32_t state_flags; //!< HID state flags @ref app_usbd_hid_state_flag_t.
  323. nrf_atomic_flag_t access_lock; //!< Lock flag to internal data.
  324. uint8_t idle_rate[APP_USBD_HID_REPORT_IDLE_TABLE_SIZE]; //!< HID idle rate (4ms units).
  325. app_usbd_hid_protocol_select_t selected_protocol; //!< Currently selected HID protocol.
  326. app_usbd_hid_idle_handler_t idle_handler; //!< Idle report handler.
  327. uint32_t first_idle[APP_USBD_HID_REPORT_IDLE_TABLE_SIZE]; //!< Number of frame at first idle transaction.
  328. bool lock_idle[APP_USBD_HID_REPORT_IDLE_TABLE_SIZE]; //!< Lock flag to idle transactions.
  329. bool idle_on; //!< Idle transactions flag.
  330. bool idle_id_report; //!< Idle transactions with nonzero report id flag.
  331. } app_usbd_hid_ctx_t;
  332. /**
  333. * @brief Locks internal hid context.
  334. *
  335. * Simple semaphore functionality to prevent concurrent access from application and
  336. * interrupt to internal mouse data.
  337. *
  338. * @param[in] p_hid_ctx Internal hid context
  339. */
  340. static inline void app_usbd_hid_access_lock(app_usbd_hid_ctx_t * p_hid_ctx)
  341. {
  342. UNUSED_RETURN_VALUE(nrf_atomic_flag_set(&p_hid_ctx->access_lock));
  343. __DSB();
  344. }
  345. /**
  346. * @brief Unlocks internal hid context.
  347. *
  348. * Simple semaphore functionality to prevent concurrent access from application and
  349. * interrupt to internal mouse data.
  350. *
  351. * @param[in] p_hid_ctx Internal hid context.
  352. */
  353. static inline void app_usbd_hid_access_unlock(app_usbd_hid_ctx_t * p_hid_ctx)
  354. {
  355. UNUSED_RETURN_VALUE(nrf_atomic_flag_clear(&p_hid_ctx->access_lock));
  356. __DSB();
  357. }
  358. /**
  359. * @brief Tests whether internal lock is acquired.
  360. *
  361. * @param[in] p_hid_ctx Internal HID context.
  362. *
  363. * @retval true Locked.
  364. * @retval false Unlocked.
  365. */
  366. static inline bool app_usbd_hid_access_lock_test(app_usbd_hid_ctx_t * p_hid_ctx)
  367. {
  368. return p_hid_ctx->access_lock != 0;
  369. }
  370. /**
  371. * @brief Set one of the HID internal state flags.
  372. *
  373. * @param[in] p_hid_ctx Internal HID context.
  374. * @param[in] flag Flag to set.
  375. */
  376. static inline void app_usbd_hid_state_flag_set(app_usbd_hid_ctx_t * p_hid_ctx,
  377. app_usbd_hid_state_flag_t flag)
  378. {
  379. UNUSED_RETURN_VALUE(nrf_atomic_u32_or(&p_hid_ctx->state_flags, 1u << flag));
  380. }
  381. /**
  382. * @brief Clear one of the HID internal state flags.
  383. *
  384. * @param[in] p_hid_ctx Internal HID context.
  385. * @param[in] flag Flag to clear.
  386. */
  387. static inline void app_usbd_hid_state_flag_clr(app_usbd_hid_ctx_t * p_hid_ctx,
  388. app_usbd_hid_state_flag_t flag)
  389. {
  390. UNUSED_RETURN_VALUE(nrf_atomic_u32_and(&p_hid_ctx->state_flags, ~(1u << flag)));
  391. }
  392. /**
  393. * @brief Test one of the HID internal state flags.
  394. *
  395. * @param[in] p_hid_ctx Internal HID context.
  396. * @param[in] flag Flag to test.
  397. *
  398. * @retval true Flag is set.
  399. * @retval false Flag is not set.
  400. */
  401. static inline bool app_usbd_hid_state_flag_test(app_usbd_hid_ctx_t * p_hid_ctx,
  402. app_usbd_hid_state_flag_t flag)
  403. {
  404. return ((p_hid_ctx->state_flags >> flag) & 1) == 1;
  405. }
  406. /**
  407. * @brief Checks whether HID endpoint transfer required.
  408. *
  409. * @param[in] p_hid_ctx Internal HID context.
  410. *
  411. * @retval true Input endpoint transfer required.
  412. * @retval false Transfer in progress or not allowed.
  413. */
  414. static inline bool app_usbd_hid_trans_required(app_usbd_hid_ctx_t * p_hid_ctx)
  415. {
  416. if (app_usbd_hid_state_flag_test(p_hid_ctx, APP_USBD_HID_STATE_FLAG_SUSPENDED) != 0)
  417. {
  418. UNUSED_RETURN_VALUE(app_usbd_wakeup_req());
  419. return false;
  420. }
  421. return app_usbd_hid_state_flag_test(p_hid_ctx, APP_USBD_HID_STATE_FLAG_TRANS_IN_PROGRESS) == 0;
  422. }
  423. /**
  424. * @brief Validates internal hid state.
  425. *
  426. * HID Mouse has to receive some USBD events before functions from this module could be used.
  427. *
  428. * @param[in] p_hid_ctx Internal hid context.
  429. *
  430. * @retval true State is valid.
  431. * @retval false State is invalid.
  432. */
  433. static inline bool app_usbd_hid_state_valid(app_usbd_hid_ctx_t * p_hid_ctx)
  434. {
  435. /*Check whether internal flags allow to enable mouse*/
  436. if ((app_usbd_hid_state_flag_test(p_hid_ctx, APP_USBD_HID_STATE_FLAG_APPENDED) == 0) ||
  437. (app_usbd_hid_state_flag_test(p_hid_ctx, APP_USBD_HID_STATE_FLAG_STARTED) == 0))
  438. {
  439. return false;
  440. }
  441. return true;
  442. }
  443. /**
  444. * @brief HID generic event handler.
  445. *
  446. * This handler should process every class event after specific class handler.
  447. * This approach allow to handle some events in the same way in all HID sub-classes.
  448. *
  449. * @param[in] p_inst Generic class instance.
  450. * @param[in] p_hinst HID class instance.
  451. * @param[in] p_hid_ctx HID context.
  452. * @param[in] p_event Complex event structure.
  453. *
  454. * @return Standard error code.
  455. */
  456. ret_code_t app_usbd_hid_event_handler(app_usbd_class_inst_t const * p_inst,
  457. app_usbd_hid_inst_t const * p_hinst,
  458. app_usbd_hid_ctx_t * p_hid_ctx,
  459. app_usbd_complex_evt_t const * p_event);
  460. /**
  461. * @brief Returns IN report buffer.
  462. *
  463. * @param[in] p_hinst HID class instance.
  464. *
  465. * @return Report buffer handle or NULL if report doesn't exist.
  466. */
  467. app_usbd_hid_report_buffer_t * app_usbd_hid_rep_buff_in_get(app_usbd_hid_inst_t const * p_hinst);
  468. /**
  469. * @brief Returns OUT report buffer.
  470. *
  471. * Output reports are handled in interrupt handler so only one buffer is required. Buffer returned by
  472. * this function has predefined size, which should be equal (maximum OUTPUT report size + 1). To receive
  473. * OUT report this function should be called on @ref APP_USBD_HID_USER_EVT_OUT_REPORT_READY event.
  474. *
  475. * @param[in] p_hinst HID class instance.
  476. *
  477. * @return Report buffer handle or NULL if report doesn't exist.
  478. */
  479. static inline app_usbd_hid_report_buffer_t const *
  480. app_usbd_hid_rep_buff_out_get(app_usbd_hid_inst_t const * p_hinst)
  481. {
  482. ASSERT(p_hinst);
  483. return p_hinst->p_rep_buffer_out;
  484. }
  485. /**
  486. * @brief Returns FEATURE report buffer.
  487. *
  488. * @param[in] p_hinst HID class instance.
  489. *
  490. * @return Report buffer handle or NULL if report doesn't exist.
  491. */
  492. app_usbd_hid_report_buffer_t const * app_usbd_hid_rep_buff_feature_get(app_usbd_hid_inst_t const * p_hinst);
  493. /**
  494. * @brief Returns HID selected protocol.
  495. *
  496. * @param[in] p_hid_ctx HID context.
  497. *
  498. * @return Currently selected protocol (@ref app_usbd_hid_protocol_select_t).
  499. */
  500. static inline app_usbd_hid_protocol_select_t app_usbd_hid_selected_protocol_get(app_usbd_hid_ctx_t * p_hid_ctx)
  501. {
  502. ASSERT(p_hid_ctx);
  503. return p_hid_ctx->selected_protocol;
  504. }
  505. /**
  506. * @brief Auxiliary function to access to HID IN endpoint address.
  507. *
  508. * @param[in] p_inst Class instance data.
  509. *
  510. * @return IN endpoint address.
  511. */
  512. static inline nrf_drv_usbd_ep_t app_usbd_hid_epin_addr_get(app_usbd_class_inst_t const * p_inst)
  513. {
  514. app_usbd_class_iface_conf_t const * class_iface;
  515. class_iface = app_usbd_class_iface_get(p_inst, APP_USBD_HID_IFACE_IDX);
  516. app_usbd_class_ep_conf_t const * ep_cfg;
  517. ep_cfg = app_usbd_class_iface_ep_get(class_iface, APP_USBD_HID_EPIN_IDX);
  518. return app_usbd_class_ep_address_get(ep_cfg);
  519. }
  520. /**
  521. * @brief Auxiliary function to access to HID generic OUT endpoint address.
  522. *
  523. * @param[in] p_inst Class instance data.
  524. *
  525. * @return OUT endpoint address.
  526. */
  527. static inline nrf_drv_usbd_ep_t app_usbd_hid_epout_addr_get(app_usbd_class_inst_t const * p_inst)
  528. {
  529. app_usbd_class_iface_conf_t const * class_iface;
  530. class_iface = app_usbd_class_iface_get(p_inst, APP_USBD_HID_IFACE_IDX);
  531. app_usbd_class_ep_conf_t const * ep_cfg;
  532. ep_cfg = app_usbd_class_iface_ep_get(class_iface, APP_USBD_HID_EPOUT_IDX);
  533. return app_usbd_class_ep_address_get(ep_cfg);
  534. }
  535. /** @} */
  536. #ifdef __cplusplus
  537. }
  538. #endif
  539. #endif /* APP_USBD_HID_H__ */