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 
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 
52  .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
53 
54  .USBSpecification = VERSION_BCD(02.00),
55  .Class = USB_CSCP_NoDeviceClass,
56  .SubClass = USB_CSCP_NoDeviceSubclass,
57  .Protocol = USB_CSCP_NoDeviceProtocol,
58 
59  .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
60 
61  .VendorID = 0x1fc9, /* NXP */
62  .ProductID = 0x2045,
63  .ReleaseNumber = VERSION_BCD(01.00),
64 
65  .ManufacturerStrIndex = 0x01,
66  .ProductStrIndex = 0x02,
67  .SerialNumStrIndex = USE_INTERNAL_SERIAL,
68 
69  .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
70 };
71 
78  .Config = {
79  .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
80 
82  .TotalInterfaces = 1,
83 
84  .ConfigurationNumber = 1,
85  .ConfigurationStrIndex = NO_DESCRIPTOR,
86 
87  .ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
88 
89  .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
90  },
91 
92  .MS_Interface = {
93  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
94 
95  .InterfaceNumber = 0,
96  .AlternateSetting = 0,
97 
98  .TotalEndpoints = 2,
99 
103 
105  },
106 
107  .MS_DataInEndpoint = {
108  .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
109 
113  .PollingIntervalMS = 0x01
114  },
115 
116  .MS_DataOutEndpoint = {
117  .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
118 
122  .PollingIntervalMS = 0x01
123  },
124  .MS_Termination = 0x00
125 };
126 
131 uint8_t LanguageString[] = {
132  USB_STRING_LEN(1),
133  DTYPE_String,
135 };
137 
142 uint8_t ManufacturerString[] = {
143  USB_STRING_LEN(3),
144  DTYPE_String,
145  WBVAL('N'),
146  WBVAL('X'),
147  WBVAL('P'),
148 };
150 
155 uint8_t ProductString[] = {
156  USB_STRING_LEN(27),
157  DTYPE_String,
158  WBVAL('L'),
159  WBVAL('P'),
160  WBVAL('C'),
161  WBVAL('U'),
162  WBVAL('S'),
163  WBVAL('B'),
164  WBVAL('l'),
165  WBVAL('i'),
166  WBVAL('b'),
167  WBVAL(' '),
168  WBVAL('M'),
169  WBVAL('a'),
170  WBVAL('s'),
171  WBVAL('s'),
172  WBVAL(' '),
173  WBVAL('S'),
174  WBVAL('t'),
175  WBVAL('o'),
176  WBVAL('r'),
177  WBVAL('a'),
178  WBVAL('g'),
179  WBVAL('e'),
180  WBVAL(' '),
181  WBVAL('D'),
182  WBVAL('e'),
183  WBVAL('m'),
184  WBVAL('o'),
185 };
187 
194 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
195  const uint8_t wIndex,
196  const void * *const DescriptorAddress)
197 {
198  const uint8_t DescriptorType = (wValue >> 8);
199  const uint8_t DescriptorNumber = (wValue & 0xFF);
200 
201  const void *Address = NULL;
202  uint16_t Size = NO_DESCRIPTOR;
203 
204  switch (DescriptorType) {
205  case DTYPE_Device:
206  Address = &DeviceDescriptor;
207  Size = sizeof(USB_Descriptor_Device_t);
208  break;
209 
210  case DTYPE_Configuration:
211  Address = &ConfigurationDescriptor;
212  Size = sizeof(USB_Descriptor_Configuration_t);
213  break;
214 
215  case DTYPE_String:
216  switch (DescriptorNumber) {
217  case 0x00:
218  Address = LanguageStringPtr;
219  Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
220  break;
221 
222  case 0x01:
223  Address = ManufacturerStringPtr;
224  Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
225  break;
226 
227  case 0x02:
228  Address = ProductStringPtr;
229  Size = pgm_read_byte(&ProductStringPtr->Header.Size);
230  break;
231  }
232 
233  break;
234  }
235 
236  *DescriptorAddress = Address;
237  return Size;
238 }