discoverpixy
usbh_def.h
Go to the documentation of this file.
1 
34 #ifndef USBH_DEF_H
35 #define USBH_DEF_H
36 
37 #ifndef USBH_NULL
38 #define USBH_NULL ((void *)0)
39 #endif
40 
41 #ifndef FALSE
42 #define FALSE 0
43 #endif
44 
45 #ifndef TRUE
46 #define TRUE 1
47 #endif
48 
49 
50 #define ValBit(VAR,POS) (VAR & (1 << POS))
51 #define SetBit(VAR,POS) (VAR |= (1 << POS))
52 #define ClrBit(VAR,POS) (VAR &= ((1 << POS)^255))
53 
54 #define LE16(addr) (((u16)(*((u8 *)(addr))))\
55  + (((u16)(*(((u8 *)(addr)) + 1))) << 8))
56 
57 #define USB_LEN_DESC_HDR 0x02
58 #define USB_LEN_DEV_DESC 0x12
59 #define USB_LEN_CFG_DESC 0x09
60 #define USB_LEN_IF_DESC 0x09
61 #define USB_LEN_EP_DESC 0x07
62 #define USB_LEN_OTG_DESC 0x03
63 #define USB_LEN_SETUP_PKT 0x08
64 
65 /* bmRequestType :D7 Data Phase Transfer Direction */
66 #define USB_REQ_DIR_MASK 0x80
67 #define USB_H2D 0x00
68 #define USB_D2H 0x80
69 
70 /* bmRequestType D6..5 Type */
71 #define USB_REQ_TYPE_STANDARD 0x00
72 #define USB_REQ_TYPE_CLASS 0x20
73 #define USB_REQ_TYPE_VENDOR 0x40
74 #define USB_REQ_TYPE_RESERVED 0x60
75 
76 /* bmRequestType D4..0 Recipient */
77 #define USB_REQ_RECIPIENT_DEVICE 0x00
78 #define USB_REQ_RECIPIENT_INTERFACE 0x01
79 #define USB_REQ_RECIPIENT_ENDPOINT 0x02
80 #define USB_REQ_RECIPIENT_OTHER 0x03
81 
82 /* Table 9-4. Standard Request Codes */
83 /* bRequest , Value */
84 #define USB_REQ_GET_STATUS 0x00
85 #define USB_REQ_CLEAR_FEATURE 0x01
86 #define USB_REQ_SET_FEATURE 0x03
87 #define USB_REQ_SET_ADDRESS 0x05
88 #define USB_REQ_GET_DESCRIPTOR 0x06
89 #define USB_REQ_SET_DESCRIPTOR 0x07
90 #define USB_REQ_GET_CONFIGURATION 0x08
91 #define USB_REQ_SET_CONFIGURATION 0x09
92 #define USB_REQ_GET_INTERFACE 0x0A
93 #define USB_REQ_SET_INTERFACE 0x0B
94 #define USB_REQ_SYNCH_FRAME 0x0C
95 
96 /* Table 9-5. Descriptor Types of USB Specifications */
97 #define USB_DESC_TYPE_DEVICE 1
98 #define USB_DESC_TYPE_CONFIGURATION 2
99 #define USB_DESC_TYPE_STRING 3
100 #define USB_DESC_TYPE_INTERFACE 4
101 #define USB_DESC_TYPE_ENDPOINT 5
102 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6
103 #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7
104 #define USB_DESC_TYPE_INTERFACE_POWER 8
105 #define USB_DESC_TYPE_HID 0x21
106 #define USB_DESC_TYPE_HID_REPORT 0x22
107 
108 
109 #define USB_DEVICE_DESC_SIZE 18
110 #define USB_CONFIGURATION_DESC_SIZE 9
111 #define USB_HID_DESC_SIZE 9
112 #define USB_INTERFACE_DESC_SIZE 9
113 #define USB_ENDPOINT_DESC_SIZE 7
114 
115 /* Descriptor Type and Descriptor Index */
116 /* Use the following values when calling the function USBH_GetDescriptor */
117 #define USB_DESC_DEVICE ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00)
118 #define USB_DESC_CONFIGURATION ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00)
119 #define USB_DESC_STRING ((USB_DESC_TYPE_STRING << 8) & 0xFF00)
120 #define USB_DESC_INTERFACE ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
121 #define USB_DESC_ENDPOINT ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
122 #define USB_DESC_DEVICE_QUALIFIER ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00)
123 #define USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00)
124 #define USB_DESC_INTERFACE_POWER ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00)
125 #define USB_DESC_HID_REPORT ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00)
126 #define USB_DESC_HID ((USB_DESC_TYPE_HID << 8) & 0xFF00)
127 
128 
129 #define USB_EP_TYPE_CTRL 0x00
130 #define USB_EP_TYPE_ISOC 0x01
131 #define USB_EP_TYPE_BULK 0x02
132 #define USB_EP_TYPE_INTR 0x03
133 
134 #define USB_EP_DIR_OUT 0x00
135 #define USB_EP_DIR_IN 0x80
136 #define USB_EP_DIR_MSK 0x80
137 
138 /* supported classes */
139 #define USB_MSC_CLASS 0x08
140 #define USB_HID_CLASS 0x03
141 
142 /* Interface Descriptor field values for HID Boot Protocol */
143 #define HID_BOOT_CODE 0x01
144 #define HID_KEYBRD_BOOT_CODE 0x01
145 #define HID_MOUSE_BOOT_CODE 0x02
146 
147 /* As per USB specs 9.2.6.4 :Standard request with data request timeout: 5sec
148  Standard request with no data stage timeout : 50ms */
149 #define DATA_STAGE_TIMEOUT 5000
150 #define NODATA_STAGE_TIMEOUT 50
151 
157 #define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \
158  + USB_INTERFACE_DESC_SIZE\
159  + (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE))
160 
161 
162 #define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\
163  ConfigurationDescriptor.wTotalLength)
164 
165 
166 /* This Union is copied from usb_core.h */
167 typedef union
168 {
169  uint16_t w;
170  struct BW
171  {
172  uint8_t msb;
173  uint8_t lsb;
174  }
175  bw;
176 }
178 
179 
180 typedef union _USB_Setup
181 {
182  uint8_t d8[8];
183 
185  {
186  uint8_t bmRequestType;
187  uint8_t bRequest;
188  uint16_t_uint8_t wValue;
189  uint16_t_uint8_t wIndex;
190  uint16_t_uint8_t wLength;
191  } b;
192 }
194 
195 typedef struct _DescHeader
196 {
197  uint8_t bLength;
198  uint8_t bDescriptorType;
199 }
201 
202 typedef struct _DeviceDescriptor
203 {
204  uint8_t bLength;
205  uint8_t bDescriptorType;
206  uint16_t bcdUSB; /* USB Specification Number which device complies too */
207  uint8_t bDeviceClass;
208  uint8_t bDeviceSubClass;
209  uint8_t bDeviceProtocol;
210  /* If equal to Zero, each interface specifies its own class
211  code if equal to 0xFF, the class code is vendor specified.
212  Otherwise field is valid Class Code.*/
213  uint8_t bMaxPacketSize;
214  uint16_t idVendor; /* Vendor ID (Assigned by USB Org) */
215  uint16_t idProduct; /* Product ID (Assigned by Manufacturer) */
216  uint16_t bcdDevice; /* Device Release Number */
217  uint8_t iManufacturer; /* Index of Manufacturer String Descriptor */
218  uint8_t iProduct; /* Index of Product String Descriptor */
219  uint8_t iSerialNumber; /* Index of Serial Number String Descriptor */
220  uint8_t bNumConfigurations; /* Number of Possible Configurations */
221 }
223 
224 
226 {
227  uint8_t bLength;
228  uint8_t bDescriptorType;
229  uint16_t wTotalLength; /* Total Length of Data Returned */
230  uint8_t bNumInterfaces; /* Number of Interfaces */
231  uint8_t bConfigurationValue; /* Value to use as an argument to select this configuration*/
232  uint8_t iConfiguration; /*Index of String Descriptor Describing this configuration */
233  uint8_t bmAttributes; /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/
234  uint8_t bMaxPower; /*Maximum Power Consumption */
235 }
237 
238 
239 typedef struct _HIDDescriptor
240 {
241  uint8_t bLength;
242  uint8_t bDescriptorType;
243  uint16_t bcdHID; /* indicates what endpoint this descriptor is describing */
244  uint8_t bCountryCode; /* specifies the transfer type. */
245  uint8_t bNumDescriptors; /* specifies the transfer type. */
246  uint8_t bReportDescriptorType; /* Maximum Packet Size this endpoint is capable of sending or receiving */
247  uint16_t wItemLength; /* is used to specify the polling interval of certain transfers. */
248 }
250 
251 
252 typedef struct _InterfaceDescriptor
253 {
254  uint8_t bLength;
255  uint8_t bDescriptorType;
256  uint8_t bInterfaceNumber;
257  uint8_t bAlternateSetting; /* Value used to select alternative setting */
258  uint8_t bNumEndpoints; /* Number of Endpoints used for this interface */
259  uint8_t bInterfaceClass; /* Class Code (Assigned by USB Org) */
260  uint8_t bInterfaceSubClass; /* Subclass Code (Assigned by USB Org) */
261  uint8_t bInterfaceProtocol; /* Protocol Code */
262  uint8_t iInterface; /* Index of String Descriptor Describing this interface */
263 
264 }
266 
267 
268 typedef struct _EndpointDescriptor
269 {
270  uint8_t bLength;
271  uint8_t bDescriptorType;
272  uint8_t bEndpointAddress; /* indicates what endpoint this descriptor is describing */
273  uint8_t bmAttributes; /* specifies the transfer type. */
274  uint16_t wMaxPacketSize; /* Maximum Packet Size this endpoint is capable of sending or receiving */
275  uint8_t bInterval; /* is used to specify the polling interval of certain transfers. */
276 }
278 #endif
279 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
280 
Definition: usbh_def.h:195
Definition: usbh_def.h:268
Definition: usbh_def.h:202
Definition: usbh_def.h:184
Definition: usbh_def.h:170
Definition: usbh_def.h:225
Definition: usbh_def.h:167
Definition: usbh_def.h:180
Definition: usbh_def.h:239
Definition: usbh_def.h:252