STM32L486xx 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   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */
00035 
00036 /* Define to prevent recursive inclusion -------------------------------------*/
00037 #ifndef __STM32L4xx_HAL_HCD_H
00038 #define __STM32L4xx_HAL_HCD_H
00039 
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #include "stm32l4xx_ll_usb.h"
00046 
00047 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
00048 
00049 /** @addtogroup STM32L4xx_HAL_Driver
00050   * @{
00051   */
00052 
00053 /** @addtogroup HCD
00054   * @{
00055   */
00056 
00057 /* Exported types ------------------------------------------------------------*/
00058 /** @defgroup HCD_Exported_Types HCD Exported Types
00059   * @{
00060   */
00061 
00062 /** @defgroup HCD_Exported_Types_Group1 HCD State Structure definition
00063   * @{
00064   */
00065 typedef enum
00066 {
00067   HAL_HCD_STATE_RESET    = 0x00,
00068   HAL_HCD_STATE_READY    = 0x01,
00069   HAL_HCD_STATE_ERROR    = 0x02,
00070   HAL_HCD_STATE_BUSY     = 0x03,
00071   HAL_HCD_STATE_TIMEOUT  = 0x04
00072 } HCD_StateTypeDef;
00073 
00074 typedef USB_OTG_GlobalTypeDef   HCD_TypeDef;
00075 typedef USB_OTG_CfgTypeDef      HCD_InitTypeDef;
00076 typedef USB_OTG_HCTypeDef       HCD_HCTypeDef;
00077 typedef USB_OTG_URBStateTypeDef HCD_URBStateTypeDef;
00078 typedef USB_OTG_HCStateTypeDef  HCD_HCStateTypeDef;
00079 /**
00080   * @}
00081   */
00082 
00083 /** @defgroup HCD_Exported_Types_Group2 HCD Handle Structure definition
00084   * @{
00085   */
00086 typedef struct __HCD_HandleTypeDef
00087 {
00088   HCD_TypeDef               *Instance;  /*!< Register base address    */
00089   HCD_InitTypeDef           Init;       /*!< HCD required parameters  */
00090   HCD_HCTypeDef             hc[16];     /*!< Host channels parameters */
00091   HAL_LockTypeDef           Lock;       /*!< HCD peripheral status    */
00092   __IO HCD_StateTypeDef     State;      /*!< HCD communication state  */
00093   __IO  uint32_t            ErrorCode;  /*!< HCD Error code           */
00094   void                      *pData;     /*!< Pointer Stack Handler    */
00095 #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
00096   void (* SOFCallback)(struct __HCD_HandleTypeDef *hhcd);                               /*!< USB OTG HCD SOF callback                */
00097   void (* ConnectCallback)(struct __HCD_HandleTypeDef *hhcd);                           /*!< USB OTG HCD Connect callback            */
00098   void (* DisconnectCallback)(struct __HCD_HandleTypeDef *hhcd);                        /*!< USB OTG HCD Disconnect callback         */
00099   void (* PortEnabledCallback)(struct __HCD_HandleTypeDef *hhcd);                       /*!< USB OTG HCD Port Enable callback        */
00100   void (* PortDisabledCallback)(struct __HCD_HandleTypeDef *hhcd);                      /*!< USB OTG HCD Port Disable callback       */
00101   void (* HC_NotifyURBChangeCallback)(struct __HCD_HandleTypeDef *hhcd, uint8_t chnum,
00102                                       HCD_URBStateTypeDef urb_state);                   /*!< USB OTG HCD Host Channel Notify URB Change callback  */
00103 
00104   void (* MspInitCallback)(struct __HCD_HandleTypeDef *hhcd);                           /*!< USB OTG HCD Msp Init callback           */
00105   void (* MspDeInitCallback)(struct __HCD_HandleTypeDef *hhcd);                         /*!< USB OTG HCD Msp DeInit callback         */
00106 #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
00107 } HCD_HandleTypeDef;
00108 /**
00109   * @}
00110   */
00111 
00112 /**
00113   * @}
00114   */
00115 
00116 /* Exported constants --------------------------------------------------------*/
00117 /** @defgroup HCD_Exported_Constants HCD Exported Constants
00118   * @{
00119   */
00120 
00121 /** @defgroup HCD_Speed HCD Speed
00122   * @{
00123   */
00124 #define HCD_SPEED_HIGH               0U
00125 #define HCD_SPEED_LOW                2U
00126 #define HCD_SPEED_FULL               3U
00127 /**
00128   * @}
00129   */
00130 
00131 /** @defgroup HCD_PHY_Module HCD PHY Module
00132   * @{
00133   */
00134 #define HCD_PHY_ULPI                 1U
00135 #define HCD_PHY_EMBEDDED             2U
00136 /**
00137   * @}
00138   */
00139 
00140 /** @defgroup HCD_Error_Code_definition HCD Error Code definition
00141   * @brief  HCD Error Code definition
00142   * @{
00143   */
00144 #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
00145 #define  HAL_HCD_ERROR_INVALID_CALLBACK                        (0x00000010U)    /*!< Invalid Callback error  */
00146 #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
00147 
00148 /**
00149   * @}
00150   */
00151 
00152 /**
00153   * @}
00154   */
00155 
00156 /* Exported macro ------------------------------------------------------------*/
00157 /** @defgroup HCD_Exported_Macros HCD Exported Macros
00158  *  @brief macros to handle interrupts and specific clock configurations
00159  * @{
00160  */
00161 #define __HAL_HCD_ENABLE(__HANDLE__)                   (void)USB_EnableGlobalInt ((__HANDLE__)->Instance)
00162 #define __HAL_HCD_DISABLE(__HANDLE__)                  (void)USB_DisableGlobalInt ((__HANDLE__)->Instance)
00163 
00164 #define __HAL_HCD_GET_FLAG(__HANDLE__, __INTERRUPT__)      ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__))
00165 #define __HAL_HCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__)    (((__HANDLE__)->Instance->GINTSTS) = (__INTERRUPT__))
00166 #define __HAL_HCD_IS_INVALID_INTERRUPT(__HANDLE__)         (USB_ReadInterrupts((__HANDLE__)->Instance) == 0U)
00167 
00168 #define __HAL_HCD_CLEAR_HC_INT(chnum, __INTERRUPT__)  (USBx_HC(chnum)->HCINT = (__INTERRUPT__))
00169 #define __HAL_HCD_MASK_HALT_HC_INT(chnum)             (USBx_HC(chnum)->HCINTMSK &= ~USB_OTG_HCINTMSK_CHHM)
00170 #define __HAL_HCD_UNMASK_HALT_HC_INT(chnum)           (USBx_HC(chnum)->HCINTMSK |= USB_OTG_HCINTMSK_CHHM)
00171 #define __HAL_HCD_MASK_ACK_HC_INT(chnum)              (USBx_HC(chnum)->HCINTMSK &= ~USB_OTG_HCINTMSK_ACKM)
00172 #define __HAL_HCD_UNMASK_ACK_HC_INT(chnum)            (USBx_HC(chnum)->HCINTMSK |= USB_OTG_HCINTMSK_ACKM)
00173 /**
00174   * @}
00175   */
00176 
00177 /* Exported functions --------------------------------------------------------*/
00178 /** @addtogroup HCD_Exported_Functions HCD Exported Functions
00179   * @{
00180   */
00181 
00182 /** @defgroup HCD_Exported_Functions_Group1 Initialization and de-initialization functions
00183   * @{
00184   */
00185 HAL_StatusTypeDef      HAL_HCD_Init(HCD_HandleTypeDef *hhcd);
00186 HAL_StatusTypeDef      HAL_HCD_DeInit(HCD_HandleTypeDef *hhcd);
00187 HAL_StatusTypeDef      HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd,
00188                                        uint8_t ch_num,
00189                                        uint8_t epnum,
00190                                        uint8_t dev_address,
00191                                        uint8_t speed,
00192                                        uint8_t ep_type,
00193                                        uint16_t mps);
00194 
00195 HAL_StatusTypeDef     HAL_HCD_HC_Halt(HCD_HandleTypeDef *hhcd, uint8_t ch_num);
00196 void                  HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd);
00197 void                  HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd);
00198 
00199 #if (USE_HAL_HCD_REGISTER_CALLBACKS == 1U)
00200 /** @defgroup HAL_HCD_Callback_ID_enumeration_definition HAL USB OTG HCD Callback ID enumeration definition
00201   * @brief  HAL USB OTG HCD Callback ID enumeration definition
00202   * @{
00203   */
00204 typedef enum
00205 {
00206   HAL_HCD_SOF_CB_ID           = 0x01,       /*!< USB HCD SOF callback ID           */
00207   HAL_HCD_CONNECT_CB_ID       = 0x02,       /*!< USB HCD Connect callback ID       */
00208   HAL_HCD_DISCONNECT_CB_ID   = 0x03,       /*!< USB HCD Disconnect callback ID    */
00209   HAL_HCD_PORT_ENABLED_CB_ID   = 0x04,      /*!< USB HCD Port Enable callback ID   */
00210   HAL_HCD_PORT_DISABLED_CB_ID  = 0x05,      /*!< USB HCD Port Disable callback ID  */
00211 
00212   HAL_HCD_MSPINIT_CB_ID       = 0x06,       /*!< USB HCD MspInit callback ID       */
00213   HAL_HCD_MSPDEINIT_CB_ID     = 0x07        /*!< USB HCD MspDeInit callback ID     */
00214 
00215 } HAL_HCD_CallbackIDTypeDef;
00216 /**
00217   * @}
00218   */
00219 
00220 /** @defgroup HAL_HCD_Callback_pointer_definition HAL USB OTG HCD Callback pointer definition
00221   * @brief  HAL USB OTG HCD Callback pointer definition
00222   * @{
00223   */
00224 
00225 typedef void (*pHCD_CallbackTypeDef)(HCD_HandleTypeDef *hhcd);                   /*!< pointer to a common USB OTG HCD callback function  */
00226 typedef void (*pHCD_HC_NotifyURBChangeCallbackTypeDef)(HCD_HandleTypeDef *hhcd,
00227                                                        uint8_t epnum,
00228                                                        HCD_URBStateTypeDef urb_state);   /*!< pointer to USB OTG HCD host channel  callback */
00229 /**
00230   * @}
00231   */
00232 
00233 HAL_StatusTypeDef HAL_HCD_RegisterCallback(HCD_HandleTypeDef *hhcd, HAL_HCD_CallbackIDTypeDef CallbackID, pHCD_CallbackTypeDef pCallback);
00234 HAL_StatusTypeDef HAL_HCD_UnRegisterCallback(HCD_HandleTypeDef *hhcd, HAL_HCD_CallbackIDTypeDef CallbackID);
00235 
00236 HAL_StatusTypeDef HAL_HCD_RegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd, pHCD_HC_NotifyURBChangeCallbackTypeDef pCallback);
00237 HAL_StatusTypeDef HAL_HCD_UnRegisterHC_NotifyURBChangeCallback(HCD_HandleTypeDef *hhcd);
00238 #endif /* USE_HAL_HCD_REGISTER_CALLBACKS */
00239 /**
00240   * @}
00241   */
00242 
00243 /* I/O operation functions  ***************************************************/
00244 /** @addtogroup HCD_Exported_Functions_Group2 Input and Output operation functions
00245   * @{
00246   */
00247 HAL_StatusTypeDef       HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd,
00248                                                  uint8_t pipe,
00249                                                  uint8_t direction,
00250                                                  uint8_t ep_type,
00251                                                  uint8_t token,
00252                                                  uint8_t *pbuff,
00253                                                  uint16_t length,
00254                                                  uint8_t do_ping);
00255 
00256 /* Non-Blocking mode: Interrupt */
00257 void             HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd);
00258 void             HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd);
00259 void             HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd);
00260 void             HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd);
00261 void             HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd);
00262 void             HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef *hhcd);
00263 void             HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd,
00264                                                      uint8_t chnum,
00265                                                      HCD_URBStateTypeDef urb_state);
00266 /**
00267   * @}
00268   */
00269 
00270 /* Peripheral Control functions  **********************************************/
00271 /** @addtogroup HCD_Exported_Functions_Group3 Peripheral Control functions
00272   * @{
00273   */
00274 HAL_StatusTypeDef       HAL_HCD_ResetPort(HCD_HandleTypeDef *hhcd);
00275 HAL_StatusTypeDef       HAL_HCD_Start(HCD_HandleTypeDef *hhcd);
00276 HAL_StatusTypeDef       HAL_HCD_Stop(HCD_HandleTypeDef *hhcd);
00277 /**
00278   * @}
00279   */
00280 
00281 /* Peripheral State functions  ************************************************/
00282 /** @addtogroup HCD_Exported_Functions_Group4 Peripheral State functions
00283   * @{
00284   */
00285 HCD_StateTypeDef        HAL_HCD_GetState(HCD_HandleTypeDef *hhcd);
00286 HCD_URBStateTypeDef     HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnum);
00287 uint32_t                HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef *hhcd, uint8_t chnum);
00288 HCD_HCStateTypeDef      HAL_HCD_HC_GetState(HCD_HandleTypeDef *hhcd, uint8_t chnum);
00289 uint32_t                HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd);
00290 uint32_t                HAL_HCD_GetCurrentSpeed(HCD_HandleTypeDef *hhcd);
00291 /**
00292   * @}
00293   */
00294 
00295 /**
00296   * @}
00297   */
00298 
00299 /* Private macros ------------------------------------------------------------*/
00300 /** @defgroup HCD_Private_Macros HCD Private Macros
00301  * @{
00302  */
00303 
00304 /**
00305   * @}
00306   */
00307 
00308 /* Private functions prototypes ----------------------------------------------*/
00309 /** @defgroup HCD_Private_Functions_Prototypes HCD Private Functions Prototypes
00310   * @{
00311   */
00312 
00313 /**
00314   * @}
00315   */
00316 
00317 /* Private functions ---------------------------------------------------------*/
00318 /** @defgroup HCD_Private_Functions HCD Private Functions
00319   * @{
00320   */
00321 
00322 /**
00323   * @}
00324   */
00325 
00326 /**
00327   * @}
00328   */
00329 
00330 /**
00331   * @}
00332   */
00333 
00334 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
00335 
00336 #ifdef __cplusplus
00337 }
00338 #endif
00339 
00340 #endif /* __STM32L4xx_HAL_HCD_H */
00341 
00342 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/