STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
usbh_def.h
Go to the documentation of this file.
1 
28 /* Define to prevent recursive ----------------------------------------------*/
29 #ifndef USBH_DEF_H
30 #define USBH_DEF_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------*/
37 #include "usbh_conf.h"
38 
52 #ifndef NULL
53 #define NULL 0
54 #endif
55 
56 #ifndef FALSE
57 #define FALSE 0
58 #endif
59 
60 #ifndef TRUE
61 #define TRUE 1
62 #endif
63 
64 
65 #define ValBit(VAR,POS) (VAR & (1 << POS))
66 #define SetBit(VAR,POS) (VAR |= (1 << POS))
67 #define ClrBit(VAR,POS) (VAR &= ((1 << POS)^255))
68 
69 #define LE16(addr) (((uint16_t)(*((uint8_t *)(addr))))\
70  + (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8))
71 
72 #define LE16S(addr) (uint16_t)(LE16((addr)))
73 
74 #define LE32(addr) ((((uint32_t)(*(((uint8_t *)(addr)) + 0))) + \
75  (((uint32_t)(*(((uint8_t *)(addr)) + 1))) << 8) + \
76  (((uint32_t)(*(((uint8_t *)(addr)) + 2))) << 16) + \
77  (((uint32_t)(*(((uint8_t *)(addr)) + 3))) << 24)))
78 
79 #define LE64(addr) ((((uint64_t)(*(((uint8_t *)(addr)) + 0))) + \
80  (((uint64_t)(*(((uint8_t *)(addr)) + 1))) << 8) +\
81  (((uint64_t)(*(((uint8_t *)(addr)) + 2))) << 16) +\
82  (((uint64_t)(*(((uint8_t *)(addr)) + 3))) << 24) +\
83  (((uint64_t)(*(((uint8_t *)(addr)) + 4))) << 32) +\
84  (((uint64_t)(*(((uint8_t *)(addr)) + 5))) << 40) +\
85  (((uint64_t)(*(((uint8_t *)(addr)) + 6))) << 48) +\
86  (((uint64_t)(*(((uint8_t *)(addr)) + 7))) << 56)))
87 
88 
89 #define LE24(addr) ((((uint32_t)(*(((uint8_t *)(addr)) + 0))) + \
90  (((uint32_t)(*(((uint8_t *)(addr)) + 1))) << 8) + \
91  (((uint32_t)(*(((uint8_t *)(addr)) + 2))) << 16)))
92 
93 
94 #define LE32S(addr) (int32_t)(LE32((addr)))
95 
96 
97 
98 #define USB_LEN_DESC_HDR 0x02
99 #define USB_LEN_DEV_DESC 0x12
100 #define USB_LEN_CFG_DESC 0x09
101 #define USB_LEN_IF_DESC 0x09
102 #define USB_LEN_EP_DESC 0x07
103 #define USB_LEN_OTG_DESC 0x03
104 #define USB_LEN_SETUP_PKT 0x08
105 
106 /* bmRequestType :D7 Data Phase Transfer Direction */
107 #define USB_REQ_DIR_MASK 0x80
108 #define USB_H2D 0x00
109 #define USB_D2H 0x80
110 
111 /* bmRequestType D6..5 Type */
112 #define USB_REQ_TYPE_STANDARD 0x00
113 #define USB_REQ_TYPE_CLASS 0x20
114 #define USB_REQ_TYPE_VENDOR 0x40
115 #define USB_REQ_TYPE_RESERVED 0x60
116 
117 /* bmRequestType D4..0 Recipient */
118 #define USB_REQ_RECIPIENT_DEVICE 0x00
119 #define USB_REQ_RECIPIENT_INTERFACE 0x01
120 #define USB_REQ_RECIPIENT_ENDPOINT 0x02
121 #define USB_REQ_RECIPIENT_OTHER 0x03
122 
123 /* Table 9-4. Standard Request Codes */
124 /* bRequest , Value */
125 #define USB_REQ_GET_STATUS 0x00
126 #define USB_REQ_CLEAR_FEATURE 0x01
127 #define USB_REQ_SET_FEATURE 0x03
128 #define USB_REQ_SET_ADDRESS 0x05
129 #define USB_REQ_GET_DESCRIPTOR 0x06
130 #define USB_REQ_SET_DESCRIPTOR 0x07
131 #define USB_REQ_GET_CONFIGURATION 0x08
132 #define USB_REQ_SET_CONFIGURATION 0x09
133 #define USB_REQ_GET_INTERFACE 0x0A
134 #define USB_REQ_SET_INTERFACE 0x0B
135 #define USB_REQ_SYNCH_FRAME 0x0C
136 
137 /* Table 9-5. Descriptor Types of USB Specifications */
138 #define USB_DESC_TYPE_DEVICE 1
139 #define USB_DESC_TYPE_CONFIGURATION 2
140 #define USB_DESC_TYPE_STRING 3
141 #define USB_DESC_TYPE_INTERFACE 4
142 #define USB_DESC_TYPE_ENDPOINT 5
143 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6
144 #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7
145 #define USB_DESC_TYPE_INTERFACE_POWER 8
146 #define USB_DESC_TYPE_HID 0x21
147 #define USB_DESC_TYPE_HID_REPORT 0x22
148 
149 
150 #define USB_DEVICE_DESC_SIZE 18
151 #define USB_CONFIGURATION_DESC_SIZE 9
152 #define USB_HID_DESC_SIZE 9
153 #define USB_INTERFACE_DESC_SIZE 9
154 #define USB_ENDPOINT_DESC_SIZE 7
155 
156 /* Descriptor Type and Descriptor Index */
157 /* Use the following values when calling the function USBH_GetDescriptor */
158 #define USB_DESC_DEVICE ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00)
159 #define USB_DESC_CONFIGURATION ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00)
160 #define USB_DESC_STRING ((USB_DESC_TYPE_STRING << 8) & 0xFF00)
161 #define USB_DESC_INTERFACE ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
162 #define USB_DESC_ENDPOINT ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
163 #define USB_DESC_DEVICE_QUALIFIER ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00)
164 #define USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00)
165 #define USB_DESC_INTERFACE_POWER ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00)
166 #define USB_DESC_HID_REPORT ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00)
167 #define USB_DESC_HID ((USB_DESC_TYPE_HID << 8) & 0xFF00)
168 
169 
170 #define USB_EP_TYPE_CTRL 0x00
171 #define USB_EP_TYPE_ISOC 0x01
172 #define USB_EP_TYPE_BULK 0x02
173 #define USB_EP_TYPE_INTR 0x03
174 
175 #define USB_EP_DIR_OUT 0x00
176 #define USB_EP_DIR_IN 0x80
177 #define USB_EP_DIR_MSK 0x80
178 
179 #ifndef USBH_MAX_PIPES_NBR
180  #define USBH_MAX_PIPES_NBR 15
181 #endif /* USBH_MAX_PIPES_NBR */
182 
183 #define USBH_DEVICE_ADDRESS_DEFAULT 0
184 #define USBH_MAX_ERROR_COUNT 2
185 #define USBH_DEVICE_ADDRESS 1
186 
187 
193 #define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \
194  + USB_INTERFACE_DESC_SIZE\
195  + (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE))
196 
197 
198 #define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\
199  ConfigurationDescriptor.wTotalLength)
200 
201 
202 typedef union
203 {
204  uint16_t w;
205  struct BW
206  {
207  uint8_t msb;
208  uint8_t lsb;
209  }
210  bw;
211 }
213 
214 
215 typedef union _USB_Setup
216 {
217  uint32_t d8[2];
218 
220  {
221  uint8_t bmRequestType;
222  uint8_t bRequest;
226  } b;
227 }
229 
230 typedef struct _DescHeader
231 {
232  uint8_t bLength;
234 }
236 
237 typedef struct _DeviceDescriptor
238 {
239  uint8_t bLength;
241  uint16_t bcdUSB; /* USB Specification Number which device complies too */
242  uint8_t bDeviceClass;
243  uint8_t bDeviceSubClass;
245  /* If equal to Zero, each interface specifies its own class
246  code if equal to 0xFF, the class code is vendor specified.
247  Otherwise field is valid Class Code.*/
248  uint8_t bMaxPacketSize;
249  uint16_t idVendor; /* Vendor ID (Assigned by USB Org) */
250  uint16_t idProduct; /* Product ID (Assigned by Manufacturer) */
251  uint16_t bcdDevice; /* Device Release Number */
252  uint8_t iManufacturer; /* Index of Manufacturer String Descriptor */
253  uint8_t iProduct; /* Index of Product String Descriptor */
254  uint8_t iSerialNumber; /* Index of Serial Number String Descriptor */
255  uint8_t bNumConfigurations; /* Number of Possible Configurations */
256 }
258 
259 typedef struct _EndpointDescriptor
260 {
261  uint8_t bLength;
263  uint8_t bEndpointAddress; /* indicates what endpoint this descriptor is describing */
264  uint8_t bmAttributes; /* specifies the transfer type. */
265  uint16_t wMaxPacketSize; /* Maximum Packet Size this endpoint is capable of sending or receiving */
266  uint8_t bInterval; /* is used to specify the polling interval of certain transfers. */
267 }
269 
270 typedef struct _InterfaceDescriptor
271 {
272  uint8_t bLength;
275  uint8_t bAlternateSetting; /* Value used to select alternative setting */
276  uint8_t bNumEndpoints; /* Number of Endpoints used for this interface */
277  uint8_t bInterfaceClass; /* Class Code (Assigned by USB Org) */
278  uint8_t bInterfaceSubClass; /* Subclass Code (Assigned by USB Org) */
279  uint8_t bInterfaceProtocol; /* Protocol Code */
280  uint8_t iInterface; /* Index of String Descriptor Describing this interface */
282 }
284 
285 
287 {
288  uint8_t bLength;
290  uint16_t wTotalLength; /* Total Length of Data Returned */
291  uint8_t bNumInterfaces; /* Number of Interfaces */
292  uint8_t bConfigurationValue; /* Value to use as an argument to select this configuration*/
293  uint8_t iConfiguration; /*Index of String Descriptor Describing this configuration */
294  uint8_t bmAttributes; /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/
295  uint8_t bMaxPower; /*Maximum Power Consumption */
297 }
299 
300 
301 /* Following USB Host status */
302 typedef enum
303 {
304  USBH_OK = 0,
311 
312 
317 typedef enum
318 {
322 
324 
325 /* Following states are used for gState */
326 typedef enum
327 {
342 
343 /* Following states are used for EnumerationState */
344 typedef enum
345 {
355 
356 /* Following states are used for CtrlXferStateMachine */
357 typedef enum
358 {
374 
375 
376 /* Following states are used for RequestState */
377 typedef enum
378 {
383 
384 typedef enum {
392 
393 typedef enum
394 {
400 }
402 
403 /* Control request structure */
404 typedef struct
405 {
406  uint8_t pipe_in;
407  uint8_t pipe_out;
408  uint8_t pipe_size;
409  uint8_t *buff;
410  uint16_t length;
411  uint16_t timer;
413  CTRL_StateTypeDef state;
414  uint8_t errorcount;
415 
417 
418 /* Attached device structure */
419 typedef struct
420 {
421 #if (USBH_KEEP_CFG_DESCRIPTOR == 1)
422  uint8_t CfgDesc_Raw[USBH_MAX_SIZE_CONFIGURATION];
423 #endif
424  uint8_t Data[USBH_MAX_DATA_BUFFER];
425  uint8_t address;
426  uint8_t speed;
427  __IO uint8_t is_connected;
431 
433 
434 struct _USBH_HandleTypeDef;
435 
436 /* USB Host Class structure */
437 typedef struct
438 {
439  const char *Name;
440  uint8_t ClassCode;
441  USBH_StatusTypeDef (*Init) (struct _USBH_HandleTypeDef *phost);
442  USBH_StatusTypeDef (*DeInit) (struct _USBH_HandleTypeDef *phost);
443  USBH_StatusTypeDef (*Requests) (struct _USBH_HandleTypeDef *phost);
444  USBH_StatusTypeDef (*BgndProcess) (struct _USBH_HandleTypeDef *phost);
445  USBH_StatusTypeDef (*SOFProcess) (struct _USBH_HandleTypeDef *phost);
446  void* pData;
448 
449 /* USB Host handle structure */
450 typedef struct _USBH_HandleTypeDef
451 {
452  __IO HOST_StateTypeDef gState; /* Host State Machine Value */
453  ENUM_StateTypeDef EnumState; /* Enumeration state Machine */
454  CMD_StateTypeDef RequestState;
459  uint32_t ClassNumber;
460  uint32_t Pipes[15];
461  __IO uint32_t Timer;
462  uint8_t id;
463  void* pData;
464  void (* pUser )(struct _USBH_HandleTypeDef *pHandle, uint8_t id);
465 
466 #if (USBH_USE_OS == 1)
467  osMessageQId os_event;
468  osThreadId thread;
469 #endif
470 
472 
473 
474 #if defined ( __GNUC__ )
475  #ifndef __weak
476  #define __weak __attribute__((weak))
477  #endif /* __weak */
478  #ifndef __packed
479  #define __packed __attribute__((__packed__))
480  #endif /* __packed */
481 #endif /* __GNUC__ */
482 
483 #ifdef __cplusplus
484 }
485 #endif
486 
487 #endif /* USBH_DEF_H */
488 
489 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
490 
CMD_StateTypeDef RequestState
Definition: usbh_def.h:454
const char * Name
Definition: usbh_def.h:439
#define USBH_MAX_NUM_SUPPORTED_CLASS
USB_Setup_TypeDef setup
Definition: usbh_def.h:412
USBH_DeviceTypeDef device
Definition: usbh_def.h:456
#define USBH_MAX_SIZE_CONFIGURATION
__IO uint32_t Timer
Definition: usbh_def.h:461
CMD_StateTypeDef
Definition: usbh_def.h:377
uint8_t iSerialNumber
Definition: usbh_def.h:254
USBH_OSEventTypeDef
Definition: usbh_def.h:393
uint8_t bNumConfigurations
Definition: usbh_def.h:255
uint16_t_uint8_t wValue
Definition: usbh_def.h:223
uint8_t ClassCode
Definition: usbh_def.h:440
uint8_t bInterfaceClass
Definition: usbh_def.h:277
uint8_t bLength
Definition: usbh_def.h:232
HOST_StateTypeDef
Definition: usbh_def.h:326
uint32_t ClassNumber
Definition: usbh_def.h:459
uint8_t iManufacturer
Definition: usbh_def.h:252
uint8_t bEndpointAddress
Definition: usbh_def.h:263
uint8_t bMaxPacketSize
Definition: usbh_def.h:248
uint8_t bDeviceSubClass
Definition: usbh_def.h:243
uint8_t bDeviceClass
Definition: usbh_def.h:242
uint16_t_uint8_t wLength
Definition: usbh_def.h:225
uint16_t idVendor
Definition: usbh_def.h:249
#define USBH_MAX_NUM_ENDPOINTS
uint8_t iProduct
Definition: usbh_def.h:253
uint8_t bmAttributes
Definition: usbh_def.h:264
ENUM_StateTypeDef
Definition: usbh_def.h:344
ENUM_StateTypeDef EnumState
Definition: usbh_def.h:453
uint8_t * buff
Definition: usbh_def.h:409
USBH_CfgDescTypeDef CfgDesc
Definition: usbh_def.h:430
struct _InterfaceDescriptor USBH_InterfaceDescTypeDef
USBH_CtrlTypeDef Control
Definition: usbh_def.h:455
#define USBH_MAX_NUM_INTERFACES
#define __IO
Definition: core_cm0.h:213
uint8_t bInterfaceNumber
Definition: usbh_def.h:274
struct _EndpointDescriptor USBH_EpDescTypeDef
uint16_t bcdUSB
Definition: usbh_def.h:241
CTRL_StateTypeDef
Definition: usbh_def.h:357
struct _DeviceDescriptor USBH_DevDescTypeDef
uint8_t bDescriptorType
Definition: usbh_def.h:233
uint16_t wMaxPacketSize
Definition: usbh_def.h:265
uint8_t bInterfaceSubClass
Definition: usbh_def.h:278
uint8_t bAlternateSetting
Definition: usbh_def.h:275
USBH_URBStateTypeDef
Definition: usbh_def.h:384
uint16_t w
Definition: usbh_def.h:204
QueueHandle_t osMessageQId
Definition: cmsis_os.h:321
#define USBH_MAX_DATA_BUFFER
struct _ConfigurationDescriptor USBH_CfgDescTypeDef
uint8_t pipe_in
Definition: usbh_def.h:406
USBH_StatusTypeDef
Definition: usbh_def.h:302
__IO HOST_StateTypeDef gState
Definition: usbh_def.h:452
union _USB_Setup USB_Setup_TypeDef
uint16_t idProduct
Definition: usbh_def.h:250
uint8_t current_interface
Definition: usbh_def.h:428
CTRL_StateTypeDef state
Definition: usbh_def.h:413
uint8_t pipe_out
Definition: usbh_def.h:407
uint16_t timer
Definition: usbh_def.h:411
uint8_t pipe_size
Definition: usbh_def.h:408
uint8_t bNumEndpoints
Definition: usbh_def.h:276
uint8_t bInterfaceProtocol
Definition: usbh_def.h:279
USBH_SpeedTypeDef
Definition: usbh_def.h:317
USBH_DevDescTypeDef DevDesc
Definition: usbh_def.h:429
uint16_t length
Definition: usbh_def.h:410
USBH_ClassTypeDef * pActiveClass
Definition: usbh_def.h:458
uint8_t errorcount
Definition: usbh_def.h:414
uint16_t_uint8_t wIndex
Definition: usbh_def.h:224
struct _USBH_HandleTypeDef USBH_HandleTypeDef
uint8_t bDeviceProtocol
Definition: usbh_def.h:244
__IO uint8_t is_connected
Definition: usbh_def.h:427
struct _DescHeader USBH_DescHeader_t
uint16_t bcdDevice
Definition: usbh_def.h:251
TaskHandle_t osThreadId
Definition: cmsis_os.h:301