Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / lib / main / STM32F4 / Drivers / STM32F4xx_HAL_Driver / Inc / stm32f4xx_hal_pcd.h
blobb4a825f39b7fadf480c820e6527cb86bdb79610a
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_hal_pcd.h
4 * @author MCD Application Team
5 * @version V1.7.1
6 * @date 14-April-2017
7 * @brief Header file of PCD HAL module.
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
36 */
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_PCD_H
40 #define __STM32F4xx_HAL_PCD_H
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || \
46 defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
47 defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) || \
48 defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
49 defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
50 /* Includes ------------------------------------------------------------------*/
51 #include "stm32f4xx_ll_usb.h"
53 /** @addtogroup STM32F4xx_HAL_Driver
54 * @{
57 /** @addtogroup PCD
58 * @{
59 */
61 /* Exported types ------------------------------------------------------------*/
62 /** @defgroup PCD_Exported_Types PCD Exported Types
63 * @{
66 /**
67 * @brief PCD State structure definition
69 typedef enum
71 HAL_PCD_STATE_RESET = 0x00U,
72 HAL_PCD_STATE_READY = 0x01U,
73 HAL_PCD_STATE_ERROR = 0x02U,
74 HAL_PCD_STATE_BUSY = 0x03U,
75 HAL_PCD_STATE_TIMEOUT = 0x04U
76 } PCD_StateTypeDef;
78 #ifdef USB_OTG_GLPMCFG_LPMEN
79 /* Device LPM suspend state */
80 typedef enum
82 LPM_L0 = 0x00U, /* on */
83 LPM_L1 = 0x01U, /* LPM L1 sleep */
84 LPM_L2 = 0x02U, /* suspend */
85 LPM_L3 = 0x03U /* off */
86 }PCD_LPM_StateTypeDef;
87 #endif /* USB_OTG_GLPMCFG_LPMEN */
89 typedef USB_OTG_GlobalTypeDef PCD_TypeDef;
90 typedef USB_OTG_CfgTypeDef PCD_InitTypeDef;
91 typedef USB_OTG_EPTypeDef PCD_EPTypeDef ;
93 /**
94 * @brief PCD Handle Structure definition
95 */
96 typedef struct
98 PCD_TypeDef *Instance; /*!< Register base address */
99 PCD_InitTypeDef Init; /*!< PCD required parameters */
100 PCD_EPTypeDef IN_ep[16U]; /*!< IN endpoint parameters */
101 PCD_EPTypeDef OUT_ep[16U]; /*!< OUT endpoint parameters */
102 HAL_LockTypeDef Lock; /*!< PCD peripheral status */
103 __IO PCD_StateTypeDef State; /*!< PCD communication state */
104 uint32_t Setup[12U]; /*!< Setup packet buffer */
105 #ifdef USB_OTG_GLPMCFG_LPMEN
106 PCD_LPM_StateTypeDef LPM_State; /*!< LPM State */
107 uint32_t BESL;
108 uint32_t lpm_active; /*!< Enable or disable the Link Power Management .
109 This parameter can be set to ENABLE or DISABLE */
110 #endif /* USB_OTG_GLPMCFG_LPMEN */
111 #ifdef USB_OTG_GCCFG_BCDEN
112 uint32_t battery_charging_active; /*!< Enable or disable Battery charging.
113 This parameter can be set to ENABLE or DISABLE */
114 #endif /* USB_OTG_GCCFG_BCDEN */
115 void *pData; /*!< Pointer to upper stack Handler */
116 } PCD_HandleTypeDef;
119 * @}
122 /* Include PCD HAL Extension module */
123 #include "stm32f4xx_hal_pcd_ex.h"
125 /* Exported constants --------------------------------------------------------*/
126 /** @defgroup PCD_Exported_Constants PCD Exported Constants
127 * @{
130 /** @defgroup PCD_Speed PCD Speed
131 * @{
133 #define PCD_SPEED_HIGH 0U
134 #define PCD_SPEED_HIGH_IN_FULL 1U
135 #define PCD_SPEED_FULL 2U
137 * @}
140 /** @defgroup PCD_PHY_Module PCD PHY Module
141 * @{
143 #define PCD_PHY_ULPI 1U
144 #define PCD_PHY_EMBEDDED 2U
146 * @}
149 /** @defgroup PCD_Turnaround_Timeout Turnaround Timeout Value
150 * @{
152 #ifndef USBD_HS_TRDT_VALUE
153 #define USBD_HS_TRDT_VALUE 9U
154 #endif /* USBD_HS_TRDT_VALUE */
155 #ifndef USBD_FS_TRDT_VALUE
156 #define USBD_FS_TRDT_VALUE 5U
157 #endif /* USBD_FS_TRDT_VALUE */
159 * @}
163 * @}
166 /* Exported macros -----------------------------------------------------------*/
167 /** @defgroup PCD_Exported_Macros PCD Exported Macros
168 * @brief macros to handle interrupts and specific clock configurations
169 * @{
171 #define __HAL_PCD_ENABLE(__HANDLE__) USB_EnableGlobalInt ((__HANDLE__)->Instance)
172 #define __HAL_PCD_DISABLE(__HANDLE__) USB_DisableGlobalInt ((__HANDLE__)->Instance)
174 #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__))
175 #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->GINTSTS) &= (__INTERRUPT__))
176 #define __HAL_PCD_IS_INVALID_INTERRUPT(__HANDLE__) (USB_ReadInterrupts((__HANDLE__)->Instance) == 0U)
178 #define __HAL_PCD_UNGATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) &= \
179 ~(USB_OTG_PCGCCTL_STOPCLK)
181 #define __HAL_PCD_GATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) |= USB_OTG_PCGCCTL_STOPCLK
183 #define __HAL_PCD_IS_PHY_SUSPENDED(__HANDLE__) ((*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE))&0x10U)
185 #define USB_OTG_FS_WAKEUP_EXTI_RISING_EDGE 0x08U
186 #define USB_OTG_FS_WAKEUP_EXTI_FALLING_EDGE 0x0CU
187 #define USB_OTG_FS_WAKEUP_EXTI_RISING_FALLING_EDGE 0x10U
189 #define USB_OTG_HS_WAKEUP_EXTI_RISING_EDGE 0x08U
190 #define USB_OTG_HS_WAKEUP_EXTI_FALLING_EDGE 0x0CU
191 #define USB_OTG_HS_WAKEUP_EXTI_RISING_FALLING_EDGE 0x10U
193 #define USB_OTG_HS_WAKEUP_EXTI_LINE 0x00100000U /*!< External interrupt line 20 Connected to the USB HS EXTI Line */
194 #define USB_OTG_FS_WAKEUP_EXTI_LINE 0x00040000U /*!< External interrupt line 18 Connected to the USB FS EXTI Line */
196 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= (USB_OTG_HS_WAKEUP_EXTI_LINE)
197 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE)
198 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_HS_WAKEUP_EXTI_LINE)
199 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = (USB_OTG_HS_WAKEUP_EXTI_LINE)
201 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_EDGE() do{EXTI->FTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE);\
202 EXTI->RTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE;\
203 }while(0U)
205 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_FALLING_EDGE() do{EXTI->FTSR |= (USB_OTG_HS_WAKEUP_EXTI_LINE);\
206 EXTI->RTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE);\
207 }while(0U)
209 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_FALLING_EDGE() do{EXTI->RTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE);\
210 EXTI->FTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE);\
211 EXTI->RTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE;\
212 EXTI->FTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE;\
213 }while(0U)
215 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_GENERATE_SWIT() (EXTI->SWIER |= USB_OTG_FS_WAKEUP_EXTI_LINE)
217 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= USB_OTG_FS_WAKEUP_EXTI_LINE
218 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE)
219 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_FS_WAKEUP_EXTI_LINE)
220 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = USB_OTG_FS_WAKEUP_EXTI_LINE
222 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE() do{EXTI->FTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE);\
223 EXTI->RTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE;\
224 }while(0U)
226 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_FALLING_EDGE() do{EXTI->FTSR |= (USB_OTG_FS_WAKEUP_EXTI_LINE);\
227 EXTI->RTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE);\
228 }while(0U)
230 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_FALLING_EDGE() do{EXTI->RTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE);\
231 EXTI->FTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE);\
232 EXTI->RTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE;\
233 EXTI->FTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE;\
234 }while(0U)
236 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_GENERATE_SWIT() (EXTI->SWIER |= USB_OTG_FS_WAKEUP_EXTI_LINE)
238 * @}
241 /* Exported functions --------------------------------------------------------*/
242 /** @addtogroup PCD_Exported_Functions PCD Exported Functions
243 * @{
246 /* Initialization/de-initialization functions ********************************/
247 /** @addtogroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
248 * @{
250 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd);
251 HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd);
252 void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
253 void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
255 * @}
258 /* I/O operation functions ***************************************************/
259 /* Non-Blocking mode: Interrupt */
260 /** @addtogroup PCD_Exported_Functions_Group2 Input and Output operation functions
261 * @{
263 /* Non-Blocking mode: Interrupt */
264 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd);
265 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd);
266 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
268 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
269 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
270 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
271 void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
272 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
273 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
274 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
275 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
276 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
277 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
278 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
280 * @}
283 /* Peripheral Control functions **********************************************/
284 /** @addtogroup PCD_Exported_Functions_Group3 Peripheral Control functions
285 * @{
287 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd);
288 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd);
289 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address);
290 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type);
291 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
292 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
293 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
294 uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
295 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
296 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
297 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
298 HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
299 HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
301 * @}
304 /* Peripheral State functions ************************************************/
305 /** @addtogroup PCD_Exported_Functions_Group4 Peripheral State functions
306 * @{
308 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd);
310 * @}
314 * @}
317 /* Private macros ------------------------------------------------------------*/
318 /** @defgroup PCD_Private_Macros PCD Private Macros
319 * @{
323 * @}
327 * @}
331 * @}
333 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||
334 STM32F401xC || STM32F401xE || STM32F411xE || STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Rx ||
335 STM32F412Vx || STM32F412Cx || STM32F413xx || STM32F423xx */
336 #ifdef __cplusplus
338 #endif
341 #endif /* __STM32F4xx_HAL_PCD_H */
343 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/