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