Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Inc / stm32h7xx_hal_opamp.h
blob006ff5ab75644cda4ede2429acf01ced4fc160ca
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 * <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_OPAMP_H
22 #define STM32H7xx_HAL_OPAMP_H
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx_hal_def.h"
31 /** @addtogroup STM32H7xx_HAL_Driver
32 * @{
35 /** @addtogroup OPAMP
36 * @{
37 */
39 /* Exported types ------------------------------------------------------------*/
41 /** @defgroup OPAMP_Exported_Types OPAMP Exported Types
42 * @{
45 /**
46 * @brief OPAMP Init structure definition
49 typedef struct
52 uint32_t PowerMode; /*!< Specifies the power mode Normal or High Speed.
53 This parameter must be a value of @ref OPAMP_PowerMode */
55 uint32_t Mode; /*!< Specifies the OPAMP mode
56 This parameter must be a value of @ref OPAMP_Mode
57 mode is either Standalone, - Follower or PGA */
59 uint32_t InvertingInput; /*!< Specifies the inverting input in Standalone & PGA modes
60 - In Standalone mode i.e when mode is OPAMP_STANDALONE_MODE
61 This parameter must be a value of @ref OPAMP_InvertingInput
62 - In Follower mode i.e when mode is OPAMP_FOLLOWER_MODE
63 & In PGA mode i.e when mode is OPAMP_PGA_MODE
64 This parameter is Not Applicable */
66 uint32_t NonInvertingInput; /*!< Specifies the non inverting input of the opamp:
67 This parameter must be a value of @ref OPAMP_NonInvertingInput */
69 uint32_t PgaGain; /*!< Specifies the gain in PGA mode
70 i.e. when mode is OPAMP_PGA_MODE.
71 This parameter must be a value of @ref OPAMP_PgaGain */
73 uint32_t PgaConnect; /*!< Specifies the inverting pin in PGA mode
74 i.e. when mode is OPAMP_PGA_MODE
75 This parameter must be a value of @ref OPAMP_PgaConnect
76 Either: not connected, connected to VINM0, connected to VINM1
77 (VINM0 or VINM1 are typically used for external filtering) */
79 uint32_t UserTrimming; /*!< Specifies the trimming mode
80 This parameter must be a value of @ref OPAMP_UserTrimming
81 UserTrimming is either factory or user trimming.*/
83 uint32_t TrimmingValueP; /*!< Specifies the offset trimming value (PMOS) in Normal Mode
84 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
85 This parameter must be a number between Min_Data = 0 and Max_Data = 31.
86 16 is typical default value */
88 uint32_t TrimmingValueN; /*!< Specifies the offset trimming value (NMOS) in Normal Mode
89 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
90 This parameter must be a number between Min_Data = 0 and Max_Data = 31.
91 16 is typical default value */
93 uint32_t TrimmingValuePHighSpeed; /*!< Specifies the offset trimming value (PMOS) in High Speed Mode
94 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
95 This parameter must be a number between Min_Data = 0 and Max_Data = 31.
96 16 is typical default value */
98 uint32_t TrimmingValueNHighSpeed; /*!< Specifies the offset trimming value (NMOS) in High Speed Mode
99 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
100 This parameter must be a number between Min_Data = 0 and Max_Data = 31.
101 16 is typical default value */
103 }OPAMP_InitTypeDef;
105 /**
106 * @brief HAL State structures definition
109 typedef enum
111 HAL_OPAMP_STATE_RESET = 0x00000000U, /*!< OPAMP is not yet Initialized */
113 HAL_OPAMP_STATE_READY = 0x00000001U, /*!< OPAMP is initialized and ready for use */
114 HAL_OPAMP_STATE_CALIBBUSY = 0x00000002U, /*!< OPAMP is enabled in auto calibration mode */
116 HAL_OPAMP_STATE_BUSY = 0x00000004U, /*!< OPAMP is enabled and running in normal mode */
117 HAL_OPAMP_STATE_BUSYLOCKED = 0x00000005U /*!< OPAMP is locked
118 only system reset allows reconfiguring the opamp. */
120 }HAL_OPAMP_StateTypeDef;
122 /**
123 * @brief OPAMP Handle Structure definition
125 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
126 typedef struct __OPAMP_HandleTypeDef
127 #else
128 typedef struct
129 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
131 OPAMP_TypeDef *Instance; /*!< OPAMP instance's registers base address */
132 OPAMP_InitTypeDef Init; /*!< OPAMP required parameters */
133 HAL_StatusTypeDef Status; /*!< OPAMP peripheral status */
134 HAL_LockTypeDef Lock; /*!< Locking object */
135 __IO HAL_OPAMP_StateTypeDef State; /*!< OPAMP communication state */
137 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
138 void (* MspInitCallback) (struct __OPAMP_HandleTypeDef *hopamp);
139 void (* MspDeInitCallback) (struct __OPAMP_HandleTypeDef *hopamp);
140 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
141 } OPAMP_HandleTypeDef;
143 /**
144 * @brief HAl_OPAMP_TrimmingValueTypeDef definition
147 typedef uint32_t HAL_OPAMP_TrimmingValueTypeDef;
150 * @}
153 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
155 * @brief HAL OPAMP Callback ID enumeration definition
157 typedef enum
159 HAL_OPAMP_MSPINIT_CB_ID = 0x01U, /*!< OPAMP MspInit Callback ID */
160 HAL_OPAMP_MSPDEINIT_CB_ID = 0x02U, /*!< OPAMP MspDeInit Callback ID */
161 HAL_OPAMP_ALL_CB_ID = 0x03U /*!< OPAMP All ID */
162 }HAL_OPAMP_CallbackIDTypeDef;
165 * @brief HAL OPAMP Callback pointer definition
167 typedef void (*pOPAMP_CallbackTypeDef)(OPAMP_HandleTypeDef *hopamp);
168 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
171 /* Exported constants --------------------------------------------------------*/
172 /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants
173 * @{
176 /** @defgroup OPAMP_Mode OPAMP Mode
177 * @{
179 #define OPAMP_STANDALONE_MODE 0x00000000U /*!< standalone mode */
180 #define OPAMP_PGA_MODE OPAMP_CSR_VMSEL_1 /*!< PGA mode */
181 #define OPAMP_FOLLOWER_MODE (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< follower mode */
184 * @}
187 /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input
188 * @{
191 #define OPAMP_NONINVERTINGINPUT_IO0 0x00000000U /*!< OPAMP non-inverting input connected to dedicated IO pin */
192 #define OPAMP_NONINVERTINGINPUT_DAC_CH OPAMP_CSR_VPSEL_0 /*!< OPAMP non-inverting input connected internally to DAC channel */
193 #if defined(DAC2)
194 #define OPAMP_NONINVERTINGINPUT_DAC2_CH OPAMP_CSR_VPSEL_1 /*!< Only OPAMP2 non-inverting input connected internally to DAC2 channel */
195 #endif /* DAC2 */
198 * @}
201 /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input
202 * @{
205 #define OPAMP_INVERTINGINPUT_IO0 0x00000000U /*!< OPAMP inverting input connected to dedicated IO pin */
206 #define OPAMP_INVERTINGINPUT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to dedicated IO pin */
209 * @}
212 /** @defgroup OPAMP_PgaConnect OPAMP Pga Connect
213 * @{
216 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_NO 0x00000000U /*!< In PGA mode, the inverting input is not connected */
217 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0 OPAMP_CSR_PGGAIN_2 /*!< In PGA mode, the inverting input is connected to VINM0 */
218 #define OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS OPAMP_CSR_PGGAIN_3 /*!< In PGA mode, the inverting input is connected to VINM0 or bias */
219 #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 */
223 * @}
226 /** @defgroup OPAMP_PgaGain OPAMP Pga Gain
227 * @{
230 #define OPAMP_PGA_GAIN_2_OR_MINUS_1 0x00000000U /*!< PGA gain could be 2 or -1 */
231 #define OPAMP_PGA_GAIN_4_OR_MINUS_3 OPAMP_CSR_PGGAIN_0 /*!< PGA gain could be 4 or -3 */
232 #define OPAMP_PGA_GAIN_8_OR_MINUS_7 OPAMP_CSR_PGGAIN_1 /*!< PGA gain could be 8 or -7 */
233 #define OPAMP_PGA_GAIN_16_OR_MINUS_15 (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1) /*!< PGA gain could be 16 or -15 */
236 * @}
239 /** @defgroup OPAMP_PowerMode OPAMP PowerMode
240 * @{
242 #define OPAMP_POWERMODE_NORMAL 0x00000000U
243 #define OPAMP_POWERMODE_HIGHSPEED OPAMP_CSR_OPAHSM
246 * @}
250 /** @defgroup OPAMP_VREF OPAMP VREF
251 * @{
254 #define OPAMP_VREF_3VDDA 0x00000000U /*!< OPAMP Vref = 3.3% VDDA */
255 #define OPAMP_VREF_10VDDA OPAMP_CSR_CALSEL_0 /*!< OPAMP Vref = 10% VDDA */
256 #define OPAMP_VREF_50VDDA OPAMP_CSR_CALSEL_1 /*!< OPAMP Vref = 50% VDDA */
257 #define OPAMP_VREF_90VDDA OPAMP_CSR_CALSEL /*!< OPAMP Vref = 90% VDDA */
260 * @}
263 /** @defgroup OPAMP_UserTrimming OPAMP User Trimming
264 * @{
266 #define OPAMP_TRIMMING_FACTORY 0x00000000U /*!< Factory trimming */
267 #define OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< User trimming */
271 * @}
274 /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming
275 * @{
277 #define OPAMP_FACTORYTRIMMING_DUMMY 0xFFFFFFFFU /*!< Dummy value if trimming value could not be retrieved */
279 #define OPAMP_FACTORYTRIMMING_N 0x00000000U /*!< Offset trimming N */
280 #define OPAMP_FACTORYTRIMMING_P 0x00000001U /*!< Offset trimming P */
283 * @}
287 * @}
290 /* Private constants ---------------------------------------------------------*/
291 /** @defgroup OPAMP_Private_Constants OPAMP Private Constants
292 * @brief OPAMP Private constants and defines
293 * @{
296 /* NONINVERTING bit position in OTR & HSOTR */
297 #define OPAMP_INPUT_NONINVERTING (8U) /*!< Non inverting input */
299 /* Offset trimming time: during calibration, minimum time needed between two */
300 /* steps to have 1 mV accuracy. */
301 /* Refer to datasheet, electrical characteristics: parameter tOFFTRIM Typ=2ms.*/
302 /* Unit: ms. */
303 #define OPAMP_TRIMMING_DELAY (2U)
306 * @}
309 /* Exported macros -----------------------------------------------------------*/
310 /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros
311 * @{
314 /** @brief Reset OPAMP handle state.
315 * @param __HANDLE__: OPAMP handle.
316 * @retval None
318 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET)
321 * @}
324 /* Private macro -------------------------------------------------------------*/
326 /** @defgroup OPAMP_Private_Macros OPAMP Private Macros
327 * @{
330 #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \
331 ((INPUT) == OPAMP_PGA_MODE) || \
332 ((INPUT) == OPAMP_FOLLOWER_MODE))
334 #define IS_OPAMP_INVERTING_INPUT_STANDALONE(INPUT) (((INPUT) == OPAMP_INVERTINGINPUT_IO0) || \
335 ((INPUT) == OPAMP_INVERTINGINPUT_IO1))
337 #if defined(DAC2)
338 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
339 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH) || \
340 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC2_CH))
341 #else
342 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
343 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH))
344 #endif /* DAC2 */
346 #define IS_OPAMP_PGACONNECT(CONNECT) (((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_NO) || \
347 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0) || \
348 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_BIAS) || \
349 ((CONNECT) == OPAMP_PGA_CONNECT_INVERTINGINPUT_IO0_IO1_BIAS))
351 #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2_OR_MINUS_1) || \
352 ((GAIN) == OPAMP_PGA_GAIN_4_OR_MINUS_3) || \
353 ((GAIN) == OPAMP_PGA_GAIN_8_OR_MINUS_7) || \
354 ((GAIN) == OPAMP_PGA_GAIN_16_OR_MINUS_15))
357 #define IS_OPAMP_VREF(VREF) (((VREF) == OPAMP_VREF_3VDDA) || \
358 ((VREF) == OPAMP_VREF_10VDDA) || \
359 ((VREF) == OPAMP_VREF_50VDDA) || \
360 ((VREF) == OPAMP_VREF_90VDDA))
362 #define IS_OPAMP_POWERMODE(TRIMMING) (((TRIMMING) == OPAMP_POWERMODE_NORMAL) || \
363 ((TRIMMING) == OPAMP_POWERMODE_HIGHSPEED) )
366 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \
367 ((TRIMMING) == OPAMP_TRIMMING_USER))
370 #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1FU)
372 #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \
373 ((TRIMMING) == OPAMP_FACTORYTRIMMING_P))
376 * @}
379 /* Include OPAMP HAL Extended module */
380 #include "stm32h7xx_hal_opamp_ex.h"
382 /* Exported functions --------------------------------------------------------*/
383 /** @addtogroup OPAMP_Exported_Functions
384 * @{
387 /** @addtogroup OPAMP_Exported_Functions_Group1
388 * @{
390 /* Initialization/de-initialization functions **********************************/
391 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp);
392 HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp);
393 void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp);
394 void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp);
396 * @}
399 /** @addtogroup OPAMP_Exported_Functions_Group2
400 * @{
403 /* I/O operation functions *****************************************************/
404 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp);
405 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp);
406 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp);
409 * @}
412 /** @addtogroup OPAMP_Exported_Functions_Group3
413 * @{
416 /* Peripheral Control functions ************************************************/
417 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
418 /* OPAMP callback registering/unregistering */
419 HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId, pOPAMP_CallbackTypeDef pCallback);
420 HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackId);
421 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
422 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp);
423 HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset);
426 * @}
429 /** @addtogroup OPAMP_Exported_Functions_Group4
430 * @{
433 /* Peripheral State functions **************************************************/
434 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp);
437 * @}
441 * @}
445 * @}
449 * @}
452 #ifdef __cplusplus
454 #endif
456 #endif /* STM32H7xx_HAL_OPAMP_H */
458 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/