Details | 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 |
||
5 | * @brief General defines for the usb device library |
||
6 | ****************************************************************************** |
||
7 | * @attention |
||
8 | * |
||
9 | * <h2><center>© Copyright (c) 2015 STMicroelectronics. |
||
10 | * All rights reserved.</center></h2> |
||
11 | * |
||
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 |
||
16 | * |
||
17 | ****************************************************************************** |
||
18 | */ |
||
19 | |||
20 | /* Define to prevent recursive inclusion -------------------------------------*/ |
||
21 | #ifndef __USBD_DEF_H |
||
22 | #define __USBD_DEF_H |
||
23 | |||
24 | #ifdef __cplusplus |
||
25 | extern "C" { |
||
26 | #endif |
||
27 | |||
28 | /* Includes ------------------------------------------------------------------*/ |
||
29 | #include "usbd_conf.h" |
||
30 | |||
31 | /** @addtogroup STM32_USBD_DEVICE_LIBRARY |
||
32 | * @{ |
||
33 | */ |
||
34 | |||
35 | /** @defgroup USB_DEF |
||
36 | * @brief general defines for the usb device library file |
||
37 | * @{ |
||
38 | */ |
||
39 | |||
40 | /** @defgroup USB_DEF_Exported_Defines |
||
41 | * @{ |
||
42 | */ |
||
43 | |||
44 | #ifndef NULL |
||
45 | #define NULL 0U |
||
46 | #endif /* NULL */ |
||
47 | |||
48 | #ifndef USBD_MAX_NUM_INTERFACES |
||
49 | #define USBD_MAX_NUM_INTERFACES 1U |
||
50 | #endif /* USBD_MAX_NUM_CONFIGURATION */ |
||
51 | |||
52 | #ifndef USBD_MAX_NUM_CONFIGURATION |
||
53 | #define USBD_MAX_NUM_CONFIGURATION 1U |
||
54 | #endif /* USBD_MAX_NUM_CONFIGURATION */ |
||
55 | |||
56 | #ifndef USBD_LPM_ENABLED |
||
57 | #define USBD_LPM_ENABLED 0U |
||
58 | #endif /* USBD_LPM_ENABLED */ |
||
59 | |||
60 | #ifndef USBD_SELF_POWERED |
||
61 | #define USBD_SELF_POWERED 1U |
||
62 | #endif /*USBD_SELF_POWERED */ |
||
63 | |||
64 | #ifndef USBD_SUPPORT_USER_STRING_DESC |
||
65 | #define USBD_SUPPORT_USER_STRING_DESC 0U |
||
66 | #endif /* USBD_SUPPORT_USER_STRING_DESC */ |
||
67 | |||
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 |
||
76 | |||
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 |
||
83 | |||
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 |
||
88 | |||
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 |
||
93 | |||
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 |
||
105 | |||
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 |
||
114 | |||
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 | |||
128 | /* Device Status */ |
||
129 | #define USBD_STATE_DEFAULT 0x01U |
||
130 | #define USBD_STATE_ADDRESSED 0x02U |
||
131 | #define USBD_STATE_CONFIGURED 0x03U |
||
132 | #define USBD_STATE_SUSPENDED 0x04U |
||
133 | |||
134 | |||
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 |
||
143 | |||
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 |
||
148 | |||
149 | |||
150 | /** |
||
151 | * @} |
||
152 | */ |
||
153 | |||
154 | |||
155 | /** @defgroup USBD_DEF_Exported_TypesDefinitions |
||
156 | * @{ |
||
157 | */ |
||
158 | |||
159 | typedef struct usb_setup_req |
||
160 | { |
||
161 | uint8_t bmRequest; |
||
162 | uint8_t bRequest; |
||
163 | uint16_t wValue; |
||
164 | uint16_t wIndex; |
||
165 | uint16_t wLength; |
||
166 | } USBD_SetupReqTypedef; |
||
167 | |||
168 | struct _USBD_HandleTypeDef; |
||
169 | |||
170 | typedef struct _Device_cb |
||
171 | { |
||
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); |
||
178 | /* Class Specific Endpoints*/ |
||
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); |
||
184 | |||
185 | uint8_t *(*GetHSConfigDescriptor)(uint16_t *length); |
||
186 | uint8_t *(*GetFSConfigDescriptor)(uint16_t *length); |
||
187 | uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length); |
||
188 | uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length); |
||
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 | |||
193 | } USBD_ClassTypeDef; |
||
194 | |||
195 | /* Following USB Device Speed */ |
||
196 | typedef enum |
||
197 | { |
||
198 | USBD_SPEED_HIGH = 0U, |
||
199 | USBD_SPEED_FULL = 1U, |
||
200 | USBD_SPEED_LOW = 2U, |
||
201 | } USBD_SpeedTypeDef; |
||
202 | |||
203 | /* Following USB Device status */ |
||
204 | typedef enum |
||
205 | { |
||
206 | USBD_OK = 0U, |
||
207 | USBD_BUSY, |
||
208 | USBD_FAIL, |
||
209 | } USBD_StatusTypeDef; |
||
210 | |||
211 | /* USB Device descriptors structure */ |
||
212 | typedef struct |
||
213 | { |
||
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 |
||
224 | } USBD_DescriptorsTypeDef; |
||
225 | |||
226 | /* USB Device handle structure */ |
||
227 | typedef struct |
||
228 | { |
||
229 | uint32_t status; |
||
230 | uint32_t is_used; |
||
231 | uint32_t total_length; |
||
232 | uint32_t rem_length; |
||
233 | uint32_t maxpacket; |
||
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; |
||
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; |
||
248 | uint8_t dev_state; |
||
249 | uint8_t dev_old_state; |
||
250 | uint8_t dev_address; |
||
251 | uint8_t dev_connection_status; |
||
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; |
||
258 | void *pClassData; |
||
259 | void *pUserData; |
||
260 | void *pData; |
||
261 | } USBD_HandleTypeDef; |
||
262 | |||
263 | /** |
||
264 | * @} |
||
265 | */ |
||
266 | |||
267 | |||
268 | |||
269 | /** @defgroup USBD_DEF_Exported_Macros |
||
270 | * @{ |
||
271 | */ |
||
272 | #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \ |
||
273 | (((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U)) |
||
274 | |||
275 | #define LOBYTE(x) ((uint8_t)((x) & 0x00FFU)) |
||
276 | #define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U)) |
||
277 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
||
278 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
||
279 | |||
280 | |||
281 | #if defined ( __GNUC__ ) |
||
282 | #ifndef __weak |
||
283 | #define __weak __attribute__((weak)) |
||
284 | #endif /* __weak */ |
||
285 | #ifndef __packed |
||
286 | #define __packed __attribute__((__packed__)) |
||
287 | #endif /* __packed */ |
||
288 | #endif /* __GNUC__ */ |
||
289 | |||
290 | |||
291 | /* In HS mode and when the DMA is used, all variables and data structures dealing |
||
292 | with the DMA during the transaction process should be 4-bytes aligned */ |
||
293 | |||
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__ */ |
||
313 | |||
314 | |||
315 | /** |
||
316 | * @} |
||
317 | */ |
||
318 | |||
319 | /** @defgroup USBD_DEF_Exported_Variables |
||
320 | * @{ |
||
321 | */ |
||
322 | |||
323 | /** |
||
324 | * @} |
||
325 | */ |
||
326 | |||
327 | /** @defgroup USBD_DEF_Exported_FunctionsPrototype |
||
328 | * @{ |
||
329 | */ |
||
330 | |||
331 | /** |
||
332 | * @} |
||
333 | */ |
||
334 | |||
335 | #ifdef __cplusplus |
||
336 | } |
||
337 | #endif |
||
338 | |||
339 | #endif /* __USBD_DEF_H */ |
||
340 | |||
341 | /** |
||
342 | * @} |
||
343 | */ |
||
344 | |||
345 | /** |
||
346 | * @} |
||
347 | */ |
||
348 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |