Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /** |
2 | ****************************************************************************** |
||
3 | * @file usbd_def.h |
||
4 | * @author MCD Application Team |
||
9 | mjames | 5 | * @brief General defines for the usb device library |
2 | mjames | 6 | ****************************************************************************** |
7 | * @attention |
||
8 | * |
||
9 | mjames | 9 | * <h2><center>© Copyright (c) 2015 STMicroelectronics. |
10 | * All rights reserved.</center></h2> |
||
2 | mjames | 11 | * |
9 | mjames | 12 | * This software component is licensed by ST under Ultimate Liberty license |
13 | * SLA0044, the "License"; You may not use this file except in compliance with |
||
14 | * the License. You may obtain a copy of the License at: |
||
15 | * www.st.com/SLA0044 |
||
2 | mjames | 16 | * |
17 | ****************************************************************************** |
||
9 | mjames | 18 | */ |
2 | mjames | 19 | |
20 | /* Define to prevent recursive inclusion -------------------------------------*/ |
||
21 | #ifndef __USBD_DEF_H |
||
22 | #define __USBD_DEF_H |
||
23 | |||
24 | #ifdef __cplusplus |
||
9 | mjames | 25 | extern "C" { |
2 | mjames | 26 | #endif |
27 | |||
28 | /* Includes ------------------------------------------------------------------*/ |
||
29 | #include "usbd_conf.h" |
||
30 | |||
31 | /** @addtogroup STM32_USBD_DEVICE_LIBRARY |
||
32 | * @{ |
||
33 | */ |
||
9 | mjames | 34 | |
2 | mjames | 35 | /** @defgroup USB_DEF |
36 | * @brief general defines for the usb device library file |
||
37 | * @{ |
||
9 | mjames | 38 | */ |
2 | mjames | 39 | |
40 | /** @defgroup USB_DEF_Exported_Defines |
||
41 | * @{ |
||
9 | mjames | 42 | */ |
2 | mjames | 43 | |
44 | #ifndef NULL |
||
9 | mjames | 45 | #define NULL 0U |
46 | #endif /* NULL */ |
||
2 | mjames | 47 | |
9 | mjames | 48 | #ifndef USBD_MAX_NUM_INTERFACES |
49 | #define USBD_MAX_NUM_INTERFACES 1U |
||
50 | #endif /* USBD_MAX_NUM_CONFIGURATION */ |
||
2 | mjames | 51 | |
9 | mjames | 52 | #ifndef USBD_MAX_NUM_CONFIGURATION |
53 | #define USBD_MAX_NUM_CONFIGURATION 1U |
||
54 | #endif /* USBD_MAX_NUM_CONFIGURATION */ |
||
2 | mjames | 55 | |
9 | mjames | 56 | #ifndef USBD_LPM_ENABLED |
57 | #define USBD_LPM_ENABLED 0U |
||
58 | #endif /* USBD_LPM_ENABLED */ |
||
2 | mjames | 59 | |
9 | mjames | 60 | #ifndef USBD_SELF_POWERED |
61 | #define USBD_SELF_POWERED 1U |
||
62 | #endif /*USBD_SELF_POWERED */ |
||
2 | mjames | 63 | |
9 | mjames | 64 | #ifndef USBD_SUPPORT_USER_STRING_DESC |
65 | #define USBD_SUPPORT_USER_STRING_DESC 0U |
||
66 | #endif /* USBD_SUPPORT_USER_STRING_DESC */ |
||
2 | mjames | 67 | |
9 | mjames | 68 | #define USB_LEN_DEV_QUALIFIER_DESC 0x0AU |
69 | #define USB_LEN_DEV_DESC 0x12U |
||
70 | #define USB_LEN_CFG_DESC 0x09U |
||
71 | #define USB_LEN_IF_DESC 0x09U |
||
72 | #define USB_LEN_EP_DESC 0x07U |
||
73 | #define USB_LEN_OTG_DESC 0x03U |
||
74 | #define USB_LEN_LANGID_STR_DESC 0x04U |
||
75 | #define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U |
||
2 | mjames | 76 | |
9 | mjames | 77 | #define USBD_IDX_LANGID_STR 0x00U |
78 | #define USBD_IDX_MFC_STR 0x01U |
||
79 | #define USBD_IDX_PRODUCT_STR 0x02U |
||
80 | #define USBD_IDX_SERIAL_STR 0x03U |
||
81 | #define USBD_IDX_CONFIG_STR 0x04U |
||
82 | #define USBD_IDX_INTERFACE_STR 0x05U |
||
2 | mjames | 83 | |
9 | mjames | 84 | #define USB_REQ_TYPE_STANDARD 0x00U |
85 | #define USB_REQ_TYPE_CLASS 0x20U |
||
86 | #define USB_REQ_TYPE_VENDOR 0x40U |
||
87 | #define USB_REQ_TYPE_MASK 0x60U |
||
2 | mjames | 88 | |
9 | mjames | 89 | #define USB_REQ_RECIPIENT_DEVICE 0x00U |
90 | #define USB_REQ_RECIPIENT_INTERFACE 0x01U |
||
91 | #define USB_REQ_RECIPIENT_ENDPOINT 0x02U |
||
92 | #define USB_REQ_RECIPIENT_MASK 0x03U |
||
2 | mjames | 93 | |
9 | mjames | 94 | #define USB_REQ_GET_STATUS 0x00U |
95 | #define USB_REQ_CLEAR_FEATURE 0x01U |
||
96 | #define USB_REQ_SET_FEATURE 0x03U |
||
97 | #define USB_REQ_SET_ADDRESS 0x05U |
||
98 | #define USB_REQ_GET_DESCRIPTOR 0x06U |
||
99 | #define USB_REQ_SET_DESCRIPTOR 0x07U |
||
100 | #define USB_REQ_GET_CONFIGURATION 0x08U |
||
101 | #define USB_REQ_SET_CONFIGURATION 0x09U |
||
102 | #define USB_REQ_GET_INTERFACE 0x0AU |
||
103 | #define USB_REQ_SET_INTERFACE 0x0BU |
||
104 | #define USB_REQ_SYNCH_FRAME 0x0CU |
||
2 | mjames | 105 | |
9 | mjames | 106 | #define USB_DESC_TYPE_DEVICE 0x01U |
107 | #define USB_DESC_TYPE_CONFIGURATION 0x02U |
||
108 | #define USB_DESC_TYPE_STRING 0x03U |
||
109 | #define USB_DESC_TYPE_INTERFACE 0x04U |
||
110 | #define USB_DESC_TYPE_ENDPOINT 0x05U |
||
111 | #define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U |
||
112 | #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U |
||
113 | #define USB_DESC_TYPE_BOS 0x0FU |
||
2 | mjames | 114 | |
9 | mjames | 115 | #define USB_CONFIG_REMOTE_WAKEUP 0x02U |
116 | #define USB_CONFIG_SELF_POWERED 0x01U |
||
117 | |||
118 | #define USB_FEATURE_EP_HALT 0x00U |
||
119 | #define USB_FEATURE_REMOTE_WAKEUP 0x01U |
||
120 | #define USB_FEATURE_TEST_MODE 0x02U |
||
121 | |||
122 | #define USB_DEVICE_CAPABITY_TYPE 0x10U |
||
123 | |||
124 | #define USB_HS_MAX_PACKET_SIZE 512U |
||
125 | #define USB_FS_MAX_PACKET_SIZE 64U |
||
126 | #define USB_MAX_EP0_SIZE 64U |
||
127 | |||
2 | mjames | 128 | /* Device Status */ |
9 | mjames | 129 | #define USBD_STATE_DEFAULT 0x01U |
130 | #define USBD_STATE_ADDRESSED 0x02U |
||
131 | #define USBD_STATE_CONFIGURED 0x03U |
||
132 | #define USBD_STATE_SUSPENDED 0x04U |
||
2 | mjames | 133 | |
134 | |||
9 | mjames | 135 | /* EP0 State */ |
136 | #define USBD_EP0_IDLE 0x00U |
||
137 | #define USBD_EP0_SETUP 0x01U |
||
138 | #define USBD_EP0_DATA_IN 0x02U |
||
139 | #define USBD_EP0_DATA_OUT 0x03U |
||
140 | #define USBD_EP0_STATUS_IN 0x04U |
||
141 | #define USBD_EP0_STATUS_OUT 0x05U |
||
142 | #define USBD_EP0_STALL 0x06U |
||
2 | mjames | 143 | |
9 | mjames | 144 | #define USBD_EP_TYPE_CTRL 0x00U |
145 | #define USBD_EP_TYPE_ISOC 0x01U |
||
146 | #define USBD_EP_TYPE_BULK 0x02U |
||
147 | #define USBD_EP_TYPE_INTR 0x03U |
||
2 | mjames | 148 | |
149 | |||
150 | /** |
||
151 | * @} |
||
9 | mjames | 152 | */ |
2 | mjames | 153 | |
154 | |||
155 | /** @defgroup USBD_DEF_Exported_TypesDefinitions |
||
156 | * @{ |
||
157 | */ |
||
158 | |||
9 | mjames | 159 | typedef struct usb_setup_req |
2 | mjames | 160 | { |
9 | mjames | 161 | uint8_t bmRequest; |
162 | uint8_t bRequest; |
||
163 | uint16_t wValue; |
||
164 | uint16_t wIndex; |
||
165 | uint16_t wLength; |
||
166 | } USBD_SetupReqTypedef; |
||
2 | mjames | 167 | |
168 | struct _USBD_HandleTypeDef; |
||
9 | mjames | 169 | |
2 | mjames | 170 | typedef struct _Device_cb |
171 | { |
||
9 | mjames | 172 | uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx); |
173 | uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx); |
||
174 | /* Control Endpoints*/ |
||
175 | uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); |
||
176 | uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev); |
||
177 | uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev); |
||
2 | mjames | 178 | /* Class Specific Endpoints*/ |
9 | mjames | 179 | uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); |
180 | uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); |
||
181 | uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev); |
||
182 | uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); |
||
183 | uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); |
||
2 | mjames | 184 | |
9 | mjames | 185 | uint8_t *(*GetHSConfigDescriptor)(uint16_t *length); |
186 | uint8_t *(*GetFSConfigDescriptor)(uint16_t *length); |
||
2 | mjames | 187 | uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length); |
188 | uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length); |
||
9 | mjames | 189 | #if (USBD_SUPPORT_USER_STRING_DESC == 1U) |
190 | uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length); |
||
191 | #endif |
||
192 | |||
2 | mjames | 193 | } USBD_ClassTypeDef; |
194 | |||
195 | /* Following USB Device Speed */ |
||
9 | mjames | 196 | typedef enum |
2 | mjames | 197 | { |
9 | mjames | 198 | USBD_SPEED_HIGH = 0U, |
199 | USBD_SPEED_FULL = 1U, |
||
200 | USBD_SPEED_LOW = 2U, |
||
201 | } USBD_SpeedTypeDef; |
||
2 | mjames | 202 | |
203 | /* Following USB Device status */ |
||
9 | mjames | 204 | typedef enum |
205 | { |
||
206 | USBD_OK = 0U, |
||
2 | mjames | 207 | USBD_BUSY, |
208 | USBD_FAIL, |
||
9 | mjames | 209 | } USBD_StatusTypeDef; |
2 | mjames | 210 | |
211 | /* USB Device descriptors structure */ |
||
212 | typedef struct |
||
213 | { |
||
9 | mjames | 214 | uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
215 | uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
||
216 | uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
||
217 | uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
||
218 | uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
||
219 | uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
||
220 | uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
||
221 | #if (USBD_LPM_ENABLED == 1U) |
||
222 | uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
||
223 | #endif |
||
2 | mjames | 224 | } USBD_DescriptorsTypeDef; |
225 | |||
226 | /* USB Device handle structure */ |
||
227 | typedef struct |
||
9 | mjames | 228 | { |
2 | mjames | 229 | uint32_t status; |
9 | mjames | 230 | uint32_t is_used; |
231 | uint32_t total_length; |
||
232 | uint32_t rem_length; |
||
233 | uint32_t maxpacket; |
||
2 | mjames | 234 | } USBD_EndpointTypeDef; |
235 | |||
236 | /* USB Device handle structure */ |
||
237 | typedef struct _USBD_HandleTypeDef |
||
238 | { |
||
239 | uint8_t id; |
||
240 | uint32_t dev_config; |
||
241 | uint32_t dev_default_config; |
||
9 | mjames | 242 | uint32_t dev_config_status; |
243 | USBD_SpeedTypeDef dev_speed; |
||
244 | USBD_EndpointTypeDef ep_in[16]; |
||
245 | USBD_EndpointTypeDef ep_out[16]; |
||
246 | uint32_t ep0_state; |
||
247 | uint32_t ep0_data_len; |
||
2 | mjames | 248 | uint8_t dev_state; |
249 | uint8_t dev_old_state; |
||
250 | uint8_t dev_address; |
||
9 | mjames | 251 | uint8_t dev_connection_status; |
2 | mjames | 252 | uint8_t dev_test_mode; |
253 | uint32_t dev_remote_wakeup; |
||
254 | |||
255 | USBD_SetupReqTypedef request; |
||
256 | USBD_DescriptorsTypeDef *pDesc; |
||
257 | USBD_ClassTypeDef *pClass; |
||
9 | mjames | 258 | void *pClassData; |
259 | void *pUserData; |
||
260 | void *pData; |
||
2 | mjames | 261 | } USBD_HandleTypeDef; |
262 | |||
263 | /** |
||
264 | * @} |
||
9 | mjames | 265 | */ |
2 | mjames | 266 | |
267 | |||
268 | |||
269 | /** @defgroup USBD_DEF_Exported_Macros |
||
270 | * @{ |
||
9 | mjames | 271 | */ |
2 | mjames | 272 | #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \ |
9 | mjames | 273 | (((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U)) |
2 | mjames | 274 | |
9 | mjames | 275 | #define LOBYTE(x) ((uint8_t)((x) & 0x00FFU)) |
276 | #define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U)) |
||
2 | mjames | 277 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
278 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
||
279 | |||
280 | |||
281 | #if defined ( __GNUC__ ) |
||
9 | mjames | 282 | #ifndef __weak |
283 | #define __weak __attribute__((weak)) |
||
284 | #endif /* __weak */ |
||
285 | #ifndef __packed |
||
286 | #define __packed __attribute__((__packed__)) |
||
287 | #endif /* __packed */ |
||
2 | mjames | 288 | #endif /* __GNUC__ */ |
289 | |||
290 | |||
291 | /* In HS mode and when the DMA is used, all variables and data structures dealing |
||
9 | mjames | 292 | with the DMA during the transaction process should be 4-bytes aligned */ |
2 | mjames | 293 | |
9 | mjames | 294 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ |
295 | #ifndef __ALIGN_END |
||
296 | #define __ALIGN_END __attribute__ ((aligned (4U))) |
||
297 | #endif /* __ALIGN_END */ |
||
298 | #ifndef __ALIGN_BEGIN |
||
299 | #define __ALIGN_BEGIN |
||
300 | #endif /* __ALIGN_BEGIN */ |
||
301 | #else |
||
302 | #ifndef __ALIGN_END |
||
303 | #define __ALIGN_END |
||
304 | #endif /* __ALIGN_END */ |
||
305 | #ifndef __ALIGN_BEGIN |
||
306 | #if defined (__CC_ARM) /* ARM Compiler */ |
||
307 | #define __ALIGN_BEGIN __align(4U) |
||
308 | #elif defined (__ICCARM__) /* IAR Compiler */ |
||
309 | #define __ALIGN_BEGIN |
||
310 | #endif /* __CC_ARM */ |
||
311 | #endif /* __ALIGN_BEGIN */ |
||
312 | #endif /* __GNUC__ */ |
||
2 | mjames | 313 | |
9 | mjames | 314 | |
2 | mjames | 315 | /** |
316 | * @} |
||
9 | mjames | 317 | */ |
2 | mjames | 318 | |
319 | /** @defgroup USBD_DEF_Exported_Variables |
||
320 | * @{ |
||
9 | mjames | 321 | */ |
2 | mjames | 322 | |
323 | /** |
||
324 | * @} |
||
9 | mjames | 325 | */ |
2 | mjames | 326 | |
327 | /** @defgroup USBD_DEF_Exported_FunctionsPrototype |
||
328 | * @{ |
||
9 | mjames | 329 | */ |
2 | mjames | 330 | |
331 | /** |
||
332 | * @} |
||
9 | mjames | 333 | */ |
2 | mjames | 334 | |
335 | #ifdef __cplusplus |
||
336 | } |
||
337 | #endif |
||
338 | |||
339 | #endif /* __USBD_DEF_H */ |
||
340 | |||
341 | /** |
||
342 | * @} |
||
9 | mjames | 343 | */ |
2 | mjames | 344 | |
345 | /** |
||
346 | * @} |
||
9 | mjames | 347 | */ |
2 | mjames | 348 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |