]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/libs4c/usb/base/usb/usb_spec.h
Update of system-less architecture and board support code to actual uLAN.sf.net version.
[lincan.git] / embedded / libs4c / usb / base / usb / usb_spec.h
1 /*************************************************/
2 /***   Module : USB specification              ***/
3 /***   Author : Roman Bartosinski 29.07.2002   ***/
4 /***   Modify : 08.08.2002, 14.01.2003         ***/
5 /*************************************************/
6
7 #ifndef _USB_SPECIFICATIONS_AND_DEFINITIONS_MODULE
8  #define _USB_SPECIFICATIONS_AND_DEFINITIONS_MODULE
9
10 /*#include <inttypes.h>*/
11 #include <types.h>
12
13 #ifndef PACKED
14   #ifdef  __GNUC__
15     #define PACKED __attribute__((packed))
16   #else /*__GNUC__*/
17     #define PACKED /*nothing*/
18   #endif /*__GNUC__*/
19 #endif
20
21 /* this section is from __USB100.H__ and __CHAP9.H__ and define USB constants and structs */
22
23 /* *** USB Device Request *** (spec. 9.3) */
24   typedef struct _tag_usb_device_request {
25     uint8_t  bmRequestType;
26     uint8_t  bRequest;
27     uint16_t wValue;
28     uint16_t wIndex;
29     uint16_t wLength;
30   } USB_DEVICE_REQUEST;
31
32 /****************************************************************************************/ 
33 /*** definitions for USB tranfer standard packets described in USB secif. - chapter 9 ***/
34 /****************************************************************************************/
35   #define DEVICE_ADDRESS_MASK   0x7F
36
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
74
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
78
79 /* values for standard request Clear Feature */
80   #define USB_FEATURE_ENDPOINT_STALL          0x0000
81   #define USB_FEATURE_REMOTE_WAKEUP           0x0001
82
83
84 /*******************************************************/
85 /*** Standard USB Descriptor Definitions (spec. 9.6) ***/
86 /*******************************************************/
87
88 /* *** DEVICE *** (spec. 9.6.1) */
89   struct _tag_usb_device_descriptor {
90     uint8_t  bLength;
91     uint8_t  bDescriptorType;
92     uint16_t bcdUSB;
93     uint8_t  bDeviceClass;
94     uint8_t  bDeviceSubClass;
95     uint8_t  bDeviceProtocol;
96     uint8_t  bMaxPacketSize0;
97     uint16_t idVendor;
98     uint16_t idProduct;
99     uint16_t bcdDevice;
100     uint8_t  iManufacturer;
101     uint8_t  iProduct;
102     uint8_t  iSerialNumber;
103     uint8_t  bNumConfigurations;
104   } PACKED;
105   typedef struct _tag_usb_device_descriptor 
106     USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
107
108 /* *** DEVICE_QUALIFIER *** (spec. 9.6.2) */
109   struct _tag_usb_device_qualifier_descriptor {
110     uint8_t  bLength;
111     uint8_t  bDescriptorType;
112     uint16_t bcdUSB;
113     uint8_t  bDeviceClass;
114     uint8_t  bDeviceSubClass;
115     uint8_t  bDeviceProtocol;
116     uint8_t  bMaxPacketSize0;
117     uint8_t  bNumConfigurations;
118     uint8_t  bReserved;
119   } PACKED;
120   typedef struct _tag_usb_device_qualifier_descriptor
121     USB_DEVICE_QUALIFIER_DESCRIPTOR, *PUSB_DEVICE_QUALIFIER_DESCRIPTOR;
122
123 /* *** CONFIGURATION *** (spec. 9.6.3) */
124   struct _tag_usb_configuration_descriptor {
125     uint8_t  bLength;
126     uint8_t  bDescriptorType;
127     uint16_t wTotalLength;
128     uint8_t  bNumInterfaces;
129     uint8_t  bConfigurationValue;
130     uint8_t  iConfiguration;
131     uint8_t  bmAttributes;
132     uint8_t  MaxPower;
133   } PACKED;
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
144
145 /* *** OTHER_SPEED_CONFIGURATION *** (spec. 9.6.4) */
146   struct _tag_usb_other_speed_configuration {
147     uint8_t  bLength;
148     uint8_t  bDescriptorType;
149     uint16_t wTotalLength;
150     uint8_t  bNumInterfaces;
151     uint8_t  bConfigurationValue;
152     uint8_t  iConfiguration;
153     uint8_t  bmAttributes;
154     uint8_t  bMaxPower;
155   } PACKED;
156   typedef struct _tag_usb_other_speed_configuration
157     USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR, *PUSB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR;
158
159 /* *** INTERFACE *** (spec. 9.6.5) */
160   struct _tag_usb_interface_descriptor {
161     uint8_t  bLength;
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;
169     uint8_t  iInterface;
170   } PACKED;
171   typedef struct _tag_usb_interface_descriptor
172     USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;
173
174 /* *** ENDPOINT *** (spec. 9.6.6) */
175   struct _tag_usb_endpoint_descriptor {
176     uint8_t  bLength;
177     uint8_t  bDescriptorType;
178     uint8_t  bEndpointAddress;
179     uint8_t  bmAttributes;
180     uint16_t wMaxPacketSize;
181     uint8_t  bInterval;
182   } PACKED;
183   typedef struct _tag_usb_endpoint_descriptor
184     USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;
185
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
197
198 /* *** STRING *** (spec. 9.6.7) */
199   struct _tag_usb_string_descriptor {
200     uint8_t  bLength;
201     uint8_t  bDescriptorType;
202     uint8_t  bString[];
203   } PACKED;
204   typedef struct _tag_usb_string_descriptor
205     USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR;
206   
207
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
223
224   /* define application specific device class subclasses */
225   #define USB_APPL_SUBCLASS_FIRMWARE_UPDATE     0x01
226   #define USB_APPL_SUBCLASS_IRDA_USB_BRIDGE     0x02
227                                                            
228 #endif