Merge maintenance-8.x.x fixes into master
[inav.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Inc / stm32h7xx_hal_opamp.h
blob60b39bcb94130eb517055943e15a94607e847245
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_opamp.h
4 * @author MCD Application Team
5 * @brief Header file of OPAMP HAL module.
6 ******************************************************************************
7 * @attention
9 * Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
16 ******************************************************************************
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32H7xx_HAL_OPAMP_H
21 #define STM32H7xx_HAL_OPAMP_H
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h7xx_hal_def.h"
30 /** @addtogroup STM32H7xx_HAL_Driver
31 * @{
34 /** @addtogroup OPAMP
35 * @{
36 */
38 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup OPAMP_Exported_Types OPAMP Exported Types
41 * @{
44 /**
45 * @brief OPAMP Init structure definition
48 typedef struct
51 uint32_t PowerMode; /*!< Specifies the power mode Normal or High Speed.
52 This parameter must be a value of @ref OPAMP_PowerMode */
54 uint32_t Mode; /*!< Specifies the OPAMP mode
55 This parameter must be a value of @ref OPAMP_Mode
56 mode is either Standalone, - Follower or PGA */
58 uint32_t InvertingInput; /*!< Specifies the inverting input in Standalone & PGA modes
59 - In Standalone mode i.e when mode is OPAMP_STANDALONE_MODE
60 This parameter must be a value of @ref OPAMP_InvertingInput
61 - In Follower mode i.e when mode is OPAMP_FOLLOWER_MODE
62 & In PGA mode i.e when mode is OPAMP_PGA_MODE
63 This parameter is Not Applicable */
65 uint32_t NonInvertingInput; /*!< Specifies the non inverting input of the opamp:
66 This parameter must be a value of @ref OPAMP_NonInvertingInput */
68 uint32_t PgaGain; /*!< Specifies the gain in PGA mode
69 i.e. when mode is OPAMP_PGA_MODE.
70 This parameter must be a value of @ref OPAMP_PgaGain */
72 uint32_t PgaConnect; /*!< Specifies the inverting pin in PGA mode
73 i.e. when mode is OPAMP_PGA_MODE
74 This parameter must be a value of @ref OPAMP_PgaConnect
75 Either: not connected, connected to VINM0, connected to VINM1
76 (VINM0 or VINM1 are typically used for external filtering) */
78 uint32_t UserTrimming; /*!< Specifies the trimming mode
79 This parameter must be a value of @ref OPAMP_UserTrimming
80 UserTrimming is either factory or user trimming.*/
82 uint32_t TrimmingValueP; /*!< Specifies the offset trimming value (PMOS) in Normal Mode
83 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
84 This parameter must be a number between Min_Data = 0 and Max_Data = 31.
85 16 is typical default value */
87 uint32_t TrimmingValueN; /*!< Specifies the offset trimming value (NMOS) in Normal Mode
88 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
89 This parameter must be a number between Min_Data = 0 and Max_Data = 31.
90 16 is typical default value */
92 uint32_t TrimmingValuePHighSpeed; /*!< Specifies the offset trimming value (PMOS) in High Speed Mode
93 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
94 This parameter must be a number between Min_Data = 0 and Max_Data = 31.
95 16 is typical default value */
97 uint32_t TrimmingValueNHighSpeed; /*!< Specifies the offset trimming value (NMOS) in High Speed Mode
98 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
99 This parameter must be a number between Min_Data = 0 and Max_Data = 31.
100 16 is typical default value */
102 }OPAMP_InitTypeDef;
104 /**
105 * @brief HAL State structures definition
108 typedef enum
110 HAL_OPAMP_STATE_RESET = 0x00000000U, /*!< OPAMP is not yet Initialized */
112 HAL_OPAMP_STATE_READY = 0x00000001U, /*!< OPAMP is initialized and ready for use */
113 HAL_OPAMP_STATE_CALIBBUSY = 0x00000002U, /*!< OPAMP is enabled in auto calibration mode */
115 HAL_OPAMP_STATE_BUSY = 0x00000004U, /*!< OPAMP is enabled and running in normal mode */
116 HAL_OPAMP_STATE_BUSYLOCKED = 0x00000005U /*!< OPAMP is locked
117 only system reset allows reconfiguring the opamp. */
119 }HAL_OPAMP_StateTypeDef;
121 /**
122 * @brief OPAMP Handle Structure definition
124 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
125 typedef struct __OPAMP_HandleTypeDef
126 #else
127 typedef struct
128 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
130 OPAMP_TypeDef *Instance; /*!< OPAMP instance's registers base address */
131 OPAMP_InitTypeDef Init; /*!< OPAMP required parameters */
132 HAL_StatusTypeDef Status; /*!< OPAMP peripheral status */
133 HAL_LockTypeDef Lock; /*!< Locking object */
134 __IO HAL_OPAMP_StateTypeDef State; /*!< OPAMP communication state */
136 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
137 void (* MspInitCallback) (struct __OPAMP_HandleTypeDef *hopamp);
138 void (* MspDeInitCallback) (struct __OPAMP_HandleTypeDef *hopamp);
139 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
140 } OPAMP_HandleTypeDef;
142 /**
143 * @brief HAl_OPAMP_TrimmingValueTypeDef definition
146 typedef uint32_t HAL_OPAMP_TrimmingValueTypeDef;
148 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
150 * @brief HAL OPAMP Callback ID enumeration definition
152 typedef enum
154 HAL_OPAMP_MSPINIT_CB_ID = 0x01U, /*!< OPAMP MspInit Callback ID */
155 HAL_OPAMP_MSPDEINIT_CB_ID = 0x02U, /*!< OPAMP MspDeInit Callback ID */
156 HAL_OPAMP_ALL_CB_ID = 0x03U /*!< OPAMP All ID */
157 }HAL_OPAMP_CallbackIDTypeDef;
160 * @brief HAL OPAMP Callback pointer definition
162 typedef void (*pOPAMP_CallbackTypeDef)(OPAMP_HandleTypeDef *hopamp);
163 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
165 * @}
168 /* Exported constants --------------------------------------------------------*/
169 /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants
170 * @{
173 /** @defgroup OPAMP_Mode OPAMP Mode
174 * @{
176 #define OPAMP_STANDALONE_MODE 0x00000000U /*!< standalone mode */
177 #define OPAMP_PGA_MODE OPAMP_CSR_VMSEL_1 /*!< PGA mode */
178 #define OPAMP_FOLLOWER_MODE (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< follower mode */
181 * @}
184 /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input
185 * @{
188 #define OPAMP_NONINVERTINGINPUT_IO0 0x00000000U /*!< OPAMP non-inverting input connected to dedicated IO pin */
189 #define OPAMP_NONINVERTINGINPUT_DAC_CH OPAMP_CSR_VPSEL_0 /*!< OPAMP non-inverting input connected internally to DAC channel */
190 #if defined(DAC2)
191 #define OPAMP_NONINVERTINGINPUT_DAC2_CH OPAMP_CSR_VPSEL_1 /*!< Only OPAMP2 non-inverting input connected internally to DAC2 channel */
192 #endif /* DAC2 */
195 * @}
198 /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input
199 * @{
202 #define OPAMP_INVERTINGINPUT_IO0 0x00000000U /*!< OPAMP inverting input connected to dedicated IO pin */
203 #define OPAMP_INVERTINGINPUT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to dedicated IO pin */
206 * @}
209 /** @defgroup OPAMP_PgaConnect OPAMP Pga Connect
210 * @{
213 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_NO 0x00000000U /*!< In PGA mode, the inverting input is not connected */
214 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0 OPAMP_CSR_PGGAIN_2 /*!< In PGA mode, the inverting input is connected to VINM0 */
215 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS OPAMP_CSR_PGGAIN_3 /*!< In PGA mode, the inverting input is connected to VINM0 or bias */
216 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_IO1_BIAS (OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_3) /*!< In PGA mode, the inverting input is connected to VINM0 or bias , VINM1 connected for filtering */
220 * @}
223 /** @defgroup OPAMP_PgaGain OPAMP Pga Gain
224 * @{
227 #define OPAMP_PGA_GAIN_2_OR_MINUS_1 0x00000000U /*!< PGA gain could be 2 or -1 */
228 #define OPAMP_PGA_GAIN_4_OR_MINUS_3 OPAMP_CSR_PGGAIN_0 /*!< PGA gain could be 4 or -3 */
229 #define OPAMP_PGA_GAIN_8_OR_MINUS_7 OPAMP_CSR_PGGAIN_1 /*!< PGA gain could be 8 or -7 */
230 #define OPAMP_PGA_GAIN_16_OR_MINUS_15 (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1) /*!< PGA gain could be 16 or -15 */
233 * @}
236 /** @defgroup OPAMP_PowerMode OPAMP PowerMode
237 * @{
239 #define OPAMP_POWERMODE_NORMAL 0x00000000U
240 #define OPAMP_POWERMODE_HIGHSPEED OPAMP_CSR_OPAHSM
243 * @}
247 /** @defgroup OPAMP_VREF OPAMP VREF
248 * @{
251 #define OPAMP_VREF_3VDDA 0x00000000U /*!< OPAMP Vref = 3.3% VDDA */
252 #define OPAMP_VREF_10VDDA OPAMP_CSR_CALSEL_0 /*!< OPAMP Vref = 10% VDDA */
253 #define OPAMP_VREF_50VDDA OPAMP_CSR_CALSEL_1 /*!< OPAMP Vref = 50% VDDA */
254 #define OPAMP_VREF_90VDDA OPAMP_CSR_CALSEL /*!< OPAMP Vref = 90% VDDA */
257 * @}
260 /** @defgroup OPAMP_UserTrimming OPAMP User Trimming
261 * @{
263 #define OPAMP_TRIMMING_FACTORY 0x00000000U /*!< Factory trimming */
264 #define OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< User trimming */
268 * @}
271 /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming
272 * @{
274 #define OPAMP_FACTORYTRIMMING_DUMMY 0xFFFFFFFFU /*!< Dummy value if trimming value could not be retrieved */
276 #define OPAMP_FACTORYTRIMMING_N 0x00000000U /*!< Offset trimming N */
277 #define OPAMP_FACTORYTRIMMING_P 0x00000001U /*!< Offset trimming P */
280 * @}
284 * @}
287 /* Private constants ---------------------------------------------------------*/
288 /** @defgroup OPAMP_Private_Constants OPAMP Private Constants
289 * @brief OPAMP Private constants and defines
290 * @{
293 /* NONINVERTING bit position in OTR & HSOTR */
294 #define OPAMP_INPUT_NONINVERTING (8U) /*!< Non inverting input */
296 /* Offset trimming time: during calibration, minimum time needed between two */
297 /* steps to have 1 mV accuracy. */
298 /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=2ms.*/
299 /* Unit: ms. */
300 #define OPAMP_TRIMMING_DELAY (2U)
303 * @}
306 /* Exported macros -----------------------------------------------------------*/
307 /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros
308 * @{
311 /** @brief Reset OPAMP handle state.
312 * @param __HANDLE__: OPAMP handle.
313 * @retval None
315 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET)
318 * @}
321 /* Private macro -------------------------------------------------------------*/
323 /** @defgroup OPAMP_Private_Macros OPAMP Private Macros
324 * @{
327 #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \
328 ((INPUT) == OPAMP_PGA_MODE) || \
329 ((INPUT) == OPAMP_FOLLOWER_MODE))
331 #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
332 ((INPUT) == OPAMP_INVERTINGINPUT_IO1))
334 #if defined(DAC2)
335 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
336 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH) || \
337 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC2_CH))
338 #else
339 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
340 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH))
341 #endif /* DAC2 */
343 #define IS_OPAMP_PGACONNECT(CONNECT) (((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_NO) || \
344 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0) || \
345 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS) || \
346 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_IO1_BIAS))
348 #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2_OR_MINUS_1) || \
349 ((GAIN) == OPAMP_PGA_GAIN_4_OR_MINUS_3) || \
350 ((GAIN) == OPAMP_PGA_GAIN_8_OR_MINUS_7) || \
351 ((GAIN) == OPAMP_PGA_GAIN_16_OR_MINUS_15))
354 #define IS_OPAMP_VREF(VREF) (((VREF) == OPAMP_VREF_3VDDA) || \
355 ((VREF) == OPAMP_VREF_10VDDA) || \
356 ((VREF) == OPAMP_VREF_50VDDA) || \
357 ((VREF) == OPAMP_VREF_90VDDA))
359 #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMAL) || \
360 ((TRIMMING) == OPAMP_POWERMODE_HIGHSPEED) )
363 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \
364 ((TRIMMING) == OPAMP_TRIMMING_USER))
367 #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1FU)
369 #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \
370 ((TRIMMING) == OPAMP_FACTORYTRIMMING_P))
373 * @}
376 /* Include OPAMP HAL Extended module */
377 #include "stm32h7xx_hal_opamp_ex.h"
379 /* Exported functions --------------------------------------------------------*/
380 /** @addtogroup OPAMP_Exported_Functions
381 * @{
384 /** @addtogroup OPAMP_Exported_Functions_Group1
385 * @{
387 /* Initialization/de-initialization functions **********************************/
388 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp);
389 HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp);
390 void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp);
391 void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp);
393 * @}
396 /** @addtogroup OPAMP_Exported_Functions_Group2
397 * @{
400 /* I/O operation functions *****************************************************/
401 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp);
402 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp);
403 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp);
406 * @}
409 /** @addtogroup OPAMP_Exported_Functions_Group3
410 * @{
413 /* Peripheral Control functions ************************************************/
414 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
415 /* OPAMP callback registering/unregistering */
416 HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId, pOPAMP_CallbackTypeDef pCallback);
417 HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId);
418 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
419 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp);
420 HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (const OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset);
423 * @}
426 /** @addtogroup OPAMP_Exported_Functions_Group4
427 * @{
430 /* Peripheral State functions **************************************************/
431 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(const OPAMP_HandleTypeDef *hopamp);
434 * @}
438 * @}
442 * @}
446 * @}
449 #ifdef __cplusplus
451 #endif
453 #endif /* STM32H7xx_HAL_OPAMP_H */