app_usbd_audio_internal.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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_AUDIO_INTERNAL_H__
  41. #define APP_USBD_AUDIO_INTERNAL_H__
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /**
  46. * @defgroup app_usbd_audio_internal USB Audio internals
  47. * @brief @tagAPI52840 USB Audio class internals.
  48. * @ingroup app_usbd_audio
  49. * @{
  50. */
  51. /**
  52. * @brief Forward declaration of type defined by @ref APP_USBD_CLASS_TYPEDEF in audio class.
  53. *
  54. */
  55. APP_USBD_CLASS_FORWARD(app_usbd_audio);
  56. /*lint -save -e165*/
  57. /**
  58. * @brief Forward declaration of @ref app_usbd_audio_user_event_e
  59. *
  60. */
  61. enum app_usbd_audio_user_event_e;
  62. /*lint -restore*/
  63. /**
  64. * @brief User event handler.
  65. *
  66. * @param[in] p_inst Class instance.
  67. * @param[in] event User event.
  68. *
  69. */
  70. typedef void (*app_usbd_audio_user_ev_handler_t)(app_usbd_class_inst_t const * p_inst,
  71. enum app_usbd_audio_user_event_e event);
  72. /**
  73. * @brief Audio subclass descriptor.
  74. */
  75. typedef struct {
  76. size_t size;
  77. uint8_t type;
  78. uint8_t const * const p_data;
  79. } app_usbd_audio_subclass_desc_t;
  80. /**
  81. * @brief Audio class part of class instance data.
  82. */
  83. typedef struct {
  84. app_usbd_audio_subclass_desc_t const * const p_format_dsc; //!< Audio class Format descriptor
  85. app_usbd_audio_subclass_desc_t const * const p_input_dsc; //!< Audio class Input Terminal descriptor
  86. app_usbd_audio_subclass_desc_t const * const p_output_dsc; //!< Audio class Output Terminal descriptor
  87. app_usbd_audio_subclass_desc_t const * const p_feature_dsc; //!< Audio class Feature Unit descriptor
  88. uint8_t delay; //!< Streaming delay
  89. uint16_t format; //!< FormatTag (@ref app_usbd_audio_as_iface_format_tag_t)
  90. uint16_t ep_size; //!< Endpoint size
  91. uint8_t terminal_link; //!< Terminal link in AS Interface Descriptor
  92. app_usbd_audio_subclass_t type_streaming; //!< Streaming type MIDISTREAMING/AUDIOSTREAMING (@ref app_usbd_audio_subclass_t)
  93. app_usbd_audio_user_ev_handler_t user_ev_handler; //!< User event handler
  94. } app_usbd_audio_inst_t;
  95. /**
  96. * @brief Audio class request target.
  97. */
  98. typedef enum {
  99. APP_USBD_AUDIO_CLASS_REQ_IN, /**< Audio class request IN */
  100. APP_USBD_AUDIO_CLASS_REQ_OUT, /**< Audio class request OUT */
  101. APP_USBD_AUDIO_EP_REQ_IN, /**< Audio class endpoint request IN */
  102. APP_USBD_AUDIO_EP_REQ_OUT, /**< Audio class endpoint request OUT */
  103. } app_usbd_audio_class_req_target_t;
  104. /**
  105. * @brief Audio class specific request handled via control endpoint.
  106. */
  107. typedef struct {
  108. app_usbd_audio_class_req_target_t req_target; //!< Request target
  109. app_usbd_audio_req_type_t req_type; //!< Request type
  110. uint8_t control; //!< Request control field
  111. uint8_t channel; //!< Channel ID
  112. uint8_t interface; //!< Interface ID
  113. uint8_t entity; //!< Entity ID
  114. uint16_t length; //!< Request payload length
  115. uint8_t payload[64]; //!< Request payload
  116. } app_usbd_audio_req_t;
  117. /**
  118. * @brief Audio class context.
  119. *
  120. */
  121. typedef struct {
  122. app_usbd_audio_req_t request; //!< Audio class request
  123. bool streaming; //!< Streaming flag
  124. app_usbd_sof_interrupt_handler_t sof_handler; //!< SOF event handler
  125. } app_usbd_audio_ctx_t;
  126. /**
  127. * @brief Audio class configuration macro.
  128. *
  129. * Used by @ref APP_USBD_AUDIO_GLOBAL_DEF
  130. *
  131. * @param iface_control Interface number of audio control.
  132. * @param iface_stream Interface number of audio stream.
  133. */
  134. #define APP_USBD_AUDIO_CONFIG(iface_control, iface_stream) \
  135. ((iface_control), \
  136. (iface_stream, 0))
  137. /**
  138. * @brief Only IN audio stream configuration.
  139. *
  140. * @param iface_control Interface number of audio control.
  141. * @param iface_stream_in Interface number of audio stream on IN endpoint.
  142. */
  143. #define APP_USBD_AUDIO_CONFIG_IN(iface_control, iface_stream_in) \
  144. ((iface_control), (iface_stream_in, NRF_DRV_USBD_EPIN8))
  145. /**
  146. * @brief Only OUT audio stream configuration.
  147. *
  148. * @param iface_control Interface number of audio control.
  149. * @param iface_stream_out Interface number of audio stream on OUT endpoint.
  150. */
  151. #define APP_USBD_AUDIO_CONFIG_OUT(iface_control, iface_stream_out) \
  152. ((iface_control), (iface_stream_out, NRF_DRV_USBD_EPOUT8))
  153. /**
  154. * @brief Specific class constant data for audio class.
  155. *
  156. * @ref app_usbd_audio_inst_t
  157. */
  158. #define APP_USBD_AUDIO_INSTANCE_SPECIFIC_DEC app_usbd_audio_inst_t inst;
  159. /**
  160. * @brief Configures audio class instance.
  161. *
  162. * @param user_event_handler User event handler.
  163. * @param format_descriptor Audio class Format descriptor.
  164. * @param input_descriptor Audio class Input Terminal descriptor.
  165. * @param output_descriptor Audio class Output Terminal descriptor.
  166. * @param feature_descriptor Audio class Feature Unit descriptor.
  167. * @param dlay Streaming delay.
  168. * @param frmat FormatTag (@ref app_usbd_audio_as_iface_format_tag_t).
  169. * @param ep_siz Endpoint size.
  170. * @param type_str Streaming type MIDISTREAMING/AUDIOSTREAMING.
  171. * @param terminal Terminal link in AS Interface Descriptor.
  172. */
  173. #define APP_USBD_AUDIO_INST_CONFIG(user_event_handler, \
  174. format_descriptor, \
  175. input_descriptor, \
  176. output_descriptor, \
  177. feature_descriptor, \
  178. dlay, \
  179. frmat, \
  180. ep_siz, \
  181. type_str, \
  182. terminal) \
  183. .inst = { \
  184. .user_ev_handler = user_event_handler, \
  185. .p_format_dsc = format_descriptor, \
  186. .p_input_dsc = input_descriptor, \
  187. .p_output_dsc = output_descriptor, \
  188. .p_feature_dsc = feature_descriptor, \
  189. .delay = dlay, \
  190. .format = frmat, \
  191. .ep_size = ep_siz, \
  192. .type_streaming = type_str, \
  193. .terminal_link = terminal \
  194. }
  195. /**
  196. * @brief Specific class data for audio class.
  197. *
  198. * @ref app_usbd_audio_ctx_t
  199. */
  200. #define APP_USBD_AUDIO_DATA_SPECIFIC_DEC app_usbd_audio_ctx_t ctx;
  201. /**
  202. * @brief Audio class descriptors config macro.
  203. *
  204. * @param interface_number Interface number.
  205. * @param ... Extracted endpoint list.
  206. */
  207. #define APP_USBD_AUDIO_DSC_CONFIG(interface_number, ...) { \
  208. APP_USBD_AUDIO_INTERFACE_DSC(interface_number, \
  209. 0, \
  210. 0, \
  211. APP_USBD_AUDIO_SUBCLASS_AUDIOCONTROL) \
  212. }
  213. /**
  214. * @brief Public audio class interface.
  215. *
  216. */
  217. extern const app_usbd_class_methods_t app_usbd_audio_class_methods;
  218. /**
  219. * @brief Global definition of @ref app_usbd_audio_t class
  220. *
  221. */
  222. #define APP_USBD_AUDIO_GLOBAL_DEF_INTERNAL(instance_name, \
  223. interfaces_configs, \
  224. user_ev_handler, \
  225. format_descriptor, \
  226. input_descriptor, \
  227. output_descriptor, \
  228. feature_descriptor, \
  229. delay, \
  230. format, \
  231. ep_size, \
  232. type_str, \
  233. terminal_link) \
  234. APP_USBD_CLASS_INST_GLOBAL_DEF( \
  235. instance_name, \
  236. app_usbd_audio, \
  237. &app_usbd_audio_class_methods, \
  238. interfaces_configs, \
  239. (APP_USBD_AUDIO_INST_CONFIG(user_ev_handler, \
  240. format_descriptor, \
  241. input_descriptor, \
  242. output_descriptor, \
  243. feature_descriptor, \
  244. delay, \
  245. format, \
  246. ep_size, \
  247. type_str, \
  248. terminal_link)) \
  249. )
  250. /** @} */
  251. #ifdef __cplusplus
  252. }
  253. #endif
  254. #endif /* APP_USBD_AUDIO_INTERNAL_H__ */