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 Mouse report.
45  * Min X/Y Axis values: -1
46  * Max X/Y Axis values: 1
47  * Min physical X/Y Axis values (used to determine resolution): -1
48  * Max physical X/Y Axis values (used to determine resolution): 1
49  * Buttons: 3
50  * Absolute screen coordinates: false
51  */
52  HID_DESCRIPTOR_MOUSE(-1, 1, -1, 1, 3, false)
53 };
54 
61  .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
62 
63  .USBSpecification = VERSION_BCD(01.10),
64  .Class = USB_CSCP_NoDeviceClass,
65  .SubClass = USB_CSCP_NoDeviceSubclass,
66  .Protocol = USB_CSCP_NoDeviceProtocol,
67 
68  .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
69 
70  .VendorID = 0x1fc9, /* NXP */
71  .ProductID = 0x2041,
72  .ReleaseNumber = VERSION_BCD(00.01),
73 
74  .ManufacturerStrIndex = 0x01,
75  .ProductStrIndex = 0x02,
76  .SerialNumStrIndex = NO_DESCRIPTOR,
77 
78  .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
79 };
80 
87  .Config = {
88  .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
89 
90  .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t) - 1, // termination byte not included in size
91  .TotalInterfaces = 1,
92 
93  .ConfigurationNumber = 1,
94  .ConfigurationStrIndex = NO_DESCRIPTOR,
95 
97 
99  },
100 
101  .HID_Interface = {
102  .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
103 
104  .InterfaceNumber = 0x00,
105  .AlternateSetting = 0x00,
106 
107  .TotalEndpoints = 1,
108 
112 
114  },
115 
116  .HID_MouseHID = {
117  .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
118 
119  .HIDSpec = VERSION_BCD(01.11),
120  .CountryCode = 0x00,
121  .TotalReportDescriptors = 1,
122  .HIDReportType = HID_DTYPE_Report,
123  .HIDReportLength = sizeof(MouseReport)
124  },
125 
126  .HID_ReportINEndpoint = {
127  .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
128 
129  // Begin
130  // .EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | MOUSE_EPNUM),
132  // End
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(20),
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('M'),
182  WBVAL('o'),
183  WBVAL('u'),
184  WBVAL('s'),
185  WBVAL('e'),
186  WBVAL(' '),
187  WBVAL('D'),
188  WBVAL('e'),
189  WBVAL('m'),
190  WBVAL('o'),
191 };
193 
200 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
201  const uint8_t wIndex,
202  const void * *const DescriptorAddress)
203 {
204  const uint8_t DescriptorType = (wValue >> 8);
205  const uint8_t DescriptorNumber = (wValue & 0xFF);
206 
207  const void *Address = NULL;
208  uint16_t Size = NO_DESCRIPTOR;
209 
210  switch (DescriptorType) {
211  case DTYPE_Device:
212  Address = &DeviceDescriptor;
213  Size = sizeof(USB_Descriptor_Device_t);
214  break;
215 
216  case DTYPE_Configuration:
217  Address = &ConfigurationDescriptor;
218  Size = sizeof(USB_Descriptor_Configuration_t);
219  break;
220 
221  case DTYPE_String:
222  switch (DescriptorNumber) {
223  case 0x00:
224  Address = LanguageStringPtr;
225  Size = pgm_read_byte(&LanguageStringPtr->Header.Size);
226  break;
227 
228  case 0x01:
229  Address = ManufacturerStringPtr;
230  Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size);
231  break;
232 
233  case 0x02:
234  Address = ProductStringPtr;
235  Size = pgm_read_byte(&ProductStringPtr->Header.Size);
236  break;
237  }
238 
239  break;
240 
241  case HID_DTYPE_HID:
242  Address = &ConfigurationDescriptor.HID_MouseHID;
243  Size = sizeof(USB_HID_Descriptor_HID_t);
244  break;
245 
246  case HID_DTYPE_Report:
247  Address = &MouseReport;
248  Size = sizeof(MouseReport);
249  break;
250  }
251 
252  *DescriptorAddress = Address;
253  return Size;
254 }