1 |
/*---------------------------------------------------------------------------- |
---|
2 |
* U S B - K e r n e l |
---|
3 |
*---------------------------------------------------------------------------- |
---|
4 |
* Name: USB.H |
---|
5 |
* Purpose: USB Definitions |
---|
6 |
* Version: V1.10 |
---|
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 LPC microcontroller devices only. Nothing else gives you |
---|
14 |
* the right to use this software. |
---|
15 |
* |
---|
16 |
* Copyright (c) 2005-2007 Keil Software. |
---|
17 |
*---------------------------------------------------------------------------*/ |
---|
18 |
|
---|
19 |
#ifndef __USB_H__ |
---|
20 |
#define __USB_H__ |
---|
21 |
|
---|
22 |
|
---|
23 |
typedef __packed union { |
---|
24 |
WORD W; |
---|
25 |
__packed struct { |
---|
26 |
BYTE L; |
---|
27 |
BYTE H; |
---|
28 |
} WB; |
---|
29 |
} WORD_BYTE; |
---|
30 |
|
---|
31 |
|
---|
32 |
/* bmRequestType.Dir */ |
---|
33 |
#define REQUEST_HOST_TO_DEVICE 0 |
---|
34 |
#define REQUEST_DEVICE_TO_HOST 1 |
---|
35 |
|
---|
36 |
/* bmRequestType.Type */ |
---|
37 |
#define REQUEST_STANDARD 0 |
---|
38 |
#define REQUEST_CLASS 1 |
---|
39 |
#define REQUEST_VENDOR 2 |
---|
40 |
#define REQUEST_RESERVED 3 |
---|
41 |
|
---|
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 |
---|
47 |
|
---|
48 |
/* bmRequestType Definition */ |
---|
49 |
typedef __packed union _REQUEST_TYPE { |
---|
50 |
__packed struct _BM { |
---|
51 |
BYTE Recipient : 5; |
---|
52 |
BYTE Type : 2; |
---|
53 |
BYTE Dir : 1; |
---|
54 |
} BM; |
---|
55 |
BYTE B; |
---|
56 |
} REQUEST_TYPE; |
---|
57 |
|
---|
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 |
---|
70 |
|
---|
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 |
---|
75 |
|
---|
76 |
/* USB Standard Feature selectors */ |
---|
77 |
#define USB_FEATURE_ENDPOINT_STALL 0 |
---|
78 |
#define USB_FEATURE_REMOTE_WAKEUP 1 |
---|
79 |
|
---|
80 |
/* USB Default Control Pipe Setup Packet */ |
---|
81 |
typedef __packed struct _USB_SETUP_PACKET { |
---|
82 |
REQUEST_TYPE bmRequestType; |
---|
83 |
BYTE bRequest; |
---|
84 |
WORD_BYTE wValue; |
---|
85 |
WORD_BYTE wIndex; |
---|
86 |
WORD wLength; |
---|
87 |
} USB_SETUP_PACKET; |
---|
88 |
|
---|
89 |
|
---|
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 |
|
---|
100 |
/* USB Device Classes */ |
---|
101 |
#define USB_DEVICE_CLASS_RESERVED 0x00 |
---|
102 |
#define USB_DEVICE_CLASS_AUDIO 0x01 |
---|
103 |
#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02 |
---|
104 |
#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03 |
---|
105 |
#define USB_DEVICE_CLASS_MONITOR 0x04 |
---|
106 |
#define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05 |
---|
107 |
#define USB_DEVICE_CLASS_POWER 0x06 |
---|
108 |
#define USB_DEVICE_CLASS_PRINTER 0x07 |
---|
109 |
#define USB_DEVICE_CLASS_STORAGE 0x08 |
---|
110 |
#define USB_DEVICE_CLASS_HUB 0x09 |
---|
111 |
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF |
---|
112 |
|
---|
113 |
/* bmAttributes in Configuration Descriptor */ |
---|
114 |
#define USB_CONFIG_POWERED_MASK 0xC0 |
---|
115 |
#define USB_CONFIG_BUS_POWERED 0x80 |
---|
116 |
#define USB_CONFIG_SELF_POWERED 0xC0 |
---|
117 |
#define USB_CONFIG_REMOTE_WAKEUP 0x20 |
---|
118 |
|
---|
119 |
/* bMaxPower in Configuration Descriptor */ |
---|
120 |
#define USB_CONFIG_POWER_MA(mA) ((mA)/2) |
---|
121 |
|
---|
122 |
/* bEndpointAddress in Endpoint Descriptor */ |
---|
123 |
#define USB_ENDPOINT_DIRECTION_MASK 0x80 |
---|
124 |
#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) |
---|
125 |
#define USB_ENDPOINT_IN(addr) ((addr) | 0x80) |
---|
126 |
|
---|
127 |
/* bmAttributes in Endpoint Descriptor */ |
---|
128 |
#define USB_ENDPOINT_TYPE_MASK 0x03 |
---|
129 |
#define USB_ENDPOINT_TYPE_CONTROL 0x00 |
---|
130 |
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 |
---|
131 |
#define USB_ENDPOINT_TYPE_BULK 0x02 |
---|
132 |
#define USB_ENDPOINT_TYPE_INTERRUPT 0x03 |
---|
133 |
#define USB_ENDPOINT_SYNC_MASK 0x0C |
---|
134 |
#define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00 |
---|
135 |
#define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04 |
---|
136 |
#define USB_ENDPOINT_SYNC_ADAPTIVE 0x08 |
---|
137 |
#define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C |
---|
138 |
#define USB_ENDPOINT_USAGE_MASK 0x30 |
---|
139 |
#define USB_ENDPOINT_USAGE_DATA 0x00 |
---|
140 |
#define USB_ENDPOINT_USAGE_FEEDBACK 0x10 |
---|
141 |
#define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20 |
---|
142 |
#define USB_ENDPOINT_USAGE_RESERVED 0x30 |
---|
143 |
|
---|
144 |
/* USB Standard Device Descriptor */ |
---|
145 |
typedef __packed struct _USB_DEVICE_DESCRIPTOR { |
---|
146 |
BYTE bLength; |
---|
147 |
BYTE bDescriptorType; |
---|
148 |
WORD bcdUSB; |
---|
149 |
BYTE bDeviceClass; |
---|
150 |
BYTE bDeviceSubClass; |
---|
151 |
BYTE bDeviceProtocol; |
---|
152 |
BYTE bMaxPacketSize0; |
---|
153 |
WORD idVendor; |
---|
154 |
WORD idProduct; |
---|
155 |
WORD bcdDevice; |
---|
156 |
BYTE iManufacturer; |
---|
157 |
BYTE iProduct; |
---|
158 |
BYTE iSerialNumber; |
---|
159 |
BYTE bNumConfigurations; |
---|
160 |
} USB_DEVICE_DESCRIPTOR; |
---|
161 |
|
---|
162 |
/* USB 2.0 Device Qualifier Descriptor */ |
---|
163 |
typedef __packed struct _USB_DEVICE_QUALIFIER_DESCRIPTOR { |
---|
164 |
BYTE bLength; |
---|
165 |
BYTE bDescriptorType; |
---|
166 |
WORD bcdUSB; |
---|
167 |
BYTE bDeviceClass; |
---|
168 |
BYTE bDeviceSubClass; |
---|
169 |
BYTE bDeviceProtocol; |
---|
170 |
BYTE bMaxPacketSize0; |
---|
171 |
BYTE bNumConfigurations; |
---|
172 |
BYTE bReserved; |
---|
173 |
} USB_DEVICE_QUALIFIER_DESCRIPTOR; |
---|
174 |
|
---|
175 |
/* USB Standard Configuration Descriptor */ |
---|
176 |
typedef __packed struct _USB_CONFIGURATION_DESCRIPTOR { |
---|
177 |
BYTE bLength; |
---|
178 |
BYTE bDescriptorType; |
---|
179 |
WORD wTotalLength; |
---|
180 |
BYTE bNumInterfaces; |
---|
181 |
BYTE bConfigurationValue; |
---|
182 |
BYTE iConfiguration; |
---|
183 |
BYTE bmAttributes; |
---|
184 |
BYTE bMaxPower; |
---|
185 |
} USB_CONFIGURATION_DESCRIPTOR; |
---|
186 |
|
---|
187 |
/* USB Standard Interface Descriptor */ |
---|
188 |
typedef __packed struct _USB_INTERFACE_DESCRIPTOR { |
---|
189 |
BYTE bLength; |
---|
190 |
BYTE bDescriptorType; |
---|
191 |
BYTE bInterfaceNumber; |
---|
192 |
BYTE bAlternateSetting; |
---|
193 |
BYTE bNumEndpoints; |
---|
194 |
BYTE bInterfaceClass; |
---|
195 |
BYTE bInterfaceSubClass; |
---|
196 |
BYTE bInterfaceProtocol; |
---|
197 |
BYTE iInterface; |
---|
198 |
} USB_INTERFACE_DESCRIPTOR; |
---|
199 |
|
---|
200 |
/* USB Standard Endpoint Descriptor */ |
---|
201 |
typedef __packed struct _USB_ENDPOINT_DESCRIPTOR { |
---|
202 |
BYTE bLength; |
---|
203 |
BYTE bDescriptorType; |
---|
204 |
BYTE bEndpointAddress; |
---|
205 |
BYTE bmAttributes; |
---|
206 |
WORD wMaxPacketSize; |
---|
207 |
BYTE bInterval; |
---|
208 |
} USB_ENDPOINT_DESCRIPTOR; |
---|
209 |
|
---|
210 |
/* USB String Descriptor */ |
---|
211 |
typedef __packed struct _USB_STRING_DESCRIPTOR { |
---|
212 |
BYTE bLength; |
---|
213 |
BYTE bDescriptorType; |
---|
214 |
WORD bString/*[]*/; |
---|
215 |
} USB_STRING_DESCRIPTOR; |
---|
216 |
|
---|
217 |
/* USB Common Descriptor */ |
---|
218 |
typedef __packed struct _USB_COMMON_DESCRIPTOR { |
---|
219 |
BYTE bLength; |
---|
220 |
BYTE bDescriptorType; |
---|
221 |
} USB_COMMON_DESCRIPTOR; |
---|
222 |
|
---|
223 |
|
---|
224 |
#endif /* __USB_H__ */ |
---|