1 /*
2  * @brief This file contains USB composite class example using USBD ROM stack.
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2013
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products.  This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #include "app_usbd_cfg.h"
33 
34 /*****************************************************************************
35  * Private types/enumerations/variables
36  ****************************************************************************/
37 
38 /*****************************************************************************
39  * Public types/enumerations/variables
40  ****************************************************************************/
41 
42 /**
43  * HID Mouse Report Descriptor
44  */
45 const uint8_t Mouse_ReportDescriptor[] = {
46 	HID_UsagePage(HID_USAGE_PAGE_GENERIC),
47 	HID_Usage(HID_USAGE_GENERIC_MOUSE),
48 	HID_Collection(HID_Application),
49 	HID_Usage(HID_USAGE_GENERIC_POINTER),
50 	HID_Collection(HID_Physical),
51 	HID_UsagePage(HID_USAGE_PAGE_BUTTON),
52 	HID_UsageMin(1),
53 	HID_UsageMax(3),
54 	HID_LogicalMin(0),
55 	HID_LogicalMax(1),
56 	HID_ReportCount(3),
57 	HID_ReportSize(1),
58 	HID_Input(HID_Data | HID_Variable | HID_Absolute),
59 	HID_ReportCount(1),
60 	HID_ReportSize(5),
61 	HID_Input(HID_Constant),
62 	HID_UsagePage(HID_USAGE_PAGE_GENERIC),
63 	HID_Usage(HID_USAGE_GENERIC_X),
64 	HID_Usage(HID_USAGE_GENERIC_Y),
65 	HID_LogicalMin( (uint8_t) -127),
66 	HID_LogicalMax(127),
67 	HID_ReportSize(8),
68 	HID_ReportCount(2),
69 	HID_Input(HID_Data | HID_Variable | HID_Relative),
70 	HID_EndCollection,
71 	HID_EndCollection,
72 };
73 const uint16_t Mouse_ReportDescSize = sizeof(Mouse_ReportDescriptor);
74 
75 /**
76  * USB Standard Device Descriptor
77  */
78 ALIGNED(4) const uint8_t USB_DeviceDescriptor[] = {
79 	USB_DEVICE_DESC_SIZE,			/* bLength */
80 	USB_DEVICE_DESCRIPTOR_TYPE,		/* bDescriptorType */
81 	WBVAL(0x0200),					/* bcdUSB : 2.00*/
82 	0x00,							/* bDeviceClass */
83 	0x00,							/* bDeviceSubClass */
84 	0x00,							/* bDeviceProtocol */
85 	USB_MAX_PACKET0,				/* bMaxPacketSize0 */
86 	WBVAL(0x1FC9),					/* idVendor */
87 	WBVAL(0x0087),					/* idProduct */
88 	WBVAL(0x0100),					/* bcdDevice : 1.00 */
89 	0x01,							/* iManufacturer */
90 	0x02,							/* iProduct */
91 	0x03,							/* iSerialNumber */
92 	0x01							/* bNumConfigurations */
93 };
94 
95 /**
96  * USB FSConfiguration Descriptor
97  * All Descriptors (Configuration, Interface, Endpoint, Class, Vendor)
98  */
99 ALIGNED(4) uint8_t USB_FsConfigDescriptor[] = {
100 	/* Configuration 1 */
101 	USB_CONFIGURATION_DESC_SIZE,			/* bLength */
102 	USB_CONFIGURATION_DESCRIPTOR_TYPE,		/* bDescriptorType */
103 	WBVAL(									/* wTotalLength */
104 		USB_CONFIGURATION_DESC_SIZE     +
105 		/* HID class related descriptors */
106 		USB_INTERFACE_DESC_SIZE         +
107 		HID_DESC_SIZE                   +
108 		USB_ENDPOINT_DESC_SIZE          +
109 		/* CDC class related descriptors */
110 		USB_INTERFACE_ASSOC_DESC_SIZE   +	/* interface association descriptor */
111 		USB_INTERFACE_DESC_SIZE         +	/* communication control interface */
112 		0x0013                          +	/* CDC functions */
113 		1 * USB_ENDPOINT_DESC_SIZE      +	/* interrupt endpoint */
114 		USB_INTERFACE_DESC_SIZE         +	/* communication data interface */
115 		2 * USB_ENDPOINT_DESC_SIZE      +	/* bulk endpoints */
116 		0
117 		),
118 	0x03,							/* bNumInterfaces */
119 	0x01,							/* bConfigurationValue */
120 	0x00,							/* iConfiguration */
121 	USB_CONFIG_SELF_POWERED,		/* bmAttributes */
122 	USB_CONFIG_POWER_MA(2),			/* bMaxPower */
123 
124 	/* Interface 0, Alternate Setting 0, HID Class */
125 	USB_INTERFACE_DESC_SIZE,		/* bLength */
126 	USB_INTERFACE_DESCRIPTOR_TYPE,	/* bDescriptorType */
127 	USB_HID_IF_NUM,					/* bInterfaceNumber */
128 	0x00,							/* bAlternateSetting */
129 	0x01,							/* bNumEndpoints */
130 	USB_DEVICE_CLASS_HUMAN_INTERFACE,	/* bInterfaceClass */
131 	HID_SUBCLASS_BOOT,				/* bInterfaceSubClass */
132 	HID_PROTOCOL_MOUSE,				/* bInterfaceProtocol */
133 	0x04,							/* iInterface */
134 	/* HID Class Descriptor */
135 	/* HID_DESC_OFFSET = 0x0012 */
136 	HID_DESC_SIZE,					/* bLength */
137 	HID_HID_DESCRIPTOR_TYPE,		/* bDescriptorType */
138 	WBVAL(0x0111),					/* bcdHID : 1.11*/
139 	0x00,							/* bCountryCode */
140 	0x01,							/* bNumDescriptors */
141 	HID_REPORT_DESCRIPTOR_TYPE,		/* bDescriptorType */
142 	WBVAL(sizeof(Mouse_ReportDescriptor)),	/* wDescriptorLength */
143 	/* Endpoint, HID Interrupt In */
144 	USB_ENDPOINT_DESC_SIZE,			/* bLength */
145 	USB_ENDPOINT_DESCRIPTOR_TYPE,	/* bDescriptorType */
146 	HID_EP_IN,						/* bEndpointAddress */
147 	USB_ENDPOINT_TYPE_INTERRUPT,	/* bmAttributes */
148 	WBVAL(0x0008),					/* wMaxPacketSize */
149 	HID_MOUSE_REPORT_INTERVAL,		/* bInterval */
150 
151 	/* Interface association descriptor IAD*/
152 	USB_INTERFACE_ASSOC_DESC_SIZE,		/* bLength */
153 	USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE,	/* bDescriptorType */
154 	USB_CDC_CIF_NUM,					/* bFirstInterface */
155 	0x02,								/* bInterfaceCount */
156 	CDC_COMMUNICATION_INTERFACE_CLASS,	/* bFunctionClass */
157 	CDC_ABSTRACT_CONTROL_MODEL,			/* bFunctionSubClass */
158 	0x00,								/* bFunctionProtocol */
159 	0x05,								/* iFunction */
160 
161 	/* Interface 1, Alternate Setting 0, Communication class interface descriptor */
162 	USB_INTERFACE_DESC_SIZE,			/* bLength */
163 	USB_INTERFACE_DESCRIPTOR_TYPE,		/* bDescriptorType */
164 	USB_CDC_CIF_NUM,					/* bInterfaceNumber: Number of Interface */
165 	0x00,								/* bAlternateSetting: Alternate setting */
166 	0x01,								/* bNumEndpoints: One endpoint used */
167 	CDC_COMMUNICATION_INTERFACE_CLASS,	/* bInterfaceClass: Communication Interface Class */
168 	CDC_ABSTRACT_CONTROL_MODEL,			/* bInterfaceSubClass: Abstract Control Model */
169 	0x00,								/* bInterfaceProtocol: no protocol used */
170 	0x05,								/* iInterface: */
171 	/* Header Functional Descriptor*/
172 	0x05,								/* bLength: CDC header Descriptor size */
173 	CDC_CS_INTERFACE,					/* bDescriptorType: CS_INTERFACE */
174 	CDC_HEADER,							/* bDescriptorSubtype: Header Func Desc */
175 	WBVAL(CDC_V1_10),					/* bcdCDC 1.10 */
176 	/* Call Management Functional Descriptor*/
177 	0x05,								/* bFunctionLength */
178 	CDC_CS_INTERFACE,					/* bDescriptorType: CS_INTERFACE */
179 	CDC_CALL_MANAGEMENT,				/* bDescriptorSubtype: Call Management Func Desc */
180 	0x01,								/* bmCapabilities: device handles call management */
181 	USB_CDC_DIF_NUM,					/* bDataInterface: CDC data IF ID */
182 	/* Abstract Control Management Functional Descriptor*/
183 	0x04,								/* bFunctionLength */
184 	CDC_CS_INTERFACE,					/* bDescriptorType: CS_INTERFACE */
185 	CDC_ABSTRACT_CONTROL_MANAGEMENT,	/* bDescriptorSubtype: Abstract Control Management desc */
186 	0x02,								/* bmCapabilities: SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported */
187 	/* Union Functional Descriptor*/
188 	0x05,								/* bFunctionLength */
189 	CDC_CS_INTERFACE,					/* bDescriptorType: CS_INTERFACE */
190 	CDC_UNION,							/* bDescriptorSubtype: Union func desc */
191 	USB_CDC_CIF_NUM,					/* bMasterInterface: Communication class interface is master */
192 	USB_CDC_DIF_NUM,					/* bSlaveInterface0: Data class interface is slave 0 */
193 	/* Endpoint 1 Descriptor*/
194 	USB_ENDPOINT_DESC_SIZE,				/* bLength */
195 	USB_ENDPOINT_DESCRIPTOR_TYPE,		/* bDescriptorType */
196 	USB_CDC_INT_EP,						/* bEndpointAddress */
197 	USB_ENDPOINT_TYPE_INTERRUPT,		/* bmAttributes */
198 	WBVAL(0x0010),						/* wMaxPacketSize */
199 	0x02,			/* 2ms */           /* bInterval */
200 
201 	/* Interface 2, Alternate Setting 0, Data class interface descriptor*/
202 	USB_INTERFACE_DESC_SIZE,			/* bLength */
203 	USB_INTERFACE_DESCRIPTOR_TYPE,		/* bDescriptorType */
204 	USB_CDC_DIF_NUM,					/* bInterfaceNumber: Number of Interface */
205 	0x00,								/* bAlternateSetting: no alternate setting */
206 	0x02,								/* bNumEndpoints: two endpoints used */
207 	CDC_DATA_INTERFACE_CLASS,			/* bInterfaceClass: Data Interface Class */
208 	0x00,								/* bInterfaceSubClass: no subclass available */
209 	0x00,								/* bInterfaceProtocol: no protocol used */
210 	0x05,								/* iInterface: */
211 	/* Endpoint, EP Bulk Out */
212 	USB_ENDPOINT_DESC_SIZE,				/* bLength */
213 	USB_ENDPOINT_DESCRIPTOR_TYPE,		/* bDescriptorType */
214 	USB_CDC_OUT_EP,						/* bEndpointAddress */
215 	USB_ENDPOINT_TYPE_BULK,				/* bmAttributes */
216 	WBVAL(USB_FS_MAX_BULK_PACKET),		/* wMaxPacketSize */
217 	0x00,								/* bInterval: ignore for Bulk transfer */
218 	/* Endpoint, EP Bulk In */
219 	USB_ENDPOINT_DESC_SIZE,				/* bLength */
220 	USB_ENDPOINT_DESCRIPTOR_TYPE,		/* bDescriptorType */
221 	USB_CDC_IN_EP,						/* bEndpointAddress */
222 	USB_ENDPOINT_TYPE_BULK,				/* bmAttributes */
223 	WBVAL(64),							/* wMaxPacketSize */
224 	0x00,								/* bInterval: ignore for Bulk transfer */
225 
226 	/* Terminator */
227 	0								/* bLength */
228 };
229 
230 /**
231  * USB String Descriptor (optional)
232  */
233 const uint8_t USB_StringDescriptor[] = {
234 	/* Index 0x00: LANGID Codes */
235 	0x04,							/* bLength */
236 	USB_STRING_DESCRIPTOR_TYPE,		/* bDescriptorType */
237 	WBVAL(0x0409),					/* wLANGID : US English */
238 	/* Index 0x01: Manufacturer */
239 	(18 * 2 + 2),					/* bLength (18 Char + Type + lenght) */
240 	USB_STRING_DESCRIPTOR_TYPE,		/* bDescriptorType */
241 	'N', 0,
242 	'X', 0,
243 	'P', 0,
244 	' ', 0,
245 	'S', 0,
246 	'e', 0,
247 	'm', 0,
248 	'i', 0,
249 	'c', 0,
250 	'o', 0,
251 	'n', 0,
252 	'd', 0,
253 	'u', 0,
254 	'c', 0,
255 	't', 0,
256 	'o', 0,
257 	'r', 0,
258 	's', 0,
259 	/* Index 0x02: Product */
260 	(13 * 2 + 2),					/* bLength (13 Char + Type + lenght) */
261 	USB_STRING_DESCRIPTOR_TYPE,		/* bDescriptorType */
262 	'L', 0,
263 	'P', 0,
264 	'C', 0,
265 	'1', 0,
266 	'5', 0,
267 	'x', 0,
268 	'x', 0,
269 	' ', 0,
270 	'M', 0,
271 	'O', 0,
272 	'U', 0,
273 	'S', 0,
274 	'E', 0,
275 	/* Index 0x03: Serial Number */
276 	(13 * 2 + 2),					/* bLength (13 Char + Type + lenght) */
277 	USB_STRING_DESCRIPTOR_TYPE,		/* bDescriptorType */
278 	'A', 0,
279 	'B', 0,
280 	'C', 0,
281 	'D', 0,
282 	'1', 0,
283 	'2', 0,
284 	'3', 0,
285 	'4', 0,
286 	'5', 0,
287 	'6', 0,
288 	'7', 0,
289 	'8', 0,
290 	'9', 0,
291 	/* Index 0x04: Interface 0, Alternate Setting 0 */
292 	(9 * 2 + 2),					/* bLength (9 Char + Type + lenght) */
293 	USB_STRING_DESCRIPTOR_TYPE,		/* bDescriptorType */
294 	'H', 0,
295 	'I', 0,
296 	'D', 0,
297 	' ', 0,
298 	'M', 0,
299 	'O', 0,
300 	'U', 0,
301 	'S', 0,
302 	'E', 0,
303 	/* Index 0x05: Interface 1, Alternate Setting 0 */
304 	( 4 * 2 + 2),						/* bLength (4 Char + Type + lenght) */
305 	USB_STRING_DESCRIPTOR_TYPE,			/* bDescriptorType */
306 	'V', 0,
307 	'C', 0,
308 	'O', 0,
309 	'M', 0,
310 };
311