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 Keyboard report.
45  * Max simultaneous keys: 6
46  */
48 };
49 
56  .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
57 
58  .USBSpecification = VERSION_BCD(01.10),
59  .Class = USB_CSCP_NoDeviceClass,
60  .SubClass = USB_CSCP_NoDeviceSubclass,
61  .Protocol = USB_CSCP_NoDeviceProtocol,
62 
63  .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
64 
65  .VendorID = 0x1fc9, /* NXP */
66  .ProductID = 0x2042,
67  .ReleaseNumber = VERSION_BCD(00.01),
68 
69  .ManufacturerStrIndex = 0x01,
70  .ProductStrIndex = 0x02,
71  .SerialNumStrIndex = NO_DESCRIPTOR,
72 
73  .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
74 };
75 
82  .Config = {
83  .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
84 
85  .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t) - 1, // termination byte not included in size
86  .TotalInterfaces = 1,
87 
88  .ConfigurationNumber = 1,
89  .ConfigurationStrIndex = NO_DESCRIPTOR,
90 
92 
94  },
95 
96  .HID_Interface = {
97  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
98 
99  .InterfaceNumber = 0x00,
100  .AlternateSetting = 0x00,
101 
102  .TotalEndpoints = 1,
103 
107 
109  },
110 
111  .HID_KeyboardHID = {
112  .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
113 
114  .HIDSpec = VERSION_BCD(01.11),
115  .CountryCode = 0x00,
116  .TotalReportDescriptors = 1,
117  .HIDReportType = HID_DTYPE_Report,
118  .HIDReportLength = sizeof(KeyboardReport)
119  },
120 
121  .HID_ReportINEndpoint = {
122  .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
123 
127  .PollingIntervalMS = 0x01
128  },
129  .HID_Termination = 0x00
130 };
131 
136 uint8_t LanguageString[] = {
137  USB_STRING_LEN(1),
138  DTYPE_String,
140 };
142 
147 uint8_t ManufacturerString[] = {
148  USB_STRING_LEN(3),
149  DTYPE_String,
150  WBVAL('N'),
151  WBVAL('X'),
152  WBVAL('P'),
153 };
155 
160 uint8_t ProductString[] = {
161  USB_STRING_LEN(23),
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('K'),
174  WBVAL('e'),
175  WBVAL('y'),
176  WBVAL('b'),
177  WBVAL('o'),
178  WBVAL('a'),
179  WBVAL('r'),
180  WBVAL('d'),
181  WBVAL(' '),
182  WBVAL('D'),
183  WBVAL('e'),
184  WBVAL('m'),
185  WBVAL('o'),
186 };
188 
195 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
196  const uint8_t wIndex,
197  const void * *const DescriptorAddress)
198 {
199  const uint8_t DescriptorType = (wValue >> 8);
200  const uint8_t DescriptorNumber = (wValue & 0xFF);
201 
202  const void *Address = NULL;
203  uint16_t Size = NO_DESCRIPTOR;
204 
205  switch (DescriptorType) {
206  case DTYPE_Device:
207  Address = &DeviceDescriptor;
208  Size = sizeof(USB_Descriptor_Device_t);
209  break;
210 
211  case DTYPE_Configuration:
212  Address = &ConfigurationDescriptor;
213  Size = sizeof(USB_Descriptor_Configuration_t);
214  break;
215 
216  case DTYPE_String:
217  switch (DescriptorNumber) {
218  case 0x00:
219  Address = LanguageStringPtr;
220  Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
221  break;
222 
223  case 0x01:
224  Address = ManufacturerStringPtr;
225  Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
226  break;
227 
228  case 0x02:
229  Address = ProductStringPtr;
230  Size = pgm_read_byte(&ProductStringPtr->Header.Size);
231  break;
232  }
233 
234  break;
235 
236  case HID_DTYPE_HID:
237  Address = &ConfigurationDescriptor.HID_KeyboardHID;
238  Size = sizeof(USB_HID_Descriptor_HID_t);
239  break;
240 
241  case HID_DTYPE_Report:
242  Address = &KeyboardReport;
243  Size = sizeof(KeyboardReport);
244  break;
245  }
246 
247  *DescriptorAddress = Address;
248  return Size;
249 }