1 /*----------------------------------------------------------------------------
3 *----------------------------------------------------------------------------
5 * Purpose: USB Definitions
7 *----------------------------------------------------------------------------
8 * This software is supplied "AS IS" without any warranties, express,
9 * implied or statutory, including but not limited to the implied
10 * warranties of fitness for purpose, satisfactory quality and
11 * noninfringement. Keil extends you a royalty-free right to reproduce
12 * and distribute executable files created using this software for use
13 * on NXP Semiconductors LPC microcontroller devices only. Nothing else
14 * gives you the right to use this software.
16 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
17 *---------------------------------------------------------------------------*/
28 } __attribute__((packed
)) WB
;
29 } __attribute__((packed
)) WORD_BYTE
;
32 /* bmRequestType.Dir */
33 #define REQUEST_HOST_TO_DEVICE 0
34 #define REQUEST_DEVICE_TO_HOST 1
36 /* bmRequestType.Type */
37 #define REQUEST_STANDARD 0
38 #define REQUEST_CLASS 1
39 #define REQUEST_VENDOR 2
40 #define REQUEST_RESERVED 3
42 /* bmRequestType.Recipient */
43 #define REQUEST_TO_DEVICE 0
44 #define REQUEST_TO_INTERFACE 1
45 #define REQUEST_TO_ENDPOINT 2
46 #define REQUEST_TO_OTHER 3
48 /* bmRequestType Definition */
49 typedef union _REQUEST_TYPE
{
51 uint8_t Recipient
: 5;
54 } __attribute__((packed
)) BM
;
56 } __attribute__((packed
)) REQUEST_TYPE
;
58 /* USB Standard Request Codes */
59 #define USB_REQUEST_GET_STATUS 0
60 #define USB_REQUEST_CLEAR_FEATURE 1
61 #define USB_REQUEST_SET_FEATURE 3
62 #define USB_REQUEST_SET_ADDRESS 5
63 #define USB_REQUEST_GET_DESCRIPTOR 6
64 #define USB_REQUEST_SET_DESCRIPTOR 7
65 #define USB_REQUEST_GET_CONFIGURATION 8
66 #define USB_REQUEST_SET_CONFIGURATION 9
67 #define USB_REQUEST_GET_INTERFACE 10
68 #define USB_REQUEST_SET_INTERFACE 11
69 #define USB_REQUEST_SYNC_FRAME 12
71 /* USB GET_STATUS Bit Values */
72 #define USB_GETSTATUS_SELF_POWERED 0x01
73 #define USB_GETSTATUS_REMOTE_WAKEUP 0x02
74 #define USB_GETSTATUS_ENDPOINT_STALL 0x01
76 /* USB Standard Feature selectors */
77 #define USB_FEATURE_ENDPOINT_STALL 0
78 #define USB_FEATURE_REMOTE_WAKEUP 1
80 /* USB Default Control Pipe Setup Packet */
81 typedef struct _USB_SETUP_PACKET
{
82 REQUEST_TYPE bmRequestType
;
87 } __attribute__((packed
)) USB_SETUP_PACKET
;
90 /* USB Descriptor Types */
91 #define USB_DEVICE_DESCRIPTOR_TYPE 1
92 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
93 #define USB_STRING_DESCRIPTOR_TYPE 3
94 #define USB_INTERFACE_DESCRIPTOR_TYPE 4
95 #define USB_ENDPOINT_DESCRIPTOR_TYPE 5
96 #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6
97 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
98 #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8
99 #define USB_OTG_DESCRIPTOR_TYPE 9
100 #define USB_DEBUG_DESCRIPTOR_TYPE 10
101 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11
103 /* USB Device Classes */
104 #define USB_DEVICE_CLASS_RESERVED 0x00
105 #define USB_DEVICE_CLASS_AUDIO 0x01
106 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
107 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
108 #define USB_DEVICE_CLASS_MONITOR 0x04
109 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
110 #define USB_DEVICE_CLASS_POWER 0x06
111 #define USB_DEVICE_CLASS_PRINTER 0x07
112 #define USB_DEVICE_CLASS_STORAGE 0x08
113 #define USB_DEVICE_CLASS_HUB 0x09
114 #define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF
115 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
117 /* bmAttributes in Configuration Descriptor */
118 #define USB_CONFIG_POWERED_MASK 0x40
119 #define USB_CONFIG_BUS_POWERED 0x80
120 #define USB_CONFIG_SELF_POWERED 0xC0
121 #define USB_CONFIG_REMOTE_WAKEUP 0x20
123 /* bMaxPower in Configuration Descriptor */
124 #define USB_CONFIG_POWER_MA(mA) ((mA)/2)
126 /* bEndpointAddress in Endpoint Descriptor */
127 #define USB_ENDPOINT_DIRECTION_MASK 0x80
128 #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
129 #define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
131 /* bmAttributes in Endpoint Descriptor */
132 #define USB_ENDPOINT_TYPE_MASK 0x03
133 #define USB_ENDPOINT_TYPE_CONTROL 0x00
134 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
135 #define USB_ENDPOINT_TYPE_BULK 0x02
136 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
137 #define USB_ENDPOINT_SYNC_MASK 0x0C
138 #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00
139 #define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04
140 #define USB_ENDPOINT_SYNC_ADAPTIVE 0x08
141 #define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C
142 #define USB_ENDPOINT_USAGE_MASK 0x30
143 #define USB_ENDPOINT_USAGE_DATA 0x00
144 #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
145 #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20
146 #define USB_ENDPOINT_USAGE_RESERVED 0x30
148 /* USB Standard Device Descriptor */
149 typedef struct _USB_DEVICE_DESCRIPTOR
{
151 uint8_t bDescriptorType
;
153 uint8_t bDeviceClass
;
154 uint8_t bDeviceSubClass
;
155 uint8_t bDeviceProtocol
;
156 uint8_t bMaxPacketSize0
;
160 uint8_t iManufacturer
;
162 uint8_t iSerialNumber
;
163 uint8_t bNumConfigurations
;
164 } __attribute__((packed
)) USB_DEVICE_DESCRIPTOR
;
166 /* USB 2.0 Device Qualifier Descriptor */
167 typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR
{
169 uint8_t bDescriptorType
;
171 uint8_t bDeviceClass
;
172 uint8_t bDeviceSubClass
;
173 uint8_t bDeviceProtocol
;
174 uint8_t bMaxPacketSize0
;
175 uint8_t bNumConfigurations
;
177 } __attribute__((packed
)) USB_DEVICE_QUALIFIER_DESCRIPTOR
;
179 /* USB Standard Configuration Descriptor */
180 typedef struct _USB_CONFIGURATION_DESCRIPTOR
{
182 uint8_t bDescriptorType
;
183 uint16_t wTotalLength
;
184 uint8_t bNumInterfaces
;
185 uint8_t bConfigurationValue
;
186 uint8_t iConfiguration
;
187 uint8_t bmAttributes
;
189 } __attribute__((packed
)) USB_CONFIGURATION_DESCRIPTOR
;
191 /* USB Standard Interface Descriptor */
192 typedef struct _USB_INTERFACE_DESCRIPTOR
{
194 uint8_t bDescriptorType
;
195 uint8_t bInterfaceNumber
;
196 uint8_t bAlternateSetting
;
197 uint8_t bNumEndpoints
;
198 uint8_t bInterfaceClass
;
199 uint8_t bInterfaceSubClass
;
200 uint8_t bInterfaceProtocol
;
202 } __attribute__((packed
)) USB_INTERFACE_DESCRIPTOR
;
204 /* USB Standard Endpoint Descriptor */
205 typedef struct _USB_ENDPOINT_DESCRIPTOR
{
207 uint8_t bDescriptorType
;
208 uint8_t bEndpointAddress
;
209 uint8_t bmAttributes
;
210 uint16_t wMaxPacketSize
;
212 } __attribute__((packed
)) USB_ENDPOINT_DESCRIPTOR
;
214 /* USB String Descriptor */
215 typedef struct _USB_STRING_DESCRIPTOR
{
217 uint8_t bDescriptorType
;
218 uint16_t bString
/*[]*/;
219 } __attribute__((packed
)) USB_STRING_DESCRIPTOR
;
221 /* USB Common Descriptor */
222 typedef struct _USB_COMMON_DESCRIPTOR
{
224 uint8_t bDescriptorType
;
225 } __attribute__((packed
)) USB_COMMON_DESCRIPTOR
;
228 #endif /* __USB_H__ */