usb_audio_desc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #include "include.h"
  2. #include "usb_com.h"
  3. #include "usb_desc.h"
  4. #if USB_AUDIO_EN
  5. AT(.rodata.usb.desc)
  6. const uint8_t desc_itf_header_audio[] = {
  7. 0x09, /* Num bytes of this descriptor */
  8. INTERFACE_DESCRIPTOR, /* Interface descriptor type */
  9. USB_AUDIO_CTL_ITF_INDEX, /* Interface Number*/
  10. 0x00, /* Alternate interface number */
  11. 0x00, /* Num endpoints of this interface */
  12. 0x01, /* Interface Class: Audio */
  13. 0x01, /* Interface Sub Class: Audio Control */
  14. 0x00, /* Class specific protocol */
  15. 0x00, /* Index of Interface string descriptor */
  16. #if (AUDIO_TOTAL_NR == 1)
  17. 0x09, /* Num bytes of this descriptor */
  18. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  19. UA_HEADER_DESCRIPTOR, /* HEADER descriptor */
  20. 0x00, /* Audio 1.0 LSB */
  21. 0x01, /* Audio 1.0 MSB */
  22. 0x27, /* Total Size of Audio Control LSB, sizeof(desc_itf_header_audio) - 9*/
  23. 0x00, /* Total Size of Audio Control MSB */
  24. AUDIO_TOTAL_NR, /* Num Audio OUT Streaming Interface */
  25. USB_AUDIO_CTL_ITF_INDEX + 1, /* Number of Audio Streaming Nr1*/
  26. #elif (AUDIO_TOTAL_NR == 2)
  27. 0x0a, /* Num bytes of this descriptor */
  28. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  29. UA_HEADER_DESCRIPTOR, /* HEADER descriptor */
  30. 0x00, /* Audio 1.0 LSB */
  31. 0x01, /* Audio 1.0 MSB */
  32. 0x46, /* Total Size of Audio Control LSB, sizeof(desc_itf_header_audio) - 9 */
  33. 0x00, /* Total Size of Audio Control MSB */
  34. AUDIO_TOTAL_NR, /* Num Audio OUT Streaming Interface */
  35. USB_AUDIO_STREAM_MIC_ITF_INDEX, /* Number of Audio Streaming Nr1*/
  36. USB_AUDIO_STREAM_SPEAKER_ITF_INDEX, /* Number of Audio Streaming Nr2*/
  37. #endif // AUDIO_TOTAL_NR
  38. #if USB_SPEAKER_EN
  39. 0x0c, /* Num bytes of this descriptor */
  40. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  41. UA_INPUT_TERM_DESCRIPTOR, /* INPUT_TERMINAL descriptor */
  42. UA_SPEAKER_INPUT_ID, /* Terminal ID, The same of speaker stream TID */
  43. 0x01, /* Terminal Type: 0x0101 - USB Streaming LSB */
  44. 0x01, /* Terminal Type: 0x0101 - USB Streaming MSB */
  45. 0x00, /* Associate Terminal */
  46. 0x01, /* NrChannel, */
  47. 0x04, /* Channel Config LSB (D0: Left Front, D1:Right Front) */
  48. 0x00, /* Channel Config MSB */
  49. 0x00, /* Channel Name */
  50. 0x00, /* Index of Channel String */
  51. 0x09, /* Num bytes of this descriptor */
  52. AUDIO_INTERFACE_DESCRIPTOR, /* bDescriptorType, Audio Control Interface descriptor type */
  53. UA_FEATURE_UNIT_DESCRIPTOR, /* bDescriptorSubtype, FEATURE_UNIT descriptor subtype */
  54. UA_SPEAKER_UNIT_ID, /* bUnitID, Feature Unit ID */
  55. UA_SPEAKER_INPUT_ID, /* bSourceID */
  56. 0x01, /* Control Size */
  57. 0x01, /* bmaControls(0): D0(Mute), D1(Volume), mute and volume control supported for master channel */
  58. 0x00, /* bmaControls(1) */
  59. 0x00, /* Index of Feature String */
  60. 0x09, /* Num bytes of this descriptor */
  61. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  62. UA_OUTPUT_TERM_DESCRIPTOR, /* OUTPUT_TERMINAL descriptor */
  63. UA_SPEAKER_OUTPUT_ID, /* Terminal ID */
  64. 0x01, /* Terminal Type: 0x0301 = Speaker LSB */
  65. 0x03, /* Terminal Type: 0x0301 = Speaker MSB */
  66. 0x00, /* Associate Terminal */
  67. UA_SPEAKER_UNIT_ID, /* bSourceID */
  68. 0x00, /* Index of Channel String */
  69. #endif // USB_SPEAKER_EN
  70. #if USB_MIC_EN
  71. 0x0c, /* Num bytes of this descriptor */
  72. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  73. UA_INPUT_TERM_DESCRIPTOR, /* INPUT_TERMINAL descriptor */
  74. UA_MIC_INPUT_ID, /* Terminal ID */
  75. 0x01, /* Terminal Type: 0x0201 = Microphone LSB */
  76. 0x02, /* Terminal Type: 0x0201 = Microphone MSB */
  77. 0x00, /* Associate Terminal */
  78. 0x01, /* NrChannel, Single */
  79. 0x00, /* Channel Config LSB */
  80. 0x00, /* Channel Config MSB */
  81. 0x00, /* Channel Name */
  82. 0x00, /* Index of Channel String */
  83. 0x09, /* Num bytes of this descriptor */
  84. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  85. UA_FEATURE_UNIT_DESCRIPTOR, /* FEATURE_UNIT descriptor */
  86. UA_MIC_UNIT_ID, /* bUnitID, Feature Unit ID */
  87. UA_MIC_INPUT_ID, /* bSourceID */
  88. 0x01, /* Control Size */
  89. 0x03, /* bmaControls(0): D0(Mute) D1(Volume), mute and volume control supported for master channel */
  90. 0x00, /* bmaControls(1) */
  91. 0x00, /* Index of Feature String */
  92. 0x09, /* Num bytes of this descriptor */
  93. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  94. UA_OUTPUT_TERM_DESCRIPTOR, /* OUTPUT_TERMINAL descriptor */
  95. UA_MIC_OUTPUT_ID, /* Terminal ID, The same of mic stream TID */
  96. 0x01, /* Terminal Type: 0x0101 - USB Streaming LSB */
  97. 0x01, /* Terminal Type: 0x0101 - USB Streaming MSB */
  98. 0x00, /* Associate Terminal */
  99. UA_MIC_UNIT_ID, /* bSourceID */
  100. 0x00, /* Index of Channel String */
  101. #endif // USB_MIC_EN
  102. };
  103. #if USB_SPEAKER_EN
  104. AT(.rodata.usb.desc)
  105. const uint8_t desc_itf_speaker_stream_audio[] = {
  106. 0x09, /* Num bytes of this descriptor */
  107. INTERFACE_DESCRIPTOR, /* Interface descriptor type */
  108. USB_AUDIO_STREAM_SPEAKER_ITF_INDEX, /* Interface Number*/
  109. 0x00, /* Alternate interface number */
  110. 0x00, /* Num endpoints of this interface */
  111. 0x01, /* Interface Class: Audio */
  112. 0x02, /* Interface Sub Class: Audio Streaming */
  113. 0x00, /* Class specific protocol: */
  114. 0x00, /* Index of Interface string descriptor */
  115. 0x09, /* Num bytes of this descriptor */
  116. INTERFACE_DESCRIPTOR, /* Interface descriptor type */
  117. USB_AUDIO_STREAM_SPEAKER_ITF_INDEX, /* Interface Number (it will be rewrite by lib) */
  118. 0x01, /* Alternate interface number */
  119. 0x01, /* Num endpoints of this interface */
  120. 0x01, /* Interface Class: Audio */
  121. 0x02, /* Interface Sub Class: Audio Streaming */
  122. 0x00, /* Class specific protocol: */
  123. 0x00, /* Index of Interface string descriptor */
  124. 0x07, /* Num bytes of this descriptor */
  125. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  126. UA_STREAM_GENERAL_DESCRIPTOR, /* AS_GENERAL descriptor */
  127. UA_SPEAKER_INPUT_ID, /* Terminal ID of Input Terminal, Audio USB Stream ID */
  128. 0x01, /* Interface Delay */
  129. 0x01, /* PCM Format 0x0001 = 16bit LSB */
  130. 0x00, /* PCM Format MSB */
  131. 0x0b, /* Num bytes of this descriptor */
  132. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  133. UA_STREAM_FORMAT_DESCRIPTOR, /* FORMAT_TYPE descriptor */
  134. 0x01, /* FORMAT_TYPE */
  135. 0x01, /* NrChannel */
  136. 0x02, /* frame = 2byte */
  137. 0x10, /* 16bit per sample */
  138. 0x01, /* One Frequency supported */
  139. BYTE0(AUDIO_SPEAKER_SAMPLE), /* Sample Rate */
  140. BYTE1(AUDIO_SPEAKER_SAMPLE),
  141. BYTE2(AUDIO_SPEAKER_SAMPLE),
  142. //EndpointDescriptor:
  143. 0x09, /* Num bytes of this descriptor */
  144. ENDPOINT_DESCRIPTOR, /* Endpoint descriptor type */
  145. USB_AUDIO_EP_OUT_INDEX, /* Endpoint number */
  146. AUDIO_ISOOUT_TYPE, /* ISO endpoint, ADA */
  147. BYTE0(AUDIO_ISOOUT_SIZE), /* Maximum packet size LSB */
  148. BYTE1(AUDIO_ISOOUT_SIZE), /* Maximum packet size LSB */
  149. 0x01, /* ISO 1ms */
  150. 0x00, /* Refresh */
  151. 0x00, /* SynchAddress */
  152. 0x07, /* Num bytes of this descriptor */
  153. AUDIO_ENDPOINT_DESCRIPTOR, /* CS_ENDPOINT descriptor */
  154. 0x01, /* EP_GENENAL descriptor */
  155. 0x01, /* ATTR */
  156. 0x01, /* LockDelayUnits */
  157. 0x01, /* LockDelay LSB */
  158. 0x00, /* LockDelay MSB */
  159. };
  160. #endif // USB_SPEAKER_EN
  161. #if USB_MIC_EN
  162. AT(.rodata.usb.desc)
  163. const uint8_t desc_itf_mic_stream_audio[] = {
  164. 0x09, /* Num bytes of this descriptor */
  165. INTERFACE_DESCRIPTOR, /* Interface descriptor type */
  166. USB_AUDIO_STREAM_MIC_ITF_INDEX, /* Interface Number*/
  167. 0x00, /* Alternate interface number */
  168. 0x00, /* Num endpoints of this interface */
  169. 0x01, /* Interface Class: Audio */
  170. 0x02, /* Interface Sub Class: Audio Streaming */
  171. 0x00, /* Class specific protocol: */
  172. 0x00, /* Index of Interface string descriptor */
  173. 0x09, /* Num bytes of this descriptor */
  174. INTERFACE_DESCRIPTOR, /* Interface descriptor type */
  175. USB_AUDIO_STREAM_MIC_ITF_INDEX, /* Interface Number*/
  176. 0x01, /* Alternate interface number */
  177. 0x01, /* Num endpoints of this interface */
  178. 0x01, /* Interface Class: Audio */
  179. 0x02, /* Interface Sub Class: Audio Streaming */
  180. 0x00, /* Class specific protocol: */
  181. 0x00, /* Index of Interface string descriptor */
  182. 0x07, /* Num bytes of this descriptor */
  183. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  184. UA_STREAM_GENERAL_DESCRIPTOR, /* AS_GENERAL descriptor */
  185. UA_MIC_OUTPUT_ID, /* Terminal ID of Input Terminal */
  186. 0x01, /* Interface Delay */
  187. 0x01, /* PCM Format 0x0001 = 16bit LSB */
  188. 0x00, /* PCM Format MSB */
  189. 0x0b, /* Num bytes of this descriptor */
  190. AUDIO_INTERFACE_DESCRIPTOR, /* Audio Control Interface descriptor type */
  191. UA_STREAM_FORMAT_DESCRIPTOR, /* FORMAT_TYPE descriptor */
  192. 0x01, /* FORMAT_TYPE */
  193. 0x01, /* NrChannel = 1,MIC used single channel */
  194. 0x02, /* frame = 2byte */
  195. 0x10, /* 16bit per sample */
  196. 0x01, /* One Frequency supported */
  197. BYTE0(AUDIO_MIC_SAMPLE), /* Sample Rate */
  198. BYTE1(AUDIO_MIC_SAMPLE),
  199. BYTE2(AUDIO_MIC_SAMPLE),
  200. //EndpointDescriptor:
  201. 0x09, /* Num bytes of this descriptor */
  202. ENDPOINT_DESCRIPTOR, /* Endpoint descriptor type */
  203. USB_AUDIO_EP_IN_INDEX | 0x80, /* Endpoint number */
  204. AUDIO_ISOIN_TYPE, /* ISO endpoint, ASY */
  205. BYTE0(AUDIO_ISOIN_SIZE), /* Maximum packet size,sample point bytes by 1ms */
  206. BYTE1(AUDIO_ISOIN_SIZE),
  207. 0x01, /* ISO 1ms */
  208. 0x00, /* Refresh */
  209. 0x00, /* SynchAddress */
  210. 0x07, /* Num bytes of this descriptor */
  211. AUDIO_ENDPOINT_DESCRIPTOR, /* CS_ENDPOINT descriptor */
  212. 0x01, /* EP_GENENAL descriptor */
  213. 0x01, /* ATTR */
  214. 0x00, /* LockDelayUnits */
  215. 0x00, /* LockDelay LSB */
  216. 0x00, /* LockDelay MSB */
  217. };
  218. #endif // USB_MIC_EN
  219. uint8_t *usb_audio_itf_header_desc_get(uint8_t *length)
  220. {
  221. *length = sizeof(desc_itf_header_audio);
  222. return (u8 *)desc_itf_header_audio;
  223. }
  224. #if USB_SPEAKER_EN
  225. uint8_t *usb_audio_itf_speaker_stream_desc_get(uint8_t *length)
  226. {
  227. *length = sizeof(desc_itf_speaker_stream_audio);
  228. return (u8 *)desc_itf_speaker_stream_audio;
  229. }
  230. #endif // USB_SPEAKER_EN
  231. #if USB_MIC_EN
  232. uint8_t *usb_audio_itf_mic_stream_desc_get(uint8_t *length)
  233. {
  234. *length = sizeof(desc_itf_mic_stream_audio);
  235. return (u8 *)desc_itf_mic_stream_audio;
  236. }
  237. #endif // USB_MIC_EN
  238. #endif