2 ******************************************************************************
4 * @author MCD Application Team
7 * @brief Definitions used in the USB host library
8 ******************************************************************************
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
21 /** @addtogroup USBH_LIB
25 /** @addtogroup USBH_LIB_CORE
29 /** @defgroup USBH_DEF
30 * @brief This file is includes USB descriptors
38 #define USBH_NULL ((void *)0)
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))
54 #define LE16(addr) (((u16)(*((u8 *)(addr))))\
55 + (((u16)(*(((u8 *)(addr)) + 1))) << 8))
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
65 /* bmRequestType :D7 Data Phase Transfer Direction */
66 #define USB_REQ_DIR_MASK 0x80
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
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
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
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
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
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)
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
134 #define USB_EP_DIR_OUT 0x00
135 #define USB_EP_DIR_IN 0x80
136 #define USB_EP_DIR_MSK 0x80
138 /* supported classes */
139 #define USB_MSC_CLASS 0x08
140 #define USB_HID_CLASS 0x03
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
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
157 #define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \
158 + USB_INTERFACE_DESC_SIZE\
159 + (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE))
162 #define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\
163 ConfigurationDescriptor.wTotalLength)
166 /* This Union is copied from usb_core.h */
180 typedef union _USB_Setup
184 struct _SetupPkt_Struc
186 uint8_t bmRequestType;
188 uint16_t_uint8_t wValue;
189 uint16_t_uint8_t wIndex;
190 uint16_t_uint8_t wLength;
195 typedef struct _DescHeader
198 uint8_t bDescriptorType;
202 typedef struct _DeviceDescriptor
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 */
222 USBH_DevDesc_TypeDef;
225 typedef struct _ConfigurationDescriptor
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 */
236 USBH_CfgDesc_TypeDef;
239 typedef struct _HIDDescriptor
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. */
249 USBH_HIDDesc_TypeDef;
252 typedef struct _InterfaceDescriptor
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 */
265 USBH_InterfaceDesc_TypeDef;
268 typedef struct _EndpointDescriptor
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. */
279 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/