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 Mass Storage device descriptor module
3  *
4  * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
5  * computer-readable structures which the host requests upon device enumeration, to determine
6  * the device's capabilities and functions.
7  *
8  * @note
9  * Copyright(C) NXP Semiconductors, 2012
10  * All rights reserved.
11  *
12  * @par
13  * Software that is described herein is for illustrative purposes only
14  * which provides customers with programming information regarding the
15  * LPC products. This software is supplied "AS IS" without any warranties of
16  * any kind, and NXP Semiconductors and its licensor disclaim any and
17  * all warranties, express or implied, including all implied warranties of
18  * merchantability, fitness for a particular purpose and non-infringement of
19  * intellectual property rights. NXP Semiconductors assumes no responsibility
20  * or liability for the use of the software, conveys no license or rights under any
21  * patent, copyright, mask work right, or any other intellectual property rights in
22  * or to any products. NXP Semiconductors reserves the right to make changes
23  * in the software without notification. NXP Semiconductors also makes no
24  * representation or warranty that such application will be suitable for the
25  * specified use without further testing or modification.
26  *
27  * @par
28  * Permission to use, copy, modify, and distribute this software and its
29  * documentation is hereby granted, under NXP Semiconductors' and its
30  * licensor's relevant copyrights in the software, without fee, provided that it
31  * is used in conjunction with NXP Semiconductors microcontrollers. This
32  * copyright, permission, and disclaimer notice must appear in all copies of
33  * this code.
34  */
35 
36 #include "Descriptors.h"
37 
38 /*****************************************************************************
39  * Private types/enumerations/variables
40  ****************************************************************************/
41 
42 /* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
43  * the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
44  * This allows the host to track a device across insertions on different ports, allowing them to retain allocated
45  * resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices
46  * so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value
47  * from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and
48  * port location).
49  */
50 
57  .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
58 
59  .USBSpecification = VERSION_BCD(02.00),
60  .Class = USB_CSCP_NoDeviceClass,
61  .SubClass = USB_CSCP_NoDeviceSubclass,
62  .Protocol = USB_CSCP_NoDeviceProtocol,
63 
64  .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
65 
66  .VendorID = 0x1fc9, /* NXP */
67  .ProductID = 0x2045,
68  .ReleaseNumber = VERSION_BCD(01.00),
69 
70  .ManufacturerStrIndex = 0x01,
71  .ProductStrIndex = 0x02,
72  .SerialNumStrIndex = USE_INTERNAL_SERIAL,
73 
74  .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
75 };
76 
83  .Config = {
84  .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
85 
87  .TotalInterfaces = 1,
88 
89  .ConfigurationNumber = 1,
90  .ConfigurationStrIndex = NO_DESCRIPTOR,
91 
92  .ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
93 
94  .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
95  },
96 
97  .MS_Interface = {
98  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
99 
100  .InterfaceNumber = 0,
101  .AlternateSetting = 0,
102 
103  .TotalEndpoints = 2,
104 
108 
110  },
111 
112  .MS_DataInEndpoint = {
113  .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
114 
118  .PollingIntervalMS = 0x01
119  },
120 
121  .MS_DataOutEndpoint = {
122  .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
123 
127  .PollingIntervalMS = 0x01
128  },
129  .MS_Termination = 0x00
130 };
131 
136 static const uint8_t LanguageString[] = {
137  USB_STRING_LEN(1),
138  DTYPE_String,
140 };
141 static const USB_Descriptor_String_t *LanguageStringPtr = (const USB_Descriptor_String_t *) LanguageString;
142 
147 static const uint8_t ManufacturerString[] = {
148  USB_STRING_LEN(3),
149  DTYPE_String,
150  WBVAL('N'),
151  WBVAL('X'),
152  WBVAL('P'),
153 };
154 static const USB_Descriptor_String_t *ManufacturerStringPtr = (const USB_Descriptor_String_t *) ManufacturerString;
155 
160 static const uint8_t ProductString[] = {
161  USB_STRING_LEN(27),
162  DTYPE_String,
163  WBVAL('L'),
164  WBVAL('P'),
165  WBVAL('C'),
166  WBVAL('U'),
167  WBVAL('S'),
168  WBVAL('B'),
169  WBVAL('l'),
170  WBVAL('i'),
171  WBVAL('b'),
172  WBVAL(' '),
173  WBVAL('M'),
174  WBVAL('a'),
175  WBVAL('s'),
176  WBVAL('s'),
177  WBVAL(' '),
178  WBVAL('S'),
179  WBVAL('t'),
180  WBVAL('o'),
181  WBVAL('r'),
182  WBVAL('a'),
183  WBVAL('g'),
184  WBVAL('e'),
185  WBVAL(' '),
186  WBVAL('D'),
187  WBVAL('e'),
188  WBVAL('m'),
189  WBVAL('o'),
190 };
191 static const USB_Descriptor_String_t *ProductStringPtr = (const USB_Descriptor_String_t *) ProductString;
192 
193 /*****************************************************************************
194  * Public types/enumerations/variables
195  ****************************************************************************/
196 
197 /*****************************************************************************
198  * Private functions
199  ****************************************************************************/
200 
201 /*****************************************************************************
202  * Public functions
203  ****************************************************************************/
204 
205 /* @brief USB Get descriptor callback function */
206 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
207  const uint8_t wIndex,
208  const void * *const DescriptorAddress)
209 {
210  const uint8_t DescriptorType = (wValue >> 8);
211  const uint8_t DescriptorNumber = (wValue & 0xFF);
212 
213  const void *Address = NULL;
214  uint16_t Size = NO_DESCRIPTOR;
215 
216  switch (DescriptorType) {
217  case DTYPE_Device:
218  Address = &DeviceDescriptor;
219  Size = sizeof(USB_Descriptor_Device_t);
220  break;
221 
222  case DTYPE_Configuration:
223  Address = &ConfigurationDescriptor;
224  Size = sizeof(USB_Descriptor_Configuration_t);
225  break;
226 
227  case DTYPE_String:
228  switch (DescriptorNumber) {
229  case 0x00:
230  Address = LanguageStringPtr;
231  Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
232  break;
233 
234  case 0x01:
235  Address = ManufacturerStringPtr;
236  Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
237  break;
238 
239  case 0x02:
240  Address = ProductStringPtr;
241  Size = pgm_read_byte(&ProductStringPtr->Header.Size);
242  break;
243  }
244 
245  break;
246  }
247 
248  *DescriptorAddress = Address;
249  return Size;
250 }