Massive corrections to the project documentation and code comments, thanks to Russian...
[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) +
195 sizeof(ConfigurationDescriptor.Audio_AudioFormatSampleRates),
196 .Type = DTYPE_CSInterface},
197 .Subtype = AUDIO_DSUBTYPE_CSInterface_FormatType,
198
199 .FormatType = 0x01,
200 .Channels = 0x01,
201
202 .SubFrameSize = 0x02,
203 .BitResolution = 16,
204 .TotalDiscreteSampleRates = 1,
205 },
206
207 .Audio_AudioFormatSampleRates =
208 {
209 AUDIO_SAMPLE_FREQ(AUDIO_SAMPLE_FREQUENCY)
210 },
211
212 .Audio_StreamEndpoint =
213 {
214 .Endpoint =
215 {
216 .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
217
218 .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | AUDIO_STREAM_EPNUM),
219 .Attributes = (EP_TYPE_ISOCHRONOUS | ENDPOINT_ATTR_SYNC | ENDPOINT_USAGE_DATA),
220 .EndpointSize = AUDIO_STREAM_EPSIZE,
221 .PollingIntervalMS = 0x01
222 },
223
224 .Refresh = 0,
225 .SyncEndpointNumber = 0
226 },
227
228 .Audio_StreamEndpoint_SPC =
229 {
230 .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Spc_t), .Type = DTYPE_CSEndpoint},
231 .Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
232
233 .Attributes = AUDIO_EP_ACCEPTS_SMALL_PACKETS,
234
235 .LockDelayUnits = 0x00,
236 .LockDelay = 0x0000
237 }
238 };
239
240 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
241 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
242 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
243 */
244 const USB_Descriptor_String_t PROGMEM LanguageString =
245 {
246 .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
247
248 .UnicodeString = {LANGUAGE_ID_ENG}
249 };
250
251 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
252 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
253 * Descriptor.
254 */
255 const USB_Descriptor_String_t PROGMEM ManufacturerString =
256 {
257 .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
258
259 .UnicodeString = L"Dean Camera"
260 };
261
262 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
263 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
264 * Descriptor.
265 */
266 const USB_Descriptor_String_t PROGMEM ProductString =
267 {
268 .Header = {.Size = USB_STRING_LEN(18), .Type = DTYPE_String},
269
270 .UnicodeString = L"LUFA Audio In Demo"
271 };
272
273 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
274 * documentation) by the application code so that the address and size of a requested descriptor can be given
275 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
276 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
277 * USB host.
278 */
279 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
280 const uint8_t wIndex,
281 const void** const DescriptorAddress)
282 {
283 const uint8_t DescriptorType = (wValue >> 8);
284 const uint8_t DescriptorNumber = (wValue & 0xFF);
285
286 const void* Address = NULL;
287 uint16_t Size = NO_DESCRIPTOR;
288
289 switch (DescriptorType)
290 {
291 case DTYPE_Device:
292 Address = &DeviceDescriptor;
293 Size = sizeof(USB_Descriptor_Device_t);
294 break;
295 case DTYPE_Configuration:
296 Address = &ConfigurationDescriptor;
297 Size = sizeof(USB_Descriptor_Configuration_t);
298 break;
299 case DTYPE_String:
300 switch (DescriptorNumber)
301 {
302 case 0x00:
303 Address = &LanguageString;
304 Size = pgm_read_byte(&LanguageString.Header.Size);
305 break;
306 case 0x01:
307 Address = &ManufacturerString;
308 Size = pgm_read_byte(&ManufacturerString.Header.Size);
309 break;
310 case 0x02:
311 Address = &ProductString;
312 Size = pgm_read_byte(&ProductString.Header.Size);
313 break;
314 }
315
316 break;
317 }
318
319 *DescriptorAddress = Address;
320 return Size;
321 }
322