1 /*************************************************/
2 /*** Module : USB specification ***/
3 /*** Author : Roman Bartosinski 29.07.2002 ***/
4 /*** Modify : 08.08.2002, 14.01.2003 ***/
5 /*************************************************/
7 #ifndef _USB_SPECIFICATIONS_AND_DEFINITIONS_MODULE
8 #define _USB_SPECIFICATIONS_AND_DEFINITIONS_MODULE
10 /*#include <inttypes.h>*/
15 #define PACKED __attribute__((packed))
17 #define PACKED /*nothing*/
21 /* this section is from __USB100.H__ and __CHAP9.H__ and define USB constants and structs */
23 /* *** USB Device Request *** (spec. 9.3) */
24 typedef struct _tag_usb_device_request {
25 uint8_t bmRequestType;
32 /****************************************************************************************/
33 /*** definitions for USB tranfer standard packets described in USB secif. - chapter 9 ***/
34 /****************************************************************************************/
35 #define DEVICE_ADDRESS_MASK 0x7F
37 /* bmRequestType D7 - Data transfer direction */
38 #define USB_DATA_DIR_MASK (uint8_t)0x80
39 #define USB_DATA_DIR_FROM_HOST (uint8_t)0x00
40 #define USB_DATA_DIR_TO_HOST (uint8_t)0x80
41 /* bmRequestType D4..D0 - Recipient */
42 #define USB_RECIPIENT (uint8_t)0x1F
43 #define USB_RECIPIENT_DEVICE (uint8_t)0x00
44 #define USB_RECIPIENT_INTERFACE (uint8_t)0x01
45 #define USB_RECIPIENT_ENDPOINT (uint8_t)0x02
46 #define USB_RECIPIENT_OTHER (uint8_t)0x03
47 /* bmRequestType D6..D5 - Type */
48 #define USB_REQUEST_TYPE_MASK (uint8_t)0x60
49 #define USB_STANDARD_REQUEST (uint8_t)0x00
50 #define USB_CLASS_REQUEST (uint8_t)0x20
51 #define USB_VENDOR_REQUEST (uint8_t)0x40
52 /* Standard request codes (spec. 9.4) */
53 #define USB_REQUEST_MASK (uint8_t)0x0F
54 #define USB_REQUEST_GET_STATUS 0x00
55 #define USB_REQUEST_CLEAR_FEATURE 0x01
56 #define USB_REQUEST_SET_FEATURE 0x03
57 #define USB_REQUEST_SET_ADDRESS 0x05
58 #define USB_REQUEST_GET_DESCRIPTOR 0x06
59 #define USB_REQUEST_SET_DESCRIPTOR 0x07
60 #define USB_REQUEST_GET_CONFIGURATION 0x08
61 #define USB_REQUEST_SET_CONFIGURATION 0x09
62 #define USB_REQUEST_GET_INTERFACE 0x0A
63 #define USB_REQUEST_SET_INTERFACE 0x0B
64 #define USB_REQUEST_SYNC_FRAME 0x0C
65 /* Descriptor types (spec. 9.4) */
66 #define USB_DESCRIPTOR_TYPE_DEVICE 0x01
67 #define USB_DESCRIPTOR_TYPE_CONFIGURATION 0x02
68 #define USB_DESCRIPTOR_TYPE_STRING 0x03
69 #define USB_DESCRIPTOR_TYPE_INTERFACE 0x04
70 #define USB_DESCRIPTOR_TYPE_ENDPOINT 0x05
71 #define USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER 0x06
72 #define USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION 0x07
73 #define USB_DESCRIPTOR_TYPE_POWER 0x08
75 /* values for the bits returned by the USB GET_STATUS command (spec. 9.4.5) */
76 #define USB_GETSTATUS_SELF_POWERED 0x01
77 #define USB_GETSTATUS_REMOTE_WAKEUP_ENABLED 0x02
79 /* values for standard request Clear Feature */
80 #define USB_FEATURE_ENDPOINT_STALL 0x0000
81 #define USB_FEATURE_REMOTE_WAKEUP 0x0001
84 /*******************************************************/
85 /*** Standard USB Descriptor Definitions (spec. 9.6) ***/
86 /*******************************************************/
88 /* *** DEVICE *** (spec. 9.6.1) */
89 struct _tag_usb_device_descriptor {
91 uint8_t bDescriptorType;
94 uint8_t bDeviceSubClass;
95 uint8_t bDeviceProtocol;
96 uint8_t bMaxPacketSize0;
100 uint8_t iManufacturer;
102 uint8_t iSerialNumber;
103 uint8_t bNumConfigurations;
105 typedef struct _tag_usb_device_descriptor
106 USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
108 /* *** DEVICE_QUALIFIER *** (spec. 9.6.2) */
109 struct _tag_usb_device_qualifier_descriptor {
111 uint8_t bDescriptorType;
113 uint8_t bDeviceClass;
114 uint8_t bDeviceSubClass;
115 uint8_t bDeviceProtocol;
116 uint8_t bMaxPacketSize0;
117 uint8_t bNumConfigurations;
120 typedef struct _tag_usb_device_qualifier_descriptor
121 USB_DEVICE_QUALIFIER_DESCRIPTOR, *PUSB_DEVICE_QUALIFIER_DESCRIPTOR;
123 /* *** CONFIGURATION *** (spec. 9.6.3) */
124 struct _tag_usb_configuration_descriptor {
126 uint8_t bDescriptorType;
127 uint16_t wTotalLength;
128 uint8_t bNumInterfaces;
129 uint8_t bConfigurationValue;
130 uint8_t iConfiguration;
131 uint8_t bmAttributes;
134 typedef struct _tag_usb_configuration_descriptor
135 USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;
136 /* definitions for bits in the bmAttributes field of a configuration descriptor. (spec. 9.6.3) */
137 #define USB_CONFIG_POWERED_MASK 0xc0
138 #define USB_CONFIG_BUS_POWERED 0x80
139 #define USB_CONFIG_SELF_POWERED 0x40
140 #define USB_CONFIG_REMOTE_WAKEUP 0x20
141 #define BUS_POWERED 0x80
142 #define SELF_POWERED 0x40
143 #define REMOTE_WAKEUP 0x20
145 /* *** OTHER_SPEED_CONFIGURATION *** (spec. 9.6.4) */
146 struct _tag_usb_other_speed_configuration {
148 uint8_t bDescriptorType;
149 uint16_t wTotalLength;
150 uint8_t bNumInterfaces;
151 uint8_t bConfigurationValue;
152 uint8_t iConfiguration;
153 uint8_t bmAttributes;
156 typedef struct _tag_usb_other_speed_configuration
157 USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR, *PUSB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR;
159 /* *** INTERFACE *** (spec. 9.6.5) */
160 struct _tag_usb_interface_descriptor {
162 uint8_t bDescriptorType;
163 uint8_t bInterfaceNumber;
164 uint8_t bAlternateSetting;
165 uint8_t bNumEndpoints;
166 uint8_t bInterfaceClass;
167 uint8_t bInterfaceSubClass;
168 uint8_t bInterfaceProtocol;
171 typedef struct _tag_usb_interface_descriptor
172 USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;
174 /* *** ENDPOINT *** (spec. 9.6.6) */
175 struct _tag_usb_endpoint_descriptor {
177 uint8_t bDescriptorType;
178 uint8_t bEndpointAddress;
179 uint8_t bmAttributes;
180 uint16_t wMaxPacketSize;
183 typedef struct _tag_usb_endpoint_descriptor
184 USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;
186 /* Endpoint direction bit, stored in address (spec. 9.6.6) */
187 #define USB_ENDPOINT_DIRECTION_MASK 0x80
188 /* test direction bit in the bEndpointAddress field of an endpoint descriptor. */
189 #define USB_ENDPOINT_DIRECTION_OUT(addr) (!((addr) & USB_ENDPOINT_DIRECTION_MASK))
190 #define USB_ENDPOINT_DIRECTION_IN(addr) ((addr) & USB_ENDPOINT_DIRECTION_MASK)
191 /* Values for bmAttributes field of an endpoint descriptor (spec. 9.6.6) */
192 #define USB_ENDPOINT_TYPE_MASK 0x03
193 #define USB_ENDPOINT_TYPE_CONTROL 0x00
194 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
195 #define USB_ENDPOINT_TYPE_BULK 0x02
196 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
198 /* *** STRING *** (spec. 9.6.7) */
199 struct _tag_usb_string_descriptor {
201 uint8_t bDescriptorType;
204 typedef struct _tag_usb_string_descriptor
205 USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR;
208 /*******************************************/
209 /*** USB_IF - Defined USB device classes ***/
210 /*******************************************/
211 #define USB_DEVICE_CLASS_RESERVED 0x00
212 #define USB_DEVICE_CLASS_AUDIO 0x01
213 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
214 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
215 #define USB_DEVICE_CLASS_MONITOR 0x04
216 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
217 #define USB_DEVICE_CLASS_POWER 0x06
218 #define USB_DEVICE_CLASS_PRINTER 0x07
219 #define USB_DEVICE_CLASS_STORAGE 0x08
220 #define USB_DEVICE_CLASS_HUB 0x09
221 #define USB_DEVICE_CLASS_APPLICATION_SPECIFIC 0xFE
222 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
224 /* define application specific device class subclasses */
225 #define USB_APPL_SUBCLASS_FIRMWARE_UPDATE 0x01
226 #define USB_APPL_SUBCLASS_IRDA_USB_BRIDGE 0x02