Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Inc / stm32h7xx_hal_pcd.h
blob821f8d96a397555c404a0a65fa03f8116203b28b
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_pcd.h
4 * @author MCD Application Team
5 * @brief Header file of PCD HAL module.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32H7xx_HAL_PCD_H
22 #define STM32H7xx_HAL_PCD_H
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx_ll_usb.h"
31 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
33 /** @addtogroup STM32H7xx_HAL_Driver
34 * @{
37 /** @addtogroup PCD
38 * @{
41 /* Exported types ------------------------------------------------------------*/
42 /** @defgroup PCD_Exported_Types PCD Exported Types
43 * @{
46 /**
47 * @brief PCD State structure definition
49 typedef enum
51 HAL_PCD_STATE_RESET = 0x00,
52 HAL_PCD_STATE_READY = 0x01,
53 HAL_PCD_STATE_ERROR = 0x02,
54 HAL_PCD_STATE_BUSY = 0x03,
55 HAL_PCD_STATE_TIMEOUT = 0x04
56 } PCD_StateTypeDef;
58 /* Device LPM suspend state */
59 typedef enum
61 LPM_L0 = 0x00, /* on */
62 LPM_L1 = 0x01, /* LPM L1 sleep */
63 LPM_L2 = 0x02, /* suspend */
64 LPM_L3 = 0x03, /* off */
65 } PCD_LPM_StateTypeDef;
67 typedef enum
69 PCD_LPM_L0_ACTIVE = 0x00, /* on */
70 PCD_LPM_L1_ACTIVE = 0x01, /* LPM L1 sleep */
71 } PCD_LPM_MsgTypeDef;
73 typedef enum
75 PCD_BCD_ERROR = 0xFF,
76 PCD_BCD_CONTACT_DETECTION = 0xFE,
77 PCD_BCD_STD_DOWNSTREAM_PORT = 0xFD,
78 PCD_BCD_CHARGING_DOWNSTREAM_PORT = 0xFC,
79 PCD_BCD_DEDICATED_CHARGING_PORT = 0xFB,
80 PCD_BCD_DISCOVERY_COMPLETED = 0x00,
82 } PCD_BCD_MsgTypeDef;
84 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
85 typedef USB_OTG_GlobalTypeDef PCD_TypeDef;
86 typedef USB_OTG_CfgTypeDef PCD_InitTypeDef;
87 typedef USB_OTG_EPTypeDef PCD_EPTypeDef;
88 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
90 /**
91 * @brief PCD Handle Structure definition
93 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
94 typedef struct __PCD_HandleTypeDef
95 #else
96 typedef struct
97 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
99 PCD_TypeDef *Instance; /*!< Register base address */
100 PCD_InitTypeDef Init; /*!< PCD required parameters */
101 __IO uint8_t USB_Address; /*!< USB Address */
102 PCD_EPTypeDef IN_ep[16]; /*!< IN endpoint parameters */
103 PCD_EPTypeDef OUT_ep[16]; /*!< OUT endpoint parameters */
104 HAL_LockTypeDef Lock; /*!< PCD peripheral status */
105 __IO PCD_StateTypeDef State; /*!< PCD communication state */
106 __IO uint32_t ErrorCode; /*!< PCD Error code */
107 uint32_t Setup[12]; /*!< Setup packet buffer */
108 PCD_LPM_StateTypeDef LPM_State; /*!< LPM State */
109 uint32_t BESL;
112 uint32_t lpm_active; /*!< Enable or disable the Link Power Management .
113 This parameter can be set to ENABLE or DISABLE */
115 uint32_t battery_charging_active; /*!< Enable or disable Battery charging.
116 This parameter can be set to ENABLE or DISABLE */
117 void *pData; /*!< Pointer to upper stack Handler */
119 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
120 void (* SOFCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD SOF callback */
121 void (* SetupStageCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Setup Stage callback */
122 void (* ResetCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Reset callback */
123 void (* SuspendCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Suspend callback */
124 void (* ResumeCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Resume callback */
125 void (* ConnectCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Connect callback */
126 void (* DisconnectCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Disconnect callback */
128 void (* DataOutStageCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD Data OUT Stage callback */
129 void (* DataInStageCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD Data IN Stage callback */
130 void (* ISOOUTIncompleteCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD ISO OUT Incomplete callback */
131 void (* ISOINIncompleteCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD ISO IN Incomplete callback */
132 void (* BCDCallback)(struct __PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); /*!< USB OTG PCD BCD callback */
133 void (* LPMCallback)(struct __PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); /*!< USB OTG PCD LPM callback */
135 void (* MspInitCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Msp Init callback */
136 void (* MspDeInitCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Msp DeInit callback */
137 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
138 } PCD_HandleTypeDef;
141 * @}
144 /* Include PCD HAL Extended module */
145 #include "stm32h7xx_hal_pcd_ex.h"
147 /* Exported constants --------------------------------------------------------*/
148 /** @defgroup PCD_Exported_Constants PCD Exported Constants
149 * @{
152 /** @defgroup PCD_Speed PCD Speed
153 * @{
155 #define PCD_SPEED_HIGH USBD_HS_SPEED
156 #define PCD_SPEED_HIGH_IN_FULL USBD_HSINFS_SPEED
157 #define PCD_SPEED_FULL USBD_FS_SPEED
159 * @}
162 /** @defgroup PCD_PHY_Module PCD PHY Module
163 * @{
165 #define PCD_PHY_ULPI 1U
166 #define PCD_PHY_EMBEDDED 2U
167 #define PCD_PHY_UTMI 3U
169 * @}
172 /** @defgroup PCD_Error_Code_definition PCD Error Code definition
173 * @brief PCD Error Code definition
174 * @{
176 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
177 #define HAL_PCD_ERROR_INVALID_CALLBACK (0x00000010U) /*!< Invalid Callback error */
178 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
181 * @}
185 * @}
188 /* Exported macros -----------------------------------------------------------*/
189 /** @defgroup PCD_Exported_Macros PCD Exported Macros
190 * @brief macros to handle interrupts and specific clock configurations
191 * @{
193 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
194 #define __HAL_PCD_ENABLE(__HANDLE__) (void)USB_EnableGlobalInt ((__HANDLE__)->Instance)
195 #define __HAL_PCD_DISABLE(__HANDLE__) (void)USB_DisableGlobalInt ((__HANDLE__)->Instance)
197 #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__))
198 #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->GINTSTS) &= (__INTERRUPT__))
199 #define __HAL_PCD_IS_INVALID_INTERRUPT(__HANDLE__) (USB_ReadInterrupts((__HANDLE__)->Instance) == 0U)
202 #define __HAL_PCD_UNGATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) &= \
203 ~(USB_OTG_PCGCCTL_STOPCLK)
205 #define __HAL_PCD_GATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) |= USB_OTG_PCGCCTL_STOPCLK
207 #define __HAL_PCD_IS_PHY_SUSPENDED(__HANDLE__) ((*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE)) & 0x10U)
209 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT() EXTI_D1->IMR2 |= (USB_OTG_HS_WAKEUP_EXTI_LINE)
210 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_DISABLE_IT() EXTI_D1->IMR2 &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE)
211 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT() EXTI_D1->IMR2 |= (USB_OTG_FS_WAKEUP_EXTI_LINE)
212 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_DISABLE_IT() EXTI_D1->IMR2 &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE)
213 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
217 * @}
220 /* Exported functions --------------------------------------------------------*/
221 /** @addtogroup PCD_Exported_Functions PCD Exported Functions
222 * @{
225 /* Initialization/de-initialization functions ********************************/
226 /** @addtogroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
227 * @{
229 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd);
230 HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd);
231 void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
232 void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
234 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
235 /** @defgroup HAL_PCD_Callback_ID_enumeration_definition HAL USB OTG PCD Callback ID enumeration definition
236 * @brief HAL USB OTG PCD Callback ID enumeration definition
237 * @{
239 typedef enum
241 HAL_PCD_SOF_CB_ID = 0x01, /*!< USB PCD SOF callback ID */
242 HAL_PCD_SETUPSTAGE_CB_ID = 0x02, /*!< USB PCD Setup Stage callback ID */
243 HAL_PCD_RESET_CB_ID = 0x03, /*!< USB PCD Reset callback ID */
244 HAL_PCD_SUSPEND_CB_ID = 0x04, /*!< USB PCD Suspend callback ID */
245 HAL_PCD_RESUME_CB_ID = 0x05, /*!< USB PCD Resume callback ID */
246 HAL_PCD_CONNECT_CB_ID = 0x06, /*!< USB PCD Connect callback ID */
247 HAL_PCD_DISCONNECT_CB_ID = 0x07, /*!< USB PCD Disconnect callback ID */
249 HAL_PCD_MSPINIT_CB_ID = 0x08, /*!< USB PCD MspInit callback ID */
250 HAL_PCD_MSPDEINIT_CB_ID = 0x09 /*!< USB PCD MspDeInit callback ID */
252 } HAL_PCD_CallbackIDTypeDef;
254 * @}
257 /** @defgroup HAL_PCD_Callback_pointer_definition HAL USB OTG PCD Callback pointer definition
258 * @brief HAL USB OTG PCD Callback pointer definition
259 * @{
262 typedef void (*pPCD_CallbackTypeDef)(PCD_HandleTypeDef *hpcd); /*!< pointer to a common USB OTG PCD callback function */
263 typedef void (*pPCD_DataOutStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD Data OUT Stage callback */
264 typedef void (*pPCD_DataInStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD Data IN Stage callback */
265 typedef void (*pPCD_IsoOutIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD ISO OUT Incomplete callback */
266 typedef void (*pPCD_IsoInIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD ISO IN Incomplete callback */
267 typedef void (*pPCD_LpmCallbackTypeDef)(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); /*!< pointer to USB OTG PCD LPM callback */
268 typedef void (*pPCD_BcdCallbackTypeDef)(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); /*!< pointer to USB OTG PCD BCD callback */
271 * @}
274 HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID, pPCD_CallbackTypeDef pCallback);
275 HAL_StatusTypeDef HAL_PCD_UnRegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID);
277 HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd, pPCD_DataOutStageCallbackTypeDef pCallback);
278 HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd);
280 HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd, pPCD_DataInStageCallbackTypeDef pCallback);
281 HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd);
283 HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd, pPCD_IsoOutIncpltCallbackTypeDef pCallback);
284 HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd);
286 HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd, pPCD_IsoInIncpltCallbackTypeDef pCallback);
287 HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd);
289 HAL_StatusTypeDef HAL_PCD_RegisterBcdCallback(PCD_HandleTypeDef *hpcd, pPCD_BcdCallbackTypeDef pCallback);
290 HAL_StatusTypeDef HAL_PCD_UnRegisterBcdCallback(PCD_HandleTypeDef *hpcd);
292 HAL_StatusTypeDef HAL_PCD_RegisterLpmCallback(PCD_HandleTypeDef *hpcd, pPCD_LpmCallbackTypeDef pCallback);
293 HAL_StatusTypeDef HAL_PCD_UnRegisterLpmCallback(PCD_HandleTypeDef *hpcd);
294 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
296 * @}
299 /* I/O operation functions ***************************************************/
300 /* Non-Blocking mode: Interrupt */
301 /** @addtogroup PCD_Exported_Functions_Group2 Input and Output operation functions
302 * @{
304 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd);
305 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd);
306 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
308 void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
309 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
310 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
311 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
312 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
313 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
314 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
316 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
317 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
318 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
319 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
321 * @}
324 /* Peripheral Control functions **********************************************/
325 /** @addtogroup PCD_Exported_Functions_Group3 Peripheral Control functions
326 * @{
328 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd);
329 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd);
330 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address);
331 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type);
332 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
333 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
334 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
335 uint32_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
336 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
337 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
338 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
339 HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
340 HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
342 * @}
345 /* Peripheral State functions ************************************************/
346 /** @addtogroup PCD_Exported_Functions_Group4 Peripheral State functions
347 * @{
349 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd);
351 * @}
355 * @}
358 /* Private constants ---------------------------------------------------------*/
359 /** @defgroup PCD_Private_Constants PCD Private Constants
360 * @{
362 /** @defgroup USB_EXTI_Line_Interrupt USB EXTI line interrupt
363 * @{
365 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
366 #define USB_OTG_FS_WAKEUP_EXTI_LINE (0x1U << 12) /*!< USB FS EXTI Line WakeUp Interrupt */
367 #define USB_OTG_HS_WAKEUP_EXTI_LINE (0x1U << 11) /*!< USB HS EXTI Line WakeUp Interrupt */
368 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
372 * @}
375 * @}
378 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
379 #ifndef USB_OTG_DOEPINT_OTEPSPR
380 #define USB_OTG_DOEPINT_OTEPSPR (0x1UL << 5) /*!< Status Phase Received interrupt */
381 #endif
383 #ifndef USB_OTG_DOEPMSK_OTEPSPRM
384 #define USB_OTG_DOEPMSK_OTEPSPRM (0x1UL << 5) /*!< Setup Packet Received interrupt mask */
385 #endif
387 #ifndef USB_OTG_DOEPINT_NAK
388 #define USB_OTG_DOEPINT_NAK (0x1UL << 13) /*!< NAK interrupt */
389 #endif
391 #ifndef USB_OTG_DOEPMSK_NAKM
392 #define USB_OTG_DOEPMSK_NAKM (0x1UL << 13) /*!< OUT Packet NAK interrupt mask */
393 #endif
395 #ifndef USB_OTG_DOEPINT_STPKTRX
396 #define USB_OTG_DOEPINT_STPKTRX (0x1UL << 15) /*!< Setup Packet Received interrupt */
397 #endif
399 #ifndef USB_OTG_DOEPMSK_NYETM
400 #define USB_OTG_DOEPMSK_NYETM (0x1UL << 14) /*!< Setup Packet Received interrupt mask */
401 #endif
402 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
404 /* Private macros ------------------------------------------------------------*/
405 /** @defgroup PCD_Private_Macros PCD Private Macros
406 * @{
410 * @}
414 * @}
418 * @}
420 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
422 #ifdef __cplusplus
424 #endif
426 #endif /* STM32H7xx_HAL_PCD_H */
428 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/