LPCOpen Platform  v1.03
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; /**< byte wide access memeber */
134  uint8_t B;
135  BM_T BM;
136 } ;
138 typedef union _REQUEST_TYPE REQUEST_TYPE;
139 
144 #define USB_REQUEST_GET_STATUS 0
145 
146 #define USB_REQUEST_CLEAR_FEATURE 1
147 
148 #define USB_REQUEST_SET_FEATURE 3
149 
150 #define USB_REQUEST_SET_ADDRESS 5
151 
152 #define USB_REQUEST_GET_DESCRIPTOR 6
153 
154 #define USB_REQUEST_SET_DESCRIPTOR 7
155 
156 #define USB_REQUEST_GET_CONFIGURATION 8
157 
158 #define USB_REQUEST_SET_CONFIGURATION 9
159 
160 #define USB_REQUEST_GET_INTERFACE 10
161 
162 #define USB_REQUEST_SET_INTERFACE 11
163 
164 #define USB_REQUEST_SYNC_FRAME 12
165 
171 #define USB_GETSTATUS_SELF_POWERED 0x01
172 
173 #define USB_GETSTATUS_REMOTE_WAKEUP 0x02
174 
175 #define USB_GETSTATUS_ENDPOINT_STALL 0x01
176 
182 #define USB_FEATURE_ENDPOINT_STALL 0
183 
184 #define USB_FEATURE_REMOTE_WAKEUP 1
185 
186 #define USB_FEATURE_TEST_MODE 2
187 
190 PRE_PACK struct POST_PACK _USB_SETUP_PACKET
191 {
192  REQUEST_TYPE bmRequestType;
195  uint8_t bRequest;
199  WORD_BYTE wValue;
202  WORD_BYTE wIndex;
206  uint16_t wLength;
210 } ;
212 typedef struct _USB_SETUP_PACKET USB_SETUP_PACKET;
213 
214 
219 #define USB_DEVICE_DESCRIPTOR_TYPE 1
220 
221 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
222 
223 #define USB_STRING_DESCRIPTOR_TYPE 3
224 
225 #define USB_INTERFACE_DESCRIPTOR_TYPE 4
226 
227 #define USB_ENDPOINT_DESCRIPTOR_TYPE 5
228 
229 #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6
230 
231 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
232 
233 #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8
234 
235 #define USB_OTG_DESCRIPTOR_TYPE 9
236 
237 #define USB_DEBUG_DESCRIPTOR_TYPE 10
238 
239 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11
240 
246 #define USB_DEVICE_CLASS_RESERVED 0x00
247 
248 #define USB_DEVICE_CLASS_AUDIO 0x01
249 
250 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
251 
252 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
253 
254 #define USB_DEVICE_CLASS_MONITOR 0x04
255 
256 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
257 
258 #define USB_DEVICE_CLASS_POWER 0x06
259 
260 #define USB_DEVICE_CLASS_PRINTER 0x07
261 
262 #define USB_DEVICE_CLASS_STORAGE 0x08
263 
264 #define USB_DEVICE_CLASS_HUB 0x09
265 
266 #define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF
267 
268 #define USB_DEVICE_CLASS_APP 0xFE
269 
270 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
271 
277 #define USB_CONFIG_POWERED_MASK 0x40
278 
279 #define USB_CONFIG_BUS_POWERED 0x80
280 
281 #define USB_CONFIG_SELF_POWERED 0xC0
282 
283 #define USB_CONFIG_REMOTE_WAKEUP 0x20
284 
287 //#define USB_CONFIG_POWER_MA(mA) ((mA)/2)
288 
293 #define USB_ENDPOINT_DIRECTION_MASK 0x80
294 
295 #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
296 
297 #define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
298 
304 #define USB_ENDPOINT_TYPE_MASK 0x03
305 
306 #define USB_ENDPOINT_TYPE_CONTROL 0x00
307 
308 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
309 
310 #define USB_ENDPOINT_TYPE_BULK 0x02
311 
312 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
313 
314 #define USB_ENDPOINT_SYNC_MASK 0x0C
315 
316 #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00
317 
318 #define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04
319 
320 #define USB_ENDPOINT_SYNC_ADAPTIVE 0x08
321 
322 #define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C
323 
324 #define USB_ENDPOINT_USAGE_MASK 0x30
325 
326 #define USB_ENDPOINT_USAGE_DATA 0x00
327 
328 #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
329 
330 #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20
331 
332 #define USB_ENDPOINT_USAGE_RESERVED 0x30
333 
336 #define USB_ENDPOINT_0_HS_MAXP 64
337 
338 #define USB_ENDPOINT_0_LS_MAXP 8
339 
340 #define USB_ENDPOINT_BULK_HS_MAXP 512
341 
343 PRE_PACK struct POST_PACK _USB_DEVICE_DESCRIPTOR
344 {
345  uint8_t bLength;
346  uint8_t bDescriptorType;
347  uint16_t bcdUSB;
353  uint8_t bDeviceClass;
368  uint8_t bDeviceSubClass;
377  uint8_t bDeviceProtocol;
393  uint8_t bMaxPacketSize0;
398  uint16_t idVendor;
399  uint16_t idProduct;
400  uint16_t bcdDevice;
401  uint8_t iManufacturer;
402  uint8_t iProduct;
403  uint8_t iSerialNumber;
406  uint8_t bNumConfigurations;
407 } ;
409 typedef struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR;
410 
412 PRE_PACK struct POST_PACK _USB_DEVICE_QUALIFIER_DESCRIPTOR
413 {
414  uint8_t bLength;
415  uint8_t bDescriptorType;
416  uint16_t bcdUSB;
417  uint8_t bDeviceClass;
418  uint8_t bDeviceSubClass;
419  uint8_t bDeviceProtocol;
420  uint8_t bMaxPacketSize0;
421  uint8_t bNumConfigurations;
422  uint8_t bReserved;
423 } ;
425 typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR USB_DEVICE_QUALIFIER_DESCRIPTOR;
426 
428 PRE_PACK struct POST_PACK _USB_CONFIGURATION_DESCRIPTOR
429 {
430  uint8_t bLength;
431  uint8_t bDescriptorType;
432  uint16_t wTotalLength;
437  uint8_t bNumInterfaces;
438  uint8_t bConfigurationValue;
441  uint8_t iConfiguration;
443  uint8_t bmAttributes;
459  uint8_t bMaxPower;
483 } ;
485 typedef struct _USB_CONFIGURATION_DESCRIPTOR USB_CONFIGURATION_DESCRIPTOR;
486 
488 PRE_PACK struct POST_PACK _USB_INTERFACE_DESCRIPTOR
489 {
490  uint8_t bLength;
491  uint8_t bDescriptorType;
492  uint8_t bInterfaceNumber;
496  uint8_t bAlternateSetting;
498  uint8_t bNumEndpoints;
502  uint8_t bInterfaceClass;
509  uint8_t bInterfaceSubClass;
517  uint8_t bInterfaceProtocol;
531  uint8_t iInterface;
532 } ;
534 typedef struct _USB_INTERFACE_DESCRIPTOR USB_INTERFACE_DESCRIPTOR;
535 
537 PRE_PACK struct POST_PACK _USB_ENDPOINT_DESCRIPTOR
538 {
539  uint8_t bLength;
540  uint8_t bDescriptorType;
541  uint8_t bEndpointAddress;
549  uint8_t bmAttributes;
573  uint16_t wMaxPacketSize;
593  uint8_t bInterval;
615 } ;
617 typedef struct _USB_ENDPOINT_DESCRIPTOR USB_ENDPOINT_DESCRIPTOR;
618 
620 PRE_PACK struct POST_PACK _USB_STRING_DESCRIPTOR
621 {
622  uint8_t bLength;
623  uint8_t bDescriptorType;
624  uint16_t bString/*[]*/;
625 } ;
627 typedef struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR;
628 
630 PRE_PACK struct POST_PACK _USB_COMMON_DESCRIPTOR
631 {
632  uint8_t bLength;
633  uint8_t bDescriptorType;
634 } ;
636 typedef struct _USB_COMMON_DESCRIPTOR USB_COMMON_DESCRIPTOR;
637 
639 PRE_PACK struct POST_PACK _USB_OTHER_SPEED_CONFIGURATION
640 {
641  uint8_t bLength;
642  uint8_t bDescriptorType;
643  uint16_t wTotalLength;
644  uint8_t bNumInterfaces;
645  uint8_t bConfigurationValue;
646  uint8_t IConfiguration;
647  uint8_t bmAttributes;
648  uint8_t bMaxPower;
649 } ;
651 typedef struct _USB_OTHER_SPEED_CONFIGURATION USB_OTHER_SPEED_CONFIGURATION;
652 
656 typedef void* USBD_HANDLE_T;
657 
658 #define WBVAL(x) ((x) & 0xFF),(((x) >> 8) & 0xFF)
659 #define B3VAL(x) ((x) & 0xFF),(((x) >> 8) & 0xFF),(((x) >> 16) & 0xFF)
660 
661 #define USB_DEVICE_DESC_SIZE (sizeof(USB_DEVICE_DESCRIPTOR))
662 #define USB_CONFIGUARTION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR))
663 #define USB_INTERFACE_DESC_SIZE (sizeof(USB_INTERFACE_DESCRIPTOR))
664 #define USB_ENDPOINT_DESC_SIZE (sizeof(USB_ENDPOINT_DESCRIPTOR))
665 #define USB_DEVICE_QUALI_SIZE (sizeof(USB_DEVICE_QUALIFIER_DESCRIPTOR))
666 #define USB_OTHER_SPEED_CONF_SIZE (sizeof(USB_OTHER_SPEED_CONFIGURATION))
667 
674 #endif /* __USB_H__ */