STM32H735xx HAL User Manual
stm32h7xx_ll_opamp.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32h7xx_ll_opamp.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of OPAMP LL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * Copyright (c) 2017 STMicroelectronics.
00010   * All rights reserved.
00011   *
00012   * This software is licensed under terms that can be found in the LICENSE file
00013   * in the root directory of this software component.
00014   * If no LICENSE file comes with this software, it is provided AS-IS.
00015   *
00016   ******************************************************************************
00017   */
00018 
00019 /* Define to prevent recursive inclusion -------------------------------------*/
00020 #ifndef __STM32H7xx_LL_OPAMP_H
00021 #define __STM32H7xx_LL_OPAMP_H
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 /* Includes ------------------------------------------------------------------*/
00028 #include "stm32h7xx.h"
00029 
00030 /** @addtogroup STM32H7xx_LL_Driver
00031   * @{
00032   */
00033 
00034 #if defined (OPAMP1) || defined (OPAMP2)
00035 
00036 /** @defgroup OPAMP_LL OPAMP
00037   * @{
00038   */
00039 
00040 /* Private types -------------------------------------------------------------*/
00041 /* Private variables ---------------------------------------------------------*/
00042 
00043 /* Private constants ---------------------------------------------------------*/
00044 /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants
00045   * @{
00046   */
00047 
00048 /* Internal mask for OPAMP power mode:                                        */
00049 /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for:         */
00050 /* - OPAMP power mode into control register                                   */
00051 /* - OPAMP trimming register offset                                           */
00052 
00053 /* Internal register offset for OPAMP trimming configuration */
00054 #define OPAMP_POWERMODE_OTR_REGOFFSET       0x00000000U
00055 #define OPAMP_POWERMODE_HSOTR_REGOFFSET     0x00000001U
00056 #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK  (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_HSOTR_REGOFFSET)
00057 
00058 /* Mask for OPAMP power mode into control register */
00059 #define OPAMP_POWERMODE_CSR_BIT_MASK        (OPAMP_CSR_OPAHSM)
00060 
00061 /* Internal mask for OPAMP trimming of transistors differential pair NMOS     */
00062 /* or PMOS.                                                                   */
00063 /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for:          */
00064 /* - OPAMP trimming selection of transistors differential pair                */
00065 /* - OPAMP trimming values of transistors differential pair                   */
00066 #define OPAMP_TRIMMING_SELECT_MASK          0x00030000U
00067 #define OPAMP_TRIMMING_VALUE_MASK           (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN)
00068 
00069 /**
00070   * @}
00071   */
00072 
00073 
00074 /* Private macros ------------------------------------------------------------*/
00075 /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
00076   * @{
00077   */
00078 
00079 /**
00080   * @brief  Driver macro reserved for internal use: set a pointer to
00081   *         a register from a register basis from which an offset
00082   *         is applied.
00083   * @param  __REG__ Register basis from which the offset is applied.
00084   * @param  __REG_OFFSET__ Offset to be applied (unit: number of registers).
00085   * @retval Register address
00086 */
00087 #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__)                        \
00088  ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
00089 
00090 
00091 
00092 /**
00093   * @}
00094   */
00095 
00096 
00097 /* Exported types ------------------------------------------------------------*/
00098 #if defined(USE_FULL_LL_DRIVER)
00099 /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
00100   * @{
00101   */
00102 
00103 /**
00104   * @brief  Structure definition of some features of OPAMP instance.
00105   */
00106 typedef struct
00107 {
00108   uint32_t PowerMode;                   /*!< Set OPAMP power mode.
00109                                              This parameter can be a value of @ref OPAMP_LL_EC_POWER_MODE
00110 
00111                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
00112 
00113 
00114   uint32_t FunctionalMode;              /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
00115                                              This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
00116                                              @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
00117 
00118                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
00119 
00120   uint32_t InputNonInverting;           /*!< Set OPAMP input non-inverting connection.
00121                                              This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
00122 
00123                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
00124 
00125   uint32_t InputInverting;              /*!< Set OPAMP inverting input connection.
00126                                              This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
00127                                              @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.
00128 
00129                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
00130 
00131 } LL_OPAMP_InitTypeDef;
00132 
00133 /**
00134   * @}
00135   */
00136 #endif /* USE_FULL_LL_DRIVER */
00137 
00138 /* Exported constants --------------------------------------------------------*/
00139 /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
00140   * @{
00141   */
00142 
00143 /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
00144   * @{
00145   */
00146 #define LL_OPAMP_MODE_FUNCTIONAL        0x00000000U                               /*!< OPAMP functional mode */
00147 #define LL_OPAMP_MODE_CALIBRATION       (OPAMP_CSR_CALON)                           /*!< OPAMP calibration mode */
00148 /**
00149   * @}
00150   */
00151 
00152 /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
00153   * @{
00154   */
00155 #define LL_OPAMP_MODE_STANDALONE        0x00000000U                                                 /*!< OPAMP functional mode, OPAMP operation in standalone */
00156 #define LL_OPAMP_MODE_FOLLOWER          (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0)                       /*!< OPAMP functional mode, OPAMP operation in follower */
00157 #define LL_OPAMP_MODE_PGA               (OPAMP_CSR_VMSEL_1)                                           /*!< OPAMP functional mode, OPAMP operation in PGA */
00158 #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 */
00159 #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
00160                                                                                                           - Input signal on VINM0, bias on VINPx: negative gain
00161                                                                                                           - Bias on VINM0, input signal on VINPx: positive gain */
00162 #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
00163                                                                                                           - Input signal on VINM0, bias on VINPx: negative gain
00164                                                                                                           - Bias on VINM0, input signal on VINPx: positive gain
00165                                                                                                           And VINM1 is connected too for filtering */
00166 
00167 /**
00168   * @}
00169   */
00170 
00171 /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
00172   * @note Gain sign:
00173   *         - is positive if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
00174   *           @ref LL_OPAMP_MODE_PGA or LL_OPAMP_MODE_PGA_IO0
00175   *         - may be positive or negative if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
00176   *           @ref LL_OPAMP_MODE_PGA_IO0_BIAS or LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
00177   *       see @ref OPAMP_LL_EC_FUNCTIONAL_MODE for more details
00178   * @{
00179   */
00180 #define LL_OPAMP_PGA_GAIN_2_OR_MINUS_1             0x00000000U                                                    /*!< OPAMP PGA gain 2  or -1  */
00181 #define LL_OPAMP_PGA_GAIN_4_OR_MINUS_3             (                                          OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4  or -3  */
00182 #define LL_OPAMP_PGA_GAIN_8_OR_MINUS_7             (                     OPAMP_CSR_PGGAIN_1                     ) /*!< OPAMP PGA gain 8  or -7  */
00183 #define LL_OPAMP_PGA_GAIN_16_OR_MINUS_15           (                     OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 16 or -15 */
00184 /**
00185   * @}
00186   */
00187 
00188 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
00189   * @{
00190   */
00191 #define LL_OPAMP_INPUT_NONINVERT_IO0         0x00000000U           /*!< OPAMP non inverting input connected to I/O VINP0
00192                                                                         (PB0  for OPAMP1, PE9  for OPAMP2)
00193                                                                         Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
00194 #define LL_OPAMP_INPUT_NONINVERT_DAC         OPAMP_CSR_VPSEL_0     /*!< OPAMP non inverting input connected internally to DAC channel
00195                                                                         (DAC1_CH1 for OPAMP1, DAC1_CH2  for OPAMP2)
00196                                                                         Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
00197 #if defined(DAC2)
00198 #define LL_OPAMP_INPUT_NONINVERT_DAC2        OPAMP_CSR_VPSEL_1     /*!< OPAMP non inverting input connected internally to DAC2 channel
00199                                                                         (DAC3 only for OPAMP2)*/
00200 #endif /* DAC2 */
00201 
00202 /**
00203   * @}
00204   */
00205 
00206 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
00207   * @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with negative gain or bias.
00208   *       Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin).
00209   * @{
00210   */
00211 #define LL_OPAMP_INPUT_INVERT_IO0         0x00000000U              /*!< OPAMP inverting input connected to I/O VINM0
00212                                                                         (PC5  for OPAMP1, PE8  for OPAMP2)
00213                                                                         Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
00214 #define LL_OPAMP_INPUT_INVERT_IO1         OPAMP_CSR_VMSEL_0        /*!< OPAMP inverting input connected to I/0 VINM1
00215                                                                         (PA7  for OPAMP1, PG1  for OPAMP2)
00216                                                                         Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
00217 #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).
00218                                                                         Note: On this STM32 series, this literal include cases of value 0x11 for mode follower and value 0x10 for mode PGA. */
00219 /**
00220   * @}
00221   */
00222 
00223 
00224 
00225 /** @defgroup OPAMP_LL_EC_POWER_MODE OPAMP PowerMode
00226   * @{
00227   */
00228 #define LL_OPAMP_POWERMODE_NORMAL        (OPAMP_POWERMODE_OTR_REGOFFSET)                            /*!< OPAMP output in normal mode */
00229 #define LL_OPAMP_POWERMODE_HIGHSPEED     (OPAMP_POWERMODE_HSOTR_REGOFFSET | OPAMP_CSR_OPAHSM)       /*!< OPAMP output in highspeed mode */
00230 /**
00231   * @}
00232   */
00233 
00234 /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
00235   * @{
00236   */
00237 #define LL_OPAMP_TRIMMING_FACTORY       0x00000000U             /*!< OPAMP trimming factors set to factory values */
00238 #define LL_OPAMP_TRIMMING_USER          OPAMP_CSR_USERTRIM      /*!< OPAMP trimming factors set to user values */
00239 /**
00240   * @}
00241   */
00242 
00243 /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
00244   * @{
00245   */
00246 #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). */
00247 #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). */
00248 #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). */
00249 #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). */
00250 #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). */
00251 #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). */
00252 /**
00253   * @}
00254   */
00255 
00256 /** @defgroup OPAMP_LL_EC_HW_DELAYS  Definitions of OPAMP hardware constraints delays
00257   * @note   Only OPAMP peripheral HW delays are defined in OPAMP LL driver driver,
00258   *         not timeout values.
00259   *         For details on delays values, refer to descriptions in source code
00260   *         above each literal definition.
00261   * @{
00262   */
00263 
00264 /* Delay for OPAMP startup time (transition from state disable to enable).    */
00265 /* Note: OPAMP startup time depends on board application environment:         */
00266 /*       impedance connected to OPAMP output.                                 */
00267 /*       The delay below is specified under conditions:                       */
00268 /*        - OPAMP in functional mode follower                                 */
00269 /*        - load impedance of 4kOhm (min), 50pF (max)                         */
00270 /* Literal set to maximum value (refer to device datasheet,                   */
00271 /* parameter "tWAKEUP").                                                      */
00272 /* Unit: us                                                                   */
00273 #define LL_OPAMP_DELAY_STARTUP_US         (3U)  /*!< Delay for OPAMP startup time */
00274 /**
00275   * @}
00276   */
00277 
00278 /**
00279   * @}
00280   */
00281 
00282 /* Exported macro ------------------------------------------------------------*/
00283 /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
00284   * @{
00285   */
00286 /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
00287   * @{
00288   */
00289 /**
00290   * @brief  Write a value in OPAMP LL_OPAMP_GetPowerModeregister
00291   * @param  __INSTANCE__ OPAMP Instance
00292   * @param  __REG__ Register to be written
00293   * @param  __VALUE__ Value to be written in the register
00294   * @retval None
00295   */
00296 #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
00297 
00298 /**
00299   * @brief  Read a value in OPAMP register
00300   * @param  __INSTANCE__ OPAMP Instance
00301   * @param  __REG__ Register to be read
00302   * @retval Register value
00303   */
00304 #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
00305 /**
00306   * @}
00307   */
00308 /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro
00309   * @{
00310   */
00311 
00312 /**
00313   * @brief  Helper macro to select the OPAMP common instance
00314   *         to which is belonging the selected OPAMP instance.
00315   * @note   OPAMP common register instance can be used to
00316   *         set parameters common to several OPAMP instances.
00317   *         Refer to functions having argument "OPAMPxy_COMMON" as parameter.
00318   * @param  __OPAMPx__ OPAMP instance
00319   * @retval OPAMP common instance
00320   */
00321 #if defined(OPAMP1) && defined(OPAMP2)
00322 #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__)                                 \
00323   (OPAMP12_COMMON)
00324 #endif
00325 
00326 /**
00327   * @brief  Helper macro to check if all OPAMP instances sharing the same
00328   *         OPAMP common instance are disabled.
00329   * @note   This check is required by functions with setting conditioned to
00330   *         OPAMP state:
00331   *         All OPAMP instances of the OPAMP common group must be disabled.
00332   *         Refer to functions having argument "OPAMPxy_COMMON" as parameter.
00333   * @retval 0: All OPAMP instances sharing the same OPAMP common instance
00334   *            are disabled.
00335   *         1: At least one OPAMP instance sharing the same OPAMP common instance
00336   *            is enabled
00337   */
00338 #if defined(OPAMP1) && defined(OPAMP2)
00339 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE()                            \
00340   (LL_OPAMP_IsEnabled(OPAMP1) |                                                \
00341    LL_OPAMP_IsEnabled(OPAMP2)  )
00342 #endif
00343 
00344 /**
00345   * @}
00346   */
00347 
00348 /**
00349   * @}
00350   */
00351 
00352 /* Exported functions --------------------------------------------------------*/
00353 /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
00354   * @{
00355   */
00356 
00357 /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
00358   * @{
00359   */
00360 
00361 /**
00362   * @brief  Set OPAMP mode calibration or functional.
00363   * @note   OPAMP mode corresponds to functional or calibration mode:
00364   *          - functional mode: OPAMP operation in standalone, follower, ...
00365   *            Set functional mode using function
00366   *            @ref LL_OPAMP_SetFunctionalMode().
00367   *          - calibration mode: offset calibration of the selected
00368   *            transistors differential pair NMOS or PMOS.
00369   * @rmtoll CSR      CALON          LL_OPAMP_SetMode
00370   * @param  OPAMPx OPAMP instance
00371   * @param  Mode This parameter can be one of the following values:
00372   *         @arg @ref LL_OPAMP_MODE_FUNCTIONAL
00373   *         @arg @ref LL_OPAMP_MODE_CALIBRATION
00374   * @retval None
00375   */
00376 __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
00377 {
00378   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
00379 }
00380 
00381 /**
00382   * @brief  Get OPAMP mode calibration or functional.
00383   * @note   OPAMP mode corresponds to functional or calibration mode:
00384   *          - functional mode: OPAMP operation in standalone, follower, ...
00385   *            Set functional mode using function
00386   *            @ref LL_OPAMP_SetFunctionalMode().
00387   *          - calibration mode: offset calibration of the selected
00388   *            transistors differential pair NMOS or PMOS.
00389   * @rmtoll CSR      CALON          LL_OPAMP_GetMode
00390   * @param  OPAMPx OPAMP instance
00391   * @retval Returned value can be one of the following values:
00392   *         @arg @ref LL_OPAMP_MODE_FUNCTIONAL
00393   *         @arg @ref LL_OPAMP_MODE_CALIBRATION
00394   */
00395 __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
00396 {
00397   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
00398 }
00399 
00400 /**
00401   * @brief  Set OPAMP functional mode by setting internal connections.
00402   *         OPAMP operation in standalone, follower, ...
00403   * @note   This function reset bit of calibration mode to ensure
00404   *         to be in functional mode, in order to have OPAMP parameters
00405   *         (inputs selection, ...) set with the corresponding OPAMP mode
00406   *         to be effective.
00407   * @rmtoll CSR      VMSEL          LL_OPAMP_SetFunctionalMode
00408   * @param  OPAMPx OPAMP instance
00409   * @param  FunctionalMode This parameter can be one of the following values:
00410   *         @arg @ref LL_OPAMP_MODE_STANDALONE
00411   *         @arg @ref LL_OPAMP_MODE_FOLLOWER
00412   *         @arg @ref LL_OPAMP_MODE_PGA
00413   *         @arg @ref LL_OPAMP_MODE_PGA_IO0
00414   *         @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
00415   *         @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
00416   * @retval None
00417   */
00418 __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
00419 {
00420   /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
00421   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL | OPAMP_CSR_CALON, FunctionalMode);
00422 }
00423 
00424 /**
00425   * @brief  Get OPAMP functional mode from setting of internal connections.
00426   *         OPAMP operation in standalone, follower, ...
00427   * @rmtoll CSR      VMSEL          LL_OPAMP_GetFunctionalMode
00428   * @param  OPAMPx OPAMP instance
00429   * @retval Returned value can be one of the following values:
00430   *         @arg @ref LL_OPAMP_MODE_STANDALONE
00431   *         @arg @ref LL_OPAMP_MODE_FOLLOWER
00432   *         @arg @ref LL_OPAMP_MODE_PGA
00433   *         @arg @ref LL_OPAMP_MODE_PGA_IO0
00434   *         @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
00435   *         @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
00436   */
00437 __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
00438 {
00439   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL));
00440 }
00441 
00442 /**
00443   * @brief  Set OPAMP PGA gain.
00444   * @note   Preliminarily, OPAMP must be set in mode PGA
00445   *         using function @ref LL_OPAMP_SetFunctionalMode().
00446   * @rmtoll CSR      PGGAIN         LL_OPAMP_SetPGAGain
00447   * @param  OPAMPx OPAMP instance
00448   * @param  PGAGain This parameter can be one of the following values:
00449   *         @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
00450   *         @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
00451   *         @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
00452   *         @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
00453   * @retval None
00454   */
00455 __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
00456 {
00457   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0, PGAGain);
00458 }
00459 
00460 /**
00461   * @brief  Get OPAMP PGA gain.
00462   * @note   Preliminarily, OPAMP must be set in mode PGA
00463   *         using function @ref LL_OPAMP_SetFunctionalMode().
00464   * @rmtoll CSR      PGGAIN         LL_OPAMP_GetPGAGain
00465   * @param  OPAMPx OPAMP instance
00466   * @retval Returned value can be one of the following values:
00467   *         @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
00468   *         @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
00469   *         @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
00470   *         @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
00471   */
00472 __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
00473 {
00474   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0));
00475 }
00476 
00477 /**
00478   * @brief  Set OPAMP power mode normal or highspeed.
00479   * @note   OPAMP highspeed mode allows output stage to have a better slew rate.
00480   * @rmtoll CSR      OPAHSM     LL_OPAMP_SetPowerMode
00481   * @param  OPAMPx OPAMP instance
00482   * @param  PowerMode This parameter can be one of the following values:
00483   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
00484   *         @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
00485   * @retval None
00486   */
00487 __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
00488 {
00489   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAHSM, (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK));
00490 }
00491 
00492 /**
00493   * @brief  Get OPAMP power mode normal or highspeed.
00494   * @note   OPAMP highspeed mode allows output stage to have a better slew rate.
00495   * @rmtoll CSR      OPAHSM     LL_OPAMP_GetPowerMode
00496   * @param  OPAMPx OPAMP instance
00497   * @retval Returned value can be one of the following values:
00498   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
00499   *         @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
00500   */
00501 __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
00502 {
00503   uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAHSM));
00504 
00505   return (uint32_t)(power_mode | (power_mode >> (OPAMP_CSR_OPAHSM_Pos)));
00506 }
00507 /**
00508   * @}
00509   */
00510 
00511 /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
00512   * @{
00513   */
00514 
00515 /**
00516   * @brief  Set OPAMP non-inverting input connection.
00517   * @rmtoll CSR      VPSEL          LL_OPAMP_SetInputNonInverting
00518   * @param  OPAMPx OPAMP instance
00519   * @param  InputNonInverting This parameter can be one of the following values:
00520   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
00521   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
00522   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC2 (Only for OPAMP2)
00523   * @retval None
00524   */
00525 __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
00526 {
00527   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
00528 }
00529 
00530 /**
00531   * @brief  Get OPAMP non-inverting input connection.
00532   * @rmtoll CSR      VPSEL          LL_OPAMP_GetInputNonInverting
00533   * @param  OPAMPx OPAMP instance
00534   * @retval Returned value can be one of the following values:
00535   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
00536   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
00537   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC2 (Only for OPAMP2)
00538   */
00539 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
00540 {
00541   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
00542 }
00543 
00544 /**
00545   * @brief  Set OPAMP inverting input connection.
00546   * @note   OPAMP inverting input is used with OPAMP in mode standalone
00547   *         or PGA with external capacitors for filtering circuit.
00548   *         Otherwise (OPAMP in mode follower), OPAMP inverting input
00549   *         is not used (not connected to GPIO pin).
00550   * @rmtoll CSR      VMSEL          LL_OPAMP_SetInputInverting
00551   * @param  OPAMPx OPAMP instance
00552   * @param  InputInverting This parameter can be one of the following values:
00553   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO0
00554   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO1
00555   *         @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
00556   * @retval None
00557   */
00558 __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
00559 {
00560   /* Manage cases of OPAMP inverting input not connected (0x10 and 0x11)      */
00561   /* to not modify OPAMP mode follower or PGA.                                */
00562   /* Bit OPAMP_CSR_VMSEL_1 is set by OPAMP mode (follower, PGA). */
00563   MODIFY_REG(OPAMPx->CSR, (~(InputInverting >> 1)) & OPAMP_CSR_VMSEL_0, InputInverting);
00564 }
00565 
00566 /**
00567   * @brief  Get OPAMP inverting input connection.
00568   * @rmtoll CSR      VMSEL          LL_OPAMP_GetInputInverting
00569   * @param  OPAMPx OPAMP instance
00570   * @retval Returned value can be one of the following values:
00571   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO0
00572   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO1
00573   *         @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
00574   */
00575 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
00576 {
00577   uint32_t input_inverting = READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL);
00578 
00579   /* Manage cases 0x10 and 0x11 to return the same value: OPAMP inverting     */
00580   /* input not connected.                                                     */
00581   return (input_inverting & ~((input_inverting >> 1) & OPAMP_CSR_VMSEL_0));
00582 }
00583 
00584 /**
00585   * @}
00586   */
00587 
00588 /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
00589   * @{
00590   */
00591 
00592 /**
00593   * @brief  Set OPAMP trimming mode.
00594   * @rmtoll CSR      USERTRIM       LL_OPAMP_SetTrimmingMode
00595   * @param  OPAMPx OPAMP instance
00596   * @param  TrimmingMode This parameter can be one of the following values:
00597   *         @arg @ref LL_OPAMP_TRIMMING_FACTORY
00598   *         @arg @ref LL_OPAMP_TRIMMING_USER
00599   * @retval None
00600   */
00601 __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
00602 {
00603   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
00604 }
00605 
00606 /**
00607   * @brief  Get OPAMP trimming mode.
00608   * @rmtoll CSR      USERTRIM       LL_OPAMP_GetTrimmingMode
00609   * @param  OPAMPx OPAMP instance
00610   * @retval Returned value can be one of the following values:
00611   *         @arg @ref LL_OPAMP_TRIMMING_FACTORY
00612   *         @arg @ref LL_OPAMP_TRIMMING_USER
00613   */
00614 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx)
00615 {
00616   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
00617 }
00618 
00619 /**
00620   * @brief  Set OPAMP offset to calibrate the selected transistors
00621   *         differential pair NMOS or PMOS.
00622   * @note   Preliminarily, OPAMP must be set in mode calibration
00623   *         using function @ref LL_OPAMP_SetMode().
00624   * @rmtoll CSR      CALSEL         LL_OPAMP_SetCalibrationSelection
00625   * @param  OPAMPx OPAMP instance
00626   * @param  TransistorsDiffPair This parameter can be one of the following values:
00627   *         @arg @ref LL_OPAMP_TRIMMING_NMOS            (1)
00628   *         @arg @ref LL_OPAMP_TRIMMING_PMOS            (1)
00629   *         @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
00630   *         @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
00631   *
00632   *         (1) Default parameters to be used for calibration
00633   *             using two trimming steps (one with each transistors differential
00634   *             pair NMOS and PMOS)
00635   * @retval None
00636   */
00637 __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
00638 {
00639   /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because            */
00640   /* containing other bits reserved for other purpose.                        */
00641   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, ((TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK) >> 4));
00642 }
00643 
00644 /**
00645   * @brief  Get OPAMP offset to calibrate the selected transistors
00646   *         differential pair NMOS or PMOS.
00647   * @note   Preliminarily, OPAMP must be set in mode calibration
00648   *         using function @ref LL_OPAMP_SetMode().
00649   * @rmtoll CSR      CALSEL         LL_OPAMP_GetCalibrationSelection
00650   * @param  OPAMPx OPAMP instance
00651   * @retval Returned value can be one of the following values:
00652   *         @arg @ref LL_OPAMP_TRIMMING_NMOS            (1)
00653   *         @arg @ref LL_OPAMP_TRIMMING_PMOS            (1)
00654   *         @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
00655   *         @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
00656   *
00657   *         (1) Default parameters to be used for calibration
00658   *             using two trimming steps (one with each transistors differential
00659   *             pair NMOS and PMOS)
00660   */
00661 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
00662 {
00663   uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
00664 
00665   return (uint32_t)((CalibrationSelection << 4)|
00666           (((CalibrationSelection & OPAMP_CSR_CALSEL_1) == 0UL) ? OPAMP_OTR_TRIMOFFSETN : OPAMP_OTR_TRIMOFFSETP));
00667 }
00668 
00669 /**
00670   * @brief  Get OPAMP calibration result of toggling output.
00671   * @note   This functions returns:
00672   *         0 if OPAMP calibration output is reset
00673   *         1 if OPAMP calibration output is set
00674   * @rmtoll CSR      OUTCAL         LL_OPAMP_IsCalibrationOutputSet
00675   * @param  OPAMPx OPAMP instance
00676   * @retval State of bit (1 or 0).
00677   */
00678 __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
00679 {
00680   return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT)?1UL:0UL);
00681 }
00682 
00683 /**
00684   * @brief  Set OPAMP trimming factor for the selected transistors
00685   *         differential pair NMOS or PMOS, corresponding to the selected
00686   *         power mode.
00687   * @rmtoll OTR      TRIMOFFSETN    LL_OPAMP_SetTrimmingValue\n
00688   *         OTR      TRIMOFFSETP    LL_OPAMP_SetTrimmingValue\n
00689   *         HSOTR    TRIMHSOFFSETN  LL_OPAMP_SetTrimmingValue\n
00690   *         HSOTR    TRIMHSOFFSETP  LL_OPAMP_SetTrimmingValue
00691   * @param  OPAMPx OPAMP instance
00692   * @param  PowerMode This parameter can be one of the following values:
00693   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
00694   *         @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
00695   * @param  TransistorsDiffPair This parameter can be one of the following values:
00696   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
00697   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
00698   * @param  TrimmingValue 0x00...0x1F
00699   * @retval None
00700   */
00701 __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
00702 {
00703   __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
00704 
00705   /* Set bits with position in register depending on parameter                */
00706   /* "TransistorsDiffPair".                                                   */
00707   /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because             */
00708   /* containing other bits reserved for other purpose.                        */
00709   MODIFY_REG(*preg,
00710              (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) << 1U,
00711              TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
00712 }
00713 
00714 /**
00715   * @brief  Get OPAMP trimming factor for the selected transistors
00716   *         differential pair NMOS or PMOS, corresponding to the selected
00717   *         power mode.
00718   * @rmtoll OTR      TRIMOFFSETN    LL_OPAMP_GetTrimmingValue\n
00719   *         OTR      TRIMOFFSETP    LL_OPAMP_GetTrimmingValue\n
00720   *         HSOTR    TRIMHSOFFSETN  LL_OPAMP_GetTrimmingValue\n
00721   *         HSOTR    TRIMHSOFFSETP  LL_OPAMP_GetTrimmingValue
00722   * @param  OPAMPx OPAMP instance
00723   * @param  PowerMode This parameter can be one of the following values:
00724   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
00725   *         @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
00726   * @param  TransistorsDiffPair This parameter can be one of the following values:
00727   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
00728   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
00729   * @retval 0x0...0x1F
00730   */
00731 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair)
00732 {
00733   const __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
00734 
00735   /* Retrieve bits with position in register depending on parameter           */
00736   /* "TransistorsDiffPair".                                                   */
00737   /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because             */
00738   /* containing other bits reserved for other purpose.                        */
00739   return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
00740                     >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
00741 }
00742 
00743 /**
00744   * @}
00745   */
00746 
00747 /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
00748   * @{
00749   */
00750 /**
00751   * @brief  Enable OPAMP instance.
00752   * @note   After enable from off state, OPAMP requires a delay
00753   *         to fulfill wake up time specification.
00754   *         Refer to device datasheet, parameter "tWAKEUP".
00755   * @rmtoll CSR      OPAMPXEN       LL_OPAMP_Enable
00756   * @param  OPAMPx OPAMP instance
00757   * @retval None
00758   */
00759 __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
00760 {
00761   SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
00762 }
00763 
00764 /**
00765   * @brief  Disable OPAMP instance.
00766   * @rmtoll CSR      OPAMPXEN       LL_OPAMP_Disable
00767   * @param  OPAMPx OPAMP instance
00768   * @retval None
00769   */
00770 __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
00771 {
00772   CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
00773 }
00774 
00775 /**
00776   * @brief  Get OPAMP instance enable state
00777   *         (0: OPAMP is disabled, 1: OPAMP is enabled)
00778   * @rmtoll CSR      OPAMPXEN       LL_OPAMP_IsEnabled
00779   * @param  OPAMPx OPAMP instance
00780   * @retval State of bit (1 or 0).
00781   */
00782 __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
00783 {
00784   return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN))?1UL:0UL);
00785 }
00786 /**
00787   * @}
00788   */
00789 
00790 #if defined(USE_FULL_LL_DRIVER)
00791 /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
00792   * @{
00793   */
00794 
00795 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
00796 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
00797 void        LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
00798 
00799 /**
00800   * @}
00801   */
00802 #endif /* USE_FULL_LL_DRIVER */
00803 
00804 /**
00805   * @}
00806   */
00807 
00808 /**
00809   * @}
00810   */
00811 
00812 #endif /* OPAMP1 || OPAMP2 */
00813 
00814 /**
00815   * @}
00816   */
00817 
00818 #ifdef __cplusplus
00819 }
00820 #endif
00821 
00822 #endif /* __STM32H7xx_LL_OPAMP_H */
00823 
00824