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