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  .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 
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 
79 
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 
94 
96  },
97 
98  .Audio_ControlInterface_SPC = {
99  .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface},
101 
102  .ACSpecification = VERSION_BCD(01.00),
103  .TotalLength = (sizeof(USB_Audio_Descriptor_Interface_AC_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},
114 
115  .TerminalID = 0x01,
117  .AssociatedOutputTerminal = 0x00,
118 
119  .TotalChannels = 2,
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},
129 
130  .TerminalID = 0x02,
132  .AssociatedInputTerminal = 0x00,
133 
134  .SourceID = 0x01,
135 
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 
150 
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 
165 
167  },
168 
169  .Audio_StreamInterface_SPC = {
170  .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AS_t), .Type = DTYPE_CSInterface},
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},
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 
210  .PollingIntervalMS = 0x01
211  },
212 
213  .Refresh = 0,
214  .SyncEndpointNumber = 0
215  },
216 
217  .Audio_StreamEndpoint_SPC = {
218  .Header =
221 
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,
238 };
240 
245 uint8_t ManufacturerString[] = {
246  USB_STRING_LEN(3),
247  DTYPE_String,
248  WBVAL('N'),
249  WBVAL('X'),
250  WBVAL('P'),
251 };
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 };
287 
294 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
295  const uint8_t wIndex,
296  const void * *const DescriptorAddress)
297 {
298  const uint8_t DescriptorType = (wValue >> 8);
299  const uint8_t DescriptorNumber = (wValue & 0xFF);
300 
301  const void *Address = NULL;
302  uint16_t Size = NO_DESCRIPTOR;
303 
304  switch (DescriptorType) {
305  case DTYPE_Device:
306  Address = &DeviceDescriptor;
307  Size = sizeof(USB_Descriptor_Device_t);
308  break;
309 
310  case DTYPE_Configuration:
311  Address = &ConfigurationDescriptor;
312  Size = sizeof(USB_Descriptor_Configuration_t);
313  break;
314 
315  case DTYPE_String:
316  switch (DescriptorNumber) {
317  case 0x00:
318  Address = LanguageStringPtr;
319  Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
320  break;
321 
322  case 0x01:
323  Address = ManufacturerStringPtr;
324  Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
325  break;
326 
327  case 0x02:
328  Address = ProductStringPtr;
329  Size = pgm_read_byte(&ProductStringPtr->Header.Size);
330  break;
331  }
332 
333  break;
334  }
335 
336  *DescriptorAddress = Address;
337  return Size;
338 }