USBD ROM Stack  2.0
ROM based USB device stack
mw_usbd.h
Go to the documentation of this file.
1 /***********************************************************************
2  * $Id:: mw_usbd.h 2219 2015-12-08 22:18:38Z usb00423 $
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 #define INLINE inline
55 
56 #elif defined(__CC_ARM)
57 #define PRE_PACK __packed
58 #define POST_PACK
59 #define ALIGNED(n) __align(n)
60 #define INLINE __inline
61 
62 #elif defined(__ICCARM__)
63 #define PRE_PACK __packed
64 #define POST_PACK
65 #define PRAGMA_ALIGN_4096 _Pragma("data_alignment=4096")
66 #define PRAGMA_ALIGN_2048 _Pragma("data_alignment=2048")
67 #define PRAGMA_ALIGN_256 _Pragma("data_alignment=256")
68 #define PRAGMA_ALIGN_128 _Pragma("data_alignment=128")
69 #define PRAGMA_ALIGN_64 _Pragma("data_alignment=64")
70 #define PRAGMA_ALIGN_48 _Pragma("data_alignment=48")
71 #define PRAGMA_ALIGN_32 _Pragma("data_alignment=32")
72 #define PRAGMA_ALIGN_4 _Pragma("data_alignment=4")
73 #define ALIGNED(n) PRAGMA_ALIGN_ ## n
74 #define INLINE inline
75 #endif
76 
78 PRE_PACK struct POST_PACK _WB_T {
79  uint8_t L;
81  uint8_t H;
82 };
84 typedef struct _WB_T WB_T;
85 
87 PRE_PACK union POST_PACK __WORD_BYTE {
88  uint16_t W;
90  WB_T WB;
91 };
93 typedef union __WORD_BYTE WORD_BYTE;
94 
99 #define REQUEST_HOST_TO_DEVICE 0
100 
101 #define REQUEST_DEVICE_TO_HOST 1
102 
108 #define REQUEST_STANDARD 0
109 
110 #define REQUEST_CLASS 1
111 
112 #define REQUEST_VENDOR 2
113 
114 #define REQUEST_RESERVED 3
115 
121 #define REQUEST_TO_DEVICE 0
122 
123 #define REQUEST_TO_INTERFACE 1
124 
125 #define REQUEST_TO_ENDPOINT 2
126 
127 #define REQUEST_TO_OTHER 3
128 
131 PRE_PACK struct POST_PACK _BM_T {
132  uint8_t Recipient : 5;
134  uint8_t Type : 2;
135  uint8_t Dir : 1;
136 };
138 typedef struct _BM_T BM_T;
139 
141 PRE_PACK union POST_PACK _REQUEST_TYPE {
142  uint8_t B;
144  BM_T BM;
145 };
147 typedef union _REQUEST_TYPE REQUEST_TYPE;
148 
153 #define USB_REQUEST_GET_STATUS 0
154 
155 #define USB_REQUEST_CLEAR_FEATURE 1
156 
157 #define USB_REQUEST_SET_FEATURE 3
158 
159 #define USB_REQUEST_SET_ADDRESS 5
160 
161 #define USB_REQUEST_GET_DESCRIPTOR 6
162 
163 #define USB_REQUEST_SET_DESCRIPTOR 7
164 
165 #define USB_REQUEST_GET_CONFIGURATION 8
166 
167 #define USB_REQUEST_SET_CONFIGURATION 9
168 
169 #define USB_REQUEST_GET_INTERFACE 10
170 
171 #define USB_REQUEST_SET_INTERFACE 11
172 
173 #define USB_REQUEST_SYNC_FRAME 12
174 
180 #define USB_GETSTATUS_SELF_POWERED 0x01
181 
182 #define USB_GETSTATUS_REMOTE_WAKEUP 0x02
183 
184 #define USB_GETSTATUS_ENDPOINT_STALL 0x01
185 
191 #define USB_FEATURE_ENDPOINT_STALL 0
192 
193 #define USB_FEATURE_REMOTE_WAKEUP 1
194 
195 #define USB_FEATURE_TEST_MODE 2
196 
199 PRE_PACK struct POST_PACK _USB_SETUP_PACKET {
200  REQUEST_TYPE bmRequestType;
204  uint8_t bRequest;
208  WORD_BYTE wValue;
211  WORD_BYTE wIndex;
215  uint16_t wLength;
219 };
221 typedef struct _USB_SETUP_PACKET USB_SETUP_PACKET;
222 
227 #define USB_DEVICE_DESCRIPTOR_TYPE 1
228 
229 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
230 
231 #define USB_STRING_DESCRIPTOR_TYPE 3
232 
233 #define USB_INTERFACE_DESCRIPTOR_TYPE 4
234 
235 #define USB_ENDPOINT_DESCRIPTOR_TYPE 5
236 
237 #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6
238 
239 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
240 
241 #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8
242 
243 #define USB_OTG_DESCRIPTOR_TYPE 9
244 
245 #define USB_DEBUG_DESCRIPTOR_TYPE 10
246 
247 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11
248 #define USB_SECURITY_TYPE 12
249 #define USB_KEY_TYPE 13
250 #define USB_ENCRIPTION_TYPE 14
251 #define USB_BOS_TYPE 15
252 #define USB_DEVICE_CAPABILITY_TYPE 16
253 #define USB_WIRELESS_ENDPOINT_COMPANION_TYPE 17
254 
260 #define USB_DEVICE_CLASS_RESERVED 0x00
261 
262 #define USB_DEVICE_CLASS_AUDIO 0x01
263 
264 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
265 
266 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
267 
268 #define USB_DEVICE_CLASS_MONITOR 0x04
269 
270 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
271 
272 #define USB_DEVICE_CLASS_POWER 0x06
273 
274 #define USB_DEVICE_CLASS_PRINTER 0x07
275 
276 #define USB_DEVICE_CLASS_STORAGE 0x08
277 
278 #define USB_DEVICE_CLASS_HUB 0x09
279 
280 #define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF
281 
282 #define USB_DEVICE_CLASS_APP 0xFE
283 
284 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
285 
291 #define USB_CONFIG_POWERED_MASK 0x40
292 
293 #define USB_CONFIG_BUS_POWERED 0x80
294 
295 #define USB_CONFIG_SELF_POWERED 0xC0
296 
297 #define USB_CONFIG_REMOTE_WAKEUP 0x20
298 
301 #define USB_CONFIG_POWER_MA(mA) ((mA) / 2)
302 
307 #define USB_ENDPOINT_DIRECTION_MASK 0x80
308 
309 #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
310 
311 #define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
312 
318 #define USB_ENDPOINT_TYPE_MASK 0x03
319 
320 #define USB_ENDPOINT_TYPE_CONTROL 0x00
321 
322 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
323 
324 #define USB_ENDPOINT_TYPE_BULK 0x02
325 
326 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
327 
328 #define USB_ENDPOINT_SYNC_MASK 0x0C
329 
330 #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00
331 
332 #define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04
333 
334 #define USB_ENDPOINT_SYNC_ADAPTIVE 0x08
335 
336 #define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C
337 
338 #define USB_ENDPOINT_USAGE_MASK 0x30
339 
340 #define USB_ENDPOINT_USAGE_DATA 0x00
341 
342 #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
343 
344 #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20
345 
346 #define USB_ENDPOINT_USAGE_RESERVED 0x30
347 
350 #define USB_ENDPOINT_0_HS_MAXP 64
351 
352 #define USB_ENDPOINT_0_LS_MAXP 8
353 
354 #define USB_ENDPOINT_BULK_HS_MAXP 512
355 
357 PRE_PACK struct POST_PACK _USB_DEVICE_DESCRIPTOR {
358  uint8_t bLength;
360  uint8_t bDescriptorType;
361  uint16_t bcdUSB;
367  uint8_t bDeviceClass;
382  uint8_t bDeviceSubClass;
391  uint8_t bDeviceProtocol;
407  uint8_t bMaxPacketSize0;
412  uint16_t idVendor;
413  uint16_t idProduct;
414  uint16_t bcdDevice;
415  uint8_t iManufacturer;
416  uint8_t iProduct;
417  uint8_t iSerialNumber;
421 };
423 typedef struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR;
424 
426 PRE_PACK struct POST_PACK _USB_DEVICE_QUALIFIER_DESCRIPTOR {
427  uint8_t bLength;
429  uint8_t bDescriptorType;
430  uint16_t bcdUSB;
431  uint8_t bDeviceClass;
432  uint8_t bDeviceSubClass;
433  uint8_t bDeviceProtocol;
434  uint8_t bMaxPacketSize0;
436  uint8_t bReserved;
437 };
439 typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR USB_DEVICE_QUALIFIER_DESCRIPTOR;
440 
442 PRE_PACK struct POST_PACK _USB_CONFIGURATION_DESCRIPTOR {
443  uint8_t bLength;
445  uint8_t bDescriptorType;
446  uint16_t wTotalLength;
451  uint8_t bNumInterfaces;
455  uint8_t iConfiguration;
457  uint8_t bmAttributes;
473  uint8_t bMaxPower;
497 };
499 typedef struct _USB_CONFIGURATION_DESCRIPTOR USB_CONFIGURATION_DESCRIPTOR;
500 
502 PRE_PACK struct POST_PACK _USB_INTERFACE_DESCRIPTOR {
503  uint8_t bLength;
505  uint8_t bDescriptorType;
512  uint8_t bNumEndpoints;
516  uint8_t bInterfaceClass;
545  uint8_t iInterface;
546 };
548 typedef struct _USB_INTERFACE_DESCRIPTOR USB_INTERFACE_DESCRIPTOR;
549 
551 PRE_PACK struct POST_PACK _USB_ENDPOINT_DESCRIPTOR {
552  uint8_t bLength;
554  uint8_t bDescriptorType;
563  uint8_t bmAttributes;
587  uint16_t wMaxPacketSize;
607  uint8_t bInterval;
629 };
631 typedef struct _USB_ENDPOINT_DESCRIPTOR USB_ENDPOINT_DESCRIPTOR;
632 
634 PRE_PACK struct POST_PACK _USB_STRING_DESCRIPTOR {
635  uint8_t bLength;
637  uint8_t bDescriptorType;
638  uint16_t bString /*[]*/;
639 };
641 typedef struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR;
642 
644 PRE_PACK struct POST_PACK _USB_COMMON_DESCRIPTOR {
645  uint8_t bLength;
647  uint8_t bDescriptorType;
648 };
650 typedef struct _USB_COMMON_DESCRIPTOR USB_COMMON_DESCRIPTOR;
651 
653 PRE_PACK struct POST_PACK _USB_OTHER_SPEED_CONFIGURATION {
654  uint8_t bLength;
656  uint8_t bDescriptorType;
657  uint16_t wTotalLength;
658  uint8_t bNumInterfaces;
660  uint8_t IConfiguration;
661  uint8_t bmAttributes;
662  uint8_t bMaxPower;
663 };
665 typedef struct _USB_OTHER_SPEED_CONFIGURATION USB_OTHER_SPEED_CONFIGURATION;
666 
667 /* USB BOS Descriptor. */
668 PRE_PACK struct POST_PACK _USB_BOS_DESCRIPTOR {
669  uint8_t bLength;
670  uint8_t bDescriptorType;
671  uint16_t wTotalLength;
672  uint8_t bNumDeviceCaps;
673 };
675 typedef struct _USB_BOS_DESCRIPTOR USB_BOS_DESCRIPTOR;
676 
678 PRE_PACK struct POST_PACK _USB_SS_DEVICE_CAPABLITY_DESCRIPTOR {
679  uint8_t bLength;
680  uint8_t bDescriptorType;
681  uint8_t bDeviceCapabilityType;
682  uint8_t bAttributes;
683  uint16_t wSpeedsSupported;
684  uint8_t bFunctionalitySupport;
685  uint8_t bU1DevExitLat;
686  uint16_t bU2DevExitLat;
687 };
689 typedef struct _USB_SS_DEVICE_CAPABLITY_DESCRIPTOR USB_SS_DEVICE_CAPABILITY_DESCRIPTOR;
690 
692 PRE_PACK struct POST_PACK _USB_DEVICE_CAPABLITY_DESCRIPTOR {
693  uint8_t bLength;
694  uint8_t bDescriptorType;
695  uint8_t bDeviceCapabilityType;
696  uint32_t bmAttributes;
697 };
699 typedef struct _USB_DEVICE_CAPABLITY_DESCRIPTOR USB_DEVICE_CAPABILITY_DESCRIPTOR;
700 
704 typedef void *USBD_HANDLE_T;
705 
708 #endif /* __USB_H__ */
uint8_t bConfigurationValue
Definition: mw_usbd.h:452
Definition: mw_usbd.h:199
uint8_t H
Definition: mw_usbd.h:81
uint8_t bInterfaceClass
Definition: mw_usbd.h:516
uint16_t bcdUSB
Definition: mw_usbd.h:361
uint8_t iProduct
Definition: mw_usbd.h:416
uint8_t bDescriptorType
Definition: mw_usbd.h:445
Definition: mw_usbd.h:357
uint8_t IConfiguration
Definition: mw_usbd.h:660
uint8_t iManufacturer
Definition: mw_usbd.h:415
uint8_t bDescriptorType
Definition: mw_usbd.h:554
uint8_t bReserved
Definition: mw_usbd.h:436
uint8_t bDeviceClass
Definition: mw_usbd.h:367
uint8_t bDescriptorType
Definition: mw_usbd.h:656
BM_T BM
Definition: mw_usbd.h:144
uint8_t B
Definition: mw_usbd.h:142
uint8_t iConfiguration
Definition: mw_usbd.h:455
uint8_t Type
Definition: mw_usbd.h:134
uint16_t bcdDevice
Definition: mw_usbd.h:414
Definition: mw_usbd.h:131
uint8_t bMaxPacketSize0
Definition: mw_usbd.h:407
uint8_t L
Definition: mw_usbd.h:79
Definition: mw_usbd.h:668
uint16_t bcdUSB
Definition: mw_usbd.h:430
uint16_t idProduct
Definition: mw_usbd.h:413
uint8_t bRequest
Definition: mw_usbd.h:204
uint8_t bDescriptorType
Definition: mw_usbd.h:637
uint8_t bDeviceClass
Definition: mw_usbd.h:431
uint8_t bLength
Definition: mw_usbd.h:654
REQUEST_TYPE bmRequestType
Definition: mw_usbd.h:200
uint8_t bInterfaceSubClass
Definition: mw_usbd.h:523
Definition: mw_usbd.h:634
uint8_t bmAttributes
Definition: mw_usbd.h:661
uint16_t wTotalLength
Definition: mw_usbd.h:657
uint8_t bDeviceSubClass
Definition: mw_usbd.h:432
uint8_t bInterfaceProtocol
Definition: mw_usbd.h:531
uint8_t Recipient
Definition: mw_usbd.h:132
uint8_t bLength
Definition: mw_usbd.h:427
uint8_t bDeviceSubClass
Definition: mw_usbd.h:382
uint8_t bDeviceProtocol
Definition: mw_usbd.h:433
uint8_t bDescriptorType
Definition: mw_usbd.h:429
uint8_t bNumInterfaces
Definition: mw_usbd.h:451
WORD_BYTE wIndex
Definition: mw_usbd.h:211
Definition: mw_usbd.h:502
Definition: mw_usbd.h:442
WORD_BYTE wValue
Definition: mw_usbd.h:208
uint8_t iInterface
Definition: mw_usbd.h:545
uint8_t bMaxPower
Definition: mw_usbd.h:662
uint8_t bMaxPacketSize0
Definition: mw_usbd.h:434
uint8_t bNumConfigurations
Definition: mw_usbd.h:420
uint8_t bInterfaceNumber
Definition: mw_usbd.h:506
Definition: mw_usbd.h:426
uint8_t bLength
Definition: mw_usbd.h:645
uint8_t bLength
Definition: mw_usbd.h:443
uint8_t bMaxPower
Definition: mw_usbd.h:473
uint16_t W
Definition: mw_usbd.h:88
uint8_t bConfigurationValue
Definition: mw_usbd.h:659
uint8_t bInterval
Definition: mw_usbd.h:607
uint16_t idVendor
Definition: mw_usbd.h:412
uint8_t bDescriptorType
Definition: mw_usbd.h:505
uint8_t Dir
Definition: mw_usbd.h:135
uint8_t bEndpointAddress
Definition: mw_usbd.h:555
uint8_t bDescriptorType
Definition: mw_usbd.h:360
Definition: mw_usbd.h:87
uint8_t bNumInterfaces
Definition: mw_usbd.h:658
uint8_t bmAttributes
Definition: mw_usbd.h:457
Definition: mw_usbd.h:644
uint8_t bDescriptorType
Definition: mw_usbd.h:647
uint16_t wLength
Definition: mw_usbd.h:215
Definition: mw_usbd.h:141
uint8_t iSerialNumber
Definition: mw_usbd.h:417
Definition: mw_usbd.h:78
uint16_t wTotalLength
Definition: mw_usbd.h:446
Definition: mw_usbd.h:692
Definition: mw_usbd.h:653
uint8_t bLength
Definition: mw_usbd.h:635
uint8_t bNumEndpoints
Definition: mw_usbd.h:512
uint8_t bLength
Definition: mw_usbd.h:358
uint8_t bLength
Definition: mw_usbd.h:552
void * USBD_HANDLE_T
Definition: mw_usbd.h:704
uint8_t bLength
Definition: mw_usbd.h:503
uint16_t wMaxPacketSize
Definition: mw_usbd.h:587
WB_T WB
Definition: mw_usbd.h:90
uint8_t bmAttributes
Definition: mw_usbd.h:563
Definition: mw_usbd.h:551
uint8_t bNumConfigurations
Definition: mw_usbd.h:435
uint8_t bDeviceProtocol
Definition: mw_usbd.h:391
Definition: mw_usbd.h:678
uint8_t bAlternateSetting
Definition: mw_usbd.h:510