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 | * @version V2.4.1 |
||
6 | * @date 19-June-2015 |
||
7 | * @brief General defines for the usb device library |
||
8 | ****************************************************************************** |
||
9 | * @attention |
||
10 | * |
||
11 | * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> |
||
12 | * |
||
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
||
14 | * You may not use this file except in compliance with the License. |
||
15 | * You may obtain a copy of the License at: |
||
16 | * |
||
17 | * http://www.st.com/software_license_agreement_liberty_v2 |
||
18 | * |
||
19 | * Unless required by applicable law or agreed to in writing, software |
||
20 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
22 | * See the License for the specific language governing permissions and |
||
23 | * limitations under the License. |
||
24 | * |
||
25 | ****************************************************************************** |
||
26 | */ |
||
27 | |||
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 | |||
39 | /** @addtogroup STM32_USBD_DEVICE_LIBRARY |
||
40 | * @{ |
||
41 | */ |
||
42 | |||
43 | /** @defgroup USB_DEF |
||
44 | * @brief general defines for the usb device library file |
||
45 | * @{ |
||
46 | */ |
||
47 | |||
48 | /** @defgroup USB_DEF_Exported_Defines |
||
49 | * @{ |
||
50 | */ |
||
51 | |||
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 | |||
139 | /** |
||
140 | * @} |
||
141 | */ |
||
142 | |||
143 | |||
144 | /** @defgroup USBD_DEF_Exported_TypesDefinitions |
||
145 | * @{ |
||
146 | */ |
||
147 | |||
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; |
||
156 | }USBD_SetupReqTypedef; |
||
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 | |||
183 | } USBD_ClassTypeDef; |
||
184 | |||
185 | /* Following USB Device Speed */ |
||
186 | typedef enum |
||
187 | { |
||
188 | USBD_SPEED_HIGH = 0, |
||
189 | USBD_SPEED_FULL = 1, |
||
190 | USBD_SPEED_LOW = 2, |
||
191 | }USBD_SpeedTypeDef; |
||
192 | |||
193 | /* Following USB Device status */ |
||
194 | typedef enum { |
||
195 | USBD_OK = 0, |
||
196 | USBD_BUSY, |
||
197 | USBD_FAIL, |
||
198 | }USBD_StatusTypeDef; |
||
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 |
||
213 | } USBD_DescriptorsTypeDef; |
||
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; |
||
222 | } USBD_EndpointTypeDef; |
||
223 | |||
224 | /* USB Device handle structure */ |
||
225 | typedef struct _USBD_HandleTypeDef |
||
226 | { |
||
227 | uint8_t id; |
||
228 | uint32_t dev_config; |
||
229 | uint32_t dev_default_config; |
||
230 | uint32_t dev_config_status; |
||
231 | USBD_SpeedTypeDef dev_speed; |
||
232 | USBD_EndpointTypeDef ep_in[15]; |
||
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; |
||
239 | uint8_t dev_connection_status; |
||
240 | uint8_t dev_test_mode; |
||
241 | uint32_t dev_remote_wakeup; |
||
242 | |||
243 | USBD_SetupReqTypedef request; |
||
244 | USBD_DescriptorsTypeDef *pDesc; |
||
245 | USBD_ClassTypeDef *pClass; |
||
246 | void *pClassData; |
||
247 | void *pUserData; |
||
248 | void *pData; |
||
249 | } USBD_HandleTypeDef; |
||
250 | |||
251 | /** |
||
252 | * @} |
||
253 | */ |
||
254 | |||
255 | |||
256 | |||
257 | /** @defgroup USBD_DEF_Exported_Macros |
||
258 | * @{ |
||
259 | */ |
||
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 | |||
297 | /** |
||
298 | * @} |
||
299 | */ |
||
300 | |||
301 | /** @defgroup USBD_DEF_Exported_Variables |
||
302 | * @{ |
||
303 | */ |
||
304 | |||
305 | /** |
||
306 | * @} |
||
307 | */ |
||
308 | |||
309 | /** @defgroup USBD_DEF_Exported_FunctionsPrototype |
||
310 | * @{ |
||
311 | */ |
||
312 | |||
313 | /** |
||
314 | * @} |
||
315 | */ |
||
316 | |||
317 | #ifdef __cplusplus |
||
318 | } |
||
319 | #endif |
||
320 | |||
321 | #endif /* __USBD_DEF_H */ |
||
322 | |||
323 | /** |
||
324 | * @} |
||
325 | */ |
||
326 | |||
327 | /** |
||
328 | * @} |
||
329 | */ |
||
330 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |