PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/avr/LUFA-130303/Demos/Device/ClassDriver/AudioInput/Descriptors.c

https://bitbucket.org/idnorton/raspberry-pi
C | 327 lines | 199 code | 66 blank | 62 comment | 2 complexity | adbe41c2b60c5fd6a68fdfb37213dada MD5 | raw file
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2013.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2013 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. *
  28. * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
  29. * computer-readable structures which the host requests upon device enumeration, to determine
  30. * the device's capabilities and functions.
  31. */
  32. #include "Descriptors.h"
  33. /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
  34. * device characteristics, including the supported USB version, control endpoint size and the
  35. * number of device configurations. The descriptor is read out by the USB host when the enumeration
  36. * process begins.
  37. */
  38. const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
  39. {
  40. .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
  41. .USBSpecification = VERSION_BCD(02.00),
  42. .Class = USB_CSCP_NoDeviceClass,
  43. .SubClass = USB_CSCP_NoDeviceSubclass,
  44. .Protocol = USB_CSCP_NoDeviceProtocol,
  45. .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
  46. .VendorID = 0x03EB,
  47. .ProductID = 0x2047,
  48. .ReleaseNumber = VERSION_BCD(00.02),
  49. .ManufacturerStrIndex = 0x01,
  50. .ProductStrIndex = 0x02,
  51. .SerialNumStrIndex = NO_DESCRIPTOR,
  52. .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
  53. };
  54. /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
  55. * of the device in one of its supported configurations, including information about any device interfaces
  56. * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
  57. * a configuration so that the host may correctly communicate with the USB device.
  58. */
  59. const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
  60. {
  61. .Config =
  62. {
  63. .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
  64. .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
  65. .TotalInterfaces = 2,
  66. .ConfigurationNumber = 1,
  67. .ConfigurationStrIndex = NO_DESCRIPTOR,
  68. .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
  69. .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
  70. },
  71. .Audio_ControlInterface =
  72. {
  73. .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
  74. .InterfaceNumber = 0,
  75. .AlternateSetting = 0,
  76. .TotalEndpoints = 0,
  77. .Class = AUDIO_CSCP_AudioClass,
  78. .SubClass = AUDIO_CSCP_ControlSubclass,
  79. .Protocol = AUDIO_CSCP_ControlProtocol,
  80. .InterfaceStrIndex = NO_DESCRIPTOR
  81. },
  82. .Audio_ControlInterface_SPC =
  83. {
  84. .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface},
  85. .Subtype = AUDIO_DSUBTYPE_CSInterface_Header,
  86. .ACSpecification = VERSION_BCD(01.00),
  87. .TotalLength = (sizeof(USB_Audio_Descriptor_Interface_AC_t) +
  88. sizeof(USB_Audio_Descriptor_InputTerminal_t) +
  89. sizeof(USB_Audio_Descriptor_OutputTerminal_t)),
  90. .InCollection = 1,
  91. .InterfaceNumber = 1,
  92. },
  93. .Audio_InputTerminal =
  94. {
  95. .Header = {.Size = sizeof(USB_Audio_Descriptor_InputTerminal_t), .Type = DTYPE_CSInterface},
  96. .Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
  97. .TerminalID = 0x01,
  98. .TerminalType = AUDIO_TERMINAL_IN_MIC,
  99. .AssociatedOutputTerminal = 0x00,
  100. .TotalChannels = 1,
  101. .ChannelConfig = 0,
  102. .ChannelStrIndex = NO_DESCRIPTOR,
  103. .TerminalStrIndex = NO_DESCRIPTOR
  104. },
  105. .Audio_OutputTerminal =
  106. {
  107. .Header = {.Size = sizeof(USB_Audio_Descriptor_OutputTerminal_t), .Type = DTYPE_CSInterface},
  108. .Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
  109. .TerminalID = 0x02,
  110. .TerminalType = AUDIO_TERMINAL_STREAMING,
  111. .AssociatedInputTerminal = 0x00,
  112. .SourceID = 0x01,
  113. .TerminalStrIndex = NO_DESCRIPTOR
  114. },
  115. .Audio_StreamInterface_Alt0 =
  116. {
  117. .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
  118. .InterfaceNumber = 1,
  119. .AlternateSetting = 0,
  120. .TotalEndpoints = 0,
  121. .Class = AUDIO_CSCP_AudioClass,
  122. .SubClass = AUDIO_CSCP_AudioStreamingSubclass,
  123. .Protocol = AUDIO_CSCP_StreamingProtocol,
  124. .InterfaceStrIndex = NO_DESCRIPTOR
  125. },
  126. .Audio_StreamInterface_Alt1 =
  127. {
  128. .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
  129. .InterfaceNumber = 1,
  130. .AlternateSetting = 1,
  131. .TotalEndpoints = 1,
  132. .Class = AUDIO_CSCP_AudioClass,
  133. .SubClass = AUDIO_CSCP_AudioStreamingSubclass,
  134. .Protocol = AUDIO_CSCP_StreamingProtocol,
  135. .InterfaceStrIndex = NO_DESCRIPTOR
  136. },
  137. .Audio_StreamInterface_SPC =
  138. {
  139. .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AS_t), .Type = DTYPE_CSInterface},
  140. .Subtype = AUDIO_DSUBTYPE_CSInterface_General,
  141. .TerminalLink = 0x02,
  142. .FrameDelay = 1,
  143. .AudioFormat = 0x0001
  144. },
  145. .Audio_AudioFormat =
  146. {
  147. .Header = {.Size = sizeof(USB_Audio_Descriptor_Format_t) +
  148. sizeof(ConfigurationDescriptor.Audio_AudioFormatSampleRates),
  149. .Type = DTYPE_CSInterface},
  150. .Subtype = AUDIO_DSUBTYPE_CSInterface_FormatType,
  151. .FormatType = 0x01,
  152. .Channels = 0x01,
  153. .SubFrameSize = 0x02,
  154. .BitResolution = 16,
  155. .TotalDiscreteSampleRates = (sizeof(ConfigurationDescriptor.Audio_AudioFormatSampleRates) / sizeof(USB_Audio_SampleFreq_t))
  156. },
  157. .Audio_AudioFormatSampleRates =
  158. {
  159. AUDIO_SAMPLE_FREQ(8000),
  160. AUDIO_SAMPLE_FREQ(11025),
  161. AUDIO_SAMPLE_FREQ(22050),
  162. AUDIO_SAMPLE_FREQ(44100),
  163. AUDIO_SAMPLE_FREQ(48000),
  164. },
  165. .Audio_StreamEndpoint =
  166. {
  167. .Endpoint =
  168. {
  169. .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
  170. .EndpointAddress = AUDIO_STREAM_EPADDR,
  171. .Attributes = (EP_TYPE_ISOCHRONOUS | ENDPOINT_ATTR_SYNC | ENDPOINT_USAGE_DATA),
  172. .EndpointSize = AUDIO_STREAM_EPSIZE,
  173. .PollingIntervalMS = 0x01
  174. },
  175. .Refresh = 0,
  176. .SyncEndpointNumber = 0
  177. },
  178. .Audio_StreamEndpoint_SPC =
  179. {
  180. .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Spc_t), .Type = DTYPE_CSEndpoint},
  181. .Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
  182. .Attributes = (AUDIO_EP_ACCEPTS_SMALL_PACKETS | AUDIO_EP_SAMPLE_FREQ_CONTROL),
  183. .LockDelayUnits = 0x00,
  184. .LockDelay = 0x0000
  185. }
  186. };
  187. /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
  188. * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
  189. * via the language ID table available at USB.org what languages the device supports for its string descriptors.
  190. */
  191. const USB_Descriptor_String_t PROGMEM LanguageString =
  192. {
  193. .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
  194. .UnicodeString = {LANGUAGE_ID_ENG}
  195. };
  196. /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
  197. * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
  198. * Descriptor.
  199. */
  200. const USB_Descriptor_String_t PROGMEM ManufacturerString =
  201. {
  202. .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
  203. .UnicodeString = L"Dean Camera"
  204. };
  205. /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
  206. * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
  207. * Descriptor.
  208. */
  209. const USB_Descriptor_String_t PROGMEM ProductString =
  210. {
  211. .Header = {.Size = USB_STRING_LEN(18), .Type = DTYPE_String},
  212. .UnicodeString = L"LUFA Audio In Demo"
  213. };
  214. /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
  215. * documentation) by the application code so that the address and size of a requested descriptor can be given
  216. * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
  217. * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
  218. * USB host.
  219. */
  220. uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
  221. const uint8_t wIndex,
  222. const void** const DescriptorAddress)
  223. {
  224. const uint8_t DescriptorType = (wValue >> 8);
  225. const uint8_t DescriptorNumber = (wValue & 0xFF);
  226. const void* Address = NULL;
  227. uint16_t Size = NO_DESCRIPTOR;
  228. switch (DescriptorType)
  229. {
  230. case DTYPE_Device:
  231. Address = &DeviceDescriptor;
  232. Size = sizeof(USB_Descriptor_Device_t);
  233. break;
  234. case DTYPE_Configuration:
  235. Address = &ConfigurationDescriptor;
  236. Size = sizeof(USB_Descriptor_Configuration_t);
  237. break;
  238. case DTYPE_String:
  239. switch (DescriptorNumber)
  240. {
  241. case 0x00:
  242. Address = &LanguageString;
  243. Size = pgm_read_byte(&LanguageString.Header.Size);
  244. break;
  245. case 0x01:
  246. Address = &ManufacturerString;
  247. Size = pgm_read_byte(&ManufacturerString.Header.Size);
  248. break;
  249. case 0x02:
  250. Address = &ProductString;
  251. Size = pgm_read_byte(&ProductString.Header.Size);
  252. break;
  253. }
  254. break;
  255. }
  256. *DescriptorAddress = Address;
  257. return Size;
  258. }