STM32L443xx HAL User Manual
stm32l4xx_hal_hcd.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_hcd.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of HCD HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * Copyright (c) 2017 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 STM32L4xx_HAL_HCD_H
00021 #define STM32L4xx_HAL_HCD_H
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 /* Includes ------------------------------------------------------------------*/
00028 #include "stm32l4xx_ll_usb.h"
00029 
00030 #if defined (USB_OTG_FS)
00031 /** @addtogroup STM32L4xx_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_FULL               USBH_FSLS_SPEED
00111 #define HCD_SPEED_LOW                USBH_FSLS_SPEED
00112 /**
00113   * @}
00114   */
00115 
00116 /** @defgroup HCD_Device_Speed HCD Device Speed
00117   * @{
00118   */
00119 #define HCD_DEVICE_SPEED_HIGH               0U
00120 #define HCD_DEVICE_SPEED_FULL               1U
00121 #define HCD_DEVICE_SPEED_LOW                2U
00122 /**
00123   * @}
00124   */
00125 
00126 /** @defgroup HCD_PHY_Module HCD PHY Module
00127   * @{
00128   */
00129 #define HCD_PHY_ULPI                 1U
00130 #define HCD_PHY_EMBEDDED             2U
00131 /**
00132   * @}
00133   */
00134 
00135 /** @defgroup HCD_Error_Code_definition HCD Error Code definition
00136   * @brief  HCD Error Code definition
00137   * @{
00138   */
00139 #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
00140 #define  HAL_HCD_ERROR_INVALID_CALLBACK                        (0x00000010U)    /*!< Invalid Callback error  */
00141 #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
00142 
00143 /**
00144   * @}
00145   */
00146 
00147 /**
00148   * @}
00149   */
00150 
00151 /* Exported macro ------------------------------------------------------------*/
00152 /** @defgroup HCD_Exported_Macros HCD Exported Macros
00153   *  @brief macros to handle interrupts and specific clock configurations
00154   * @{
00155   */
00156 #define __HAL_HCD_ENABLE(__HANDLE__)                   (void)USB_EnableGlobalInt ((__HANDLE__)->Instance)
00157 #define __HAL_HCD_DISABLE(__HANDLE__)                  (void)USB_DisableGlobalInt ((__HANDLE__)->Instance)
00158 
00159 #define __HAL_HCD_GET_FLAG(__HANDLE__, __INTERRUPT__)      ((USB_ReadInterrupts((__HANDLE__)->Instance)\
00160                                                              & (__INTERRUPT__)) == (__INTERRUPT__))
00161 #define __HAL_HCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__)    (((__HANDLE__)->Instance->GINTSTS) = (__INTERRUPT__))
00162 #define __HAL_HCD_IS_INVALID_INTERRUPT(__HANDLE__)         (USB_ReadInterrupts((__HANDLE__)->Instance) == 0U)
00163 
00164 #define __HAL_HCD_CLEAR_HC_INT(chnum, __INTERRUPT__)  (USBx_HC(chnum)->HCINT = (__INTERRUPT__))
00165 #define __HAL_HCD_MASK_HALT_HC_INT(chnum)             (USBx_HC(chnum)->HCINTMSK &= ~USB_OTG_HCINTMSK_CHHM)
00166 #define __HAL_HCD_UNMASK_HALT_HC_INT(chnum)           (USBx_HC(chnum)->HCINTMSK |= USB_OTG_HCINTMSK_CHHM)
00167 #define __HAL_HCD_MASK_ACK_HC_INT(chnum)              (USBx_HC(chnum)->HCINTMSK &= ~USB_OTG_HCINTMSK_ACKM)
00168 #define __HAL_HCD_UNMASK_ACK_HC_INT(chnum)            (USBx_HC(chnum)->HCINTMSK |= USB_OTG_HCINTMSK_ACKM)
00169 /**
00170   * @}
00171   */
00172 
00173 /* Exported functions --------------------------------------------------------*/
00174 /** @addtogroup HCD_Exported_Functions HCD Exported Functions
00175   * @{
00176   */
00177 
00178 /** @defgroup HCD_Exported_Functions_Group1 Initialization and de-initialization functions
00179   * @{
00180   */
00181 HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd);
00182 HAL_StatusTypeDef HAL_HCD_DeInit(HCD_HandleTypeDef *hhcd);
00183 HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd, uint8_t ch_num,
00184                                   uint8_t epnum, uint8_t dev_address,
00185                                   uint8_t speed, uint8_t ep_type, uint16_t mps);
00186 
00187 HAL_StatusTypeDef HAL_HCD_HC_Halt(HCD_HandleTypeDef *hhcd, uint8_t ch_num);
00188 void              HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd);
00189 void              HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd);
00190 
00191 #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
00192 /** @defgroup HAL_HCD_Callback_ID_enumeration_definition HAL USB OTG HCD Callback ID enumeration definition
00193   * @brief  HAL USB OTG HCD Callback ID enumeration definition
00194   * @{
00195   */
00196 typedef enum
00197 {
00198   HAL_HCD_SOF_CB_ID            = 0x01,       /*!< USB HCD SOF callback ID           */
00199   HAL_HCD_CONNECT_CB_ID        = 0x02,       /*!< USB HCD Connect callback ID       */
00200   HAL_HCD_DISCONNECT_CB_ID     = 0x03,       /*!< USB HCD Disconnect callback ID    */
00201   HAL_HCD_PORT_ENABLED_CB_ID   = 0x04,       /*!< USB HCD Port Enable callback ID   */
00202   HAL_HCD_PORT_DISABLED_CB_ID  = 0x05,       /*!< USB HCD Port Disable callback ID  */
00203 
00204   HAL_HCD_MSPINIT_CB_ID        = 0x06,       /*!< USB HCD MspInit callback ID       */
00205   HAL_HCD_MSPDEINIT_CB_ID      = 0x07        /*!< USB HCD MspDeInit callback ID     */
00206 
00207 } HAL_HCD_CallbackIDTypeDef;
00208 /**
00209   * @}
00210   */
00211 
00212 /** @defgroup HAL_HCD_Callback_pointer_definition HAL USB OTG HCD Callback pointer definition
00213   * @brief  HAL USB OTG HCD Callback pointer definition
00214   * @{
00215   */
00216 
00217 typedef void (*pHCD_CallbackTypeDef)(HCD_HandleTypeDef *hhcd);                   /*!< pointer to a common USB OTG HCD callback function  */
00218 typedef void (*pHCD_HC_NotifyURBChangeCallbackTypeDef)(HCD_HandleTypeDef *hhcd,
00219                                                        uint8_t epnum,
00220                                                        HCD_URBStateTypeDef urb_state);   /*!< pointer to USB OTG HCD host channel  callback */
00221 /**
00222   * @}
00223   */
00224 
00225 HAL_StatusTypeDef HAL_HCD_RegisterCallback(HCD_HandleTypeDef *hhcd,
00226                                            HAL_HCD_CallbackIDTypeDef CallbackID,
00227                                            pHCD_CallbackTypeDef pCallback);
00228 
00229 HAL_StatusTypeDef HAL_HCD_UnRegisterCallback(HCD_HandleTypeDef *hhcd,
00230                                              HAL_HCD_CallbackIDTypeDef CallbackID);
00231 
00232 HAL_StatusTypeDef HAL_HCD_RegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd,
00233                                                              pHCD_HC_NotifyURBChangeCallbackTypeDef pCallback);
00234 
00235 HAL_StatusTypeDef HAL_HCD_UnRegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd);
00236 #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
00237 /**
00238   * @}
00239   */
00240 
00241 /* I/O operation functions  ***************************************************/
00242 /** @addtogroup HCD_Exported_Functions_Group2 Input and Output operation functions
00243   * @{
00244   */
00245 HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd, uint8_t ch_num,
00246                                            uint8_t direction, uint8_t ep_type,
00247                                            uint8_t token, uint8_t *pbuff,
00248                                            uint16_t length, uint8_t do_ping);
00249 
00250 /* Non-Blocking mode: Interrupt */
00251 void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd);
00252 void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd);
00253 void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd);
00254 void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd);
00255 void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd);
00256 void HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef *hhcd);
00257 void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum,
00258                                          HCD_URBStateTypeDef urb_state);
00259 /**
00260   * @}
00261   */
00262 
00263 /* Peripheral Control functions  **********************************************/
00264 /** @addtogroup HCD_Exported_Functions_Group3 Peripheral Control functions
00265   * @{
00266   */
00267 HAL_StatusTypeDef HAL_HCD_ResetPort(HCD_HandleTypeDef *hhcd);
00268 HAL_StatusTypeDef HAL_HCD_Start(HCD_HandleTypeDef *hhcd);
00269 HAL_StatusTypeDef HAL_HCD_Stop(HCD_HandleTypeDef *hhcd);
00270 /**
00271   * @}
00272   */
00273 
00274 /* Peripheral State functions  ************************************************/
00275 /** @addtogroup HCD_Exported_Functions_Group4 Peripheral State functions
00276   * @{
00277   */
00278 HCD_StateTypeDef        HAL_HCD_GetState(HCD_HandleTypeDef *hhcd);
00279 HCD_URBStateTypeDef     HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnum);
00280 HCD_HCStateTypeDef      HAL_HCD_HC_GetState(HCD_HandleTypeDef *hhcd, uint8_t chnum);
00281 uint32_t                HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef *hhcd, uint8_t chnum);
00282 uint32_t                HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd);
00283 uint32_t                HAL_HCD_GetCurrentSpeed(HCD_HandleTypeDef *hhcd);
00284 
00285 /**
00286   * @}
00287   */
00288 
00289 /**
00290   * @}
00291   */
00292 
00293 /* Private macros ------------------------------------------------------------*/
00294 /** @defgroup HCD_Private_Macros HCD Private Macros
00295   * @{
00296   */
00297 /**
00298   * @}
00299   */
00300 /* Private functions prototypes ----------------------------------------------*/
00301 
00302 /**
00303   * @}
00304   */
00305 /**
00306   * @}
00307   */
00308 #endif /* defined (USB_OTG_FS) */
00309 
00310 #ifdef __cplusplus
00311 }
00312 #endif
00313 
00314 #endif /* STM32L4xx_HAL_HCD_H */