Fix AudioOutput and AudioInput class driver demos' descriptors -- incorrect value...
[pub/USBasp.git] / Demos / Device / ClassDriver / AudioInput / Descriptors.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
46 {
47 .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
48
49 .USBSpecification = VERSION_BCD(02.00),
50 .Class = 0x00,
51 .SubClass = 0x00,
52 .Protocol = 0x00,
53
54 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
55
56 .VendorID = 0x03EB,
57 .ProductID = 0x2047,
58 .ReleaseNumber = 0x0000,
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 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 .AudioControlInterface =
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 = 0x01,
99 .SubClass = 0x01,
100 .Protocol = 0x00,
101
102 .InterfaceStrIndex = NO_DESCRIPTOR
103 },
104
105 .AudioControlInterface_SPC =
106 {
107 .Header = {.Size = sizeof(USB_Audio_Interface_AC_t), .Type = DTYPE_AudioInterface},
108 .Subtype = DSUBTYPE_Header,
109
110 .ACSpecification = VERSION_BCD(01.00),
111 .TotalLength = (sizeof(USB_Audio_Interface_AC_t) +
112 sizeof(USB_Audio_InputTerminal_t) +
113 sizeof(USB_Audio_OutputTerminal_t)),
114
115 .InCollection = 1,
116 .InterfaceNumbers = {1},
117 },
118
119 .InputTerminal =
120 {
121 .Header = {.Size = sizeof(USB_Audio_InputTerminal_t), .Type = DTYPE_AudioInterface},
122 .Subtype = DSUBTYPE_InputTerminal,
123
124 .TerminalID = 0x01,
125 .TerminalType = 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 .OutputTerminal =
136 {
137 .Header = {.Size = sizeof(USB_Audio_OutputTerminal_t), .Type = DTYPE_AudioInterface},
138 .Subtype = DSUBTYPE_OutputTerminal,
139
140 .TerminalID = 0x02,
141 .TerminalType = TERMINAL_STREAMING,
142 .AssociatedInputTerminal = 0x00,
143
144 .SourceID = 0x01,
145
146 .TerminalStrIndex = NO_DESCRIPTOR
147 },
148
149 .AudioStreamInterface_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 = 0x01,
159 .SubClass = 0x02,
160 .Protocol = 0x00,
161
162 .InterfaceStrIndex = NO_DESCRIPTOR
163 },
164
165 .AudioStreamInterface_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 = 0x01,
175 .SubClass = 0x02,
176 .Protocol = 0x00,
177
178 .InterfaceStrIndex = NO_DESCRIPTOR
179 },
180
181 .AudioStreamInterface_SPC =
182 {
183 .Header = {.Size = sizeof(USB_Audio_Interface_AS_t), .Type = DTYPE_AudioInterface},
184 .Subtype = DSUBTYPE_General,
185
186 .TerminalLink = 0x02,
187
188 .FrameDelay = 1,
189 .AudioFormat = 0x0001
190 },
191
192 .AudioFormat =
193 {
194 .Header = {.Size = sizeof(USB_Audio_Format_t), .Type = DTYPE_AudioInterface},
195 .Subtype = DSUBTYPE_Format,
196
197 .FormatType = 0x01,
198 .Channels = 0x01,
199
200 .SubFrameSize = 0x02,
201 .BitResolution = 16,
202 .SampleFrequencyType = AUDIO_TOTAL_SAMPLE_RATES,
203
204 .SampleFrequencies = {AUDIO_SAMPLE_FREQ(AUDIO_SAMPLE_FREQUENCY)}
205 },
206
207 .AudioEndpoint =
208 {
209 .Endpoint =
210 {
211 .Header = {.Size = sizeof(USB_Audio_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
212
213 .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | AUDIO_STREAM_EPNUM),
214 .Attributes = (EP_TYPE_ISOCHRONOUS | ENDPOINT_ATTR_SYNC | ENDPOINT_USAGE_DATA),
215 .EndpointSize = AUDIO_STREAM_EPSIZE,
216 .PollingIntervalMS = 1
217 },
218
219 .Refresh = 0,
220 .SyncEndpointNumber = 0
221 },
222
223 .AudioEndpoint_SPC =
224 {
225 .Header = {.Size = sizeof(USB_Audio_StreamEndpoint_Spc_t), .Type = DTYPE_AudioEndpoint},
226 .Subtype = DSUBTYPE_General,
227
228 .Attributes = 0x00,
229
230 .LockDelayUnits = 0x00,
231 .LockDelay = 0x0000
232 }
233 };
234
235 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
236 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
237 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
238 */
239 USB_Descriptor_String_t PROGMEM LanguageString =
240 {
241 .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
242
243 .UnicodeString = {LANGUAGE_ID_ENG}
244 };
245
246 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
247 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
248 * Descriptor.
249 */
250 USB_Descriptor_String_t PROGMEM ManufacturerString =
251 {
252 .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
253
254 .UnicodeString = L"Dean Camera"
255 };
256
257 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
258 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
259 * Descriptor.
260 */
261 USB_Descriptor_String_t PROGMEM ProductString =
262 {
263 .Header = {.Size = USB_STRING_LEN(18), .Type = DTYPE_String},
264
265 .UnicodeString = L"LUFA Audio In Demo"
266 };
267
268 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
269 * documentation) by the application code so that the address and size of a requested descriptor can be given
270 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
271 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
272 * USB host.
273 */
274 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)
275 {
276 const uint8_t DescriptorType = (wValue >> 8);
277 const uint8_t DescriptorNumber = (wValue & 0xFF);
278
279 void* Address = NULL;
280 uint16_t Size = NO_DESCRIPTOR;
281
282 switch (DescriptorType)
283 {
284 case DTYPE_Device:
285 Address = (void*)&DeviceDescriptor;
286 Size = sizeof(USB_Descriptor_Device_t);
287 break;
288 case DTYPE_Configuration:
289 Address = (void*)&ConfigurationDescriptor;
290 Size = sizeof(USB_Descriptor_Configuration_t);
291 break;
292 case DTYPE_String:
293 switch (DescriptorNumber)
294 {
295 case 0x00:
296 Address = (void*)&LanguageString;
297 Size = pgm_read_byte(&LanguageString.Header.Size);
298 break;
299 case 0x01:
300 Address = (void*)&ManufacturerString;
301 Size = pgm_read_byte(&ManufacturerString.Header.Size);
302 break;
303 case 0x02:
304 Address = (void*)&ProductString;
305 Size = pgm_read_byte(&ProductString.Header.Size);
306 break;
307 }
308
309 break;
310 }
311
312 *DescriptorAddress = Address;
313 return Size;
314 }