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.
Dependencies: BSP_DISCO_F746NG_patch mbed-rtos mbed
usbh_def.h
00001 /** 00002 ****************************************************************************** 00003 * @file usbh_def.h 00004 * @author MCD Application Team 00005 * @version V3.2.2 00006 * @date 07-July-2015 00007 * @brief Definitions used in the USB host library 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT 2015 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 ----------------------------------------------*/ 00029 #ifndef USBH_DEF_H 00030 #define USBH_DEF_H 00031 00032 #ifdef __cplusplus 00033 extern "C" { 00034 #endif 00035 00036 /* Includes ------------------------------------------------------------------*/ 00037 #include "usbh_conf.h" 00038 00039 /** @addtogroup USBH_LIB 00040 * @{ 00041 */ 00042 00043 /** @addtogroup USBH_LIB_CORE 00044 * @{ 00045 */ 00046 00047 /** @defgroup USBH_DEF 00048 * @brief This file is includes USB descriptors 00049 * @{ 00050 */ 00051 00052 #ifndef NULL 00053 #define NULL 0 00054 #endif 00055 00056 #ifndef FALSE 00057 #define FALSE 0 00058 #endif 00059 00060 #ifndef TRUE 00061 #define TRUE 1 00062 #endif 00063 00064 00065 #define ValBit(VAR,POS) (VAR & (1 << POS)) 00066 #define SetBit(VAR,POS) (VAR |= (1 << POS)) 00067 #define ClrBit(VAR,POS) (VAR &= ((1 << POS)^255)) 00068 00069 #define LE16(addr) (((uint16_t)(*((uint8_t *)(addr))))\ 00070 + (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) 00071 00072 #define LE16S(addr) (uint16_t)(LE16((addr))) 00073 00074 #define LE32(addr) ((((uint32_t)(*(((uint8_t *)(addr)) + 0))) + \ 00075 (((uint32_t)(*(((uint8_t *)(addr)) + 1))) << 8) + \ 00076 (((uint32_t)(*(((uint8_t *)(addr)) + 2))) << 16) + \ 00077 (((uint32_t)(*(((uint8_t *)(addr)) + 3))) << 24))) 00078 00079 #define LE64(addr) ((((uint64_t)(*(((uint8_t *)(addr)) + 0))) + \ 00080 (((uint64_t)(*(((uint8_t *)(addr)) + 1))) << 8) +\ 00081 (((uint64_t)(*(((uint8_t *)(addr)) + 2))) << 16) +\ 00082 (((uint64_t)(*(((uint8_t *)(addr)) + 3))) << 24) +\ 00083 (((uint64_t)(*(((uint8_t *)(addr)) + 4))) << 32) +\ 00084 (((uint64_t)(*(((uint8_t *)(addr)) + 5))) << 40) +\ 00085 (((uint64_t)(*(((uint8_t *)(addr)) + 6))) << 48) +\ 00086 (((uint64_t)(*(((uint8_t *)(addr)) + 7))) << 56))) 00087 00088 00089 #define LE24(addr) ((((uint32_t)(*(((uint8_t *)(addr)) + 0))) + \ 00090 (((uint32_t)(*(((uint8_t *)(addr)) + 1))) << 8) + \ 00091 (((uint32_t)(*(((uint8_t *)(addr)) + 2))) << 16))) 00092 00093 00094 #define LE32S(addr) (int32_t)(LE32((addr))) 00095 00096 00097 00098 #define USB_LEN_DESC_HDR 0x02 00099 #define USB_LEN_DEV_DESC 0x12 00100 #define USB_LEN_CFG_DESC 0x09 00101 #define USB_LEN_IF_DESC 0x09 00102 #define USB_LEN_EP_DESC 0x07 00103 #define USB_LEN_OTG_DESC 0x03 00104 #define USB_LEN_SETUP_PKT 0x08 00105 00106 /* bmRequestType :D7 Data Phase Transfer Direction */ 00107 #define USB_REQ_DIR_MASK 0x80 00108 #define USB_H2D 0x00 00109 #define USB_D2H 0x80 00110 00111 /* bmRequestType D6..5 Type */ 00112 #define USB_REQ_TYPE_STANDARD 0x00 00113 #define USB_REQ_TYPE_CLASS 0x20 00114 #define USB_REQ_TYPE_VENDOR 0x40 00115 #define USB_REQ_TYPE_RESERVED 0x60 00116 00117 /* bmRequestType D4..0 Recipient */ 00118 #define USB_REQ_RECIPIENT_DEVICE 0x00 00119 #define USB_REQ_RECIPIENT_INTERFACE 0x01 00120 #define USB_REQ_RECIPIENT_ENDPOINT 0x02 00121 #define USB_REQ_RECIPIENT_OTHER 0x03 00122 00123 /* Table 9-4. Standard Request Codes */ 00124 /* bRequest , Value */ 00125 #define USB_REQ_GET_STATUS 0x00 00126 #define USB_REQ_CLEAR_FEATURE 0x01 00127 #define USB_REQ_SET_FEATURE 0x03 00128 #define USB_REQ_SET_ADDRESS 0x05 00129 #define USB_REQ_GET_DESCRIPTOR 0x06 00130 #define USB_REQ_SET_DESCRIPTOR 0x07 00131 #define USB_REQ_GET_CONFIGURATION 0x08 00132 #define USB_REQ_SET_CONFIGURATION 0x09 00133 #define USB_REQ_GET_INTERFACE 0x0A 00134 #define USB_REQ_SET_INTERFACE 0x0B 00135 #define USB_REQ_SYNCH_FRAME 0x0C 00136 00137 /* Table 9-5. Descriptor Types of USB Specifications */ 00138 #define USB_DESC_TYPE_DEVICE 1 00139 #define USB_DESC_TYPE_CONFIGURATION 2 00140 #define USB_DESC_TYPE_STRING 3 00141 #define USB_DESC_TYPE_INTERFACE 4 00142 #define USB_DESC_TYPE_ENDPOINT 5 00143 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6 00144 #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7 00145 #define USB_DESC_TYPE_INTERFACE_POWER 8 00146 #define USB_DESC_TYPE_HID 0x21 00147 #define USB_DESC_TYPE_HID_REPORT 0x22 00148 00149 00150 #define USB_DEVICE_DESC_SIZE 18 00151 #define USB_CONFIGURATION_DESC_SIZE 9 00152 #define USB_HID_DESC_SIZE 9 00153 #define USB_INTERFACE_DESC_SIZE 9 00154 #define USB_ENDPOINT_DESC_SIZE 7 00155 00156 /* Descriptor Type and Descriptor Index */ 00157 /* Use the following values when calling the function USBH_GetDescriptor */ 00158 #define USB_DESC_DEVICE ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00) 00159 #define USB_DESC_CONFIGURATION ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00) 00160 #define USB_DESC_STRING ((USB_DESC_TYPE_STRING << 8) & 0xFF00) 00161 #define USB_DESC_INTERFACE ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00) 00162 #define USB_DESC_ENDPOINT ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00) 00163 #define USB_DESC_DEVICE_QUALIFIER ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00) 00164 #define USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00) 00165 #define USB_DESC_INTERFACE_POWER ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00) 00166 #define USB_DESC_HID_REPORT ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00) 00167 #define USB_DESC_HID ((USB_DESC_TYPE_HID << 8) & 0xFF00) 00168 00169 00170 #define USB_EP_TYPE_CTRL 0x00 00171 #define USB_EP_TYPE_ISOC 0x01 00172 #define USB_EP_TYPE_BULK 0x02 00173 #define USB_EP_TYPE_INTR 0x03 00174 00175 #define USB_EP_DIR_OUT 0x00 00176 #define USB_EP_DIR_IN 0x80 00177 #define USB_EP_DIR_MSK 0x80 00178 00179 #ifndef USBH_MAX_PIPES_NBR 00180 #define USBH_MAX_PIPES_NBR 15 00181 #endif /* USBH_MAX_PIPES_NBR */ 00182 00183 #define USBH_DEVICE_ADDRESS_DEFAULT 0 00184 #define USBH_MAX_ERROR_COUNT 2 00185 #define USBH_DEVICE_ADDRESS 1 00186 00187 00188 /** 00189 * @} 00190 */ 00191 00192 00193 #define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \ 00194 + USB_INTERFACE_DESC_SIZE\ 00195 + (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE)) 00196 00197 00198 #define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\ 00199 ConfigurationDescriptor.wTotalLength) 00200 00201 00202 typedef union 00203 { 00204 uint16_t w; 00205 struct BW 00206 { 00207 uint8_t msb; 00208 uint8_t lsb; 00209 } 00210 bw; 00211 } 00212 uint16_t_uint8_t; 00213 00214 00215 typedef union _USB_Setup 00216 { 00217 uint32_t d8[2]; 00218 00219 struct _SetupPkt_Struc 00220 { 00221 uint8_t bmRequestType; 00222 uint8_t bRequest; 00223 uint16_t_uint8_t wValue; 00224 uint16_t_uint8_t wIndex; 00225 uint16_t_uint8_t wLength; 00226 } b; 00227 } 00228 USB_Setup_TypeDef; 00229 00230 typedef struct _DescHeader 00231 { 00232 uint8_t bLength; 00233 uint8_t bDescriptorType; 00234 } 00235 USBH_DescHeader_t; 00236 00237 typedef struct _DeviceDescriptor 00238 { 00239 uint8_t bLength; 00240 uint8_t bDescriptorType; 00241 uint16_t bcdUSB; /* USB Specification Number which device complies too */ 00242 uint8_t bDeviceClass; 00243 uint8_t bDeviceSubClass; 00244 uint8_t bDeviceProtocol; 00245 /* If equal to Zero, each interface specifies its own class 00246 code if equal to 0xFF, the class code is vendor specified. 00247 Otherwise field is valid Class Code.*/ 00248 uint8_t bMaxPacketSize; 00249 uint16_t idVendor; /* Vendor ID (Assigned by USB Org) */ 00250 uint16_t idProduct; /* Product ID (Assigned by Manufacturer) */ 00251 uint16_t bcdDevice; /* Device Release Number */ 00252 uint8_t iManufacturer; /* Index of Manufacturer String Descriptor */ 00253 uint8_t iProduct; /* Index of Product String Descriptor */ 00254 uint8_t iSerialNumber; /* Index of Serial Number String Descriptor */ 00255 uint8_t bNumConfigurations; /* Number of Possible Configurations */ 00256 } 00257 USBH_DevDescTypeDef; 00258 00259 typedef struct _EndpointDescriptor 00260 { 00261 uint8_t bLength; 00262 uint8_t bDescriptorType; 00263 uint8_t bEndpointAddress; /* indicates what endpoint this descriptor is describing */ 00264 uint8_t bmAttributes; /* specifies the transfer type. */ 00265 uint16_t wMaxPacketSize; /* Maximum Packet Size this endpoint is capable of sending or receiving */ 00266 uint8_t bInterval; /* is used to specify the polling interval of certain transfers. */ 00267 } 00268 USBH_EpDescTypeDef; 00269 00270 typedef struct _InterfaceDescriptor 00271 { 00272 uint8_t bLength; 00273 uint8_t bDescriptorType; 00274 uint8_t bInterfaceNumber; 00275 uint8_t bAlternateSetting; /* Value used to select alternative setting */ 00276 uint8_t bNumEndpoints; /* Number of Endpoints used for this interface */ 00277 uint8_t bInterfaceClass; /* Class Code (Assigned by USB Org) */ 00278 uint8_t bInterfaceSubClass; /* Subclass Code (Assigned by USB Org) */ 00279 uint8_t bInterfaceProtocol; /* Protocol Code */ 00280 uint8_t iInterface; /* Index of String Descriptor Describing this interface */ 00281 USBH_EpDescTypeDef Ep_Desc[USBH_MAX_NUM_ENDPOINTS]; 00282 } 00283 USBH_InterfaceDescTypeDef; 00284 00285 00286 typedef struct _ConfigurationDescriptor 00287 { 00288 uint8_t bLength; 00289 uint8_t bDescriptorType; 00290 uint16_t wTotalLength; /* Total Length of Data Returned */ 00291 uint8_t bNumInterfaces; /* Number of Interfaces */ 00292 uint8_t bConfigurationValue; /* Value to use as an argument to select this configuration*/ 00293 uint8_t iConfiguration; /*Index of String Descriptor Describing this configuration */ 00294 uint8_t bmAttributes; /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/ 00295 uint8_t bMaxPower; /*Maximum Power Consumption */ 00296 USBH_InterfaceDescTypeDef Itf_Desc[USBH_MAX_NUM_INTERFACES]; 00297 } 00298 USBH_CfgDescTypeDef; 00299 00300 00301 /* Following USB Host status */ 00302 typedef enum 00303 { 00304 USBH_OK = 0, 00305 USBH_BUSY, 00306 USBH_FAIL, 00307 USBH_NOT_SUPPORTED, 00308 USBH_UNRECOVERED_ERROR, 00309 USBH_ERROR_SPEED_UNKNOWN, 00310 }USBH_StatusTypeDef; 00311 00312 00313 /** @defgroup USBH_CORE_Exported_Types 00314 * @{ 00315 */ 00316 00317 typedef enum 00318 { 00319 USBH_SPEED_HIGH = 0, 00320 USBH_SPEED_FULL = 1, 00321 USBH_SPEED_LOW = 2, 00322 00323 }USBH_SpeedTypeDef; 00324 00325 /* Following states are used for gState */ 00326 typedef enum 00327 { 00328 HOST_IDLE =0, 00329 HOST_DEV_WAIT_FOR_ATTACHMENT, 00330 HOST_DEV_ATTACHED, 00331 HOST_DEV_DISCONNECTED, 00332 HOST_DETECT_DEVICE_SPEED, 00333 HOST_ENUMERATION, 00334 HOST_CLASS_REQUEST, 00335 HOST_INPUT, 00336 HOST_SET_CONFIGURATION, 00337 HOST_CHECK_CLASS, 00338 HOST_CLASS, 00339 HOST_SUSPENDED, 00340 HOST_ABORT_STATE, 00341 }HOST_StateTypeDef; 00342 00343 /* Following states are used for EnumerationState */ 00344 typedef enum 00345 { 00346 ENUM_IDLE = 0, 00347 ENUM_GET_FULL_DEV_DESC, 00348 ENUM_SET_ADDR, 00349 ENUM_GET_CFG_DESC, 00350 ENUM_GET_FULL_CFG_DESC, 00351 ENUM_GET_MFC_STRING_DESC, 00352 ENUM_GET_PRODUCT_STRING_DESC, 00353 ENUM_GET_SERIALNUM_STRING_DESC, 00354 } ENUM_StateTypeDef; 00355 00356 /* Following states are used for CtrlXferStateMachine */ 00357 typedef enum 00358 { 00359 CTRL_IDLE =0, 00360 CTRL_SETUP, 00361 CTRL_SETUP_WAIT, 00362 CTRL_DATA_IN, 00363 CTRL_DATA_IN_WAIT, 00364 CTRL_DATA_OUT, 00365 CTRL_DATA_OUT_WAIT, 00366 CTRL_STATUS_IN, 00367 CTRL_STATUS_IN_WAIT, 00368 CTRL_STATUS_OUT, 00369 CTRL_STATUS_OUT_WAIT, 00370 CTRL_ERROR, 00371 CTRL_STALLED, 00372 CTRL_COMPLETE 00373 }CTRL_StateTypeDef; 00374 00375 00376 /* Following states are used for RequestState */ 00377 typedef enum 00378 { 00379 CMD_IDLE =0, 00380 CMD_SEND, 00381 CMD_WAIT 00382 } CMD_StateTypeDef; 00383 00384 typedef enum { 00385 USBH_URB_IDLE = 0, 00386 USBH_URB_DONE, 00387 USBH_URB_NOTREADY, 00388 USBH_URB_NYET, 00389 USBH_URB_ERROR, 00390 USBH_URB_STALL 00391 }USBH_URBStateTypeDef; 00392 00393 typedef enum 00394 { 00395 USBH_PORT_EVENT = 1, 00396 USBH_URB_EVENT, 00397 USBH_CONTROL_EVENT, 00398 USBH_CLASS_EVENT, 00399 USBH_STATE_CHANGED_EVENT, 00400 } 00401 USBH_OSEventTypeDef; 00402 00403 /* Control request structure */ 00404 typedef struct 00405 { 00406 uint8_t pipe_in; 00407 uint8_t pipe_out; 00408 uint8_t pipe_size; 00409 uint8_t *buff; 00410 uint16_t length; 00411 uint16_t timer; 00412 USB_Setup_TypeDef setup; 00413 CTRL_StateTypeDef state; 00414 uint8_t errorcount; 00415 00416 } USBH_CtrlTypeDef; 00417 00418 /* Attached device structure */ 00419 typedef struct 00420 { 00421 #if (USBH_KEEP_CFG_DESCRIPTOR == 1) 00422 uint8_t CfgDesc_Raw[USBH_MAX_SIZE_CONFIGURATION]; 00423 #endif 00424 uint8_t Data[USBH_MAX_DATA_BUFFER]; 00425 uint8_t address; 00426 uint8_t speed; 00427 __IO uint8_t is_connected; 00428 uint8_t current_interface; 00429 USBH_DevDescTypeDef DevDesc; 00430 USBH_CfgDescTypeDef CfgDesc; 00431 00432 }USBH_DeviceTypeDef; 00433 00434 struct _USBH_HandleTypeDef; 00435 00436 /* USB Host Class structure */ 00437 typedef struct 00438 { 00439 const char *Name; 00440 uint8_t ClassCode; 00441 USBH_StatusTypeDef (*Init) (struct _USBH_HandleTypeDef *phost); 00442 USBH_StatusTypeDef (*DeInit) (struct _USBH_HandleTypeDef *phost); 00443 USBH_StatusTypeDef (*Requests) (struct _USBH_HandleTypeDef *phost); 00444 USBH_StatusTypeDef (*BgndProcess) (struct _USBH_HandleTypeDef *phost); 00445 USBH_StatusTypeDef (*SOFProcess) (struct _USBH_HandleTypeDef *phost); 00446 void* pData; 00447 } USBH_ClassTypeDef; 00448 00449 /* USB Host handle structure */ 00450 typedef struct _USBH_HandleTypeDef 00451 { 00452 __IO HOST_StateTypeDef gState; /* Host State Machine Value */ 00453 ENUM_StateTypeDef EnumState; /* Enumeration state Machine */ 00454 CMD_StateTypeDef RequestState; 00455 USBH_CtrlTypeDef Control; 00456 USBH_DeviceTypeDef device; 00457 USBH_ClassTypeDef* pClass[USBH_MAX_NUM_SUPPORTED_CLASS]; 00458 USBH_ClassTypeDef* pActiveClass; 00459 uint32_t ClassNumber; 00460 uint32_t Pipes[15]; 00461 __IO uint32_t Timer; 00462 uint8_t id; 00463 void* pData; 00464 void (* pUser )(struct _USBH_HandleTypeDef *pHandle, uint8_t id); 00465 00466 #if (USBH_USE_OS == 1) 00467 osMessageQId os_event; 00468 osThreadId thread; 00469 #endif 00470 00471 } USBH_HandleTypeDef; 00472 00473 00474 #if defined ( __GNUC__ ) 00475 #ifndef __weak 00476 #define __weak __attribute__((weak)) 00477 #endif /* __weak */ 00478 #ifndef __packed 00479 #define __packed __attribute__((__packed__)) 00480 #endif /* __packed */ 00481 #endif /* __GNUC__ */ 00482 00483 #ifdef __cplusplus 00484 } 00485 #endif 00486 00487 #endif /* USBH_DEF_H */ 00488 00489 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 00490
Generated on Tue Jul 12 2022 14:58:22 by
1.7.2