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 /* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
38  * the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
39  * This allows the host to track a device across insertions on different ports, allowing them to retain allocated
40  * resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices
41  * so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value
42  * from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and
43  * port location).
44  */
45 
46 /*****************************************************************************
47  * Private types/enumerations/variables
48  ****************************************************************************/
49 
50 /*****************************************************************************
51  * Public types/enumerations/variables
52  ****************************************************************************/
53 
60  .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
61 
62  .USBSpecification = VERSION_BCD(02.00),
63  .Class = USB_CSCP_NoDeviceClass,
64  .SubClass = USB_CSCP_NoDeviceSubclass,
65  .Protocol = USB_CSCP_NoDeviceProtocol,
66 
67  .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
68 
69  .VendorID = 0x1fc9, /* NXP */
70  .ProductID = 0x2045,
71  .ReleaseNumber = VERSION_BCD(01.00),
72 
73  .ManufacturerStrIndex = 0x01,
74  .ProductStrIndex = 0x02,
75  .SerialNumStrIndex = USE_INTERNAL_SERIAL,
76 
77  .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
78 };
79 
86  .Config = {
87  .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
88 
90  .TotalInterfaces = 1,
91 
92  .ConfigurationNumber = 1,
93  .ConfigurationStrIndex = NO_DESCRIPTOR,
94 
95  .ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
96 
97  .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
98  },
99 
100  .MS_Interface = {
101  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
102 
103  .InterfaceNumber = 0,
104  .AlternateSetting = 0,
105 
106  .TotalEndpoints = 2,
107 
111 
113  },
114 
115  .MS_DataInEndpoint = {
116  .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
117 
121  .PollingIntervalMS = 0x01
122  },
123 
124  .MS_DataOutEndpoint = {
125  .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
126 
130  .PollingIntervalMS = 0x01
131  },
132  .MS_Termination = 0x00
133 };
134 
139 uint8_t LanguageString[] = {
140  USB_STRING_LEN(1),
141  DTYPE_String,
143 };
145 
150 uint8_t ManufacturerString[] = {
151  USB_STRING_LEN(3),
152  DTYPE_String,
153  WBVAL('N'),
154  WBVAL('X'),
155  WBVAL('P'),
156 };
158 
163 uint8_t ProductString[] = {
164  USB_STRING_LEN(27),
165  DTYPE_String,
166  WBVAL('L'),
167  WBVAL('P'),
168  WBVAL('C'),
169  WBVAL('U'),
170  WBVAL('S'),
171  WBVAL('B'),
172  WBVAL('l'),
173  WBVAL('i'),
174  WBVAL('b'),
175  WBVAL(' '),
176  WBVAL('M'),
177  WBVAL('a'),
178  WBVAL('s'),
179  WBVAL('s'),
180  WBVAL(' '),
181  WBVAL('S'),
182  WBVAL('t'),
183  WBVAL('o'),
184  WBVAL('r'),
185  WBVAL('a'),
186  WBVAL('g'),
187  WBVAL('e'),
188  WBVAL(' '),
189  WBVAL('D'),
190  WBVAL('e'),
191  WBVAL('m'),
192  WBVAL('o'),
193 };
195 
196 /*****************************************************************************
197  * Private functions
198  ****************************************************************************/
199 
200 /*****************************************************************************
201  * Public functions
202  ****************************************************************************/
203 
210 uint16_t CALLBACK_USB_GetDescriptor(uint8_t corenum,
211  const uint16_t wValue,
212  const uint8_t wIndex,
213  const void * *const DescriptorAddress)
214 {
215  const uint8_t DescriptorType = (wValue >> 8);
216  const uint8_t DescriptorNumber = (wValue & 0xFF);
217 
218  const void *Address = NULL;
219  uint16_t Size = NO_DESCRIPTOR;
220 
221  switch (DescriptorType) {
222  case DTYPE_Device:
223  Address = &DeviceDescriptor;
224  Size = sizeof(USB_Descriptor_Device_t);
225  break;
226 
227  case DTYPE_Configuration:
228  Address = &ConfigurationDescriptor;
229  Size = sizeof(USB_Descriptor_Configuration_t);
230  break;
231 
232  case DTYPE_String:
233  switch (DescriptorNumber) {
234  case 0x00:
235  Address = LanguageStringPtr;
236  Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
237  break;
238 
239  case 0x01:
240  Address = ManufacturerStringPtr;
241  Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
242  break;
243 
244  case 0x02:
245  Address = ProductStringPtr;
246  Size = pgm_read_byte(&ProductStringPtr->Header.Size);
247  break;
248  }
249 
250  break;
251  }
252 
253  *DescriptorAddress = Address;
254  return Size;
255 }