Prusa MINI Firmware overview
usbd_def.h
Go to the documentation of this file.
1 /**
2  ******************************************************************************
3  * @file usbd_def.h
4  * @author MCD Application Team
5  * @version V2.4.2
6  * @date 11-December-2015
7  * @brief General defines for the usb device library
8  ******************************************************************************
9  * @attention
10  *
11  * <h2><center>&copy; 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 
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*/
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);
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 {
228  uint32_t dev_config;
234  uint32_t ep0_state;
235  uint32_t ep0_data_len;
242 
246  void *pClassData;
247  void *pUserData;
248  void *pData;
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****/
USBD_SPEED_FULL
Definition: usbd_def.h:189
_Device_cb::DeInit
uint8_t(* DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx)
Definition: usbd_def.h:163
_USBD_HandleTypeDef::dev_old_state
uint8_t dev_old_state
Definition: usbd_def.h:237
_Device_cb::SOF
uint8_t(* SOF)(struct _USBD_HandleTypeDef *pdev)
Definition: usbd_def.h:171
USBD_EndpointTypeDef::status
uint32_t status
Definition: usbd_def.h:218
USBD_DescriptorsTypeDef
Definition: usbd_def.h:201
usb_setup_req::wLength
uint16_t wLength
Definition: usbd_def.h:155
_USBD_HandleTypeDef::request
USBD_SetupReqTypedef request
Definition: usbd_def.h:243
_Device_cb::Setup
uint8_t(* Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
Definition: usbd_def.h:165
_USBD_HandleTypeDef::pClass
USBD_ClassTypeDef * pClass
Definition: usbd_def.h:245
USBD_SPEED_LOW
Definition: usbd_def.h:190
USBD_FAIL
Definition: usbd_def.h:197
_Device_cb::DataOut
uint8_t(* DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum)
Definition: usbd_def.h:170
_USBD_HandleTypeDef::dev_state
uint8_t dev_state
Definition: usbd_def.h:236
_USBD_HandleTypeDef::ep0_state
uint32_t ep0_state
Definition: usbd_def.h:234
_USBD_HandleTypeDef::ep_in
USBD_EndpointTypeDef ep_in[15]
Definition: usbd_def.h:232
_USBD_HandleTypeDef::pDesc
USBD_DescriptorsTypeDef * pDesc
Definition: usbd_def.h:244
usb_setup_req::bmRequest
uint8_t bmRequest
Definition: usbd_def.h:151
_USBD_HandleTypeDef::ep0_data_len
uint32_t ep0_data_len
Definition: usbd_def.h:235
_USBD_HandleTypeDef::pClassData
void * pClassData
Definition: usbd_def.h:246
_USBD_HandleTypeDef::dev_config
uint32_t dev_config
Definition: usbd_def.h:228
_Device_cb::IsoINIncomplete
uint8_t(* IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum)
Definition: usbd_def.h:172
_USBD_HandleTypeDef
Definition: usbd_def.h:225
_USBD_HandleTypeDef::pData
void * pData
Definition: usbd_def.h:248
USBD_EndpointTypeDef
Definition: usbd_def.h:216
_USBD_HandleTypeDef::dev_remote_wakeup
uint32_t dev_remote_wakeup
Definition: usbd_def.h:241
_USBD_HandleTypeDef::dev_config_status
uint32_t dev_config_status
Definition: usbd_def.h:230
_Device_cb
Definition: usbd_def.h:160
_Device_cb::EP0_RxReady
uint8_t(* EP0_RxReady)(struct _USBD_HandleTypeDef *pdev)
Definition: usbd_def.h:167
USBD_EndpointTypeDef::rem_length
uint32_t rem_length
Definition: usbd_def.h:220
_Device_cb::DataIn
uint8_t(* DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum)
Definition: usbd_def.h:169
usb_setup_req::wIndex
uint16_t wIndex
Definition: usbd_def.h:154
_Device_cb::Init
uint8_t(* Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx)
Definition: usbd_def.h:162
USBD_BUSY
Definition: usbd_def.h:196
USBD_SPEED_HIGH
Definition: usbd_def.h:188
_USBD_HandleTypeDef::id
uint8_t id
Definition: usbd_def.h:227
uint8_t
const uint8_t[]
Definition: 404_html.c:3
usb_setup_req
Definition: usbd_def.h:148
_USBD_HandleTypeDef::dev_speed
USBD_SpeedTypeDef dev_speed
Definition: usbd_def.h:231
USBD_ClassTypeDef
struct _Device_cb USBD_ClassTypeDef
usb_setup_req::wValue
uint16_t wValue
Definition: usbd_def.h:153
_USBD_HandleTypeDef::ep_out
USBD_EndpointTypeDef ep_out[15]
Definition: usbd_def.h:233
_USBD_HandleTypeDef::dev_test_mode
uint8_t dev_test_mode
Definition: usbd_def.h:240
USBD_SetupReqTypedef
struct usb_setup_req USBD_SetupReqTypedef
USBD_StatusTypeDef
USBD_StatusTypeDef
Definition: usbd_def.h:194
usb_setup_req::bRequest
uint8_t bRequest
Definition: usbd_def.h:152
USBD_HandleTypeDef
struct _USBD_HandleTypeDef USBD_HandleTypeDef
_USBD_HandleTypeDef::dev_connection_status
uint8_t dev_connection_status
Definition: usbd_def.h:239
_Device_cb::IsoOUTIncomplete
uint8_t(* IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum)
Definition: usbd_def.h:173
_USBD_HandleTypeDef::pUserData
void * pUserData
Definition: usbd_def.h:247
USBD_SpeedTypeDef
USBD_SpeedTypeDef
Definition: usbd_def.h:186
length
png_uint_32 length
Definition: png.c:2247
_USBD_HandleTypeDef::dev_address
uint8_t dev_address
Definition: usbd_def.h:238
_Device_cb::EP0_TxSent
uint8_t(* EP0_TxSent)(struct _USBD_HandleTypeDef *pdev)
Definition: usbd_def.h:166
_USBD_HandleTypeDef::dev_default_config
uint32_t dev_default_config
Definition: usbd_def.h:229
usbd_conf.h
: Header for usbd_conf.c file.
USBD_OK
Definition: usbd_def.h:195
USBD_EndpointTypeDef::maxpacket
uint32_t maxpacket
Definition: usbd_def.h:221
USBD_EndpointTypeDef::total_length
uint32_t total_length
Definition: usbd_def.h:219