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 
44  /* Use the HID class driver's standard Vendor HID report.
45  * Vendor Usage Page: 1
46  * Vendor Collection Usage: 1
47  * Vendor Report IN Usage: 9
48  * Vendor Report OUT Usage: 8
49  * Vendor Report Size: GENERIC_REPORT_SIZE
50  */
51  HID_DESCRIPTOR_VENDOR(0x00, 0x01, 0x09, 0x08, GENERIC_REPORT_SIZE)
52 };
53 
60  .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
61 
62  .USBSpecification = VERSION_BCD(01.10),
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 = 0x204F,
71  .ReleaseNumber = VERSION_BCD(00.01),
72 
73  .ManufacturerStrIndex = 0x01,
74  .ProductStrIndex = 0x02,
75  .SerialNumStrIndex = NO_DESCRIPTOR,
76 
77  .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
78 };
79 
86  .Config = {
87  .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
88 
89  .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t) - 1, // termination byte not included in size
90  .TotalInterfaces = 1,
91 
92  .ConfigurationNumber = 1,
93  .ConfigurationStrIndex = NO_DESCRIPTOR,
94 
96 
98  },
99 
100  .HID_Interface = {
101  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
102 
103  .InterfaceNumber = 0x00,
104  .AlternateSetting = 0x00,
105 
106  .TotalEndpoints = 1,
107 
111 
113  },
114 
115  .HID_GenericHID = {
116  .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
117 
118  .HIDSpec = VERSION_BCD(01.11),
119  .CountryCode = 0x00,
120  .TotalReportDescriptors = 1,
121  .HIDReportType = HID_DTYPE_Report,
122  .HIDReportLength = sizeof(GenericReport)
123  },
124 
125  .HID_ReportINEndpoint = {
126  .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
127 
131  .PollingIntervalMS = 0x01
132  },
133  .HID_Termination = 0x00
134 };
135 
140 uint8_t LanguageString[] = {
141  USB_STRING_LEN(1),
142  DTYPE_String,
144 };
146 
151 uint8_t ManufacturerString[] = {
152  USB_STRING_LEN(3),
153  DTYPE_String,
154  WBVAL('N'),
155  WBVAL('X'),
156  WBVAL('P'),
157 };
159 
164 uint8_t ProductString[] = {
165  USB_STRING_LEN(26),
166  DTYPE_String,
167  WBVAL('L'),
168  WBVAL('P'),
169  WBVAL('C'),
170  WBVAL('U'),
171  WBVAL('S'),
172  WBVAL('B'),
173  WBVAL('l'),
174  WBVAL('i'),
175  WBVAL('b'),
176  WBVAL(' '),
177  WBVAL('G'),
178  WBVAL('e'),
179  WBVAL('n'),
180  WBVAL('e'),
181  WBVAL('r'),
182  WBVAL('i'),
183  WBVAL('c'),
184  WBVAL(' '),
185  WBVAL('H'),
186  WBVAL('I'),
187  WBVAL('D'),
188  WBVAL(' '),
189  WBVAL('D'),
190  WBVAL('e'),
191  WBVAL('m'),
192  WBVAL('o'),
193 };
195 
202 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
203  const uint8_t wIndex,
204  const void * *const DescriptorAddress)
205 {
206  const uint8_t DescriptorType = (wValue >> 8);
207  const uint8_t DescriptorNumber = (wValue & 0xFF);
208 
209  const void *Address = NULL;
210  uint16_t Size = NO_DESCRIPTOR;
211 
212  switch (DescriptorType) {
213  case DTYPE_Device:
214  Address = &DeviceDescriptor;
215  Size = sizeof(USB_Descriptor_Device_t);
216  break;
217 
218  case DTYPE_Configuration:
219  Address = &ConfigurationDescriptor;
220  Size = sizeof(USB_Descriptor_Configuration_t);
221  break;
222 
223  case DTYPE_String:
224  switch (DescriptorNumber) {
225  case 0x00:
226  Address = LanguageStringPtr;
227  Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
228  break;
229 
230  case 0x01:
231  Address = ManufacturerStringPtr;
232  Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
233  break;
234 
235  case 0x02:
236  Address = ProductStringPtr;
237  Size = pgm_read_byte(&ProductStringPtr->Header.Size);
238  break;
239  }
240 
241  break;
242 
243  case HID_DTYPE_HID:
244  Address = &ConfigurationDescriptor.HID_GenericHID;
245  Size = sizeof(USB_HID_Descriptor_HID_t);
246  break;
247 
248  case HID_DTYPE_Report:
249  Address = &GenericReport;
250  Size = sizeof(GenericReport);
251  break;
252  }
253 
254  *DescriptorAddress = Address;
255  return Size;
256 }