LPCOpen Platform  v1.03
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 
37 /*****************************************************************************
38  * Private types/enumerations/variables
39  ****************************************************************************/
40 
41 /*****************************************************************************
42  * Public types/enumerations/variables
43  ****************************************************************************/
44 
52  /* Use the HID class driver's standard Keyboard report.
53  * Max simultaneous keys: 6
54  */
56 };
57 
64  .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
65 
66  .USBSpecification = VERSION_BCD(01.10),
67  .Class = USB_CSCP_NoDeviceClass,
68  .SubClass = USB_CSCP_NoDeviceSubclass,
69  .Protocol = USB_CSCP_NoDeviceProtocol,
70 
71  .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
72 
73  .VendorID = 0x1fc9, /* NXP */
74  .ProductID = 0x2042,
75  .ReleaseNumber = VERSION_BCD(00.01),
76 
77  .ManufacturerStrIndex = 0x01,
78  .ProductStrIndex = 0x02,
79  .SerialNumStrIndex = NO_DESCRIPTOR,
80 
81  .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
82 };
83 
90  .Config = {
91  .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
92 
93  .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t) - 1, // termination byte not included in size
94  .TotalInterfaces = 1,
95 
96  .ConfigurationNumber = 1,
97  .ConfigurationStrIndex = NO_DESCRIPTOR,
98 
100 
102  },
103 
104  .HID_Interface = {
105  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
106 
107  .InterfaceNumber = 0x00,
108  .AlternateSetting = 0x00,
109 
110  .TotalEndpoints = 1,
111 
115 
117  },
118 
119  .HID_KeyboardHID = {
120  .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
121 
122  .HIDSpec = VERSION_BCD(01.11),
123  .CountryCode = 0x00,
124  .TotalReportDescriptors = 1,
125  .HIDReportType = HID_DTYPE_Report,
126  .HIDReportLength = sizeof(KeyboardReport)
127  },
128 
129  .HID_ReportINEndpoint = {
130  .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
131 
135  .PollingIntervalMS = 0x01
136  },
137  .HID_Termination = 0x00
138 };
139 
144 uint8_t LanguageString[] = {
145  USB_STRING_LEN(1),
146  DTYPE_String,
148 };
150 
155 uint8_t ManufacturerString[] = {
156  USB_STRING_LEN(3),
157  DTYPE_String,
158  WBVAL('N'),
159  WBVAL('X'),
160  WBVAL('P'),
161 };
163 
168 uint8_t ProductString[] = {
169  USB_STRING_LEN(23),
170  DTYPE_String,
171  WBVAL('L'),
172  WBVAL('P'),
173  WBVAL('C'),
174  WBVAL('U'),
175  WBVAL('S'),
176  WBVAL('B'),
177  WBVAL('l'),
178  WBVAL('i'),
179  WBVAL('b'),
180  WBVAL(' '),
181  WBVAL('K'),
182  WBVAL('e'),
183  WBVAL('y'),
184  WBVAL('b'),
185  WBVAL('o'),
186  WBVAL('a'),
187  WBVAL('r'),
188  WBVAL('d'),
189  WBVAL(' '),
190  WBVAL('D'),
191  WBVAL('e'),
192  WBVAL('m'),
193  WBVAL('o'),
194 };
196 
197 /*****************************************************************************
198  * Private functions
199  ****************************************************************************/
200 
201 /*****************************************************************************
202  * Public functions
203  ****************************************************************************/
204 
211 uint16_t CALLBACK_USB_GetDescriptor(uint8_t corenum,
212  const uint16_t wValue,
213  const uint8_t wIndex,
214  const void * *const DescriptorAddress)
215 {
216  const uint8_t DescriptorType = (wValue >> 8);
217  const uint8_t DescriptorNumber = (wValue & 0xFF);
218 
219  const void *Address = NULL;
220  uint16_t Size = NO_DESCRIPTOR;
221 
222  switch (DescriptorType) {
223  case DTYPE_Device:
224  Address = &DeviceDescriptor;
225  Size = sizeof(USB_Descriptor_Device_t);
226  break;
227 
228  case DTYPE_Configuration:
229  Address = &ConfigurationDescriptor;
230  Size = sizeof(USB_Descriptor_Configuration_t);
231  break;
232 
233  case DTYPE_String:
234  switch (DescriptorNumber) {
235  case 0x00:
236  Address = LanguageStringPtr;
237  Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
238  break;
239 
240  case 0x01:
241  Address = ManufacturerStringPtr;
242  Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
243  break;
244 
245  case 0x02:
246  Address = ProductStringPtr;
247  Size = pgm_read_byte(&ProductStringPtr->Header.Size);
248  break;
249  }
250 
251  break;
252 
253  case HID_DTYPE_HID:
254  Address = &ConfigurationDescriptor.HID_KeyboardHID;
255  Size = sizeof(USB_HID_Descriptor_HID_t);
256  break;
257 
258  case HID_DTYPE_Report:
259  Address = &KeyboardReport;
260  Size = sizeof(KeyboardReport);
261  break;
262  }
263 
264  *DescriptorAddress = Address;
265  return Size;
266 }