Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32G4 / Drivers / STM32G4xx_HAL_Driver / Inc / stm32g4xx_hal_rng.h
blob0868a06a20788ab88161259f7411fe7e32d8cdec
1 /**
2 ******************************************************************************
3 * @file stm32g4xx_hal_rng.h
4 * @author MCD Application Team
5 * @brief Header file of RNG HAL module.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; Copyright (c) 2018 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 STM32G4xx_HAL_RNG_H
22 #define STM32G4xx_HAL_RNG_H
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32g4xx_hal_def.h"
31 /** @addtogroup STM32G4xx_HAL_Driver
32 * @{
35 #if defined (RNG)
37 /** @defgroup RNG RNG
38 * @brief RNG HAL module driver
39 * @{
42 /* Exported types ------------------------------------------------------------*/
44 /** @defgroup RNG_Exported_Types RNG Exported Types
45 * @{
48 /** @defgroup RNG_Exported_Types_Group1 RNG Init Structure definition
49 * @{
51 typedef struct
53 uint32_t ClockErrorDetection; /*!< CED Clock error detection */
54 } RNG_InitTypeDef;
56 /**
57 * @}
60 /** @defgroup RNG_Exported_Types_Group2 RNG State Structure definition
61 * @{
63 typedef enum
65 HAL_RNG_STATE_RESET = 0x00U, /*!< RNG not yet initialized or disabled */
66 HAL_RNG_STATE_READY = 0x01U, /*!< RNG initialized and ready for use */
67 HAL_RNG_STATE_BUSY = 0x02U, /*!< RNG internal process is ongoing */
68 HAL_RNG_STATE_TIMEOUT = 0x03U, /*!< RNG timeout state */
69 HAL_RNG_STATE_ERROR = 0x04U /*!< RNG error state */
71 } HAL_RNG_StateTypeDef;
73 /**
74 * @}
77 /** @defgroup RNG_Exported_Types_Group3 RNG Handle Structure definition
78 * @{
80 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
81 typedef struct __RNG_HandleTypeDef
82 #else
83 typedef struct
84 #endif /* (USE_HAL_RNG_REGISTER_CALLBACKS) */
86 RNG_TypeDef *Instance; /*!< Register base address */
88 RNG_InitTypeDef Init; /*!< RNG configuration parameters */
90 HAL_LockTypeDef Lock; /*!< RNG locking object */
92 __IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */
94 __IO uint32_t ErrorCode; /*!< RNG Error code */
96 uint32_t RandomNumber; /*!< Last Generated RNG Data */
98 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
99 void (* ReadyDataCallback)(struct __RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< RNG Data Ready Callback */
100 void (* ErrorCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Error Callback */
102 void (* MspInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp Init callback */
103 void (* MspDeInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp DeInit callback */
104 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
106 } RNG_HandleTypeDef;
108 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
110 * @brief HAL RNG Callback ID enumeration definition
112 typedef enum
114 HAL_RNG_ERROR_CB_ID = 0x00U, /*!< RNG Error Callback ID */
116 HAL_RNG_MSPINIT_CB_ID = 0x01U, /*!< RNG MspInit callback ID */
117 HAL_RNG_MSPDEINIT_CB_ID = 0x02U /*!< RNG MspDeInit callback ID */
119 } HAL_RNG_CallbackIDTypeDef;
122 * @brief HAL RNG Callback pointer definition
124 typedef void (*pRNG_CallbackTypeDef)(RNG_HandleTypeDef *hrng); /*!< pointer to a common RNG callback function */
125 typedef void (*pRNG_ReadyDataCallbackTypeDef)(RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< pointer to an RNG Data Ready specific callback function */
127 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
130 * @}
134 * @}
137 /* Exported constants --------------------------------------------------------*/
138 /** @defgroup RNG_Exported_Constants RNG Exported Constants
139 * @{
142 /** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition
143 * @{
145 #define RNG_IT_DRDY RNG_SR_DRDY /*!< Data Ready interrupt */
146 #define RNG_IT_CEI RNG_SR_CEIS /*!< Clock error interrupt */
147 #define RNG_IT_SEI RNG_SR_SEIS /*!< Seed error interrupt */
149 * @}
152 /** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition
153 * @{
155 #define RNG_FLAG_DRDY RNG_SR_DRDY /*!< Data ready */
156 #define RNG_FLAG_CECS RNG_SR_CECS /*!< Clock error current status */
157 #define RNG_FLAG_SECS RNG_SR_SECS /*!< Seed error current status */
159 * @}
162 /** @defgroup RNG_Exported_Constants_Group3 RNG Clock Error Detection
163 * @{
165 #define RNG_CED_ENABLE 0x00000000U /*!< Clock error detection Enabled */
166 #define RNG_CED_DISABLE RNG_CR_CED /*!< Clock error detection Disabled */
168 * @}
171 /** @defgroup RNG_Error_Definition RNG Error Definition
172 * @{
174 #define HAL_RNG_ERROR_NONE 0x00000000U /*!< No error */
175 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
176 #define HAL_RNG_ERROR_INVALID_CALLBACK 0x00000001U /*!< Invalid Callback error */
177 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
178 #define HAL_RNG_ERROR_TIMEOUT 0x00000002U /*!< Timeout error */
181 * @}
185 * @}
188 /* Exported macros -----------------------------------------------------------*/
189 /** @defgroup RNG_Exported_Macros RNG Exported Macros
190 * @{
193 /** @brief Reset RNG handle state
194 * @param __HANDLE__ RNG Handle
195 * @retval None
197 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
198 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) do{ \
199 (__HANDLE__)->State = HAL_RNG_STATE_RESET; \
200 (__HANDLE__)->MspInitCallback = NULL; \
201 (__HANDLE__)->MspDeInitCallback = NULL; \
202 } while(0U)
203 #else
204 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET)
205 #endif /*USE_HAL_RNG_REGISTER_CALLBACKS */
208 * @brief Enables the RNG peripheral.
209 * @param __HANDLE__ RNG Handle
210 * @retval None
212 #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN)
215 * @brief Disables the RNG peripheral.
216 * @param __HANDLE__ RNG Handle
217 * @retval None
219 #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN)
222 * @brief Check the selected RNG flag status.
223 * @param __HANDLE__ RNG Handle
224 * @param __FLAG__ RNG flag
225 * This parameter can be one of the following values:
226 * @arg RNG_FLAG_DRDY: Data ready
227 * @arg RNG_FLAG_CECS: Clock error current status
228 * @arg RNG_FLAG_SECS: Seed error current status
229 * @retval The new state of __FLAG__ (SET or RESET).
231 #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
234 * @brief Clears the selected RNG flag status.
235 * @param __HANDLE__ RNG handle
236 * @param __FLAG__ RNG flag to clear
237 * @note WARNING: This is a dummy macro for HAL code alignment,
238 * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only.
239 * @retval None
241 #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */
244 * @brief Enables the RNG interrupts.
245 * @param __HANDLE__ RNG Handle
246 * @retval None
248 #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE)
251 * @brief Disables the RNG interrupts.
252 * @param __HANDLE__ RNG Handle
253 * @retval None
255 #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE)
258 * @brief Checks whether the specified RNG interrupt has occurred or not.
259 * @param __HANDLE__ RNG Handle
260 * @param __INTERRUPT__ specifies the RNG interrupt status flag to check.
261 * This parameter can be one of the following values:
262 * @arg RNG_IT_DRDY: Data ready interrupt
263 * @arg RNG_IT_CEI: Clock error interrupt
264 * @arg RNG_IT_SEI: Seed error interrupt
265 * @retval The new state of __INTERRUPT__ (SET or RESET).
267 #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
270 * @brief Clear the RNG interrupt status flags.
271 * @param __HANDLE__ RNG Handle
272 * @param __INTERRUPT__ specifies the RNG interrupt status flag to clear.
273 * This parameter can be one of the following values:
274 * @arg RNG_IT_CEI: Clock error interrupt
275 * @arg RNG_IT_SEI: Seed error interrupt
276 * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY.
277 * @retval None
279 #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__))
282 * @}
285 /* Exported functions --------------------------------------------------------*/
286 /** @defgroup RNG_Exported_Functions RNG Exported Functions
287 * @{
290 /** @defgroup RNG_Exported_Functions_Group1 Initialization and configuration functions
291 * @{
293 HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng);
294 HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng);
295 void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng);
296 void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng);
298 /* Callbacks Register/UnRegister functions ***********************************/
299 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
300 HAL_StatusTypeDef HAL_RNG_RegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID, pRNG_CallbackTypeDef pCallback);
301 HAL_StatusTypeDef HAL_RNG_UnRegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID);
303 HAL_StatusTypeDef HAL_RNG_RegisterReadyDataCallback(RNG_HandleTypeDef *hrng, pRNG_ReadyDataCallbackTypeDef pCallback);
304 HAL_StatusTypeDef HAL_RNG_UnRegisterReadyDataCallback(RNG_HandleTypeDef *hrng);
305 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
308 * @}
311 /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions
312 * @{
314 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit);
315 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng);
316 uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng);
318 void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng);
319 void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng);
320 void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit);
323 * @}
326 /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions
327 * @{
329 HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng);
330 uint32_t HAL_RNG_GetError(RNG_HandleTypeDef *hrng);
332 * @}
336 * @}
339 /* Private macros ------------------------------------------------------------*/
340 /** @defgroup RNG_Private_Macros RNG Private Macros
341 * @{
343 #define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \
344 ((IT) == RNG_IT_SEI))
346 #define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \
347 ((FLAG) == RNG_FLAG_CECS) || \
348 ((FLAG) == RNG_FLAG_SECS))
351 * @brief Verify the RNG Clock Error Detection mode.
352 * @param __MODE__ RNG Clock Error Detection mode
353 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
355 #define IS_RNG_CED(__MODE__) (((__MODE__) == RNG_CED_ENABLE) || \
356 ((__MODE__) == RNG_CED_DISABLE))
358 * @}
362 * @}
365 #endif /* RNG */
368 * @}
371 #ifdef __cplusplus
373 #endif
376 #endif /* STM32G4xx_HAL_RNG_H */
378 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/