2 ******************************************************************************
3 * @file stm32h7xx_hal_opamp.h
4 * @author MCD Application Team
5 * @brief Header file of OPAMP HAL module.
6 ******************************************************************************
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
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h7xx_hal_def.h"
30 /** @addtogroup STM32H7xx_HAL_Driver
38 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup OPAMP_Exported_Types OPAMP Exported Types
45 * @brief OPAMP Init structure definition
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 */
105 * @brief HAL State structures definition
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
;
122 * @brief OPAMP Handle Structure definition
124 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
125 typedef struct __OPAMP_HandleTypeDef
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
;
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
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 */
168 /* Exported constants --------------------------------------------------------*/
169 /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants
173 /** @defgroup OPAMP_Mode OPAMP Mode
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 */
184 /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input
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 */
191 #define OPAMP_NONINVERTINGINPUT_DAC2_CH OPAMP_CSR_VPSEL_1 /*!< Only OPAMP2 non-inverting input connected internally to DAC2 channel */
198 /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input
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 */
209 /** @defgroup OPAMP_PgaConnect OPAMP Pga Connect
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 */
223 /** @defgroup OPAMP_PgaGain OPAMP Pga Gain
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 */
236 /** @defgroup OPAMP_PowerMode OPAMP PowerMode
239 #define OPAMP_POWERMODE_NORMAL 0x00000000U
240 #define OPAMP_POWERMODE_HIGHSPEED OPAMP_CSR_OPAHSM
247 /** @defgroup OPAMP_VREF OPAMP VREF
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 */
260 /** @defgroup OPAMP_UserTrimming OPAMP User Trimming
263 #define OPAMP_TRIMMING_FACTORY 0x00000000U /*!< Factory trimming */
264 #define OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< User trimming */
271 /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming
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 */
287 /* Private constants ---------------------------------------------------------*/
288 /** @defgroup OPAMP_Private_Constants OPAMP Private Constants
289 * @brief OPAMP Private constants and defines
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.*/
300 #define OPAMP_TRIMMING_DELAY (2U)
306 /* Exported macros -----------------------------------------------------------*/
307 /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros
311 /** @brief Reset OPAMP handle state.
312 * @param __HANDLE__: OPAMP handle.
315 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET)
321 /* Private macro -------------------------------------------------------------*/
323 /** @defgroup OPAMP_Private_Macros OPAMP Private Macros
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))
335 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
336 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH) || \
337 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC2_CH))
339 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_IO0) || \
340 ((INPUT) == OPAMP_NONINVERTINGINPUT_DAC_CH))
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))
376 /* Include OPAMP HAL Extended module */
377 #include "stm32h7xx_hal_opamp_ex.h"
379 /* Exported functions --------------------------------------------------------*/
380 /** @addtogroup OPAMP_Exported_Functions
384 /** @addtogroup OPAMP_Exported_Functions_Group1
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
);
396 /** @addtogroup OPAMP_Exported_Functions_Group2
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
);
409 /** @addtogroup OPAMP_Exported_Functions_Group3
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
);
426 /** @addtogroup OPAMP_Exported_Functions_Group4
430 /* Peripheral State functions **************************************************/
431 HAL_OPAMP_StateTypeDef
HAL_OPAMP_GetState(const OPAMP_HandleTypeDef
*hopamp
);
453 #endif /* STM32H7xx_HAL_OPAMP_H */