cm3_usb_audio.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /** @defgroup usb_audio_defines USB Audio Type Definitions
  2. @brief <b>Defined Constants and Types for the USB Audio Type Definitions</b>
  3. @ingroup USB_defines
  4. @version 1.0.0
  5. @author @htmlonly &copy; @endhtmlonly 2014
  6. Daniel Thompson <daniel@redfelineninja.org.uk>
  7. Seb Holzapfel <schnommus@gmail.com>
  8. @date 19 April 2014
  9. LGPL License Terms @ref lgpl_license
  10. */
  11. /*
  12. * This file is part of the libopencm3 project.
  13. *
  14. * Copyright (C) 2014 Daniel Thompson <daniel@redfelineninja.org.uk>
  15. * Copyright (C) 2018 Seb Holzapfel <schnommus@gmail.com>
  16. *
  17. * This library is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Lesser General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This library is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Lesser General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Lesser General Public License
  28. * along with this library. If not, see <http://www.gnu.org/licenses/>.
  29. */
  30. /**@{*/
  31. #ifndef LIBOPENCM3_USB_AUDIO_H
  32. #define LIBOPENCM3_USB_AUDIO_H
  33. #include <stdint.h>
  34. /*
  35. * Definitions from the USB_AUDIO_ or usb_audio_ namespace come from:
  36. * "Universal Serial Bus Class Definitions for Audio Devices, Revision 1.0"
  37. */
  38. /* Table A-1: Audio Interface Class Code */
  39. #define USB_CLASS_AUDIO 0x01
  40. /* Table A-2: Audio Interface Subclass Codes */
  41. #define USB_AUDIO_SUBCLASS_UNDEFINED 0x00
  42. #define USB_AUDIO_SUBCLASS_CONTROL 0x01
  43. #define USB_AUDIO_SUBCLASS_AUDIOSTREAMING 0x02
  44. #define USB_AUDIO_SUBCLASS_MIDISTREAMING 0x03
  45. /* Table A-4: Audio Class-specific Descriptor Types */
  46. #define USB_AUDIO_DT_CS_UNDEFINED 0x20
  47. #define USB_AUDIO_DT_CS_DEVICE 0x21
  48. #define USB_AUDIO_DT_CS_CONFIGURATION 0x22
  49. #define USB_AUDIO_DT_CS_STRING 0x23
  50. #define USB_AUDIO_DT_CS_INTERFACE 0x24
  51. #define USB_AUDIO_DT_CS_ENDPOINT 0x25
  52. /* Table A-5: Audio Class-Specific AC Interface Descriptor Subtypes */
  53. #define USB_AUDIO_TYPE_AC_DESCRIPTOR_UNDEFINED 0x00
  54. #define USB_AUDIO_TYPE_HEADER 0x01
  55. #define USB_AUDIO_TYPE_INPUT_TERMINAL 0x02
  56. #define USB_AUDIO_TYPE_OUTPUT_TERMINAL 0x03
  57. #define USB_AUDIO_TYPE_MIXER_UNIT 0x04
  58. #define USB_AUDIO_TYPE_SELECTOR_UNIT 0x05
  59. #define USB_AUDIO_TYPE_FEATURE_UNIT 0x06
  60. #define USB_AUDIO_TYPE_PROCESSING_UNIT 0x07
  61. #define USB_AUDIO_TYPE_EXTENSION_UNIT 0x08
  62. /* Table 4-2: Class-Specific AC Interface Header Descriptor (head) */
  63. struct usb_audio_header_descriptor_head {
  64. uint8_t bLength;
  65. uint8_t bDescriptorType;
  66. uint8_t bDescriptorSubtype;
  67. uint16_t bcdADC;
  68. uint16_t wTotalLength;
  69. uint8_t bInCollection;
  70. /* ... */
  71. } __attribute__((packed));
  72. /* Table 4-2: Class-Specific AC Interface Header Descriptor (body) */
  73. struct usb_audio_header_descriptor_body {
  74. /* ... */
  75. uint8_t baInterfaceNr;
  76. } __attribute__((packed));
  77. /* Table 4-3: Input Terminal Descriptor */
  78. struct usb_audio_input_terminal_descriptor {
  79. uint8_t bLength;
  80. uint8_t bDescriptorType;
  81. uint8_t bDescriptorSubtype;
  82. uint8_t bTerminalID;
  83. uint16_t wTerminalType;
  84. uint8_t bAssocTerminal;
  85. uint8_t bNrChannels;
  86. uint16_t wChannelConfig;
  87. uint8_t iChannelNames;
  88. uint8_t iTerminal;
  89. } __attribute__((packed));
  90. /* Table 4-3: Output Terminal Descriptor */
  91. struct usb_audio_output_terminal_descriptor {
  92. uint8_t bLength;
  93. uint8_t bDescriptorType;
  94. uint8_t bDescriptorSubtype;
  95. uint8_t bTerminalID;
  96. uint16_t wTerminalType;
  97. uint8_t bAssocTerminal;
  98. uint8_t bSourceID;
  99. uint8_t iTerminal;
  100. } __attribute__((packed));
  101. /* Table 4-7: Feature Unit Descriptor (head) */
  102. struct usb_audio_feature_unit_descriptor_head {
  103. uint8_t bLength;
  104. uint8_t bDescriptorType;
  105. uint8_t bDescriptorSubtype;
  106. uint8_t bUnitID;
  107. uint8_t bSourceID;
  108. uint8_t bControlSize;
  109. uint16_t bmaControlMaster; /* device can assume 16-bit, given highest
  110. * defined bit in spec is bit #9.
  111. * (it is thus required bControlSize=2) */
  112. /* ... */
  113. } __attribute__((packed));
  114. /* Table 4-7: Feature Unit Descriptor (body) */
  115. struct usb_audio_feature_unit_descriptor_body {
  116. /* ... */
  117. uint16_t bmaControl;
  118. /* ... */
  119. } __attribute__((packed));
  120. /* Table 4-7: Feature Unit Descriptor (tail) */
  121. struct usb_audio_feature_unit_descriptor_tail {
  122. /* ... */
  123. uint8_t iFeature;
  124. } __attribute__((packed));
  125. /* Table 4-7: Feature Unit Descriptor (2-channel)
  126. *
  127. * This structure is a convenience covering the (common) case where
  128. * there are 2 channels associated with the feature unit
  129. */
  130. struct usb_audio_feature_unit_descriptor_2ch {
  131. struct usb_audio_feature_unit_descriptor_head head;
  132. struct usb_audio_feature_unit_descriptor_body channel_control[2];
  133. struct usb_audio_feature_unit_descriptor_tail tail;
  134. } __attribute__((packed));
  135. /* Table 4-19: Class-Specific AS Interface Descriptor */
  136. struct usb_audio_stream_interface_descriptor {
  137. uint8_t bLength;
  138. uint8_t bDescriptorType;
  139. uint8_t bDescriptorSubtype;
  140. uint8_t bTerminalLink;
  141. uint8_t bDelay;
  142. uint16_t wFormatTag;
  143. } __attribute__((packed));
  144. /* Table 4-20: Standard AS Isochronous Audio Data Endpoint Descriptor */
  145. struct usb_audio_stream_endpoint_descriptor {
  146. uint8_t bLength;
  147. uint8_t bDescriptorType;
  148. uint8_t bEndpointAddress;
  149. uint8_t bmAttributes;
  150. uint16_t wMaxPacketSize;
  151. uint8_t bInterval;
  152. uint8_t bRefresh;
  153. uint8_t bSynchAddress;
  154. } __attribute__((packed));
  155. /* Table 4-21: Class-Specific AS Isochronous Audio Data Endpoint Descriptor */
  156. struct usb_audio_stream_audio_endpoint_descriptor {
  157. uint8_t bLength;
  158. uint8_t bDescriptorType;
  159. uint8_t bDescriptorSubtype;
  160. uint8_t bmAttributes;
  161. uint8_t bLockDelayUnits;
  162. uint16_t wLockDelay;
  163. } __attribute__((packed));
  164. /*
  165. * Definitions from the USB_AUDIO_FORMAT_ or usb_audio_format_ namespace come from:
  166. * "Universal Serial Bus Device Class Definition for Audio Data Formats, Revision 1.0"
  167. */
  168. /* Table 2-1: Type I Format Type Descriptor (head) */
  169. struct usb_audio_format_type1_descriptor_head {
  170. uint8_t bLength;
  171. uint8_t bDescriptorType;
  172. uint8_t bDescriptorSubtype;
  173. uint8_t bFormatType;
  174. uint8_t bNrChannels;
  175. uint8_t bSubFrameSize;
  176. uint8_t bBitResolution;
  177. uint8_t bSamFreqType;
  178. /* ... */
  179. } __attribute__((packed));
  180. /* Table 2-2: Continuous Sampling Frequency */
  181. struct usb_audio_format_continuous_sampling_frequency {
  182. /* ... */
  183. uint32_t tLowerSamFreq : 24;
  184. uint32_t tUpperSamFreq : 24;
  185. } __attribute__((packed));
  186. /* Table 2-3: Discrete Number of Sampling Frequencies */
  187. struct usb_audio_format_discrete_sampling_frequency {
  188. /* ... */
  189. uint32_t tSamFreq : 24;
  190. } __attribute__((packed));
  191. /* Table 2-1: Type I Format Type Descriptor (1 sampling frequency)
  192. *
  193. * This structure is a convenience covering the (common) case where
  194. * only 1 discrete sampling frequency is used
  195. */
  196. struct usb_audio_format_type1_descriptor_1freq {
  197. struct usb_audio_format_type1_descriptor_head head;
  198. struct usb_audio_format_discrete_sampling_frequency freqs[1];
  199. } __attribute__((packed));
  200. #endif
  201. /**@}*/