LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 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 
37 /*****************************************************************************
38  * Private types/enumerations/variables
39  ****************************************************************************/
40 
41 /*****************************************************************************
42  * Public types/enumerations/variables
43  ****************************************************************************/
44 
51  .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
52 
53  .USBSpecification = VERSION_BCD(02.00),
54  .Class = USB_CSCP_NoDeviceClass,
55  .SubClass = USB_CSCP_NoDeviceSubclass,
56  .Protocol = USB_CSCP_NoDeviceProtocol,
57 
58  .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
59 
60  .VendorID = 0x1fc9,
61  .ProductID = 0x2047,
62  .ReleaseNumber = VERSION_BCD(00.02),
63 
64  .ManufacturerStrIndex = 0x01,
65  .ProductStrIndex = 0x02,
66  .SerialNumStrIndex = NO_DESCRIPTOR,
67 
68  .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
69 };
70 
77  .Config = {
78  .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
79 
80  .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t) - 1, // termination byte not included in size
81  .TotalInterfaces = 2,
82 
83  .ConfigurationNumber = 1,
84  .ConfigurationStrIndex = NO_DESCRIPTOR,
85 
87 
89  },
90 
91  .Audio_ControlInterface = {
92  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
93 
94  .InterfaceNumber = 0,
95  .AlternateSetting = 0,
96 
97  .TotalEndpoints = 0,
98 
102 
104  },
105 
106  .Audio_ControlInterface_SPC = {
107  .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface},
109 
110  .ACSpecification = VERSION_BCD(01.00),
111  .TotalLength = (sizeof(USB_Audio_Descriptor_Interface_AC_t) +
114 
115  .InCollection = 1,
116  .InterfaceNumber = 1,
117  },
118 
119  .Audio_InputTerminal = {
120  .Header = {.Size = sizeof(USB_Audio_Descriptor_InputTerminal_t), .Type = DTYPE_CSInterface},
122 
123  .TerminalID = 0x01,
125  .AssociatedOutputTerminal = 0x00,
126 
127  .TotalChannels = 1,
128  .ChannelConfig = 0,
129 
132  },
133 
134  .Audio_OutputTerminal = {
135  .Header = {.Size = sizeof(USB_Audio_Descriptor_OutputTerminal_t), .Type = DTYPE_CSInterface},
137 
138  .TerminalID = 0x02,
140  .AssociatedInputTerminal = 0x00,
141 
142  .SourceID = 0x01,
143 
145  },
146 
147  .Audio_StreamInterface_Alt0 = {
148  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
149 
150  .InterfaceNumber = 1,
151  .AlternateSetting = 0,
152 
153  .TotalEndpoints = 0,
154 
158 
160  },
161 
162  .Audio_StreamInterface_Alt1 = {
163  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
164 
165  .InterfaceNumber = 1,
166  .AlternateSetting = 1,
167 
168  .TotalEndpoints = 1,
169 
173 
175  },
176 
177  .Audio_StreamInterface_SPC = {
178  .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AS_t), .Type = DTYPE_CSInterface},
180 
181  .TerminalLink = 0x02,
182 
183  .FrameDelay = 1,
184  .AudioFormat = 0x0001
185  },
186 
187  .Audio_AudioFormat = {
188  .Header = {.Size = sizeof(USB_Audio_Descriptor_Format_t) +
189  sizeof(ConfigurationDescriptor.Audio_AudioFormatSampleRates),
190  .Type = DTYPE_CSInterface},
192 
193  .FormatType = 0x01,
194  .Channels = 0x01,
195 
196  .SubFrameSize = 0x02,
197  .BitResolution = 16,
198 
199  .TotalDiscreteSampleRates =
200  (sizeof(ConfigurationDescriptor.Audio_AudioFormatSampleRates) / sizeof(USB_Audio_SampleFreq_t))
201  },
202 
203  .Audio_AudioFormatSampleRates = {
204  AUDIO_SAMPLE_FREQ(8000),
205  AUDIO_SAMPLE_FREQ(11025),
206  AUDIO_SAMPLE_FREQ(22050),
207  AUDIO_SAMPLE_FREQ(44100),
208  AUDIO_SAMPLE_FREQ(48000),
209  },
210 
211  .Audio_StreamEndpoint = {
212  .Endpoint = {
213  .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
214 
218  .PollingIntervalMS = 0x01
219  },
220 
221  .Refresh = 0,
222  .SyncEndpointNumber = 0
223  },
224 
225  .Audio_StreamEndpoint_SPC = {
226  .Header =
229 
231 
232  .LockDelayUnits = 0x00,
233  .LockDelay = 0x0000
234  },
235  .Audio_Termination = 0x00
236 };
237 
242 uint8_t LanguageString[] = {
243  USB_STRING_LEN(1),
244  DTYPE_String,
246 };
248 
253 uint8_t ManufacturerString[] = {
254  USB_STRING_LEN(3),
255  DTYPE_String,
256  WBVAL('N'),
257  WBVAL('X'),
258  WBVAL('P'),
259 };
261 
266 uint8_t ProductString[] = {
267  USB_STRING_LEN(26),
268  DTYPE_String,
269  WBVAL('L'),
270  WBVAL('P'),
271  WBVAL('C'),
272  WBVAL('U'),
273  WBVAL('S'),
274  WBVAL('B'),
275  WBVAL('l'),
276  WBVAL('i'),
277  WBVAL('b'),
278  WBVAL(' '),
279  WBVAL('A'),
280  WBVAL('u'),
281  WBVAL('d'),
282  WBVAL('i'),
283  WBVAL('o'),
284  WBVAL(' '),
285  WBVAL('I'),
286  WBVAL('n'),
287  WBVAL('p'),
288  WBVAL('u'),
289  WBVAL('t'),
290  WBVAL(' '),
291  WBVAL('D'),
292  WBVAL('e'),
293  WBVAL('m'),
294  WBVAL('o'),
295 };
297 
298 /*****************************************************************************
299  * Private functions
300  ****************************************************************************/
301 
302 /*****************************************************************************
303  * Public functions
304  ****************************************************************************/
305 
312 uint16_t CALLBACK_USB_GetDescriptor(uint8_t corenum,
313  const uint16_t wValue,
314  const uint8_t wIndex,
315  const void * *const DescriptorAddress)
316 {
317  const uint8_t DescriptorType = (wValue >> 8);
318  const uint8_t DescriptorNumber = (wValue & 0xFF);
319 
320  const void *Address = NULL;
321  uint16_t Size = NO_DESCRIPTOR;
322 
323  switch (DescriptorType) {
324  case DTYPE_Device:
325  Address = &DeviceDescriptor;
326  Size = sizeof(USB_Descriptor_Device_t);
327  break;
328 
329  case DTYPE_Configuration:
330  Address = &ConfigurationDescriptor;
331  Size = sizeof(USB_Descriptor_Configuration_t);
332  break;
333 
334  case DTYPE_String:
335  switch (DescriptorNumber) {
336  case 0x00:
337  Address = LanguageStringPtr;
338  Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
339  break;
340 
341  case 0x01:
342  Address = ManufacturerStringPtr;
343  Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
344  break;
345 
346  case 0x02:
347  Address = ProductStringPtr;
348  Size = pgm_read_byte(&ProductStringPtr->Header.Size);
349  break;
350  }
351 
352  break;
353  }
354 
355  *DescriptorAddress = Address;
356  return Size;
357 }