| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

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 /*****************************************************************************
38 * Private types/enumerations/variables
39 ****************************************************************************/
40
41 /*****************************************************************************
42 * Public types/enumerations/variables
43 ****************************************************************************/
44
51 USB_Descriptor_HIDReport_Datatype_t GenericReport[] = {
52 /* Use the HID class driver's standard Vendor HID report.
53 * Vendor Usage Page: 1
54 * Vendor Collection Usage: 1
55 * Vendor Report IN Usage: 9
56 * Vendor Report OUT Usage: 8
57 * Vendor Report Size: GENERIC_REPORT_SIZE
58 */
59 HID_DESCRIPTOR_VENDOR(0x00, 0x01, 0x09, 0x08, GENERIC_REPORT_SIZE)
60 };
61
67 USB_Descriptor_Device_t DeviceDescriptor = {
68 .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
69
70 .USBSpecification = VERSION_BCD(01.10),
71 .Class = USB_CSCP_NoDeviceClass,
72 .SubClass = USB_CSCP_NoDeviceSubclass,
73 .Protocol = USB_CSCP_NoDeviceProtocol,
74
75 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
76
77 .VendorID = 0x1fc9, /* NXP */
78 .ProductID = 0x204F,
79 .ReleaseNumber = VERSION_BCD(00.01),
80
81 .ManufacturerStrIndex = 0x01,
82 .ProductStrIndex = 0x02,
83 .SerialNumStrIndex = NO_DESCRIPTOR,
84
85 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
86 };
87
93 USB_Descriptor_Configuration_t ConfigurationDescriptor = {
94 .Config = {
95 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
96
97 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t) - 1, // termination byte not included in size
98 .TotalInterfaces = 1,
99
100 .ConfigurationNumber = 1,
101 .ConfigurationStrIndex = NO_DESCRIPTOR,
102
103 .ConfigAttributes = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
104
105 .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
106 },
107
108 .HID_Interface = {
109 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
110
111 .InterfaceNumber = 0x00,
112 .AlternateSetting = 0x00,
113
114 .TotalEndpoints = 1,
115
116 .Class = HID_CSCP_HIDClass,
117 .SubClass = HID_CSCP_NonBootSubclass,
118 .Protocol = HID_CSCP_NonBootProtocol,
119
120 .InterfaceStrIndex = NO_DESCRIPTOR
121 },
122
123 .HID_GenericHID = {
124 .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
125
126 .HIDSpec = VERSION_BCD(01.11),
127 .CountryCode = 0x00,
128 .TotalReportDescriptors = 1,
129 .HIDReportType = HID_DTYPE_Report,
130 .HIDReportLength = sizeof(GenericReport)
131 },
132
133 .HID_ReportINEndpoint = {
134 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
135
136 .EndpointAddress = (ENDPOINT_DIR_IN | GENERIC_IN_EPNUM),
137 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
138 .EndpointSize = GENERIC_EPSIZE,
139 .PollingIntervalMS = 0x01
140 },
141 .HID_Termination = 0x00
142 };
143
148 uint8_t LanguageString[] = {
149 USB_STRING_LEN(1),
150 DTYPE_String,
151 WBVAL(LANGUAGE_ID_ENG),
152 };
153 USB_Descriptor_String_t *LanguageStringPtr = (USB_Descriptor_String_t *) LanguageString;
154
159 uint8_t ManufacturerString[] = {
160 USB_STRING_LEN(3),
161 DTYPE_String,
162 WBVAL('N'),
163 WBVAL('X'),
164 WBVAL('P'),
165 };
166 USB_Descriptor_String_t *ManufacturerStringPtr = (USB_Descriptor_String_t *) ManufacturerString;
167
172 uint8_t ProductString[] = {
173 USB_STRING_LEN(26),
174 DTYPE_String,
175 WBVAL('L'),
176 WBVAL('P'),
177 WBVAL('C'),
178 WBVAL('U'),
179 WBVAL('S'),
180 WBVAL('B'),
181 WBVAL('l'),
182 WBVAL('i'),
183 WBVAL('b'),
184 WBVAL(' '),
185 WBVAL('G'),
186 WBVAL('e'),
187 WBVAL('n'),
188 WBVAL('e'),
189 WBVAL('r'),
190 WBVAL('i'),
191 WBVAL('c'),
192 WBVAL(' '),
193 WBVAL('H'),
194 WBVAL('I'),
195 WBVAL('D'),
196 WBVAL(' '),
197 WBVAL('D'),
198 WBVAL('e'),
199 WBVAL('m'),
200 WBVAL('o'),
201 };
202 USB_Descriptor_String_t *ProductStringPtr = (USB_Descriptor_String_t *) ProductString;
203
204 /*****************************************************************************
205 * Private functions
206 ****************************************************************************/
207
208 /*****************************************************************************
209 * Public functions
210 ****************************************************************************/
211
218 uint16_t CALLBACK_USB_GetDescriptor(uint8_t corenum,
219 const uint16_t wValue,
220 const uint8_t wIndex,
221 const void * *const DescriptorAddress)
222 {
223 const uint8_t DescriptorType = (wValue >> 8);
224 const uint8_t DescriptorNumber = (wValue & 0xFF);
225
226 const void *Address = NULL;
227 uint16_t Size = NO_DESCRIPTOR;
228
229 switch (DescriptorType) {
230 case DTYPE_Device:
231 Address = &DeviceDescriptor;
232 Size = sizeof(USB_Descriptor_Device_t);
233 break;
234
235 case DTYPE_Configuration:
236 Address = &ConfigurationDescriptor;
237 Size = sizeof(USB_Descriptor_Configuration_t);
238 break;
239
240 case DTYPE_String:
241 switch (DescriptorNumber) {
242 case 0x00:
243 Address = LanguageStringPtr;
244 Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
245 break;
246
247 case 0x01:
248 Address = ManufacturerStringPtr;
249 Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
250 break;
251
252 case 0x02:
253 Address = ProductStringPtr;
254 Size = pgm_read_byte(&ProductStringPtr->Header.Size);
255 break;
256 }
257
258 break;
259
260 case HID_DTYPE_HID:
261 Address = &ConfigurationDescriptor.HID_GenericHID;
262 Size = sizeof(USB_HID_Descriptor_HID_t);
263 break;
264
265 case HID_DTYPE_Report:
266 Address = &GenericReport;
267 Size = sizeof(GenericReport);
268 break;
269 }
270
271 *DescriptorAddress = Address;
272 return Size;
273 }