LPCOpen Platform
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 
43 {
44  .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
45 
46  .USBSpecification = VERSION_BCD(02.00),
47  .Class = USB_CSCP_NoDeviceClass,
48  .SubClass = USB_CSCP_NoDeviceSubclass,
49  .Protocol = USB_CSCP_NoDeviceProtocol,
50 
51  .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
52 
53  .VendorID = 0x1fc9,
54  .ProductID = 0x2047,
55  .ReleaseNumber = VERSION_BCD(00.02),
56 
57  .ManufacturerStrIndex = 0x01,
58  .ProductStrIndex = 0x02,
59  .SerialNumStrIndex = NO_DESCRIPTOR,
60 
61  .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
62 };
63 
70 {
71  .Config =
72  {
73  .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
74 
75  .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t) - 1, // termination byte not included in size
76  .TotalInterfaces = 2,
77 
78  .ConfigurationNumber = 1,
79  .ConfigurationStrIndex = NO_DESCRIPTOR,
80 
82 
84  },
85 
86  .Audio_ControlInterface =
87  {
88  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
89 
90  .InterfaceNumber = 0,
91  .AlternateSetting = 0,
92 
93  .TotalEndpoints = 0,
94 
98 
100  },
101 
102  .Audio_ControlInterface_SPC =
103  {
104  .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface},
106 
107  .ACSpecification = VERSION_BCD(01.00),
108  .TotalLength = (sizeof(USB_Audio_Descriptor_Interface_AC_t) +
111 
112  .InCollection = 1,
113  .InterfaceNumber = 1,
114  },
115 
116  .Audio_InputTerminal =
117  {
118  .Header = {.Size = sizeof(USB_Audio_Descriptor_InputTerminal_t), .Type = DTYPE_CSInterface},
120 
121  .TerminalID = 0x01,
123  .AssociatedOutputTerminal = 0x00,
124 
125  .TotalChannels = 1,
126  .ChannelConfig = 0,
127 
130  },
131 
132  .Audio_OutputTerminal =
133  {
134  .Header = {.Size = sizeof(USB_Audio_Descriptor_OutputTerminal_t), .Type = DTYPE_CSInterface},
136 
137  .TerminalID = 0x02,
139  .AssociatedInputTerminal = 0x00,
140 
141  .SourceID = 0x01,
142 
144  },
145 
146  .Audio_StreamInterface_Alt0 =
147  {
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  {
164  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
165 
166  .InterfaceNumber = 1,
167  .AlternateSetting = 1,
168 
169  .TotalEndpoints = 1,
170 
174 
176  },
177 
178  .Audio_StreamInterface_SPC =
179  {
180  .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AS_t), .Type = DTYPE_CSInterface},
182 
183  .TerminalLink = 0x02,
184 
185  .FrameDelay = 1,
186  .AudioFormat = 0x0001
187  },
188 
189  .Audio_AudioFormat =
190  {
191  .Header = {.Size = sizeof(USB_Audio_Descriptor_Format_t) +
192  sizeof(ConfigurationDescriptor.Audio_AudioFormatSampleRates),
193  .Type = DTYPE_CSInterface},
195 
196  .FormatType = 0x01,
197  .Channels = 0x01,
198 
199  .SubFrameSize = 0x02,
200  .BitResolution = 16,
201 
202  .TotalDiscreteSampleRates = (sizeof(ConfigurationDescriptor.Audio_AudioFormatSampleRates) / sizeof(USB_Audio_SampleFreq_t))
203  },
204 
205  .Audio_AudioFormatSampleRates =
206  {
207  AUDIO_SAMPLE_FREQ(8000),
208  AUDIO_SAMPLE_FREQ(11025),
209  AUDIO_SAMPLE_FREQ(22050),
210  AUDIO_SAMPLE_FREQ(44100),
211  AUDIO_SAMPLE_FREQ(48000),
212  },
213 
214  .Audio_StreamEndpoint =
215  {
216  .Endpoint =
217  {
218  .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
219 
223  .PollingIntervalMS = 0x01
224  },
225 
226  .Refresh = 0,
227  .SyncEndpointNumber = 0
228  },
229 
230  .Audio_StreamEndpoint_SPC =
231  {
232  .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Spc_t), .Type = DTYPE_CSEndpoint},
234 
236 
237  .LockDelayUnits = 0x00,
238  .LockDelay = 0x0000
239  },
240  .Audio_Termination = 0x00
241 };
242 
247 uint8_t LanguageString[] =
248 {
249  USB_STRING_LEN(1),
250  DTYPE_String,
252 };
254 
260 {
261  USB_STRING_LEN(3),
262  DTYPE_String,
263  WBVAL('N'),
264  WBVAL('X'),
265  WBVAL('P'),
266 };
268 
273 uint8_t ProductString[] =
274 {
275  USB_STRING_LEN(26),
276  DTYPE_String,
277  WBVAL('L'),
278  WBVAL('P'),
279  WBVAL('C'),
280  WBVAL('U'),
281  WBVAL('S'),
282  WBVAL('B'),
283  WBVAL('l'),
284  WBVAL('i'),
285  WBVAL('b'),
286  WBVAL(' '),
287  WBVAL('A'),
288  WBVAL('u'),
289  WBVAL('d'),
290  WBVAL('i'),
291  WBVAL('o'),
292  WBVAL(' '),
293  WBVAL('I'),
294  WBVAL('n'),
295  WBVAL('p'),
296  WBVAL('u'),
297  WBVAL('t'),
298  WBVAL(' '),
299  WBVAL('D'),
300  WBVAL('e'),
301  WBVAL('m'),
302  WBVAL('o'),
303 };
305 
312 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
313  const uint8_t wIndex,
314  const void** const DescriptorAddress)
315 {
316  const uint8_t DescriptorType = (wValue >> 8);
317  const uint8_t DescriptorNumber = (wValue & 0xFF);
318 
319  const void* Address = NULL;
320  uint16_t Size = NO_DESCRIPTOR;
321 
322  switch (DescriptorType)
323  {
324  case DTYPE_Device:
325  Address = &DeviceDescriptor;
326  Size = sizeof(USB_Descriptor_Device_t);
327  break;
328  case DTYPE_Configuration:
329  Address = &ConfigurationDescriptor;
330  Size = sizeof(USB_Descriptor_Configuration_t);
331  break;
332  case DTYPE_String:
333  switch (DescriptorNumber)
334  {
335  case 0x00:
336  Address = LanguageStringPtr;
337  Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
338  break;
339  case 0x01:
340  Address = ManufacturerStringPtr;
341  Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
342  break;
343  case 0x02:
344  Address = ProductStringPtr;
345  Size = pgm_read_byte(&ProductStringPtr->Header.Size);
346  break;
347  }
348 
349  break;
350  }
351 
352  *DescriptorAddress = Address;
353  return Size;
354 }