STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
usbd_def.h
Go to the documentation of this file.
1 
28 /* Define to prevent recursive inclusion -------------------------------------*/
29 #ifndef __USBD_DEF_H
30 #define __USBD_DEF_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------*/
37 #include "usbd_conf.h"
38 
52 #ifndef NULL
53 #define NULL 0
54 #endif
55 
56 
57 #define USB_LEN_DEV_QUALIFIER_DESC 0x0A
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_LANGID_STR_DESC 0x04
64 #define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09
65 
66 #define USBD_IDX_LANGID_STR 0x00
67 #define USBD_IDX_MFC_STR 0x01
68 #define USBD_IDX_PRODUCT_STR 0x02
69 #define USBD_IDX_SERIAL_STR 0x03
70 #define USBD_IDX_CONFIG_STR 0x04
71 #define USBD_IDX_INTERFACE_STR 0x05
72 
73 #define USB_REQ_TYPE_STANDARD 0x00
74 #define USB_REQ_TYPE_CLASS 0x20
75 #define USB_REQ_TYPE_VENDOR 0x40
76 #define USB_REQ_TYPE_MASK 0x60
77 
78 #define USB_REQ_RECIPIENT_DEVICE 0x00
79 #define USB_REQ_RECIPIENT_INTERFACE 0x01
80 #define USB_REQ_RECIPIENT_ENDPOINT 0x02
81 #define USB_REQ_RECIPIENT_MASK 0x03
82 
83 #define USB_REQ_GET_STATUS 0x00
84 #define USB_REQ_CLEAR_FEATURE 0x01
85 #define USB_REQ_SET_FEATURE 0x03
86 #define USB_REQ_SET_ADDRESS 0x05
87 #define USB_REQ_GET_DESCRIPTOR 0x06
88 #define USB_REQ_SET_DESCRIPTOR 0x07
89 #define USB_REQ_GET_CONFIGURATION 0x08
90 #define USB_REQ_SET_CONFIGURATION 0x09
91 #define USB_REQ_GET_INTERFACE 0x0A
92 #define USB_REQ_SET_INTERFACE 0x0B
93 #define USB_REQ_SYNCH_FRAME 0x0C
94 
95 #define USB_DESC_TYPE_DEVICE 1
96 #define USB_DESC_TYPE_CONFIGURATION 2
97 #define USB_DESC_TYPE_STRING 3
98 #define USB_DESC_TYPE_INTERFACE 4
99 #define USB_DESC_TYPE_ENDPOINT 5
100 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6
101 #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7
102 #define USB_DESC_TYPE_BOS 0x0F
103 
104 #define USB_CONFIG_REMOTE_WAKEUP 2
105 #define USB_CONFIG_SELF_POWERED 1
106 
107 #define USB_FEATURE_EP_HALT 0
108 #define USB_FEATURE_REMOTE_WAKEUP 1
109 #define USB_FEATURE_TEST_MODE 2
110 
111 #define USB_DEVICE_CAPABITY_TYPE 0x10
112 
113 #define USB_HS_MAX_PACKET_SIZE 512
114 #define USB_FS_MAX_PACKET_SIZE 64
115 #define USB_MAX_EP0_SIZE 64
116 
117 /* Device Status */
118 #define USBD_STATE_DEFAULT 1
119 #define USBD_STATE_ADDRESSED 2
120 #define USBD_STATE_CONFIGURED 3
121 #define USBD_STATE_SUSPENDED 4
122 
123 
124 /* EP0 State */
125 #define USBD_EP0_IDLE 0
126 #define USBD_EP0_SETUP 1
127 #define USBD_EP0_DATA_IN 2
128 #define USBD_EP0_DATA_OUT 3
129 #define USBD_EP0_STATUS_IN 4
130 #define USBD_EP0_STATUS_OUT 5
131 #define USBD_EP0_STALL 6
132 
133 #define USBD_EP_TYPE_CTRL 0
134 #define USBD_EP_TYPE_ISOC 1
135 #define USBD_EP_TYPE_BULK 2
136 #define USBD_EP_TYPE_INTR 3
137 
138 
148 typedef struct usb_setup_req
149 {
150 
151  uint8_t bmRequest;
152  uint8_t bRequest;
153  uint16_t wValue;
154  uint16_t wIndex;
155  uint16_t wLength;
157 
158 struct _USBD_HandleTypeDef;
159 
160 typedef struct _Device_cb
161 {
162  uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
163  uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
164  /* Control Endpoints*/
165  uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req);
166  uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev );
167  uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev );
168  /* Class Specific Endpoints*/
169  uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
170  uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
171  uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev);
172  uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
173  uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
174 
175  uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
176  uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
177  uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
178  uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
179 #if (USBD_SUPPORT_USER_STRING == 1)
180  uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length);
181 #endif
182 
184 
185 /* Following USB Device Speed */
186 typedef enum
187 {
192 
193 /* Following USB Device status */
194 typedef enum {
195  USBD_OK = 0,
199 
200 /* USB Device descriptors structure */
201 typedef struct
202 {
203  uint8_t *(*GetDeviceDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
204  uint8_t *(*GetLangIDStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
205  uint8_t *(*GetManufacturerStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
206  uint8_t *(*GetProductStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
207  uint8_t *(*GetSerialStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
208  uint8_t *(*GetConfigurationStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
209  uint8_t *(*GetInterfaceStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
210 #if (USBD_LPM_ENABLED == 1)
211  uint8_t *(*GetBOSDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
212 #endif
214 
215 /* USB Device handle structure */
216 typedef struct
217 {
218  uint32_t status;
219  uint32_t total_length;
220  uint32_t rem_length;
221  uint32_t maxpacket;
223 
224 /* USB Device handle structure */
225 typedef struct _USBD_HandleTypeDef
226 {
227  uint8_t id;
228  uint32_t dev_config;
230  uint32_t dev_config_status;
233  USBD_EndpointTypeDef ep_out[15];
234  uint32_t ep0_state;
235  uint32_t ep0_data_len;
236  uint8_t dev_state;
237  uint8_t dev_old_state;
238  uint8_t dev_address;
240  uint8_t dev_test_mode;
242 
244  USBD_DescriptorsTypeDef *pDesc;
245  USBD_ClassTypeDef *pClass;
246  void *pClassData;
247  void *pUserData;
248  void *pData;
250 
260 #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
261  (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8))
262 
263 #define LOBYTE(x) ((uint8_t)(x & 0x00FF))
264 #define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8))
265 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
266 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
267 
268 
269 #if defined ( __GNUC__ )
270  #ifndef __weak
271  #define __weak __attribute__((weak))
272  #endif /* __weak */
273  #ifndef __packed
274  #define __packed __attribute__((__packed__))
275  #endif /* __packed */
276 #endif /* __GNUC__ */
277 
278 
279 /* In HS mode and when the DMA is used, all variables and data structures dealing
280  with the DMA during the transaction process should be 4-bytes aligned */
281 
282 #if defined (__GNUC__) /* GNU Compiler */
283  #define __ALIGN_END __attribute__ ((aligned (4)))
284  #define __ALIGN_BEGIN
285 #else
286  #define __ALIGN_END
287  #if defined (__CC_ARM) /* ARM Compiler */
288  #define __ALIGN_BEGIN __align(4)
289  #elif defined (__ICCARM__) /* IAR Compiler */
290  #define __ALIGN_BEGIN
291  #elif defined (__TASKING__) /* TASKING Compiler */
292  #define __ALIGN_BEGIN __align(4)
293  #endif /* __CC_ARM */
294 #endif /* __GNUC__ */
295 
296 
317 #ifdef __cplusplus
318 }
319 #endif
320 
321 #endif /* __USBD_DEF_H */
322 
330 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
uint32_t maxpacket
Definition: usbd_def.h:221
USBD_StatusTypeDef
Definition: usbd_def.h:194
uint8_t dev_old_state
Definition: usbd_def.h:237
uint32_t dev_default_config
Definition: usbd_def.h:229
struct _Device_cb USBD_ClassTypeDef
uint8_t bmRequest
Definition: usbd_def.h:151
uint16_t wValue
Definition: usbd_def.h:153
USBD_SpeedTypeDef
Definition: usbd_def.h:186
uint8_t bRequest
Definition: usbd_def.h:152
USBD_SetupReqTypedef request
Definition: usbd_def.h:243
uint8_t dev_address
Definition: usbd_def.h:238
struct usb_setup_req USBD_SetupReqTypedef
USBD_DescriptorsTypeDef * pDesc
Definition: usbd_def.h:244
uint32_t dev_config
Definition: usbd_def.h:228
USBD_SpeedTypeDef dev_speed
Definition: usbd_def.h:231
uint16_t wLength
Definition: usbd_def.h:155
uint32_t ep0_state
Definition: usbd_def.h:234
uint16_t wIndex
Definition: usbd_def.h:154
uint32_t ep0_data_len
Definition: usbd_def.h:235
uint8_t dev_connection_status
Definition: usbd_def.h:239
uint32_t rem_length
Definition: usbd_def.h:220
struct _USBD_HandleTypeDef USBD_HandleTypeDef
uint8_t dev_test_mode
Definition: usbd_def.h:240
USBD_ClassTypeDef * pClass
Definition: usbd_def.h:245
uint32_t dev_remote_wakeup
Definition: usbd_def.h:241
uint32_t dev_config_status
Definition: usbd_def.h:230
uint32_t total_length
Definition: usbd_def.h:219