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 * $Id: mw_usbd.h.rca 1.3 Tue Nov 1 11:45:07 2011 nlv09221 Experimental $
3 *
4 * Project: USB device ROM Stack
5 *
6 * Description:
7 * USB Definitions.
8 *
9 ***********************************************************************
10 * Copyright(C) 2011, NXP Semiconductor
11 * All rights reserved.
12 *
13 * Software that is described herein is for illustrative purposes only
14 * which provides customers with programming information regarding the
15 * products. This software is supplied "AS IS" without any warranties.
16 * NXP Semiconductors assumes no responsibility or liability for the
17 * use of the software, conveys no license or title under any patent,
18 * copyright, or mask work right to the product. NXP Semiconductors
19 * reserves the right to make changes in the software without
20 * notification. NXP Semiconductors also make no representation or
21 * warranty that such application will be suitable for the specified
22 * use without further testing or modification.
23 **********************************************************************/
24 
25 #ifndef __USB_H__
26 #define __USB_H__
27 
36 #include <stdint.h>
37 
38 #if defined(__GNUC__)
39 /* As per http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax,
40 6.29 Attributes Syntax
41 "An attribute specifier list may appear as part of a struct, union or
42 enum specifier. It may go either immediately after the struct, union
43 or enum keyword, or after the closing brace. The former syntax is
44 preferred. Where attribute specifiers follow the closing brace, they
45 are considered to relate to the structure, union or enumerated type
46 defined, not to any enclosing declaration the type specifier appears
47 in, and the type defined is not complete until after the attribute
48 specifiers."
49 So use POST_PACK immediately after struct keyword
50 */
51 #define PRE_PACK
52 #define POST_PACK __attribute__((__packed__))
53 #define ALIGNED(n) __attribute__((aligned (n)))
54 #elif defined(__arm)
55 #define PRE_PACK __packed
56 #define POST_PACK
57 #define ALIGNED(n) __align(n)
58 #endif
59 
61 PRE_PACK struct POST_PACK _WB_T
62 {
63  uint8_t L;
64  uint8_t H;
65 };
67 typedef struct _WB_T WB_T;
68 
70 PRE_PACK union POST_PACK __WORD_BYTE
71 {
72  uint16_t W;
73  WB_T WB;
74 } ;
76 typedef union __WORD_BYTE WORD_BYTE;
77 
82 #define REQUEST_HOST_TO_DEVICE 0
83 
84 #define REQUEST_DEVICE_TO_HOST 1
85 
91 #define REQUEST_STANDARD 0
92 
93 #define REQUEST_CLASS 1
94 
95 #define REQUEST_VENDOR 2
96 
97 #define REQUEST_RESERVED 3
98 
104 #define REQUEST_TO_DEVICE 0
105 
106 #define REQUEST_TO_INTERFACE 1
107 
108 #define REQUEST_TO_ENDPOINT 2
109 
110 #define REQUEST_TO_OTHER 3
111 
114 PRE_PACK struct POST_PACK _BM_T
115 {
116  uint8_t Recipient : 5;
117  uint8_t Type : 2;
118  uint8_t Dir : 1;
119 };
121 typedef struct _BM_T BM_T;
122 
124 PRE_PACK union POST_PACK _REQUEST_TYPE
125 {
126  uint8_t B;
127  BM_T BM;
128 } ;
130 typedef union _REQUEST_TYPE REQUEST_TYPE;
131 
136 #define USB_REQUEST_GET_STATUS 0
137 
138 #define USB_REQUEST_CLEAR_FEATURE 1
139 
140 #define USB_REQUEST_SET_FEATURE 3
141 
142 #define USB_REQUEST_SET_ADDRESS 5
143 
144 #define USB_REQUEST_GET_DESCRIPTOR 6
145 
146 #define USB_REQUEST_SET_DESCRIPTOR 7
147 
148 #define USB_REQUEST_GET_CONFIGURATION 8
149 
150 #define USB_REQUEST_SET_CONFIGURATION 9
151 
152 #define USB_REQUEST_GET_INTERFACE 10
153 
154 #define USB_REQUEST_SET_INTERFACE 11
155 
156 #define USB_REQUEST_SYNC_FRAME 12
157 
163 #define USB_GETSTATUS_SELF_POWERED 0x01
164 
165 #define USB_GETSTATUS_REMOTE_WAKEUP 0x02
166 
167 #define USB_GETSTATUS_ENDPOINT_STALL 0x01
168 
174 #define USB_FEATURE_ENDPOINT_STALL 0
175 
176 #define USB_FEATURE_REMOTE_WAKEUP 1
177 
178 #define USB_FEATURE_TEST_MODE 2
179 
182 PRE_PACK struct POST_PACK _USB_SETUP_PACKET
183 {
184  REQUEST_TYPE bmRequestType;
187  uint8_t bRequest;
191  WORD_BYTE wValue;
194  WORD_BYTE wIndex;
198  uint16_t wLength;
202 } ;
204 typedef struct _USB_SETUP_PACKET USB_SETUP_PACKET;
205 
206 
211 #define USB_DEVICE_DESCRIPTOR_TYPE 1
212 
213 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
214 
215 #define USB_STRING_DESCRIPTOR_TYPE 3
216 
217 #define USB_INTERFACE_DESCRIPTOR_TYPE 4
218 
219 #define USB_ENDPOINT_DESCRIPTOR_TYPE 5
220 
221 #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6
222 
223 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
224 
225 #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8
226 
227 #define USB_OTG_DESCRIPTOR_TYPE 9
228 
229 #define USB_DEBUG_DESCRIPTOR_TYPE 10
230 
231 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11
232 
238 #define USB_DEVICE_CLASS_RESERVED 0x00
239 
240 #define USB_DEVICE_CLASS_AUDIO 0x01
241 
242 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
243 
244 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
245 
246 #define USB_DEVICE_CLASS_MONITOR 0x04
247 
248 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
249 
250 #define USB_DEVICE_CLASS_POWER 0x06
251 
252 #define USB_DEVICE_CLASS_PRINTER 0x07
253 
254 #define USB_DEVICE_CLASS_STORAGE 0x08
255 
256 #define USB_DEVICE_CLASS_HUB 0x09
257 
258 #define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF
259 
260 #define USB_DEVICE_CLASS_APP 0xFE
261 
262 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
263 
269 #define USB_CONFIG_POWERED_MASK 0x40
270 
271 #define USB_CONFIG_BUS_POWERED 0x80
272 
273 #define USB_CONFIG_SELF_POWERED 0xC0
274 
275 #define USB_CONFIG_REMOTE_WAKEUP 0x20
276 
279 #define USB_CONFIG_POWER_MA(mA) ((mA)/2)
280 
285 #define USB_ENDPOINT_DIRECTION_MASK 0x80
286 
287 #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
288 
289 #define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
290 
296 #define USB_ENDPOINT_TYPE_MASK 0x03
297 
298 #define USB_ENDPOINT_TYPE_CONTROL 0x00
299 
300 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
301 
302 #define USB_ENDPOINT_TYPE_BULK 0x02
303 
304 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
305 
306 #define USB_ENDPOINT_SYNC_MASK 0x0C
307 
308 #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00
309 
310 #define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04
311 
312 #define USB_ENDPOINT_SYNC_ADAPTIVE 0x08
313 
314 #define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C
315 
316 #define USB_ENDPOINT_USAGE_MASK 0x30
317 
318 #define USB_ENDPOINT_USAGE_DATA 0x00
319 
320 #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
321 
322 #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20
323 
324 #define USB_ENDPOINT_USAGE_RESERVED 0x30
325 
328 #define USB_ENDPOINT_0_HS_MAXP 64
329 
330 #define USB_ENDPOINT_0_LS_MAXP 8
331 
332 #define USB_ENDPOINT_BULK_HS_MAXP 512
333 
335 PRE_PACK struct POST_PACK _USB_DEVICE_DESCRIPTOR
336 {
337  uint8_t bLength;
338  uint8_t bDescriptorType;
339  uint16_t bcdUSB;
345  uint8_t bDeviceClass;
360  uint8_t bDeviceSubClass;
369  uint8_t bDeviceProtocol;
385  uint8_t bMaxPacketSize0;
390  uint16_t idVendor;
391  uint16_t idProduct;
392  uint16_t bcdDevice;
393  uint8_t iManufacturer;
394  uint8_t iProduct;
395  uint8_t iSerialNumber;
398  uint8_t bNumConfigurations;
399 } ;
401 typedef struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR;
402 
404 PRE_PACK struct POST_PACK _USB_DEVICE_QUALIFIER_DESCRIPTOR
405 {
406  uint8_t bLength;
407  uint8_t bDescriptorType;
408  uint16_t bcdUSB;
409  uint8_t bDeviceClass;
410  uint8_t bDeviceSubClass;
411  uint8_t bDeviceProtocol;
412  uint8_t bMaxPacketSize0;
413  uint8_t bNumConfigurations;
414  uint8_t bReserved;
415 } ;
417 typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR USB_DEVICE_QUALIFIER_DESCRIPTOR;
418 
420 PRE_PACK struct POST_PACK _USB_CONFIGURATION_DESCRIPTOR
421 {
422  uint8_t bLength;
423  uint8_t bDescriptorType;
424  uint16_t wTotalLength;
429  uint8_t bNumInterfaces;
430  uint8_t bConfigurationValue;
433  uint8_t iConfiguration;
435  uint8_t bmAttributes;
451  uint8_t bMaxPower;
475 } ;
477 typedef struct _USB_CONFIGURATION_DESCRIPTOR USB_CONFIGURATION_DESCRIPTOR;
478 
480 PRE_PACK struct POST_PACK _USB_INTERFACE_DESCRIPTOR
481 {
482  uint8_t bLength;
483  uint8_t bDescriptorType;
484  uint8_t bInterfaceNumber;
488  uint8_t bAlternateSetting;
490  uint8_t bNumEndpoints;
494  uint8_t bInterfaceClass;
501  uint8_t bInterfaceSubClass;
509  uint8_t bInterfaceProtocol;
523  uint8_t iInterface;
524 } ;
526 typedef struct _USB_INTERFACE_DESCRIPTOR USB_INTERFACE_DESCRIPTOR;
527 
529 PRE_PACK struct POST_PACK _USB_ENDPOINT_DESCRIPTOR
530 {
531  uint8_t bLength;
532  uint8_t bDescriptorType;
533  uint8_t bEndpointAddress;
541  uint8_t bmAttributes;
565  uint16_t wMaxPacketSize;
585  uint8_t bInterval;
607 } ;
609 typedef struct _USB_ENDPOINT_DESCRIPTOR USB_ENDPOINT_DESCRIPTOR;
610 
612 PRE_PACK struct POST_PACK _USB_STRING_DESCRIPTOR
613 {
614  uint8_t bLength;
615  uint8_t bDescriptorType;
616  uint16_t bString/*[]*/;
617 } ;
619 typedef struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR;
620 
622 PRE_PACK struct POST_PACK _USB_COMMON_DESCRIPTOR
623 {
624  uint8_t bLength;
625  uint8_t bDescriptorType;
626 } ;
628 typedef struct _USB_COMMON_DESCRIPTOR USB_COMMON_DESCRIPTOR;
629 
631 PRE_PACK struct POST_PACK _USB_OTHER_SPEED_CONFIGURATION
632 {
633  uint8_t bLength;
634  uint8_t bDescriptorType;
635  uint16_t wTotalLength;
636  uint8_t bNumInterfaces;
637  uint8_t bConfigurationValue;
638  uint8_t IConfiguration;
639  uint8_t bmAttributes;
640  uint8_t bMaxPower;
641 } ;
643 typedef struct _USB_OTHER_SPEED_CONFIGURATION USB_OTHER_SPEED_CONFIGURATION;
644 
648 typedef void* USBD_HANDLE_T;
649 
652 #endif /* __USB_H__ */