STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
usbd_def.h
Go to the documentation of this file.
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 * Copyright (c) 2015 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18
19/* Define to prevent recursive inclusion -------------------------------------*/
20#ifndef __USBD_DEF_H
21#define __USBD_DEF_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/* Includes ------------------------------------------------------------------*/
28#include "usbd_conf.h"
29
30/** @addtogroup STM32_USBD_DEVICE_LIBRARY
31 * @{
32 */
33
34/** @defgroup USB_DEF
35 * @brief general defines for the usb device library file
36 * @{
37 */
38
39/** @defgroup USB_DEF_Exported_Defines
40 * @{
41 */
42
43#ifndef NULL
44#define NULL 0U
45#endif /* NULL */
46
47#ifndef USBD_MAX_NUM_INTERFACES
48#define USBD_MAX_NUM_INTERFACES 1U
49#endif /* USBD_MAX_NUM_CONFIGURATION */
50
51#ifndef USBD_MAX_NUM_CONFIGURATION
52#define USBD_MAX_NUM_CONFIGURATION 1U
53#endif /* USBD_MAX_NUM_CONFIGURATION */
54
55#ifdef USE_USBD_COMPOSITE
56#ifndef USBD_MAX_SUPPORTED_CLASS
57#define USBD_MAX_SUPPORTED_CLASS 4U
58#endif /* USBD_MAX_SUPPORTED_CLASS */
59#else
60#ifndef USBD_MAX_SUPPORTED_CLASS
61#define USBD_MAX_SUPPORTED_CLASS 1U
62#endif /* USBD_MAX_SUPPORTED_CLASS */
63#endif /* USE_USBD_COMPOSITE */
64
65#ifndef USBD_MAX_CLASS_ENDPOINTS
66#define USBD_MAX_CLASS_ENDPOINTS 5U
67#endif /* USBD_MAX_CLASS_ENDPOINTS */
68
69#ifndef USBD_MAX_CLASS_INTERFACES
70#define USBD_MAX_CLASS_INTERFACES 5U
71#endif /* USBD_MAX_CLASS_INTERFACES */
72
73#ifndef USBD_LPM_ENABLED
74#define USBD_LPM_ENABLED 0U
75#endif /* USBD_LPM_ENABLED */
76
77#ifndef USBD_SELF_POWERED
78#define USBD_SELF_POWERED 1U
79#endif /*USBD_SELF_POWERED */
80
81#ifndef USBD_MAX_POWER
82#define USBD_MAX_POWER 0x32U /* 100 mA */
83#endif /* USBD_MAX_POWER */
84
85#ifndef USBD_SUPPORT_USER_STRING_DESC
86#define USBD_SUPPORT_USER_STRING_DESC 0U
87#endif /* USBD_SUPPORT_USER_STRING_DESC */
88
89#ifndef USBD_CLASS_USER_STRING_DESC
90#define USBD_CLASS_USER_STRING_DESC 0U
91#endif /* USBD_CLASS_USER_STRING_DESC */
92
93#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU
94#define USB_LEN_DEV_DESC 0x12U
95#define USB_LEN_CFG_DESC 0x09U
96#define USB_LEN_IF_DESC 0x09U
97#define USB_LEN_EP_DESC 0x07U
98#define USB_LEN_OTG_DESC 0x03U
99#define USB_LEN_LANGID_STR_DESC 0x04U
100#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U
101
102#define USBD_IDX_LANGID_STR 0x00U
103#define USBD_IDX_MFC_STR 0x01U
104#define USBD_IDX_PRODUCT_STR 0x02U
105#define USBD_IDX_SERIAL_STR 0x03U
106#define USBD_IDX_CONFIG_STR 0x04U
107#define USBD_IDX_INTERFACE_STR 0x05U
108
109#define USB_REQ_TYPE_STANDARD 0x00U
110#define USB_REQ_TYPE_CLASS 0x20U
111#define USB_REQ_TYPE_VENDOR 0x40U
112#define USB_REQ_TYPE_MASK 0x60U
113
114#define USB_REQ_RECIPIENT_DEVICE 0x00U
115#define USB_REQ_RECIPIENT_INTERFACE 0x01U
116#define USB_REQ_RECIPIENT_ENDPOINT 0x02U
117#define USB_REQ_RECIPIENT_MASK 0x03U
118
119#define USB_REQ_GET_STATUS 0x00U
120#define USB_REQ_CLEAR_FEATURE 0x01U
121#define USB_REQ_SET_FEATURE 0x03U
122#define USB_REQ_SET_ADDRESS 0x05U
123#define USB_REQ_GET_DESCRIPTOR 0x06U
124#define USB_REQ_SET_DESCRIPTOR 0x07U
125#define USB_REQ_GET_CONFIGURATION 0x08U
126#define USB_REQ_SET_CONFIGURATION 0x09U
127#define USB_REQ_GET_INTERFACE 0x0AU
128#define USB_REQ_SET_INTERFACE 0x0BU
129#define USB_REQ_SYNCH_FRAME 0x0CU
130
131#define USB_DESC_TYPE_DEVICE 0x01U
132#define USB_DESC_TYPE_CONFIGURATION 0x02U
133#define USB_DESC_TYPE_STRING 0x03U
134#define USB_DESC_TYPE_INTERFACE 0x04U
135#define USB_DESC_TYPE_ENDPOINT 0x05U
136#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U
137#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U
138#define USB_DESC_TYPE_IAD 0x0BU
139#define USB_DESC_TYPE_BOS 0x0FU
140
141#define USB_CONFIG_REMOTE_WAKEUP 0x02U
142#define USB_CONFIG_SELF_POWERED 0x01U
143
144#define USB_FEATURE_EP_HALT 0x00U
145#define USB_FEATURE_REMOTE_WAKEUP 0x01U
146#define USB_FEATURE_TEST_MODE 0x02U
147
148#define USB_DEVICE_CAPABITY_TYPE 0x10U
149
150#define USB_CONF_DESC_SIZE 0x09U
151#define USB_IF_DESC_SIZE 0x09U
152#define USB_EP_DESC_SIZE 0x07U
153#define USB_IAD_DESC_SIZE 0x08U
154
155#define USB_HS_MAX_PACKET_SIZE 512U
156#define USB_FS_MAX_PACKET_SIZE 64U
157#define USB_MAX_EP0_SIZE 64U
158
159/* Device Status */
160#define USBD_STATE_DEFAULT 0x01U
161#define USBD_STATE_ADDRESSED 0x02U
162#define USBD_STATE_CONFIGURED 0x03U
163#define USBD_STATE_SUSPENDED 0x04U
164
165
166/* EP0 State */
167#define USBD_EP0_IDLE 0x00U
168#define USBD_EP0_SETUP 0x01U
169#define USBD_EP0_DATA_IN 0x02U
170#define USBD_EP0_DATA_OUT 0x03U
171#define USBD_EP0_STATUS_IN 0x04U
172#define USBD_EP0_STATUS_OUT 0x05U
173#define USBD_EP0_STALL 0x06U
174
175#define USBD_EP_TYPE_CTRL 0x00U
176#define USBD_EP_TYPE_ISOC 0x01U
177#define USBD_EP_TYPE_BULK 0x02U
178#define USBD_EP_TYPE_INTR 0x03U
179
180#ifdef USE_USBD_COMPOSITE
181#define USBD_EP_IN 0x80U
182#define USBD_EP_OUT 0x00U
183#define USBD_FUNC_DESCRIPTOR_TYPE 0x24U
184#define USBD_DESC_SUBTYPE_ACM 0x0FU
185#define USBD_DESC_ECM_BCD_LOW 0x00U
186#define USBD_DESC_ECM_BCD_HIGH 0x10U
187#endif /* USE_USBD_COMPOSITE */
188/**
189 * @}
190 */
191
192
193/** @defgroup USBD_DEF_Exported_TypesDefinitions
194 * @{
195 */
196
197typedef struct usb_setup_req
198{
199 uint8_t bmRequest;
200 uint8_t bRequest;
201 uint16_t wValue;
202 uint16_t wIndex;
203 uint16_t wLength;
205
206typedef struct
207{
208 uint8_t bLength;
210 uint16_t wTotalLength;
215 uint8_t bMaxPower;
216} __PACKED USBD_ConfigDescTypeDef;
217
218typedef struct
219{
220 uint8_t bLength;
222 uint16_t wTotalLength;
225
226typedef struct
227{
228 uint8_t bLength;
229 uint8_t bDescriptorType;
231 uint8_t bmAttributes;
233 uint8_t bInterval;
234} __PACKED USBD_EpDescTypeDef;
235
236typedef struct
237{
238 uint8_t bLength;
242
244
245typedef struct _Device_cb
246{
247 uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
248 uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
249 /* Control Endpoints*/
250 uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
251 uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev);
252 uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev);
253 /* Class Specific Endpoints*/
254 uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
255 uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
256 uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev);
257 uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
258 uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
259
260 uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
261 uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
262 uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
263 uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
264#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
265 uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
266#endif /* USBD_SUPPORT_USER_STRING_DESC */
267
269
270/* Following USB Device Speed */
277
278/* Following USB Device status */
286
287/* USB Device descriptors structure */
288typedef struct
289{
290 uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
291 uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
292 uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
293 uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
294 uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
295 uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
296 uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
297#if (USBD_CLASS_USER_STRING_DESC == 1)
298 uint8_t *(*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
299#endif /* USBD_CLASS_USER_STRING_DESC */
300#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1))
301 uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
302#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1) */
304
305/* USB Device handle structure */
306typedef struct
307{
308 uint32_t total_length;
309 uint32_t rem_length;
310 uint32_t bInterval;
311 uint16_t maxpacket;
312 uint8_t status;
313 uint8_t is_used;
314 uint8_t *pbuffer;
316
317#ifdef USE_USBD_COMPOSITE
318typedef enum
319{
320 CLASS_TYPE_NONE = 0,
321 CLASS_TYPE_HID = 1,
322 CLASS_TYPE_CDC = 2,
323 CLASS_TYPE_MSC = 3,
324 CLASS_TYPE_DFU = 4,
325 CLASS_TYPE_CHID = 5,
326 CLASS_TYPE_AUDIO = 6,
327 CLASS_TYPE_ECM = 7,
328 CLASS_TYPE_RNDIS = 8,
329 CLASS_TYPE_MTP = 9,
330 CLASS_TYPE_VIDEO = 10,
331 CLASS_TYPE_PRINTER = 11,
332 CLASS_TYPE_CCID = 12,
333} USBD_CompositeClassTypeDef;
334
335
336/* USB Device handle structure */
337typedef struct
338{
339 uint8_t add;
340 uint8_t type;
341 uint8_t size;
342 uint8_t is_used;
343} USBD_EPTypeDef;
344
345/* USB Device handle structure */
346typedef struct
347{
348 USBD_CompositeClassTypeDef ClassType;
349 uint32_t ClassId;
350 uint32_t Active;
351 uint32_t NumEps;
352 USBD_EPTypeDef Eps[USBD_MAX_CLASS_ENDPOINTS];
353 uint8_t *EpAdd;
354 uint32_t NumIf;
355 uint8_t Ifs[USBD_MAX_CLASS_INTERFACES];
356 uint32_t CurrPcktSze;
357} USBD_CompositeElementTypeDef;
358#endif /* USE_USBD_COMPOSITE */
359
360/* USB Device handle structure */
362{
363 uint8_t id;
364 uint32_t dev_config;
370 __IO uint32_t ep0_state;
371 uint32_t ep0_data_len;
374 uint8_t dev_address;
378 uint8_t ConfIdx;
379
386 void *pData;
387 void *pBosDesc;
389 uint32_t classId;
390 uint32_t NumClasses;
391#ifdef USE_USBD_COMPOSITE
392 USBD_CompositeElementTypeDef tclasslist[USBD_MAX_SUPPORTED_CLASS];
393#endif /* USE_USBD_COMPOSITE */
394#if (USBD_USER_REGISTER_CALLBACK == 1U)
395 void (* DevStateCallback)(uint8_t dev_state, uint8_t cfgidx); /*!< User Notification callback */
396#endif /* USBD_USER_REGISTER_CALLBACK */
398
399#if (USBD_USER_REGISTER_CALLBACK == 1U)
400typedef void (*USBD_DevStateCallbackTypeDef)(uint8_t dev_state, uint8_t cfgidx); /*!< pointer to User callback function */
401#endif /* USBD_USER_REGISTER_CALLBACK */
402
403/* USB Device endpoint direction */
404typedef enum
405{
406 OUT = 0x00,
407 IN = 0x80,
409
416/**
417 * @}
418 */
419
420
421
422/** @defgroup USBD_DEF_Exported_Macros
423 * @{
424 */
425__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
426{
427 uint16_t _SwapVal;
428 uint16_t _Byte1;
429 uint16_t _Byte2;
430 uint8_t *_pbuff = addr;
431
432 _Byte1 = *(uint8_t *)_pbuff;
433 _pbuff++;
434 _Byte2 = *(uint8_t *)_pbuff;
435
436 _SwapVal = (_Byte2 << 8) | _Byte1;
437
438 return _SwapVal;
439}
440
441#ifndef LOBYTE
442#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
443#endif /* LOBYTE */
444
445#ifndef HIBYTE
446#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
447#endif /* HIBYTE */
448
449#ifndef MIN
450#define MIN(a, b) (((a) < (b)) ? (a) : (b))
451#endif /* MIN */
452
453#ifndef MAX
454#define MAX(a, b) (((a) > (b)) ? (a) : (b))
455#endif /* MAX */
456
457#if defined ( __GNUC__ )
458#ifndef __weak
459#define __weak __attribute__((weak))
460#endif /* __weak */
461#ifndef __packed
462#define __packed __attribute__((__packed__))
463#endif /* __packed */
464#endif /* __GNUC__ */
465
466
467/* In HS mode and when the DMA is used, all variables and data structures dealing
468 with the DMA during the transaction process should be 4-bytes aligned */
469
470#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
471#ifndef __ALIGN_END
472#define __ALIGN_END __attribute__ ((aligned (4U)))
473#endif /* __ALIGN_END */
474#ifndef __ALIGN_BEGIN
475#define __ALIGN_BEGIN
476#endif /* __ALIGN_BEGIN */
477#else
478#ifndef __ALIGN_END
479#define __ALIGN_END
480#endif /* __ALIGN_END */
481#ifndef __ALIGN_BEGIN
482#if defined (__CC_ARM) /* ARM Compiler */
483#define __ALIGN_BEGIN __align(4U)
484#elif defined (__ICCARM__) /* IAR Compiler */
485#define __ALIGN_BEGIN
486#endif /* __CC_ARM */
487#endif /* __ALIGN_BEGIN */
488#endif /* __GNUC__ */
489
490
491/**
492 * @}
493 */
494
495/** @defgroup USBD_DEF_Exported_Variables
496 * @{
497 */
498
499/**
500 * @}
501 */
502
503/** @defgroup USBD_DEF_Exported_FunctionsPrototype
504 * @{
505 */
506
507/**
508 * @}
509 */
510
511#ifdef __cplusplus
512}
513#endif
514
515#endif /* __USBD_DEF_H */
516
517/**
518 * @}
519 */
520
521/**
522 * @}
523 */
524
#define __STATIC_INLINE
Definition cmsis_armcc.h:64
#define __PACKED
Definition cmsis_armcc.h:79
#define __IO
Defines 'read / write' permissions.
__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
Definition usbd_def.h:425
struct _USBD_HandleTypeDef USBD_HandleTypeDef
struct usb_setup_req USBD_SetupReqTypedef
USBD_CDC_NotifCodeTypeDef
Definition usbd_def.h:411
USBD_EPDirectionTypeDef
Definition usbd_def.h:405
USBD_SpeedTypeDef
Definition usbd_def.h:272
struct _Device_cb USBD_ClassTypeDef
USBD_StatusTypeDef
Definition usbd_def.h:280
@ CONNECTION_SPEED_CHANGE
Definition usbd_def.h:414
@ RESPONSE_AVAILABLE
Definition usbd_def.h:413
@ NETWORK_CONNECTION
Definition usbd_def.h:412
@ OUT
Definition usbd_def.h:406
@ IN
Definition usbd_def.h:407
@ USBD_SPEED_FULL
Definition usbd_def.h:274
@ USBD_SPEED_HIGH
Definition usbd_def.h:273
@ USBD_SPEED_LOW
Definition usbd_def.h:275
@ USBD_FAIL
Definition usbd_def.h:284
@ USBD_OK
Definition usbd_def.h:281
@ USBD_EMEM
Definition usbd_def.h:283
@ USBD_BUSY
Definition usbd_def.h:282
#define USBD_MAX_SUPPORTED_CLASS
Definition usbd_def.h:61
#define USBD_MAX_CLASS_ENDPOINTS
Definition usbd_def.h:66
#define USBD_MAX_CLASS_INTERFACES
Definition usbd_def.h:70
uint16_t wTotalLength
Definition usbd_def.h:222
uint8_t bDescriptorType
Definition usbd_def.h:221
uint8_t bNumDeviceCaps
Definition usbd_def.h:223
uint32_t total_length
Definition usbd_def.h:308
uint8_t(* IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum)
Definition usbd_def.h:257
uint8_t(* EP0_RxReady)(struct _USBD_HandleTypeDef *pdev)
Definition usbd_def.h:252
uint8_t(* DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum)
Definition usbd_def.h:254
uint8_t(* Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx)
Definition usbd_def.h:247
uint8_t(* IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum)
Definition usbd_def.h:258
uint8_t(* DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx)
Definition usbd_def.h:248
uint8_t(* Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
Definition usbd_def.h:250
uint8_t(* DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum)
Definition usbd_def.h:255
uint8_t(* EP0_TxSent)(struct _USBD_HandleTypeDef *pdev)
Definition usbd_def.h:251
uint8_t(* SOF)(struct _USBD_HandleTypeDef *pdev)
Definition usbd_def.h:256
uint32_t dev_default_config
Definition usbd_def.h:365
uint32_t dev_config_status
Definition usbd_def.h:366
__IO uint8_t dev_old_state
Definition usbd_def.h:373
USBD_EndpointTypeDef ep_in[16]
Definition usbd_def.h:368
USBD_EndpointTypeDef ep_out[16]
Definition usbd_def.h:369
uint32_t dev_remote_wakeup
Definition usbd_def.h:377
uint32_t dev_config
Definition usbd_def.h:364
USBD_DescriptorsTypeDef * pDesc
Definition usbd_def.h:381
void * pClassDataCmsit[USBD_MAX_SUPPORTED_CLASS]
Definition usbd_def.h:384
uint32_t NumClasses
Definition usbd_def.h:390
uint8_t dev_test_mode
Definition usbd_def.h:376
__IO uint32_t ep0_state
Definition usbd_def.h:370
uint8_t dev_connection_status
Definition usbd_def.h:375
USBD_SpeedTypeDef dev_speed
Definition usbd_def.h:367
USBD_ClassTypeDef * pClass[USBD_MAX_SUPPORTED_CLASS]
Definition usbd_def.h:382
USBD_SetupReqTypedef request
Definition usbd_def.h:380
__IO uint8_t dev_state
Definition usbd_def.h:372
uint32_t ep0_data_len
Definition usbd_def.h:371
void * pUserData[USBD_MAX_SUPPORTED_CLASS]
Definition usbd_def.h:385
uint8_t bLength
Definition usbd_def.h:208
uint8_t iConfiguration
Definition usbd_def.h:213
uint8_t bMaxPower
Definition usbd_def.h:215
uint8_t bDescriptorType
Definition usbd_def.h:209
uint8_t bEndpointAddress
Definition usbd_def.h:230
uint8_t bConfigurationValue
Definition usbd_def.h:212
uint8_t bmAttributes
Definition usbd_def.h:214
uint8_t bInterval
Definition usbd_def.h:233
uint16_t wTotalLength
Definition usbd_def.h:210
uint16_t wMaxPacketSize
Definition usbd_def.h:232
uint8_t bNumInterfaces
Definition usbd_def.h:211
uint8_t bRequest
Definition usbd_def.h:200
uint16_t wIndex
Definition usbd_def.h:202
uint16_t wValue
Definition usbd_def.h:201
uint8_t bmRequest
Definition usbd_def.h:199
uint16_t wLength
Definition usbd_def.h:203
: Header for usbd_conf.c file.