| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Descriptors.c
Go to the documentation of this file.
1 /*
2 * @brief USB Device Descriptors, for library use when in USB device mode. Descriptors are special
3 * computer-readable structures which the host requests upon device enumeration, to determine
4 * the device's capabilities and functions
5 *
6 * @note
7 * Copyright(C) NXP Semiconductors, 2012
8 * Copyright(C) Dean Camera, 2011, 2012
9 * All rights reserved.
10 *
11 * @par
12 * Software that is described herein is for illustrative purposes only
13 * which provides customers with programming information regarding the
14 * LPC products. This software is supplied "AS IS" without any warranties of
15 * any kind, and NXP Semiconductors and its licensor disclaim any and
16 * all warranties, express or implied, including all implied warranties of
17 * merchantability, fitness for a particular purpose and non-infringement of
18 * intellectual property rights. NXP Semiconductors assumes no responsibility
19 * or liability for the use of the software, conveys no license or rights under any
20 * patent, copyright, mask work right, or any other intellectual property rights in
21 * or to any products. NXP Semiconductors reserves the right to make changes
22 * in the software without notification. NXP Semiconductors also makes no
23 * representation or warranty that such application will be suitable for the
24 * specified use without further testing or modification.
25 *
26 * @par
27 * Permission to use, copy, modify, and distribute this software and its
28 * documentation is hereby granted, under NXP Semiconductors' and its
29 * licensor's relevant copyrights in the software, without fee, provided that it
30 * is used in conjunction with NXP Semiconductors microcontrollers. This
31 * copyright, permission, and disclaimer notice must appear in all copies of
32 * this code.
33 */
34
35 #include "Descriptors.h"
36
42 USB_Descriptor_Device_t DeviceDescriptor = {
43 .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
44
45 .USBSpecification = VERSION_BCD(02.00),
46 .Class = USB_CSCP_NoDeviceClass,
47 .SubClass = USB_CSCP_NoDeviceSubclass,
48 .Protocol = USB_CSCP_NoDeviceProtocol,
49
50 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
51
52 .VendorID = 0x1fc9, /* NXP */
53 .ProductID = 0x2046,
54 .ReleaseNumber = VERSION_BCD(00.01),
55
56 .ManufacturerStrIndex = 0x01,
57 .ProductStrIndex = 0x02,
58 .SerialNumStrIndex = NO_DESCRIPTOR,
59
60 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
61 };
62
68 USB_Descriptor_Configuration_t ConfigurationDescriptor = {
69 .Config = {
70 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
71
72 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t) - 1, // termination byte not included in size
73 .TotalInterfaces = 2,
74
75 .ConfigurationNumber = 1,
76 .ConfigurationStrIndex = NO_DESCRIPTOR,
77
78 .ConfigAttributes = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
79
80 .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
81 },
82
83 .Audio_ControlInterface = {
84 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
85
86 .InterfaceNumber = 0,
87 .AlternateSetting = 0,
88
89 .TotalEndpoints = 0,
90
91 .Class = AUDIO_CSCP_AudioClass,
92 .SubClass = AUDIO_CSCP_ControlSubclass,
93 .Protocol = AUDIO_CSCP_ControlProtocol,
94
95 .InterfaceStrIndex = NO_DESCRIPTOR
96 },
97
98 .Audio_ControlInterface_SPC = {
99 .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface},
100 .Subtype = AUDIO_DSUBTYPE_CSInterface_Header,
101
102 .ACSpecification = VERSION_BCD(01.00),
103 .TotalLength = (sizeof(USB_Audio_Descriptor_Interface_AC_t) +
104 sizeof(USB_Audio_Descriptor_InputTerminal_t) +
105 sizeof(USB_Audio_Descriptor_OutputTerminal_t)),
106
107 .InCollection = 1,
108 .InterfaceNumber = 1,
109 },
110
111 .Audio_InputTerminal = {
112 .Header = {.Size = sizeof(USB_Audio_Descriptor_InputTerminal_t), .Type = DTYPE_CSInterface},
113 .Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
114
115 .TerminalID = 0x01,
116 .TerminalType = AUDIO_TERMINAL_STREAMING,
117 .AssociatedOutputTerminal = 0x00,
118
119 .TotalChannels = 2,
120 .ChannelConfig = (AUDIO_CHANNEL_LEFT_FRONT | AUDIO_CHANNEL_RIGHT_FRONT),
121
122 .ChannelStrIndex = NO_DESCRIPTOR,
123 .TerminalStrIndex = NO_DESCRIPTOR
124 },
125
126 .Audio_OutputTerminal = {
127 .Header = {.Size = sizeof(USB_Audio_Descriptor_OutputTerminal_t), .Type = DTYPE_CSInterface},
128 .Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
129
130 .TerminalID = 0x02,
131 .TerminalType = AUDIO_TERMINAL_OUT_SPEAKER,
132 .AssociatedInputTerminal = 0x00,
133
134 .SourceID = 0x01,
135
136 .TerminalStrIndex = NO_DESCRIPTOR
137 },
138
139 .Audio_StreamInterface_Alt0 = {
140 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
141
142 .InterfaceNumber = 1,
143 .AlternateSetting = 0,
144
145 .TotalEndpoints = 0,
146
147 .Class = AUDIO_CSCP_AudioClass,
148 .SubClass = AUDIO_CSCP_AudioStreamingSubclass,
149 .Protocol = AUDIO_CSCP_StreamingProtocol,
150
151 .InterfaceStrIndex = NO_DESCRIPTOR
152 },
153
154 .Audio_StreamInterface_Alt1 = {
155 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
156
157 .InterfaceNumber = 1,
158 .AlternateSetting = 1,
159
160 .TotalEndpoints = 1,
161
162 .Class = AUDIO_CSCP_AudioClass,
163 .SubClass = AUDIO_CSCP_AudioStreamingSubclass,
164 .Protocol = AUDIO_CSCP_StreamingProtocol,
165
166 .InterfaceStrIndex = NO_DESCRIPTOR
167 },
168
169 .Audio_StreamInterface_SPC = {
170 .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AS_t), .Type = DTYPE_CSInterface},
171 .Subtype = AUDIO_DSUBTYPE_CSInterface_General,
172
173 .TerminalLink = 0x01,
174
175 .FrameDelay = 1,
176 .AudioFormat = 0x0001
177 },
178
179 .Audio_AudioFormat = {
180 .Header = {.Size = sizeof(USB_Audio_Descriptor_Format_t) +
181 sizeof(ConfigurationDescriptor.Audio_AudioFormatSampleRates),
182 .Type = DTYPE_CSInterface},
183 .Subtype = AUDIO_DSUBTYPE_CSInterface_FormatType,
184
185 .FormatType = 0x01,
186 .Channels = 0x02,
187
188 .SubFrameSize = 0x02,
189 .BitResolution = 16,
190
191 .TotalDiscreteSampleRates =
192 (sizeof(ConfigurationDescriptor.Audio_AudioFormatSampleRates) / sizeof(USB_Audio_SampleFreq_t)),
193 },
194
195 .Audio_AudioFormatSampleRates = {
196 AUDIO_SAMPLE_FREQ(8000),
197 AUDIO_SAMPLE_FREQ(11025),
198 AUDIO_SAMPLE_FREQ(22050),
199 AUDIO_SAMPLE_FREQ(44100),
200 AUDIO_SAMPLE_FREQ(48000),
201 },
202
203 .Audio_StreamEndpoint = {
204 .Endpoint = {
205 .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
206
207 .EndpointAddress = (ENDPOINT_DIR_OUT | AUDIO_STREAM_EPNUM),
208 .Attributes = (EP_TYPE_ISOCHRONOUS | ENDPOINT_ATTR_SYNC | ENDPOINT_USAGE_DATA),
209 .EndpointSize = AUDIO_STREAM_EPSIZE,
210 .PollingIntervalMS = 0x01
211 },
212
213 .Refresh = 0,
214 .SyncEndpointNumber = 0
215 },
216
217 .Audio_StreamEndpoint_SPC = {
218 .Header =
219 {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Spc_t), .Type = DTYPE_CSEndpoint},
220 .Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
221
222 .Attributes = (AUDIO_EP_ACCEPTS_SMALL_PACKETS | AUDIO_EP_SAMPLE_FREQ_CONTROL),
223
224 .LockDelayUnits = 0x00,
225 .LockDelay = 0x0000
226 },
227 .Audio_Termination = 0x00
228 };
229
234 uint8_t LanguageString[] = {
235 USB_STRING_LEN(1),
236 DTYPE_String,
237 WBVAL(LANGUAGE_ID_ENG),
238 };
239 USB_Descriptor_String_t *LanguageStringPtr = (USB_Descriptor_String_t *) LanguageString;
240
245 uint8_t ManufacturerString[] = {
246 USB_STRING_LEN(3),
247 DTYPE_String,
248 WBVAL('N'),
249 WBVAL('X'),
250 WBVAL('P'),
251 };
252 USB_Descriptor_String_t *ManufacturerStringPtr = (USB_Descriptor_String_t *) ManufacturerString;
253
258 uint8_t ProductString[] = {
259 USB_STRING_LEN(24),
260 DTYPE_String,
261 WBVAL('L'),
262 WBVAL('P'),
263 WBVAL('C'),
264 WBVAL('U'),
265 WBVAL('S'),
266 WBVAL('B'),
267 WBVAL('l'),
268 WBVAL('i'),
269 WBVAL('b'),
270 WBVAL(' '),
271 WBVAL('A'),
272 WBVAL('u'),
273 WBVAL('d'),
274 WBVAL('i'),
275 WBVAL('o'),
276 WBVAL(' '),
277 WBVAL('O'),
278 WBVAL('u'),
279 WBVAL('t'),
280 WBVAL(' '),
281 WBVAL('D'),
282 WBVAL('e'),
283 WBVAL('m'),
284 WBVAL('o'),
285 };
286 USB_Descriptor_String_t *ProductStringPtr = (USB_Descriptor_String_t *) ProductString;
287
294 uint16_t CALLBACK_USB_GetDescriptor(uint8_t corenum,
295 const uint16_t wValue,
296 const uint8_t wIndex,
297 const void * *const DescriptorAddress)
298 {
299 const uint8_t DescriptorType = (wValue >> 8);
300 const uint8_t DescriptorNumber = (wValue & 0xFF);
301
302 const void *Address = NULL;
303 uint16_t Size = NO_DESCRIPTOR;
304
305 switch (DescriptorType) {
306 case DTYPE_Device:
307 Address = &DeviceDescriptor;
308 Size = sizeof(USB_Descriptor_Device_t);
309 break;
310
311 case DTYPE_Configuration:
312 Address = &ConfigurationDescriptor;
313 Size = sizeof(USB_Descriptor_Configuration_t);
314 break;
315
316 case DTYPE_String:
317 switch (DescriptorNumber) {
318 case 0x00:
319 Address = LanguageStringPtr;
320 Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
321 break;
322
323 case 0x01:
324 Address = ManufacturerStringPtr;
325 Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
326 break;
327
328 case 0x02:
329 Address = ProductStringPtr;
330 Size = pgm_read_byte(&ProductStringPtr->Header.Size);
331 break;
332 }
333
334 break;
335 }
336
337 *DescriptorAddress = Address;
338 return Size;
339 }