LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
usbd.h
Go to the documentation of this file.
1 /*
2  * @brief Common definitions and declarations for the USB ROM based stack
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
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 #ifndef __USBD_H__
33 #define __USBD_H__
34 
40 #include <stdint.h>
41 
42 #if defined(__GNUC__)
43 /* As per http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax,
44 6.29 Attributes Syntax
45 "An attribute specifier list may appear as part of a struct, union or
46 enum specifier. It may go either immediately after the struct, union
47 or enum keyword, or after the closing brace. The former syntax is
48 preferred. Where attribute specifiers follow the closing brace, they
49 are considered to relate to the structure, union or enumerated type
50 defined, not to any enclosing declaration the type specifier appears
51 in, and the type defined is not complete until after the attribute
52 specifiers."
53 So use POST_PACK immediately after struct keyword
54 */
55 #define PRE_PACK
56 #define POST_PACK __attribute__((__packed__))
57 #define ALIGNED(n) __attribute__((aligned (n)))
58 #elif defined(__arm)
59 #define PRE_PACK __packed
60 #define POST_PACK
61 #define ALIGNED(n) __align(n)
62 #elif defined(__ICCARM__)
63 #define PRE_PACK __packed
64 #define POST_PACK
65 #endif
66 
68 PRE_PACK struct POST_PACK _WB_T
69 {
70  uint8_t L;
71  uint8_t H;
72 };
74 typedef struct _WB_T WB_T;
75 
77 union __WORD_BYTE
78 {
79  PRE_PACK uint16_t POST_PACK W;
80  WB_T WB;
81 } ;
83 typedef union __WORD_BYTE WORD_BYTE;
84 
89 #define REQUEST_HOST_TO_DEVICE 0
90 
91 #define REQUEST_DEVICE_TO_HOST 1
92 
98 #define REQUEST_STANDARD 0
99 
100 #define REQUEST_CLASS 1
101 
102 #define REQUEST_VENDOR 2
103 
104 #define REQUEST_RESERVED 3
105 
111 #define REQUEST_TO_DEVICE 0
112 
113 #define REQUEST_TO_INTERFACE 1
114 
115 #define REQUEST_TO_ENDPOINT 2
116 
117 #define REQUEST_TO_OTHER 3
118 
121 PRE_PACK struct POST_PACK _BM_T
122 {
123  uint8_t Recipient : 5;
124  uint8_t Type : 2;
125  uint8_t Dir : 1;
126 };
128 typedef struct _BM_T BM_T;
129 
131 union _REQUEST_TYPE
132 {
133  PRE_PACK uint8_t POST_PACK B;
134  BM_T BM;
135 } ;
137 typedef union _REQUEST_TYPE REQUEST_TYPE;
138 
143 #define USB_REQUEST_GET_STATUS 0
144 
145 #define USB_REQUEST_CLEAR_FEATURE 1
146 
147 #define USB_REQUEST_SET_FEATURE 3
148 
149 #define USB_REQUEST_SET_ADDRESS 5
150 
151 #define USB_REQUEST_GET_DESCRIPTOR 6
152 
153 #define USB_REQUEST_SET_DESCRIPTOR 7
154 
155 #define USB_REQUEST_GET_CONFIGURATION 8
156 
157 #define USB_REQUEST_SET_CONFIGURATION 9
158 
159 #define USB_REQUEST_GET_INTERFACE 10
160 
161 #define USB_REQUEST_SET_INTERFACE 11
162 
163 #define USB_REQUEST_SYNC_FRAME 12
164 
170 #define USB_GETSTATUS_SELF_POWERED 0x01
171 
172 #define USB_GETSTATUS_REMOTE_WAKEUP 0x02
173 
174 #define USB_GETSTATUS_ENDPOINT_STALL 0x01
175 
181 #define USB_FEATURE_ENDPOINT_STALL 0
182 
183 #define USB_FEATURE_REMOTE_WAKEUP 1
184 
185 #define USB_FEATURE_TEST_MODE 2
186 
189 PRE_PACK struct POST_PACK _USB_SETUP_PACKET
190 {
191  REQUEST_TYPE bmRequestType;
194  uint8_t bRequest;
198  WORD_BYTE wValue;
201  WORD_BYTE wIndex;
205  uint16_t wLength;
209 } ;
211 typedef struct _USB_SETUP_PACKET USB_SETUP_PACKET;
212 
213 
218 #define USB_DEVICE_DESCRIPTOR_TYPE 1
219 
220 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
221 
222 #define USB_STRING_DESCRIPTOR_TYPE 3
223 
224 #define USB_INTERFACE_DESCRIPTOR_TYPE 4
225 
226 #define USB_ENDPOINT_DESCRIPTOR_TYPE 5
227 
228 #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6
229 
230 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
231 
232 #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8
233 
234 #define USB_OTG_DESCRIPTOR_TYPE 9
235 
236 #define USB_DEBUG_DESCRIPTOR_TYPE 10
237 
238 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11
239 
245 #define USB_DEVICE_CLASS_RESERVED 0x00
246 
247 #define USB_DEVICE_CLASS_AUDIO 0x01
248 
249 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
250 
251 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
252 
253 #define USB_DEVICE_CLASS_MONITOR 0x04
254 
255 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
256 
257 #define USB_DEVICE_CLASS_POWER 0x06
258 
259 #define USB_DEVICE_CLASS_PRINTER 0x07
260 
261 #define USB_DEVICE_CLASS_STORAGE 0x08
262 
263 #define USB_DEVICE_CLASS_HUB 0x09
264 
265 #define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF
266 
267 #define USB_DEVICE_CLASS_APP 0xFE
268 
269 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
270 
276 #define USB_CONFIG_POWERED_MASK 0x40
277 
278 #define USB_CONFIG_BUS_POWERED 0x80
279 
280 #define USB_CONFIG_SELF_POWERED 0xC0
281 
282 #define USB_CONFIG_REMOTE_WAKEUP 0x20
283 
286 //#define USB_CONFIG_POWER_MA(mA) ((mA)/2)
287 
292 #define USB_ENDPOINT_DIRECTION_MASK 0x80
293 
294 #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
295 
296 #define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
297 
303 #define USB_ENDPOINT_TYPE_MASK 0x03
304 
305 #define USB_ENDPOINT_TYPE_CONTROL 0x00
306 
307 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
308 
309 #define USB_ENDPOINT_TYPE_BULK 0x02
310 
311 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
312 
313 #define USB_ENDPOINT_SYNC_MASK 0x0C
314 
315 #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00
316 
317 #define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04
318 
319 #define USB_ENDPOINT_SYNC_ADAPTIVE 0x08
320 
321 #define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C
322 
323 #define USB_ENDPOINT_USAGE_MASK 0x30
324 
325 #define USB_ENDPOINT_USAGE_DATA 0x00
326 
327 #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
328 
329 #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20
330 
331 #define USB_ENDPOINT_USAGE_RESERVED 0x30
332 
335 #define USB_ENDPOINT_0_HS_MAXP 64
336 
337 #define USB_ENDPOINT_0_LS_MAXP 8
338 
339 #define USB_ENDPOINT_BULK_HS_MAXP 512
340 
342 PRE_PACK struct POST_PACK _USB_DEVICE_DESCRIPTOR
343 {
344  uint8_t bLength;
345  uint8_t bDescriptorType;
346  uint16_t bcdUSB;
352  uint8_t bDeviceClass;
367  uint8_t bDeviceSubClass;
376  uint8_t bDeviceProtocol;
392  uint8_t bMaxPacketSize0;
397  uint16_t idVendor;
398  uint16_t idProduct;
399  uint16_t bcdDevice;
400  uint8_t iManufacturer;
401  uint8_t iProduct;
402  uint8_t iSerialNumber;
405  uint8_t bNumConfigurations;
406 } ;
408 typedef struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR;
409 
411 PRE_PACK struct POST_PACK _USB_DEVICE_QUALIFIER_DESCRIPTOR
412 {
413  uint8_t bLength;
414  uint8_t bDescriptorType;
415  uint16_t bcdUSB;
416  uint8_t bDeviceClass;
417  uint8_t bDeviceSubClass;
418  uint8_t bDeviceProtocol;
419  uint8_t bMaxPacketSize0;
420  uint8_t bNumConfigurations;
421  uint8_t bReserved;
422 } ;
424 typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR USB_DEVICE_QUALIFIER_DESCRIPTOR;
425 
427 PRE_PACK struct POST_PACK _USB_CONFIGURATION_DESCRIPTOR
428 {
429  uint8_t bLength;
430  uint8_t bDescriptorType;
431  uint16_t wTotalLength;
436  uint8_t bNumInterfaces;
437  uint8_t bConfigurationValue;
440  uint8_t iConfiguration;
442  uint8_t bmAttributes;
458  uint8_t bMaxPower;
482 } ;
484 typedef struct _USB_CONFIGURATION_DESCRIPTOR USB_CONFIGURATION_DESCRIPTOR;
485 
487 PRE_PACK struct POST_PACK _USB_INTERFACE_DESCRIPTOR
488 {
489  uint8_t bLength;
490  uint8_t bDescriptorType;
491  uint8_t bInterfaceNumber;
495  uint8_t bAlternateSetting;
497  uint8_t bNumEndpoints;
501  uint8_t bInterfaceClass;
508  uint8_t bInterfaceSubClass;
516  uint8_t bInterfaceProtocol;
530  uint8_t iInterface;
531 } ;
533 typedef struct _USB_INTERFACE_DESCRIPTOR USB_INTERFACE_DESCRIPTOR;
534 
536 PRE_PACK struct POST_PACK _USB_ENDPOINT_DESCRIPTOR
537 {
538  uint8_t bLength;
539  uint8_t bDescriptorType;
540  uint8_t bEndpointAddress;
548  uint8_t bmAttributes;
572  uint16_t wMaxPacketSize;
592  uint8_t bInterval;
614 } ;
616 typedef struct _USB_ENDPOINT_DESCRIPTOR USB_ENDPOINT_DESCRIPTOR;
617 
619 PRE_PACK struct POST_PACK _USB_STRING_DESCRIPTOR
620 {
621  uint8_t bLength;
622  uint8_t bDescriptorType;
623  uint16_t bString/*[]*/;
624 } ;
626 typedef struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR;
627 
629 PRE_PACK struct POST_PACK _USB_COMMON_DESCRIPTOR
630 {
631  uint8_t bLength;
632  uint8_t bDescriptorType;
633 } ;
635 typedef struct _USB_COMMON_DESCRIPTOR USB_COMMON_DESCRIPTOR;
636 
638 PRE_PACK struct POST_PACK _USB_OTHER_SPEED_CONFIGURATION
639 {
640  uint8_t bLength;
641  uint8_t bDescriptorType;
642  uint16_t wTotalLength;
643  uint8_t bNumInterfaces;
644  uint8_t bConfigurationValue;
645  uint8_t IConfiguration;
646  uint8_t bmAttributes;
647  uint8_t bMaxPower;
648 } ;
650 typedef struct _USB_OTHER_SPEED_CONFIGURATION USB_OTHER_SPEED_CONFIGURATION;
651 
655 typedef void* USBD_HANDLE_T;
656 
657 #define WBVAL(x) ((x) & 0xFF),(((x) >> 8) & 0xFF)
658 #define B3VAL(x) ((x) & 0xFF),(((x) >> 8) & 0xFF),(((x) >> 16) & 0xFF)
659 
660 #define USB_DEVICE_DESC_SIZE (sizeof(USB_DEVICE_DESCRIPTOR))
661 #define USB_CONFIGUARTION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR))
662 #define USB_INTERFACE_DESC_SIZE (sizeof(USB_INTERFACE_DESCRIPTOR))
663 #define USB_ENDPOINT_DESC_SIZE (sizeof(USB_ENDPOINT_DESCRIPTOR))
664 #define USB_DEVICE_QUALI_SIZE (sizeof(USB_DEVICE_QUALIFIER_DESCRIPTOR))
665 #define USB_OTHER_SPEED_CONF_SIZE (sizeof(USB_OTHER_SPEED_CONFIGURATION))
666 
673 #endif /* __USB_H__ */