STM32F479xx HAL User Manual
stm32f4xx_hal_hcd.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_hcd.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of HCD HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * Copyright (c) 2016 STMicroelectronics.
00010   * All rights reserved.
00011   *
00012   * This software is licensed under terms that can be found in the LICENSE file
00013   * in the root directory of this software component.
00014   * If no LICENSE file comes with this software, it is provided AS-IS.
00015   *
00016   ******************************************************************************
00017   */
00018 
00019 /* Define to prevent recursive inclusion -------------------------------------*/
00020 #ifndef STM32F4xx_HAL_HCD_H
00021 #define STM32F4xx_HAL_HCD_H
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 /* Includes ------------------------------------------------------------------*/
00028 #include "stm32f4xx_ll_usb.h"
00029 
00030 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
00031 /** @addtogroup STM32F4xx_HAL_Driver
00032   * @{
00033   */
00034 
00035 /** @addtogroup HCD HCD
00036   * @{
00037   */
00038 
00039 /* Exported types ------------------------------------------------------------*/
00040 /** @defgroup HCD_Exported_Types HCD Exported Types
00041   * @{
00042   */
00043 
00044 /** @defgroup HCD_Exported_Types_Group1 HCD State Structure definition
00045   * @{
00046   */
00047 typedef enum
00048 {
00049   HAL_HCD_STATE_RESET    = 0x00,
00050   HAL_HCD_STATE_READY    = 0x01,
00051   HAL_HCD_STATE_ERROR    = 0x02,
00052   HAL_HCD_STATE_BUSY     = 0x03,
00053   HAL_HCD_STATE_TIMEOUT  = 0x04
00054 } HCD_StateTypeDef;
00055 
00056 typedef USB_OTG_GlobalTypeDef   HCD_TypeDef;
00057 typedef USB_OTG_CfgTypeDef      HCD_InitTypeDef;
00058 typedef USB_OTG_HCTypeDef       HCD_HCTypeDef;
00059 typedef USB_OTG_URBStateTypeDef HCD_URBStateTypeDef;
00060 typedef USB_OTG_HCStateTypeDef  HCD_HCStateTypeDef;
00061 /**
00062   * @}
00063   */
00064 
00065 /** @defgroup HCD_Exported_Types_Group2 HCD Handle Structure definition
00066   * @{
00067   */
00068 #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
00069 typedef struct __HCD_HandleTypeDef
00070 #else
00071 typedef struct
00072 #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
00073 {
00074   HCD_TypeDef               *Instance;  /*!< Register base address    */
00075   HCD_InitTypeDef           Init;       /*!< HCD required parameters  */
00076   HCD_HCTypeDef             hc[16];     /*!< Host channels parameters */
00077   HAL_LockTypeDef           Lock;       /*!< HCD peripheral status    */
00078   __IO HCD_StateTypeDef     State;      /*!< HCD communication state  */
00079   __IO  uint32_t            ErrorCode;  /*!< HCD Error code           */
00080   void                      *pData;     /*!< Pointer Stack Handler    */
00081 #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
00082   void (* SOFCallback)(struct __HCD_HandleTypeDef *hhcd);                               /*!< USB OTG HCD SOF callback                */
00083   void (* ConnectCallback)(struct __HCD_HandleTypeDef *hhcd);                           /*!< USB OTG HCD Connect callback            */
00084   void (* DisconnectCallback)(struct __HCD_HandleTypeDef *hhcd);                        /*!< USB OTG HCD Disconnect callback         */
00085   void (* PortEnabledCallback)(struct __HCD_HandleTypeDef *hhcd);                       /*!< USB OTG HCD Port Enable callback        */
00086   void (* PortDisabledCallback)(struct __HCD_HandleTypeDef *hhcd);                      /*!< USB OTG HCD Port Disable callback       */
00087   void (* HC_NotifyURBChangeCallback)(struct __HCD_HandleTypeDef *hhcd, uint8_t chnum,
00088                                       HCD_URBStateTypeDef urb_state);                   /*!< USB OTG HCD Host Channel Notify URB Change callback  */
00089 
00090   void (* MspInitCallback)(struct __HCD_HandleTypeDef *hhcd);                           /*!< USB OTG HCD Msp Init callback           */
00091   void (* MspDeInitCallback)(struct __HCD_HandleTypeDef *hhcd);                         /*!< USB OTG HCD Msp DeInit callback         */
00092 #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
00093 } HCD_HandleTypeDef;
00094 /**
00095   * @}
00096   */
00097 
00098 /**
00099   * @}
00100   */
00101 
00102 /* Exported constants --------------------------------------------------------*/
00103 /** @defgroup HCD_Exported_Constants HCD Exported Constants
00104   * @{
00105   */
00106 
00107 /** @defgroup HCD_Speed HCD Speed
00108   * @{
00109   */
00110 #define HCD_SPEED_HIGH               USBH_HS_SPEED
00111 #define HCD_SPEED_FULL               USBH_FSLS_SPEED
00112 #define HCD_SPEED_LOW                USBH_FSLS_SPEED
00113 /**
00114   * @}
00115   */
00116 
00117 /** @defgroup HCD_Device_Speed HCD Device Speed
00118   * @{
00119   */
00120 #define HCD_DEVICE_SPEED_HIGH               0U
00121 #define HCD_DEVICE_SPEED_FULL               1U
00122 #define HCD_DEVICE_SPEED_LOW                2U
00123 /**
00124   * @}
00125   */
00126 
00127 /** @defgroup HCD_PHY_Module HCD PHY Module
00128   * @{
00129   */
00130 #define HCD_PHY_ULPI                 1U
00131 #define HCD_PHY_EMBEDDED             2U
00132 /**
00133   * @}
00134   */
00135 
00136 /** @defgroup HCD_Error_Code_definition HCD Error Code definition
00137   * @brief  HCD Error Code definition
00138   * @{
00139   */
00140 #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
00141 #define  HAL_HCD_ERROR_INVALID_CALLBACK                        (0x00000010U)    /*!< Invalid Callback error  */
00142 #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
00143 
00144 /**
00145   * @}
00146   */
00147 
00148 /**
00149   * @}
00150   */
00151 
00152 /* Exported macro ------------------------------------------------------------*/
00153 /** @defgroup HCD_Exported_Macros HCD Exported Macros
00154   *  @brief macros to handle interrupts and specific clock configurations
00155   * @{
00156   */
00157 #define __HAL_HCD_ENABLE(__HANDLE__)                   (void)USB_EnableGlobalInt ((__HANDLE__)->Instance)
00158 #define __HAL_HCD_DISABLE(__HANDLE__)                  (void)USB_DisableGlobalInt ((__HANDLE__)->Instance)
00159 
00160 #define __HAL_HCD_GET_FLAG(__HANDLE__, __INTERRUPT__)      ((USB_ReadInterrupts((__HANDLE__)->Instance)\
00161                                                              & (__INTERRUPT__)) == (__INTERRUPT__))
00162 #define __HAL_HCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__)    (((__HANDLE__)->Instance->GINTSTS) = (__INTERRUPT__))
00163 #define __HAL_HCD_IS_INVALID_INTERRUPT(__HANDLE__)         (USB_ReadInterrupts((__HANDLE__)->Instance) == 0U)
00164 
00165 #define __HAL_HCD_CLEAR_HC_INT(chnum, __INTERRUPT__)  (USBx_HC(chnum)->HCINT = (__INTERRUPT__))
00166 #define __HAL_HCD_MASK_HALT_HC_INT(chnum)             (USBx_HC(chnum)->HCINTMSK &= ~USB_OTG_HCINTMSK_CHHM)
00167 #define __HAL_HCD_UNMASK_HALT_HC_INT(chnum)           (USBx_HC(chnum)->HCINTMSK |= USB_OTG_HCINTMSK_CHHM)
00168 #define __HAL_HCD_MASK_ACK_HC_INT(chnum)              (USBx_HC(chnum)->HCINTMSK &= ~USB_OTG_HCINTMSK_ACKM)
00169 #define __HAL_HCD_UNMASK_ACK_HC_INT(chnum)            (USBx_HC(chnum)->HCINTMSK |= USB_OTG_HCINTMSK_ACKM)
00170 /**
00171   * @}
00172   */
00173 
00174 /* Exported functions --------------------------------------------------------*/
00175 /** @addtogroup HCD_Exported_Functions HCD Exported Functions
00176   * @{
00177   */
00178 
00179 /** @defgroup HCD_Exported_Functions_Group1 Initialization and de-initialization functions
00180   * @{
00181   */
00182 HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd);
00183 HAL_StatusTypeDef HAL_HCD_DeInit(HCD_HandleTypeDef *hhcd);
00184 HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd, uint8_t ch_num,
00185                                   uint8_t epnum, uint8_t dev_address,
00186                                   uint8_t speed, uint8_t ep_type, uint16_t mps);
00187 
00188 HAL_StatusTypeDef HAL_HCD_HC_Halt(HCD_HandleTypeDef *hhcd, uint8_t ch_num);
00189 void              HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd);
00190 void              HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd);
00191 
00192 #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
00193 /** @defgroup HAL_HCD_Callback_ID_enumeration_definition HAL USB OTG HCD Callback ID enumeration definition
00194   * @brief  HAL USB OTG HCD Callback ID enumeration definition
00195   * @{
00196   */
00197 typedef enum
00198 {
00199   HAL_HCD_SOF_CB_ID            = 0x01,       /*!< USB HCD SOF callback ID           */
00200   HAL_HCD_CONNECT_CB_ID        = 0x02,       /*!< USB HCD Connect callback ID       */
00201   HAL_HCD_DISCONNECT_CB_ID     = 0x03,       /*!< USB HCD Disconnect callback ID    */
00202   HAL_HCD_PORT_ENABLED_CB_ID   = 0x04,       /*!< USB HCD Port Enable callback ID   */
00203   HAL_HCD_PORT_DISABLED_CB_ID  = 0x05,       /*!< USB HCD Port Disable callback ID  */
00204 
00205   HAL_HCD_MSPINIT_CB_ID        = 0x06,       /*!< USB HCD MspInit callback ID       */
00206   HAL_HCD_MSPDEINIT_CB_ID      = 0x07        /*!< USB HCD MspDeInit callback ID     */
00207 
00208 } HAL_HCD_CallbackIDTypeDef;
00209 /**
00210   * @}
00211   */
00212 
00213 /** @defgroup HAL_HCD_Callback_pointer_definition HAL USB OTG HCD Callback pointer definition
00214   * @brief  HAL USB OTG HCD Callback pointer definition
00215   * @{
00216   */
00217 
00218 typedef void (*pHCD_CallbackTypeDef)(HCD_HandleTypeDef *hhcd);                   /*!< pointer to a common USB OTG HCD callback function  */
00219 typedef void (*pHCD_HC_NotifyURBChangeCallbackTypeDef)(HCD_HandleTypeDef *hhcd,
00220                                                        uint8_t epnum,
00221                                                        HCD_URBStateTypeDef urb_state);   /*!< pointer to USB OTG HCD host channel  callback */
00222 /**
00223   * @}
00224   */
00225 
00226 HAL_StatusTypeDef HAL_HCD_RegisterCallback(HCD_HandleTypeDef *hhcd,
00227                                            HAL_HCD_CallbackIDTypeDef CallbackID,
00228                                            pHCD_CallbackTypeDef pCallback);
00229 
00230 HAL_StatusTypeDef HAL_HCD_UnRegisterCallback(HCD_HandleTypeDef *hhcd,
00231                                              HAL_HCD_CallbackIDTypeDef CallbackID);
00232 
00233 HAL_StatusTypeDef HAL_HCD_RegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd,
00234                                                              pHCD_HC_NotifyURBChangeCallbackTypeDef pCallback);
00235 
00236 HAL_StatusTypeDef HAL_HCD_UnRegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd);
00237 #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
00238 /**
00239   * @}
00240   */
00241 
00242 /* I/O operation functions  ***************************************************/
00243 /** @addtogroup HCD_Exported_Functions_Group2 Input and Output operation functions
00244   * @{
00245   */
00246 HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, uint8_t ch_num,
00247                                            uint8_t direction, uint8_t ep_type,
00248                                            uint8_t token, uint8_t *pbuff,
00249                                            uint16_t length, uint8_t do_ping);
00250 
00251 /* Non-Blocking mode: Interrupt */
00252 void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd);
00253 void HAL_HCD_WKUP_IRQHandler(HCD_HandleTypeDef *hhcd);
00254 void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd);
00255 void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd);
00256 void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd);
00257 void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd);
00258 void HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef *hhcd);
00259 void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum,
00260                                          HCD_URBStateTypeDef urb_state);
00261 /**
00262   * @}
00263   */
00264 
00265 /* Peripheral Control functions  **********************************************/
00266 /** @addtogroup HCD_Exported_Functions_Group3 Peripheral Control functions
00267   * @{
00268   */
00269 HAL_StatusTypeDef HAL_HCD_ResetPort(HCD_HandleTypeDef *hhcd);
00270 HAL_StatusTypeDef HAL_HCD_Start(HCD_HandleTypeDef *hhcd);
00271 HAL_StatusTypeDef HAL_HCD_Stop(HCD_HandleTypeDef *hhcd);
00272 /**
00273   * @}
00274   */
00275 
00276 /* Peripheral State functions  ************************************************/
00277 /** @addtogroup HCD_Exported_Functions_Group4 Peripheral State functions
00278   * @{
00279   */
00280 HCD_StateTypeDef        HAL_HCD_GetState(HCD_HandleTypeDef *hhcd);
00281 HCD_URBStateTypeDef     HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnum);
00282 HCD_HCStateTypeDef      HAL_HCD_HC_GetState(HCD_HandleTypeDef *hhcd, uint8_t chnum);
00283 uint32_t                HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef *hhcd, uint8_t chnum);
00284 uint32_t                HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd);
00285 uint32_t                HAL_HCD_GetCurrentSpeed(HCD_HandleTypeDef *hhcd);
00286 
00287 /**
00288   * @}
00289   */
00290 
00291 /**
00292   * @}
00293   */
00294 
00295 /* Private macros ------------------------------------------------------------*/
00296 /** @defgroup HCD_Private_Macros HCD Private Macros
00297   * @{
00298   */
00299 /**
00300   * @}
00301   */
00302 /* Private functions prototypes ----------------------------------------------*/
00303 
00304 /**
00305   * @}
00306   */
00307 /**
00308   * @}
00309   */
00310 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
00311 
00312 #ifdef __cplusplus
00313 }
00314 #endif
00315 
00316 #endif /* STM32F4xx_HAL_HCD_H */