Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ton_demo ton_template
usbd_def.h
00001 /** 00002 ****************************************************************************** 00003 * @file usbd_def.h 00004 * @author MCD Application Team 00005 * @version V2.3.0 00006 * @date 04-November-2014 00007 * @brief General defines for the usb device library 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00012 * 00013 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00014 * You may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at: 00016 * 00017 * http://www.st.com/software_license_agreement_liberty_v2 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 * 00025 ****************************************************************************** 00026 */ 00027 00028 /* Define to prevent recursive inclusion -------------------------------------*/ 00029 #ifndef __USBD_DEF_H 00030 #define __USBD_DEF_H 00031 00032 #ifdef __cplusplus 00033 extern "C" { 00034 #endif 00035 00036 /* Includes ------------------------------------------------------------------*/ 00037 #include "usbd_conf.h" 00038 00039 /** @addtogroup STM32_USBD_DEVICE_LIBRARY 00040 * @{ 00041 */ 00042 00043 /** @defgroup USB_DEF 00044 * @brief general defines for the usb device library file 00045 * @{ 00046 */ 00047 00048 /** @defgroup USB_DEF_Exported_Defines 00049 * @{ 00050 */ 00051 00052 #ifndef NULL 00053 #define NULL 0 00054 #endif 00055 00056 00057 #define USB_LEN_DEV_QUALIFIER_DESC 0x0A 00058 #define USB_LEN_DEV_DESC 0x12 00059 #define USB_LEN_CFG_DESC 0x09 00060 #define USB_LEN_IF_DESC 0x09 00061 #define USB_LEN_EP_DESC 0x07 00062 #define USB_LEN_OTG_DESC 0x03 00063 #define USB_LEN_LANGID_STR_DESC 0x04 00064 #define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09 00065 00066 #define USBD_IDX_LANGID_STR 0x00 00067 #define USBD_IDX_MFC_STR 0x01 00068 #define USBD_IDX_PRODUCT_STR 0x02 00069 #define USBD_IDX_SERIAL_STR 0x03 00070 #define USBD_IDX_CONFIG_STR 0x04 00071 #define USBD_IDX_INTERFACE_STR 0x05 00072 00073 #define USB_REQ_TYPE_STANDARD 0x00 00074 #define USB_REQ_TYPE_CLASS 0x20 00075 #define USB_REQ_TYPE_VENDOR 0x40 00076 #define USB_REQ_TYPE_MASK 0x60 00077 00078 #define USB_REQ_RECIPIENT_DEVICE 0x00 00079 #define USB_REQ_RECIPIENT_INTERFACE 0x01 00080 #define USB_REQ_RECIPIENT_ENDPOINT 0x02 00081 #define USB_REQ_RECIPIENT_MASK 0x03 00082 00083 #define USB_REQ_GET_STATUS 0x00 00084 #define USB_REQ_CLEAR_FEATURE 0x01 00085 #define USB_REQ_SET_FEATURE 0x03 00086 #define USB_REQ_SET_ADDRESS 0x05 00087 #define USB_REQ_GET_DESCRIPTOR 0x06 00088 #define USB_REQ_SET_DESCRIPTOR 0x07 00089 #define USB_REQ_GET_CONFIGURATION 0x08 00090 #define USB_REQ_SET_CONFIGURATION 0x09 00091 #define USB_REQ_GET_INTERFACE 0x0A 00092 #define USB_REQ_SET_INTERFACE 0x0B 00093 #define USB_REQ_SYNCH_FRAME 0x0C 00094 00095 #define USB_DESC_TYPE_DEVICE 1 00096 #define USB_DESC_TYPE_CONFIGURATION 2 00097 #define USB_DESC_TYPE_STRING 3 00098 #define USB_DESC_TYPE_INTERFACE 4 00099 #define USB_DESC_TYPE_ENDPOINT 5 00100 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6 00101 #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7 00102 00103 00104 #define USB_CONFIG_REMOTE_WAKEUP 2 00105 #define USB_CONFIG_SELF_POWERED 1 00106 00107 #define USB_FEATURE_EP_HALT 0 00108 #define USB_FEATURE_REMOTE_WAKEUP 1 00109 #define USB_FEATURE_TEST_MODE 2 00110 00111 00112 #define USB_HS_MAX_PACKET_SIZE 512 00113 #define USB_FS_MAX_PACKET_SIZE 64 00114 #define USB_MAX_EP0_SIZE 64 00115 00116 /* Device Status */ 00117 #define USBD_STATE_DEFAULT 1 00118 #define USBD_STATE_ADDRESSED 2 00119 #define USBD_STATE_CONFIGURED 3 00120 #define USBD_STATE_SUSPENDED 4 00121 00122 00123 /* EP0 State */ 00124 #define USBD_EP0_IDLE 0 00125 #define USBD_EP0_SETUP 1 00126 #define USBD_EP0_DATA_IN 2 00127 #define USBD_EP0_DATA_OUT 3 00128 #define USBD_EP0_STATUS_IN 4 00129 #define USBD_EP0_STATUS_OUT 5 00130 #define USBD_EP0_STALL 6 00131 00132 #define USBD_EP_TYPE_CTRL 0 00133 #define USBD_EP_TYPE_ISOC 1 00134 #define USBD_EP_TYPE_BULK 2 00135 #define USBD_EP_TYPE_INTR 3 00136 00137 00138 /** 00139 * @} 00140 */ 00141 00142 00143 /** @defgroup USBD_DEF_Exported_TypesDefinitions 00144 * @{ 00145 */ 00146 00147 typedef struct usb_setup_req 00148 { 00149 00150 uint8_t bmRequest; 00151 uint8_t bRequest; 00152 uint16_t wValue; 00153 uint16_t wIndex; 00154 uint16_t wLength; 00155 }USBD_SetupReqTypedef; 00156 00157 struct _USBD_HandleTypeDef; 00158 00159 typedef struct _Device_cb 00160 { 00161 uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); 00162 uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx); 00163 /* Control Endpoints*/ 00164 uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req); 00165 uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev ); 00166 uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev ); 00167 /* Class Specific Endpoints*/ 00168 uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); 00169 uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); 00170 uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev); 00171 uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); 00172 uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum); 00173 00174 uint8_t *(*GetHSConfigDescriptor)(uint16_t *length); 00175 uint8_t *(*GetFSConfigDescriptor)(uint16_t *length); 00176 uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length); 00177 uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length); 00178 #if (USBD_SUPPORT_USER_STRING == 1) 00179 uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length); 00180 #endif 00181 00182 } USBD_ClassTypeDef; 00183 00184 /* Following USB Device Speed */ 00185 typedef enum 00186 { 00187 USBD_SPEED_HIGH = 0, 00188 USBD_SPEED_FULL = 1, 00189 USBD_SPEED_LOW = 2, 00190 }USBD_SpeedTypeDef; 00191 00192 /* Following USB Device status */ 00193 typedef enum { 00194 USBD_OK = 0, 00195 USBD_BUSY, 00196 USBD_FAIL, 00197 }USBD_StatusTypeDef; 00198 00199 /* USB Device descriptors structure */ 00200 typedef struct 00201 { 00202 uint8_t *(*GetDeviceDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 00203 uint8_t *(*GetLangIDStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 00204 uint8_t *(*GetManufacturerStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 00205 uint8_t *(*GetProductStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 00206 uint8_t *(*GetSerialStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 00207 uint8_t *(*GetConfigurationStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 00208 uint8_t *(*GetInterfaceStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); 00209 } USBD_DescriptorsTypeDef; 00210 00211 /* USB Device handle structure */ 00212 typedef struct 00213 { 00214 uint32_t status; 00215 uint32_t total_length; 00216 uint32_t rem_length; 00217 uint32_t maxpacket; 00218 } USBD_EndpointTypeDef; 00219 00220 /* USB Device handle structure */ 00221 typedef struct _USBD_HandleTypeDef 00222 { 00223 uint8_t id; 00224 uint32_t dev_config; 00225 uint32_t dev_default_config; 00226 uint32_t dev_config_status; 00227 USBD_SpeedTypeDef dev_speed; 00228 USBD_EndpointTypeDef ep_in[15]; 00229 USBD_EndpointTypeDef ep_out[15]; 00230 uint32_t ep0_state; 00231 uint32_t ep0_data_len; 00232 uint8_t dev_state; 00233 uint8_t dev_old_state; 00234 uint8_t dev_address; 00235 uint8_t dev_connection_status; 00236 uint8_t dev_test_mode; 00237 uint32_t dev_remote_wakeup; 00238 00239 USBD_SetupReqTypedef request; 00240 USBD_DescriptorsTypeDef *pDesc; 00241 USBD_ClassTypeDef *pClass; 00242 void *pClassData; 00243 void *pUserData; 00244 void *pData; 00245 } USBD_HandleTypeDef; 00246 00247 /** 00248 * @} 00249 */ 00250 00251 00252 00253 /** @defgroup USBD_DEF_Exported_Macros 00254 * @{ 00255 */ 00256 #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \ 00257 (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) 00258 00259 #define LOBYTE(x) ((uint8_t)(x & 0x00FF)) 00260 #define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8)) 00261 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 00262 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 00263 00264 00265 #if defined ( __GNUC__ ) 00266 #ifndef __weak 00267 #define __weak __attribute__((weak)) 00268 #endif /* __weak */ 00269 #ifndef __packed 00270 #define __packed __attribute__((__packed__)) 00271 #endif /* __packed */ 00272 #endif /* __GNUC__ */ 00273 00274 00275 /* In HS mode and when the DMA is used, all variables and data structures dealing 00276 with the DMA during the transaction process should be 4-bytes aligned */ 00277 00278 #if defined (__GNUC__) /* GNU Compiler */ 00279 #define __ALIGN_END __attribute__ ((aligned (4))) 00280 #define __ALIGN_BEGIN 00281 #else 00282 #define __ALIGN_END 00283 #if defined (__CC_ARM) /* ARM Compiler */ 00284 #define __ALIGN_BEGIN __align(4) 00285 #elif defined (__ICCARM__) /* IAR Compiler */ 00286 #define __ALIGN_BEGIN 00287 #elif defined (__TASKING__) /* TASKING Compiler */ 00288 #define __ALIGN_BEGIN __align(4) 00289 #endif /* __CC_ARM */ 00290 #endif /* __GNUC__ */ 00291 00292 00293 /** 00294 * @} 00295 */ 00296 00297 /** @defgroup USBD_DEF_Exported_Variables 00298 * @{ 00299 */ 00300 00301 /** 00302 * @} 00303 */ 00304 00305 /** @defgroup USBD_DEF_Exported_FunctionsPrototype 00306 * @{ 00307 */ 00308 00309 /** 00310 * @} 00311 */ 00312 00313 #ifdef __cplusplus 00314 } 00315 #endif 00316 00317 #endif /* __USBD_DEF_H */ 00318 00319 /** 00320 * @} 00321 */ 00322 00323 /** 00324 * @} 00325 */ 00326 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 20:52:33 by
1.7.2