2 #if (USE_STM32_USB_HOST_MODE || USE_STM32_USB_USE_DEVICE_MODE || USE_STM32_USB_OTG_MODE)
47 #define USBH_NULL ((void *)0)
59 #define ValBit(VAR,POS) (VAR & (1 << POS))
60 #define SetBit(VAR,POS) (VAR |= (1 << POS))
61 #define ClrBit(VAR,POS) (VAR &= ((1 << POS)^255))
63 #define LE16(addr) (((u16)(*((u8 *)(addr))))\
64 + (((u16)(*(((u8 *)(addr)) + 1))) << 8))
66 #define USB_LEN_DESC_HDR 0x02
67 #define USB_LEN_DEV_DESC 0x12
68 #define USB_LEN_CFG_DESC 0x09
69 #define USB_LEN_IF_DESC 0x09
70 #define USB_LEN_EP_DESC 0x07
71 #define USB_LEN_OTG_DESC 0x03
72 #define USB_LEN_SETUP_PKT 0x08
75 #define USB_REQ_DIR_MASK 0x80
80 #define USB_REQ_TYPE_STANDARD 0x00
81 #define USB_REQ_TYPE_CLASS 0x20
82 #define USB_REQ_TYPE_VENDOR 0x40
83 #define USB_REQ_TYPE_RESERVED 0x60
86 #define USB_REQ_RECIPIENT_DEVICE 0x00
87 #define USB_REQ_RECIPIENT_INTERFACE 0x01
88 #define USB_REQ_RECIPIENT_ENDPOINT 0x02
89 #define USB_REQ_RECIPIENT_OTHER 0x03
93 #define USB_REQ_GET_STATUS 0x00
94 #define USB_REQ_CLEAR_FEATURE 0x01
95 #define USB_REQ_SET_FEATURE 0x03
96 #define USB_REQ_SET_ADDRESS 0x05
97 #define USB_REQ_GET_DESCRIPTOR 0x06
98 #define USB_REQ_SET_DESCRIPTOR 0x07
99 #define USB_REQ_GET_CONFIGURATION 0x08
100 #define USB_REQ_SET_CONFIGURATION 0x09
101 #define USB_REQ_GET_INTERFACE 0x0A
102 #define USB_REQ_SET_INTERFACE 0x0B
103 #define USB_REQ_SYNCH_FRAME 0x0C
106 #define USB_DESC_TYPE_DEVICE 1
107 #define USB_DESC_TYPE_CONFIGURATION 2
108 #define USB_DESC_TYPE_STRING 3
109 #define USB_DESC_TYPE_INTERFACE 4
110 #define USB_DESC_TYPE_ENDPOINT 5
111 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6
112 #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7
113 #define USB_DESC_TYPE_INTERFACE_POWER 8
114 #define USB_DESC_TYPE_HID 0x21
115 #define USB_DESC_TYPE_HID_REPORT 0x22
118 #define USB_DEVICE_DESC_SIZE 18
119 #define USB_CONFIGURATION_DESC_SIZE 9
120 #define USB_HID_DESC_SIZE 9
121 #define USB_INTERFACE_DESC_SIZE 9
122 #define USB_ENDPOINT_DESC_SIZE 7
126 #define USB_DESC_DEVICE ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00)
127 #define USB_DESC_CONFIGURATION ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00)
128 #define USB_DESC_STRING ((USB_DESC_TYPE_STRING << 8) & 0xFF00)
129 #define USB_DESC_INTERFACE ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
130 #define USB_DESC_ENDPOINT ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
131 #define USB_DESC_DEVICE_QUALIFIER ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00)
132 #define USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00)
133 #define USB_DESC_INTERFACE_POWER ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00)
134 #define USB_DESC_HID_REPORT ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00)
135 #define USB_DESC_HID ((USB_DESC_TYPE_HID << 8) & 0xFF00)
138 #define USB_EP_TYPE_CTRL 0x00
139 #define USB_EP_TYPE_ISOC 0x01
140 #define USB_EP_TYPE_BULK 0x02
141 #define USB_EP_TYPE_INTR 0x03
143 #define USB_EP_DIR_OUT 0x00
144 #define USB_EP_DIR_IN 0x80
145 #define USB_EP_DIR_MSK 0x80
148 #define USB_MSC_CLASS 0x08
149 #define USB_HID_CLASS 0x03
152 #define HID_BOOT_CODE 0x01
153 #define HID_KEYBRD_BOOT_CODE 0x01
154 #define HID_MOUSE_BOOT_CODE 0x02
158 #define DATA_STAGE_TIMEOUT 5000
159 #define NODATA_STAGE_TIMEOUT 50
166 #define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \
167 + USB_INTERFACE_DESC_SIZE\
168 + (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE))
171 #define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\
172 ConfigurationDescriptor.wTotalLength)
189 typedef union _USB_Setup
193 struct _SetupPkt_Struc
195 uint8_t bmRequestType;
197 uint16_t_uint8_t wValue;
198 uint16_t_uint8_t wIndex;
199 uint16_t_uint8_t wLength;
204 typedef struct _DescHeader
207 uint8_t bDescriptorType;
211 typedef struct _DeviceDescriptor
214 uint8_t bDescriptorType;
216 uint8_t bDeviceClass;
217 uint8_t bDeviceSubClass;
218 uint8_t bDeviceProtocol;
222 uint8_t bMaxPacketSize;
226 uint8_t iManufacturer;
228 uint8_t iSerialNumber;
229 uint8_t bNumConfigurations;
231 USBH_DevDesc_TypeDef;
234 typedef struct _ConfigurationDescriptor
237 uint8_t bDescriptorType;
238 uint16_t wTotalLength;
239 uint8_t bNumInterfaces;
240 uint8_t bConfigurationValue;
241 uint8_t iConfiguration;
242 uint8_t bmAttributes;
245 USBH_CfgDesc_TypeDef;
248 typedef struct _HIDDescriptor
251 uint8_t bDescriptorType;
253 uint8_t bCountryCode;
254 uint8_t bNumDescriptors;
255 uint8_t bReportDescriptorType;
256 uint16_t wItemLength;
258 USBH_HIDDesc_TypeDef;
261 typedef struct _InterfaceDescriptor
264 uint8_t bDescriptorType;
265 uint8_t bInterfaceNumber;
266 uint8_t bAlternateSetting;
267 uint8_t bNumEndpoints;
268 uint8_t bInterfaceClass;
269 uint8_t bInterfaceSubClass;
270 uint8_t bInterfaceProtocol;
274 USBH_InterfaceDesc_TypeDef;
277 typedef struct _EndpointDescriptor
280 uint8_t bDescriptorType;
281 uint8_t bEndpointAddress;
282 uint8_t bmAttributes;
283 uint16_t wMaxPacketSize;
libheivs configuration file