v1.1.0
[hackover2013-badge-firmware.git] / core / usbhid-rom / usb.h
1 /*----------------------------------------------------------------------------
2 * U S B - K e r n e l
3 *----------------------------------------------------------------------------
4 * Name: usb.h
5 * Purpose: USB Definitions
6 * Version: V1.20
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.
15 *
16 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
17 *---------------------------------------------------------------------------*/
18
19 #ifndef __USB_H__
20 #define __USB_H__
21
22 #include "sysdefs.h"
23
24 typedef union
25 {
26 uint16_t W;
27 struct
28 {
29 uint8_t L;
30 uint8_t H;
31 } __attribute__ ((packed)) WB;
32 } __attribute__ ((packed)) WORD_BYTE;
33
34
35 /* bmRequestType.Dir */
36 #define REQUEST_HOST_TO_DEVICE 0
37 #define REQUEST_DEVICE_TO_HOST 1
38
39 /* bmRequestType.Type */
40 #define REQUEST_STANDARD 0
41 #define REQUEST_CLASS 1
42 #define REQUEST_VENDOR 2
43 #define REQUEST_RESERVED 3
44
45 /* bmRequestType.Recipient */
46 #define REQUEST_TO_DEVICE 0
47 #define REQUEST_TO_INTERFACE 1
48 #define REQUEST_TO_ENDPOINT 2
49 #define REQUEST_TO_OTHER 3
50
51 /* bmRequestType Definition */
52 typedef union _REQUEST_TYPE
53 {
54 struct _BM
55 {
56 uint8_t Recipient : 5;
57 uint8_t Type : 2;
58 uint8_t Dir : 1;
59 } __attribute__ ((packed)) BM;
60 uint8_t B;
61 } __attribute__ ((packed)) REQUEST_TYPE;
62
63 /* USB Standard Request Codes */
64 #define USB_REQUEST_GET_STATUS 0
65 #define USB_REQUEST_CLEAR_FEATURE 1
66 #define USB_REQUEST_SET_FEATURE 3
67 #define USB_REQUEST_SET_ADDRESS 5
68 #define USB_REQUEST_GET_DESCRIPTOR 6
69 #define USB_REQUEST_SET_DESCRIPTOR 7
70 #define USB_REQUEST_GET_CONFIGURATION 8
71 #define USB_REQUEST_SET_CONFIGURATION 9
72 #define USB_REQUEST_GET_INTERFACE 10
73 #define USB_REQUEST_SET_INTERFACE 11
74 #define USB_REQUEST_SYNC_FRAME 12
75
76 /* USB GET_STATUS Bit Values */
77 #define USB_GETSTATUS_SELF_POWERED 0x01
78 #define USB_GETSTATUS_REMOTE_WAKEUP 0x02
79 #define USB_GETSTATUS_ENDPOINT_STALL 0x01
80
81 /* USB Standard Feature selectors */
82 #define USB_FEATURE_ENDPOINT_STALL 0
83 #define USB_FEATURE_REMOTE_WAKEUP 1
84
85 /* USB Default Control Pipe Setup Packet */
86 typedef struct _USB_SETUP_PACKET
87 {
88 REQUEST_TYPE bmRequestType;
89 uint8_t bRequest;
90 WORD_BYTE wValue;
91 WORD_BYTE wIndex;
92 uint16_t wLength;
93 } __attribute__ ((packed)) USB_SETUP_PACKET;
94
95
96 /* USB Descriptor Types */
97 #define USB_DEVICE_DESCRIPTOR_TYPE 1
98 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
99 #define USB_STRING_DESCRIPTOR_TYPE 3
100 #define USB_INTERFACE_DESCRIPTOR_TYPE 4
101 #define USB_ENDPOINT_DESCRIPTOR_TYPE 5
102 #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6
103 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7
104 #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8
105 #define USB_OTG_DESCRIPTOR_TYPE 9
106 #define USB_DEBUG_DESCRIPTOR_TYPE 10
107 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11
108
109 /* USB Device Classes */
110 #define USB_DEVICE_CLASS_RESERVED 0x00
111 #define USB_DEVICE_CLASS_AUDIO 0x01
112 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
113 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
114 #define USB_DEVICE_CLASS_MONITOR 0x04
115 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
116 #define USB_DEVICE_CLASS_POWER 0x06
117 #define USB_DEVICE_CLASS_PRINTER 0x07
118 #define USB_DEVICE_CLASS_STORAGE 0x08
119 #define USB_DEVICE_CLASS_HUB 0x09
120 #define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF
121 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
122
123 /* bmAttributes in Configuration Descriptor */
124 #define USB_CONFIG_POWERED_MASK 0x40
125 #define USB_CONFIG_BUS_POWERED 0x80
126 #define USB_CONFIG_SELF_POWERED 0xC0
127 #define USB_CONFIG_REMOTE_WAKEUP 0x20
128
129 /* bMaxPower in Configuration Descriptor */
130 #define USB_CONFIG_POWER_MA(mA) ((mA)/2)
131
132 /* bEndpointAddress in Endpoint Descriptor */
133 #define USB_ENDPOINT_DIRECTION_MASK 0x80
134 #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
135 #define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
136
137 /* bmAttributes in Endpoint Descriptor */
138 #define USB_ENDPOINT_TYPE_MASK 0x03
139 #define USB_ENDPOINT_TYPE_CONTROL 0x00
140 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
141 #define USB_ENDPOINT_TYPE_BULK 0x02
142 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
143 #define USB_ENDPOINT_SYNC_MASK 0x0C
144 #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00
145 #define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04
146 #define USB_ENDPOINT_SYNC_ADAPTIVE 0x08
147 #define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C
148 #define USB_ENDPOINT_USAGE_MASK 0x30
149 #define USB_ENDPOINT_USAGE_DATA 0x00
150 #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
151 #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20
152 #define USB_ENDPOINT_USAGE_RESERVED 0x30
153
154 /* USB Standard Device Descriptor */
155 typedef struct _USB_DEVICE_DESCRIPTOR
156 {
157 uint8_t bLength;
158 uint8_t bDescriptorType;
159 uint16_t bcdUSB;
160 uint8_t bDeviceClass;
161 uint8_t bDeviceSubClass;
162 uint8_t bDeviceProtocol;
163 uint8_t bMaxPacketSize0;
164 uint16_t idVendor;
165 uint16_t idProduct;
166 uint16_t bcdDevice;
167 uint8_t iManufacturer;
168 uint8_t iProduct;
169 uint8_t iSerialNumber;
170 uint8_t bNumConfigurations;
171 } __attribute__ ((packed)) USB_DEVICE_DESCRIPTOR;
172
173 /* USB 2.0 Device Qualifier Descriptor */
174 typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR
175 {
176 uint8_t bLength;
177 uint8_t bDescriptorType;
178 uint16_t bcdUSB;
179 uint8_t bDeviceClass;
180 uint8_t bDeviceSubClass;
181 uint8_t bDeviceProtocol;
182 uint8_t bMaxPacketSize0;
183 uint8_t bNumConfigurations;
184 uint8_t bReserved;
185 } __attribute__ ((packed)) USB_DEVICE_QUALIFIER_DESCRIPTOR;
186
187 /* USB Standard Configuration Descriptor */
188 typedef struct _USB_CONFIGURATION_DESCRIPTOR
189 {
190 uint8_t bLength;
191 uint8_t bDescriptorType;
192 uint16_t wTotalLength;
193 uint8_t bNumInterfaces;
194 uint8_t bConfigurationValue;
195 uint8_t iConfiguration;
196 uint8_t bmAttributes;
197 uint8_t bMaxPower;
198 } __attribute__ ((packed)) USB_CONFIGURATION_DESCRIPTOR;
199
200 /* USB Standard Interface Descriptor */
201 typedef struct _USB_INTERFACE_DESCRIPTOR
202 {
203 uint8_t bLength;
204 uint8_t bDescriptorType;
205 uint8_t bInterfaceNumber;
206 uint8_t bAlternateSetting;
207 uint8_t bNumEndpoints;
208 uint8_t bInterfaceClass;
209 uint8_t bInterfaceSubClass;
210 uint8_t bInterfaceProtocol;
211 uint8_t iInterface;
212 } __attribute__ ((packed)) USB_INTERFACE_DESCRIPTOR;
213
214 /* USB Standard Endpoint Descriptor */
215 typedef struct _USB_ENDPOINT_DESCRIPTOR
216 {
217 uint8_t bLength;
218 uint8_t bDescriptorType;
219 uint8_t bEndpointAddress;
220 uint8_t bmAttributes;
221 uint16_t wMaxPacketSize;
222 uint8_t bInterval;
223 } __attribute__ ((packed)) USB_ENDPOINT_DESCRIPTOR;
224
225 /* USB String Descriptor */
226 typedef struct _USB_STRING_DESCRIPTOR
227 {
228 uint8_t bLength;
229 uint8_t bDescriptorType;
230 uint16_t bString/*[]*/;
231 } __attribute__ ((packed)) USB_STRING_DESCRIPTOR;
232
233 /* USB Common Descriptor */
234 typedef struct _USB_COMMON_DESCRIPTOR
235 {
236 uint8_t bLength;
237 uint8_t bDescriptorType;
238 } __attribute__ ((packed)) USB_COMMON_DESCRIPTOR;
239
240 #endif
This page took 0.056339 seconds and 5 git commands to generate.