Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Inc / stm32h7xx_ll_opamp.h
blob9808ab1e3736d39b7daba9787942b56c16e9f5a9
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_ll_opamp.h
4 * @author MCD Application Team
5 * @brief Header file of OPAMP LL 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_LL_OPAMP_H
22 #define __STM32H7xx_LL_OPAMP_H
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx.h"
31 /** @addtogroup STM32H7xx_LL_Driver
32 * @{
35 #if defined (OPAMP1) || defined (OPAMP2)
37 /** @defgroup OPAMP_LL OPAMP
38 * @{
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
44 /* Private constants ---------------------------------------------------------*/
45 /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants
46 * @{
49 /* Internal mask for OPAMP power mode: */
50 /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for: */
51 /* - OPAMP power mode into control register */
52 /* - OPAMP trimming register offset */
54 /* Internal register offset for OPAMP trimming configuration */
55 #define OPAMP_POWERMODE_OTR_REGOFFSET 0x00000000U
56 #define OPAMP_POWERMODE_HSOTR_REGOFFSET 0x00000001U
57 #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_HSOTR_REGOFFSET)
59 /* Mask for OPAMP power mode into control register */
60 #define OPAMP_POWERMODE_CSR_BIT_MASK (OPAMP_CSR_OPAHSM)
62 /* Internal mask for OPAMP trimming of transistors differential pair NMOS */
63 /* or PMOS. */
64 /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for: */
65 /* - OPAMP trimming selection of transistors differential pair */
66 /* - OPAMP trimming values of transistors differential pair */
67 #define OPAMP_TRIMMING_SELECT_MASK 0x00030000U
68 #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN)
70 /**
71 * @}
75 /* Private macros ------------------------------------------------------------*/
76 /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
77 * @{
80 /**
81 * @brief Driver macro reserved for internal use: set a pointer to
82 * a register from a register basis from which an offset
83 * is applied.
84 * @param __REG__ Register basis from which the offset is applied.
85 * @param __REG_OFFSET__ Offset to be applied (unit: number of registers).
86 * @retval Register address
88 #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \
89 ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
93 /**
94 * @}
98 /* Exported types ------------------------------------------------------------*/
99 #if defined(USE_FULL_LL_DRIVER)
100 /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
101 * @{
105 * @brief Structure definition of some features of OPAMP instance.
107 typedef struct
109 uint32_t PowerMode; /*!< Set OPAMP power mode.
110 This parameter can be a value of @ref OPAMP_LL_EC_POWER_MODE
112 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
115 uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
116 This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
117 @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
119 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
121 uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection.
122 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
124 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
126 uint32_t InputInverting; /*!< Set OPAMP inverting input connection.
127 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
128 @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin), this parameter is discarded.
130 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
132 } LL_OPAMP_InitTypeDef;
135 * @}
137 #endif /* USE_FULL_LL_DRIVER */
139 /* Exported constants --------------------------------------------------------*/
140 /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
141 * @{
144 /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
145 * @{
147 #define LL_OPAMP_MODE_FUNCTIONAL 0x00000000U /*!< OPAMP functional mode */
148 #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */
150 * @}
153 /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
154 * @{
156 #define LL_OPAMP_MODE_STANDALONE 0x00000000U /*!< OPAMP functional mode, OPAMP operation in standalone */
157 #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< OPAMP functional mode, OPAMP operation in follower */
158 #define LL_OPAMP_MODE_PGA (OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA */
159 #define LL_OPAMP_MODE_PGA_IO0 (OPAMP_CSR_PGGAIN_2|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0 for filtering */
160 #define LL_OPAMP_MODE_PGA_IO0_BIAS (OPAMP_CSR_PGGAIN_3|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0
161 - Input signal on VINM0, bias on VINPx: negative gain
162 - Bias on VINM0, input signal on VINPx: positive gain */
163 #define LL_OPAMP_MODE_PGA_IO0_IO1_BIAS (OPAMP_CSR_PGGAIN_3|OPAMP_CSR_PGGAIN_2|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0
164 - Input signal on VINM0, bias on VINPx: negative gain
165 - Bias on VINM0, input signal on VINPx: positive gain
166 And VINM1 is connected too for filtering */
169 * @}
172 /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
173 * @note Gain sign:
174 * - is positive if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
175 * @ref LL_OPAMP_MODE_PGA or LL_OPAMP_MODE_PGA_IO0
176 * - may be positive or negative if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
177 * @ref LL_OPAMP_MODE_PGA_IO0_BIAS or LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
178 * see @ref OPAMP_LL_EC_FUNCTIONAL_MODE for more details
179 * @{
181 #define LL_OPAMP_PGA_GAIN_2_OR_MINUS_1 0x00000000U /*!< OPAMP PGA gain 2 or -1 */
182 #define LL_OPAMP_PGA_GAIN_4_OR_MINUS_3 ( OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 or -3 */
183 #define LL_OPAMP_PGA_GAIN_8_OR_MINUS_7 ( OPAMP_CSR_PGGAIN_1 ) /*!< OPAMP PGA gain 8 or -7 */
184 #define LL_OPAMP_PGA_GAIN_16_OR_MINUS_15 ( OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 16 or -15 */
186 * @}
189 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
190 * @{
192 #define LL_OPAMP_INPUT_NONINVERT_IO0 0x00000000U /*!< OPAMP non inverting input connected to I/O VINP0
193 (PB0 for OPAMP1, PE9 for OPAMP2)
194 Note: On this STM32 serie, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
195 #define LL_OPAMP_INPUT_NONINVERT_DAC OPAMP_CSR_VPSEL_0 /*!< OPAMP non inverting input connected internally to DAC channel
196 (DAC1_CH1 for OPAMP1, DAC1_CH2 for OPAMP2)
197 Note: On this STM32 serie, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
198 #if defined(DAC2)
199 #define LL_OPAMP_INPUT_NONINVERT_DAC2 OPAMP_CSR_VPSEL_1 /*!< OPAMP non inverting input connected internally to DAC2 channel
200 (DAC3 only for OPAMP2)*/
201 #endif /* DAC2 */
204 * @}
207 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
208 * @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with negative gain or bias.
209 * Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin).
210 * @{
212 #define LL_OPAMP_INPUT_INVERT_IO0 0x00000000U /*!< OPAMP inverting input connected to I/O VINM0
213 (PC5 for OPAMP1, PE8 for OPAMP2)
214 Note: On this STM32 serie, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
215 #define LL_OPAMP_INPUT_INVERT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to I/0 VINM1
216 (PA7 for OPAMP1, PG1 for OPAMP2)
217 Note: On this STM32 serie, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
218 #define LL_OPAMP_INPUT_INVERT_CONNECT_NO OPAMP_CSR_VMSEL_1 /*!< OPAMP inverting input not externally connected (intended for OPAMP in mode follower or PGA with positive gain without bias).
219 Note: On this STM32 serie, this literal include cases of value 0x11 for mode follower and value 0x10 for mode PGA. */
221 * @}
226 /** @defgroup OPAMP_LL_EC_POWER_MODE OPAMP PowerMode
227 * @{
229 #define LL_OPAMP_POWERMODE_NORMAL (OPAMP_POWERMODE_OTR_REGOFFSET) /*!< OPAMP output in normal mode */
230 #define LL_OPAMP_POWERMODE_HIGHSPEED (OPAMP_POWERMODE_HSOTR_REGOFFSET | OPAMP_CSR_OPAHSM) /*!< OPAMP output in highspeed mode */
232 * @}
235 /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
236 * @{
238 #define LL_OPAMP_TRIMMING_FACTORY 0x00000000U /*!< OPAMP trimming factors set to factory values */
239 #define LL_OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< OPAMP trimming factors set to user values */
241 * @}
244 /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
245 * @{
247 #define LL_OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA (OPAMP_OTR_TRIMOFFSETN | ((OPAMP_CSR_CALSEL_1 | OPAMP_CSR_CALSEL_0) << 4)) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.9*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
248 #define LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA (OPAMP_OTR_TRIMOFFSETN | (OPAMP_CSR_CALSEL_1 << 4)) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.5*Vdda). */
249 #define LL_OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA (OPAMP_OTR_TRIMOFFSETP | (OPAMP_CSR_CALSEL_0 << 4)) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.1*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
250 #define LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA (OPAMP_OTR_TRIMOFFSETP ) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.33*Vdda). */
251 #define LL_OPAMP_TRIMMING_NMOS (LL_OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.9*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
252 #define LL_OPAMP_TRIMMING_PMOS (LL_OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.1*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
254 * @}
257 /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
258 * @note Only OPAMP IP HW delays are defined in OPAMP LL driver driver,
259 * not timeout values.
260 * For details on delays values, refer to descriptions in source code
261 * above each literal definition.
262 * @{
265 /* Delay for OPAMP startup time (transition from state disable to enable). */
266 /* Note: OPAMP startup time depends on board application environment: */
267 /* impedance connected to OPAMP output. */
268 /* The delay below is specified under conditions: */
269 /* - OPAMP in functional mode follower */
270 /* - load impedance of 4kOhm (min), 50pF (max) */
271 /* Literal set to maximum value (refer to device datasheet, */
272 /* parameter "tWAKEUP"). */
273 /* Unit: us */
274 #define LL_OPAMP_DELAY_STARTUP_US (3U) /*!< Delay for OPAMP startup time */
276 * @}
280 * @}
283 /* Exported macro ------------------------------------------------------------*/
284 /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
285 * @{
287 /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
288 * @{
291 * @brief Write a value in OPAMP LL_OPAMP_GetPowerModeregister
292 * @param __INSTANCE__ OPAMP Instance
293 * @param __REG__ Register to be written
294 * @param __VALUE__ Value to be written in the register
295 * @retval None
297 #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
300 * @brief Read a value in OPAMP register
301 * @param __INSTANCE__ OPAMP Instance
302 * @param __REG__ Register to be read
303 * @retval Register value
305 #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
307 * @}
309 /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro
310 * @{
314 * @brief Helper macro to select the OPAMP common instance
315 * to which is belonging the selected OPAMP instance.
316 * @note OPAMP common register instance can be used to
317 * set parameters common to several OPAMP instances.
318 * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
319 * @param __OPAMPx__ OPAMP instance
320 * @retval OPAMP common instance
322 #if defined(OPAMP1) && defined(OPAMP2)
323 #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \
324 (OPAMP12_COMMON)
325 #endif
328 * @brief Helper macro to check if all OPAMP instances sharing the same
329 * OPAMP common instance are disabled.
330 * @note This check is required by functions with setting conditioned to
331 * OPAMP state:
332 * All OPAMP instances of the OPAMP common group must be disabled.
333 * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
334 * @retval 0: All OPAMP instances sharing the same OPAMP common instance
335 * are disabled.
336 * 1: At least one OPAMP instance sharing the same OPAMP common instance
337 * is enabled
339 #if defined(OPAMP1) && defined(OPAMP2)
340 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
341 (LL_OPAMP_IsEnabled(OPAMP1) | \
342 LL_OPAMP_IsEnabled(OPAMP2) )
343 #endif
346 * @}
350 * @}
353 /* Exported functions --------------------------------------------------------*/
354 /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
355 * @{
358 /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
359 * @{
363 * @brief Set OPAMP mode calibration or functional.
364 * @note OPAMP mode corresponds to functional or calibration mode:
365 * - functional mode: OPAMP operation in standalone, follower, ...
366 * Set functional mode using function
367 * @ref LL_OPAMP_SetFunctionalMode().
368 * - calibration mode: offset calibration of the selected
369 * transistors differential pair NMOS or PMOS.
370 * @rmtoll CSR CALON LL_OPAMP_SetMode
371 * @param OPAMPx OPAMP instance
372 * @param Mode This parameter can be one of the following values:
373 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
374 * @arg @ref LL_OPAMP_MODE_CALIBRATION
375 * @retval None
377 __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
379 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
383 * @brief Get OPAMP mode calibration or functional.
384 * @note OPAMP mode corresponds to functional or calibration mode:
385 * - functional mode: OPAMP operation in standalone, follower, ...
386 * Set functional mode using function
387 * @ref LL_OPAMP_SetFunctionalMode().
388 * - calibration mode: offset calibration of the selected
389 * transistors differential pair NMOS or PMOS.
390 * @rmtoll CSR CALON LL_OPAMP_GetMode
391 * @param OPAMPx OPAMP instance
392 * @retval Returned value can be one of the following values:
393 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
394 * @arg @ref LL_OPAMP_MODE_CALIBRATION
396 __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
398 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
402 * @brief Set OPAMP functional mode by setting internal connections.
403 * OPAMP operation in standalone, follower, ...
404 * @note This function reset bit of calibration mode to ensure
405 * to be in functional mode, in order to have OPAMP parameters
406 * (inputs selection, ...) set with the corresponding OPAMP mode
407 * to be effective.
408 * @rmtoll CSR VMSEL LL_OPAMP_SetFunctionalMode
409 * @param OPAMPx OPAMP instance
410 * @param FunctionalMode This parameter can be one of the following values:
411 * @arg @ref LL_OPAMP_MODE_STANDALONE
412 * @arg @ref LL_OPAMP_MODE_FOLLOWER
413 * @arg @ref LL_OPAMP_MODE_PGA
414 * @arg @ref LL_OPAMP_MODE_PGA_IO0
415 * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
416 * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
417 * @retval None
419 __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
421 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
422 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL | OPAMP_CSR_CALON, FunctionalMode);
426 * @brief Get OPAMP functional mode from setting of internal connections.
427 * OPAMP operation in standalone, follower, ...
428 * @rmtoll CSR VMSEL LL_OPAMP_GetFunctionalMode
429 * @param OPAMPx OPAMP instance
430 * @retval Returned value can be one of the following values:
431 * @arg @ref LL_OPAMP_MODE_STANDALONE
432 * @arg @ref LL_OPAMP_MODE_FOLLOWER
433 * @arg @ref LL_OPAMP_MODE_PGA
434 * @arg @ref LL_OPAMP_MODE_PGA_IO0
435 * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
436 * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
438 __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
440 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL));
444 * @brief Set OPAMP PGA gain.
445 * @note Preliminarily, OPAMP must be set in mode PGA
446 * using function @ref LL_OPAMP_SetFunctionalMode().
447 * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain
448 * @param OPAMPx OPAMP instance
449 * @param PGAGain This parameter can be one of the following values:
450 * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
451 * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
452 * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
453 * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
454 * @retval None
456 __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
458 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0, PGAGain);
462 * @brief Get OPAMP PGA gain.
463 * @note Preliminarily, OPAMP must be set in mode PGA
464 * using function @ref LL_OPAMP_SetFunctionalMode().
465 * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain
466 * @param OPAMPx OPAMP instance
467 * @retval Returned value can be one of the following values:
468 * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
469 * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
470 * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
471 * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
473 __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
475 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0));
479 * @brief Set OPAMP power mode normal or highspeed.
480 * @note OPAMP highspeed mode allows output stage to have a better slew rate.
481 * @rmtoll CSR OPAHSM LL_OPAMP_SetPowerMode
482 * @param OPAMPx OPAMP instance
483 * @param PowerMode This parameter can be one of the following values:
484 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
485 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
486 * @retval None
488 __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
490 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAHSM, (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK));
494 * @brief Get OPAMP power mode normal or highspeed.
495 * @note OPAMP highspeed mode allows output stage to have a better slew rate.
496 * @rmtoll CSR OPAHSM LL_OPAMP_GetPowerMode
497 * @param OPAMPx OPAMP instance
498 * @retval Returned value can be one of the following values:
499 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
500 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
502 __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
504 uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAHSM));
506 return (uint32_t)(power_mode | (power_mode >> (OPAMP_CSR_OPAHSM_Pos)));
509 * @}
512 /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
513 * @{
517 * @brief Set OPAMP non-inverting input connection.
518 * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting
519 * @param OPAMPx OPAMP instance
520 * @param InputNonInverting This parameter can be one of the following values:
521 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
522 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
523 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC2 (Only for OPAMP2)
524 * @retval None
526 __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
528 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
532 * @brief Get OPAMP non-inverting input connection.
533 * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting
534 * @param OPAMPx OPAMP instance
535 * @retval Returned value can be one of the following values:
536 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
537 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
538 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC2 (Only for OPAMP2)
540 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
542 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
546 * @brief Set OPAMP inverting input connection.
547 * @note OPAMP inverting input is used with OPAMP in mode standalone
548 * or PGA with external capacitors for filtering circuit.
549 * Otherwise (OPAMP in mode follower), OPAMP inverting input
550 * is not used (not connected to GPIO pin).
551 * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting
552 * @param OPAMPx OPAMP instance
553 * @param InputInverting This parameter can be one of the following values:
554 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
555 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
556 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
557 * @retval None
559 __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
561 /* Manage cases of OPAMP inverting input not connected (0x10 and 0x11) */
562 /* to not modify OPAMP mode follower or PGA. */
563 /* Bit OPAMP_CSR_VMSEL_1 is set by OPAMP mode (follower, PGA). */
564 MODIFY_REG(OPAMPx->CSR, (~(InputInverting >> 1)) & OPAMP_CSR_VMSEL_0, InputInverting);
568 * @brief Get OPAMP inverting input connection.
569 * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting
570 * @param OPAMPx OPAMP instance
571 * @retval Returned value can be one of the following values:
572 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
573 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
574 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
576 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
578 uint32_t input_inverting = READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL);
580 /* Manage cases 0x10 and 0x11 to return the same value: OPAMP inverting */
581 /* input not connected. */
582 return (input_inverting & ~((input_inverting >> 1) & OPAMP_CSR_VMSEL_0));
586 * @}
589 /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
590 * @{
594 * @brief Set OPAMP trimming mode.
595 * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode
596 * @param OPAMPx OPAMP instance
597 * @param TrimmingMode This parameter can be one of the following values:
598 * @arg @ref LL_OPAMP_TRIMMING_FACTORY
599 * @arg @ref LL_OPAMP_TRIMMING_USER
600 * @retval None
602 __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
604 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
608 * @brief Get OPAMP trimming mode.
609 * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode
610 * @param OPAMPx OPAMP instance
611 * @retval Returned value can be one of the following values:
612 * @arg @ref LL_OPAMP_TRIMMING_FACTORY
613 * @arg @ref LL_OPAMP_TRIMMING_USER
615 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx)
617 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
621 * @brief Set OPAMP offset to calibrate the selected transistors
622 * differential pair NMOS or PMOS.
623 * @note Preliminarily, OPAMP must be set in mode calibration
624 * using function @ref LL_OPAMP_SetMode().
625 * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection
626 * @param OPAMPx OPAMP instance
627 * @param TransistorsDiffPair This parameter can be one of the following values:
628 * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
629 * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
630 * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
631 * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
633 * (1) Default parameters to be used for calibration
634 * using two trimming steps (one with each transistors differential
635 * pair NMOS and PMOS)
636 * @retval None
638 __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
640 /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
641 /* containing other bits reserved for other purpose. */
642 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, ((TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK) >> 4));
646 * @brief Get OPAMP offset to calibrate the selected transistors
647 * differential pair NMOS or PMOS.
648 * @note Preliminarily, OPAMP must be set in mode calibration
649 * using function @ref LL_OPAMP_SetMode().
650 * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection
651 * @param OPAMPx OPAMP instance
652 * @retval Returned value can be one of the following values:
653 * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
654 * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
655 * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
656 * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
658 * (1) Default parameters to be used for calibration
659 * using two trimming steps (one with each transistors differential
660 * pair NMOS and PMOS)
662 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
664 uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
666 return (uint32_t)((CalibrationSelection << 4)|
667 (((CalibrationSelection & OPAMP_CSR_CALSEL_1) == 0UL) ? OPAMP_OTR_TRIMOFFSETN : OPAMP_OTR_TRIMOFFSETP));
671 * @brief Get OPAMP calibration result of toggling output.
672 * @note This functions returns:
673 * 0 if OPAMP calibration output is reset
674 * 1 if OPAMP calibration output is set
675 * @rmtoll CSR OUTCAL LL_OPAMP_IsCalibrationOutputSet
676 * @param OPAMPx OPAMP instance
677 * @retval State of bit (1 or 0).
679 __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
681 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT)?1UL:0UL);
685 * @brief Set OPAMP trimming factor for the selected transistors
686 * differential pair NMOS or PMOS, corresponding to the selected
687 * power mode.
688 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n
689 * OTR TRIMOFFSETP LL_OPAMP_SetTrimmingValue\n
690 * HSOTR TRIMHSOFFSETN LL_OPAMP_SetTrimmingValue\n
691 * HSOTR TRIMHSOFFSETP LL_OPAMP_SetTrimmingValue
692 * @param OPAMPx OPAMP instance
693 * @param PowerMode This parameter can be one of the following values:
694 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
695 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
696 * @param TransistorsDiffPair This parameter can be one of the following values:
697 * @arg @ref LL_OPAMP_TRIMMING_NMOS
698 * @arg @ref LL_OPAMP_TRIMMING_PMOS
699 * @param TrimmingValue 0x00...0x1F
700 * @retval None
702 __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
704 __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
706 /* Set bits with position in register depending on parameter */
707 /* "TransistorsDiffPair". */
708 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
709 /* containing other bits reserved for other purpose. */
710 MODIFY_REG(*preg,
711 (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) << 1U,
712 TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
716 * @brief Get OPAMP trimming factor for the selected transistors
717 * differential pair NMOS or PMOS, corresponding to the selected
718 * power mode.
719 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n
720 * OTR TRIMOFFSETP LL_OPAMP_GetTrimmingValue\n
721 * HSOTR TRIMHSOFFSETN LL_OPAMP_GetTrimmingValue\n
722 * HSOTR TRIMHSOFFSETP LL_OPAMP_GetTrimmingValue
723 * @param OPAMPx OPAMP instance
724 * @param PowerMode This parameter can be one of the following values:
725 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
726 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
727 * @param TransistorsDiffPair This parameter can be one of the following values:
728 * @arg @ref LL_OPAMP_TRIMMING_NMOS
729 * @arg @ref LL_OPAMP_TRIMMING_PMOS
730 * @retval 0x0...0x1F
732 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair)
734 const __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
736 /* Retrieve bits with position in register depending on parameter */
737 /* "TransistorsDiffPair". */
738 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
739 /* containing other bits reserved for other purpose. */
740 return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
741 >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
745 * @}
748 /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
749 * @{
752 * @brief Enable OPAMP instance.
753 * @note After enable from off state, OPAMP requires a delay
754 * to fullfill wake up time specification.
755 * Refer to device datasheet, parameter "tWAKEUP".
756 * @rmtoll CSR OPAMPXEN LL_OPAMP_Enable
757 * @param OPAMPx OPAMP instance
758 * @retval None
760 __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
762 SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
766 * @brief Disable OPAMP instance.
767 * @rmtoll CSR OPAMPXEN LL_OPAMP_Disable
768 * @param OPAMPx OPAMP instance
769 * @retval None
771 __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
773 CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
777 * @brief Get OPAMP instance enable state
778 * (0: OPAMP is disabled, 1: OPAMP is enabled)
779 * @rmtoll CSR OPAMPXEN LL_OPAMP_IsEnabled
780 * @param OPAMPx OPAMP instance
781 * @retval State of bit (1 or 0).
783 __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
785 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN))?1UL:0UL);
788 * @}
791 #if defined(USE_FULL_LL_DRIVER)
792 /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
793 * @{
796 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
797 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
798 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
801 * @}
803 #endif /* USE_FULL_LL_DRIVER */
806 * @}
810 * @}
813 #endif /* OPAMP1 || OPAMP2 */
816 * @}
819 #ifdef __cplusplus
821 #endif
823 #endif /* __STM32H7xx_LL_OPAMP_H */
825 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/