| 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 MouseReport[] = {
52 /* Use the HID class driver's standard Mouse report.
53 * Min X/Y Axis values: -1
54 * Max X/Y Axis values: 1
55 * Min physical X/Y Axis values (used to determine resolution): -1
56 * Max physical X/Y Axis values (used to determine resolution): 1
57 * Buttons: 3
58 * Absolute screen coordinates: false
59 */
60 HID_DESCRIPTOR_MOUSE(-1, 1, -1, 1, 3, false)
61 };
62
68 USB_Descriptor_Device_t DeviceDescriptor = {
69 .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
70
71 .USBSpecification = VERSION_BCD(01.10),
72 .Class = USB_CSCP_NoDeviceClass,
73 .SubClass = USB_CSCP_NoDeviceSubclass,
74 .Protocol = USB_CSCP_NoDeviceProtocol,
75
76 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
77
78 .VendorID = 0x1fc9, /* NXP */
79 .ProductID = 0x2041,
80 .ReleaseNumber = VERSION_BCD(00.01),
81
82 .ManufacturerStrIndex = 0x01,
83 .ProductStrIndex = 0x02,
84 .SerialNumStrIndex = NO_DESCRIPTOR,
85
86 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
87 };
88
94 USB_Descriptor_Configuration_t ConfigurationDescriptor = {
95 .Config = {
96 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
97
98 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t) - 1, // termination byte not included in size
99 .TotalInterfaces = 1,
100
101 .ConfigurationNumber = 1,
102 .ConfigurationStrIndex = NO_DESCRIPTOR,
103
104 .ConfigAttributes = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
105
106 .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
107 },
108
109 .HID_Interface = {
110 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
111
112 .InterfaceNumber = 0x00,
113 .AlternateSetting = 0x00,
114
115 .TotalEndpoints = 1,
116
117 .Class = HID_CSCP_HIDClass,
118 .SubClass = HID_CSCP_BootSubclass,
119 .Protocol = HID_CSCP_MouseBootProtocol,
120
121 .InterfaceStrIndex = NO_DESCRIPTOR
122 },
123
124 .HID_MouseHID = {
125 .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
126
127 .HIDSpec = VERSION_BCD(01.11),
128 .CountryCode = 0x00,
129 .TotalReportDescriptors = 1,
130 .HIDReportType = HID_DTYPE_Report,
131 .HIDReportLength = sizeof(MouseReport)
132 },
133
134 .HID_ReportINEndpoint = {
135 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
136
137 // Begin
138 // .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | MOUSE_EPNUM),
139 .EndpointAddress = (ENDPOINT_DIR_IN | MOUSE_EPNUM),
140 // End
141 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
142 .EndpointSize = MOUSE_EPSIZE,
143 .PollingIntervalMS = 0x01
144 },
145 .HID_Termination = 0x00
146 };
147
152 uint8_t LanguageString[] = {
153 USB_STRING_LEN(1),
154 DTYPE_String,
155 WBVAL(LANGUAGE_ID_ENG),
156 };
157 USB_Descriptor_String_t *LanguageStringPtr = (USB_Descriptor_String_t *) LanguageString;
158
163 uint8_t ManufacturerString[] = {
164 USB_STRING_LEN(3),
165 DTYPE_String,
166 WBVAL('N'),
167 WBVAL('X'),
168 WBVAL('P'),
169 };
170 USB_Descriptor_String_t *ManufacturerStringPtr = (USB_Descriptor_String_t *) ManufacturerString;
171
176 uint8_t ProductString[] = {
177 USB_STRING_LEN(20),
178 DTYPE_String,
179 WBVAL('L'),
180 WBVAL('P'),
181 WBVAL('C'),
182 WBVAL('U'),
183 WBVAL('S'),
184 WBVAL('B'),
185 WBVAL('l'),
186 WBVAL('i'),
187 WBVAL('b'),
188 WBVAL(' '),
189 WBVAL('M'),
190 WBVAL('o'),
191 WBVAL('u'),
192 WBVAL('s'),
193 WBVAL('e'),
194 WBVAL(' '),
195 WBVAL('D'),
196 WBVAL('e'),
197 WBVAL('m'),
198 WBVAL('o'),
199 };
200 USB_Descriptor_String_t *ProductStringPtr = (USB_Descriptor_String_t *) ProductString;
201
202 /*****************************************************************************
203 * Private functions
204 ****************************************************************************/
205
206 /*****************************************************************************
207 * Public functions
208 ****************************************************************************/
209
216 uint16_t CALLBACK_USB_GetDescriptor(uint8_t corenum,
217 const uint16_t wValue,
218 const uint8_t wIndex,
219 const void * *const DescriptorAddress)
220 {
221 const uint8_t DescriptorType = (wValue >> 8);
222 const uint8_t DescriptorNumber = (wValue & 0xFF);
223
224 const void *Address = NULL;
225 uint16_t Size = NO_DESCRIPTOR;
226
227 switch (DescriptorType) {
228 case DTYPE_Device:
229 Address = &DeviceDescriptor;
230 Size = sizeof(USB_Descriptor_Device_t);
231 break;
232
233 case DTYPE_Configuration:
234 Address = &ConfigurationDescriptor;
235 Size = sizeof(USB_Descriptor_Configuration_t);
236 break;
237
238 case DTYPE_String:
239 switch (DescriptorNumber) {
240 case 0x00:
241 Address = LanguageStringPtr;
242 Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
243 break;
244
245 case 0x01:
246 Address = ManufacturerStringPtr;
247 Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
248 break;
249
250 case 0x02:
251 Address = ProductStringPtr;
252 Size = pgm_read_byte(&ProductStringPtr->Header.Size);
253 break;
254 }
255
256 break;
257
258 case HID_DTYPE_HID:
259 Address = &ConfigurationDescriptor.HID_MouseHID;
260 Size = sizeof(USB_HID_Descriptor_HID_t);
261 break;
262
263 case HID_DTYPE_Report:
264 Address = &MouseReport;
265 Size = sizeof(MouseReport);
266 break;
267 }
268
269 *DescriptorAddress = Address;
270 return Size;
271 }