STM32L486xx HAL User Manual
stm32l4xx_ll_opamp.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_ll_opamp.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of OPAMP LL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */
00035 
00036 /* Define to prevent recursive inclusion -------------------------------------*/
00037 #ifndef __STM32L4xx_LL_OPAMP_H
00038 #define __STM32L4xx_LL_OPAMP_H
00039 
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #include "stm32l4xx.h"
00046 
00047 /** @addtogroup STM32L4xx_LL_Driver
00048   * @{
00049   */
00050 
00051 #if defined (OPAMP1) || defined (OPAMP2)
00052 
00053 /** @defgroup OPAMP_LL OPAMP
00054   * @{
00055   */
00056 
00057 /* Private types -------------------------------------------------------------*/
00058 /* Private variables ---------------------------------------------------------*/
00059 
00060 /* Private constants ---------------------------------------------------------*/
00061 /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants
00062   * @{
00063   */
00064 
00065 /* Internal mask for OPAMP power mode:                                        */
00066 /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for:         */
00067 /* - OPAMP power mode into control register                                   */
00068 /* - OPAMP trimming register offset                                           */
00069 
00070 /* Internal register offset for OPAMP trimming configuration */
00071 #define OPAMP_POWERMODE_OTR_REGOFFSET       ((uint32_t)0x00000000U)
00072 #define OPAMP_POWERMODE_LPOTR_REGOFFSET     ((uint32_t)0x00000001U)
00073 #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK  (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_LPOTR_REGOFFSET)
00074 
00075 /* Mask for OPAMP power mode into control register */
00076 #define OPAMP_POWERMODE_CSR_BIT_MASK        (OPAMP_CSR_OPALPM)
00077 
00078 /* Internal mask for OPAMP trimming of transistors differential pair NMOS     */
00079 /* or PMOS.                                                                   */
00080 /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for:          */
00081 /* - OPAMP trimming selection of transistors differential pair                */
00082 /* - OPAMP trimming values of transistors differential pair                   */
00083 #define OPAMP_TRIMMING_SELECT_MASK          (OPAMP1_CSR_CALSEL)
00084 #define OPAMP_TRIMMING_VALUE_MASK           (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN)
00085 
00086 /**
00087   * @}
00088   */
00089 
00090 
00091 /* Private macros ------------------------------------------------------------*/
00092 /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
00093   * @{
00094   */
00095 
00096 /**
00097   * @brief  Driver macro reserved for internal use: set a pointer to
00098   *         a register from a register basis from which an offset
00099   *         is applied.
00100   * @param  __REG__ Register basis from which the offset is applied.
00101   * @param  __REG_OFFSET__ Offset to be applied (unit: number of registers).
00102   * @retval Register address
00103 */
00104 #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__)                        \
00105  ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
00106 
00107 
00108 
00109 
00110 /**
00111   * @}
00112   */
00113 
00114 
00115 /* Exported types ------------------------------------------------------------*/
00116 #if defined(USE_FULL_LL_DRIVER)
00117 /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
00118   * @{
00119   */
00120 
00121 /**
00122   * @brief  Structure definition of some features of OPAMP instance.
00123   */
00124 typedef struct
00125 {
00126   uint32_t PowerMode;                   /*!< Set OPAMP power mode.
00127                                              This parameter can be a value of @ref OPAMP_LL_EC_POWERMODE
00128                                              
00129                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
00130 
00131   uint32_t FunctionalMode;              /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
00132                                              This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
00133                                              @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
00134                                              
00135                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
00136 
00137   uint32_t InputNonInverting;           /*!< Set OPAMP input non-inverting connection.
00138                                              This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
00139                                              
00140                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
00141 
00142   uint32_t InputInverting;              /*!< Set OPAMP inverting input connection.
00143                                              This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
00144                                              @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.
00145                                              
00146                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
00147 
00148 } LL_OPAMP_InitTypeDef;
00149 
00150 /**
00151   * @}
00152   */
00153 #endif /* USE_FULL_LL_DRIVER */
00154 
00155 /* Exported constants --------------------------------------------------------*/
00156 /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
00157   * @{
00158   */
00159 
00160 /** @defgroup OPAMP_LL_EC_POWERSUPPLY_RANGE OPAMP power supply range
00161   * @{
00162   */
00163 #define LL_OPAMP_POWERSUPPLY_RANGE_LOW  ((uint32_t)0x00000000U) /*!< Power supply range low. On STM32L4 serie: Vdda lower than 2.4V. */
00164 #define LL_OPAMP_POWERSUPPLY_RANGE_HIGH (OPAMP1_CSR_OPARANGE)   /*!< Power supply range high. On STM32L4 serie: Vdda higher than 2.4V. */
00165 /**
00166   * @}
00167   */
00168 
00169 /** @defgroup OPAMP_LL_EC_POWERMODE OPAMP power mode
00170   * @{
00171   */
00172 #define LL_OPAMP_POWERMODE_NORMAL       (OPAMP_POWERMODE_OTR_REGOFFSET)                      /*!< OPAMP power mode normal */
00173 #define LL_OPAMP_POWERMODE_LOWPOWER     (OPAMP_POWERMODE_LPOTR_REGOFFSET | OPAMP_CSR_OPALPM) /*!< OPAMP power mode low-power */
00174 /**
00175   * @}
00176   */
00177 
00178 /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
00179   * @{
00180   */
00181 #define LL_OPAMP_MODE_FUNCTIONAL        ((uint32_t)0x00000000U)                     /*!< OPAMP functional mode */
00182 #define LL_OPAMP_MODE_CALIBRATION       (OPAMP_CSR_CALON)                           /*!< OPAMP calibration mode */
00183 /**
00184   * @}
00185   */
00186 
00187 /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
00188   * @{
00189   */
00190 #define LL_OPAMP_MODE_STANDALONE        ((uint32_t)0x00000000U)                     /*!< OPAMP functional mode, OPAMP operation in standalone */
00191 #define LL_OPAMP_MODE_FOLLOWER          (OPAMP_CSR_OPAMODE_1 | OPAMP_CSR_OPAMODE_0) /*!< OPAMP functional mode, OPAMP operation in follower */
00192 #define LL_OPAMP_MODE_PGA               (OPAMP_CSR_OPAMODE_1)                       /*!< OPAMP functional mode, OPAMP operation in PGA */
00193 /**
00194   * @}
00195   */
00196 
00197 /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
00198   * @{
00199   */
00200 #define LL_OPAMP_PGA_GAIN_2             ((uint32_t)0x00000000U)                    /*!< OPAMP PGA gain 2 */
00201 #define LL_OPAMP_PGA_GAIN_4             (OPAMP_CSR_PGGAIN_0)                       /*!< OPAMP PGA gain 4 */
00202 #define LL_OPAMP_PGA_GAIN_8             (OPAMP_CSR_PGGAIN_1)                       /*!< OPAMP PGA gain 8 */
00203 #define LL_OPAMP_PGA_GAIN_16            (OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0 ) /*!< OPAMP PGA gain 16 */
00204 /**
00205   * @}
00206   */
00207 
00208 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
00209   * @{
00210   */
00211 #define LL_OPAMP_INPUT_NONINVERT_IO0      ((uint32_t)0x00000000U) /*!< OPAMP non inverting input connected to GPIO pin (pin PA0 for OPAMP1, pin PA6 for OPAMP2) */
00212 #define LL_OPAMP_INPUT_NONINV_DAC1_CH1    (OPAMP1_CSR_VPSEL)      /*!< OPAMP non inverting input connected to DAC1 channel1 output */
00213 /**
00214   * @}
00215   */
00216 
00217 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
00218   * @{
00219   */
00220 #define LL_OPAMP_INPUT_INVERT_IO0        ((uint32_t)0x00000000U) /*!< OPAMP inverting input connected to GPIO pin (valid also in PGA mode for filtering). 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). */
00221 #define LL_OPAMP_INPUT_INVERT_IO1        (OPAMP_CSR_VMSEL_0)     /*!< OPAMP inverting input (low leakage input) connected to GPIO pin (available only on package BGA132). 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). */
00222 #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 without external capacitors for filtering) */
00223 /**
00224   * @}
00225   */
00226 
00227 /** @defgroup OPAMP_LL_EC_INPUT_LEGACY OPAMP inputs legacy literals name
00228   * @{
00229   */
00230 #define LL_OPAMP_NONINVERTINGINPUT_IO0      LL_OPAMP_INPUT_NONINVERT_IO0
00231 #define LL_OPAMP_NONINVERTINGINPUT_DAC_CH   LL_OPAMP_INPUT_NONINV_DAC1_CH1
00232 
00233 #define LL_OPAMP_INVERTINGINPUT_IO0         LL_OPAMP_INPUT_INVERT_IO0
00234 #define LL_OPAMP_INVERTINGINPUT_IO1         LL_OPAMP_INPUT_INVERT_IO1
00235 #define LL_OPAMP_INVERTINGINPUT_CONNECT_NO  LL_OPAMP_INPUT_INVERT_CONNECT_NO
00236 
00237 #define LL_OPAMP_INPUT_NONINVERT_DAC1_CH1   LL_OPAMP_INPUT_NONINV_DAC1_CH1
00238 /**
00239   * @}
00240   */
00241 
00242 /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
00243   * @{
00244   */
00245 #define LL_OPAMP_TRIMMING_FACTORY       ((uint32_t)0x00000000U) /*!< OPAMP trimming factors set to factory values */
00246 #define LL_OPAMP_TRIMMING_USER          (OPAMP_CSR_USERTRIM)    /*!< OPAMP trimming factors set to user values */
00247 /**
00248   * @}
00249   */
00250 
00251 /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
00252   * @{
00253   */
00254 #define LL_OPAMP_TRIMMING_NMOS          (OPAMP_OTR_TRIMOFFSETN)                     /*!< OPAMP trimming of transistors differential pair NMOS */
00255 #define LL_OPAMP_TRIMMING_PMOS          (OPAMP_OTR_TRIMOFFSETP | OPAMP1_CSR_CALSEL) /*!< OPAMP trimming of transistors differential pair PMOS */
00256 /**
00257   * @}
00258   */
00259 
00260 /** @defgroup OPAMP_LL_EC_HW_DELAYS  Definitions of OPAMP hardware constraints delays
00261   * @note   Only OPAMP IP HW delays are defined in OPAMP LL driver driver,
00262   *         not timeout values.
00263   *         For details on delays values, refer to descriptions in source code
00264   *         above each literal definition.
00265   * @{
00266   */
00267 
00268 /* Delay for OPAMP startup time (transition from state disable to enable).    */
00269 /* Note: OPAMP startup time depends on board application environment:         */
00270 /*       impedance connected to OPAMP output.                                 */
00271 /*       The delay below is specified under conditions:                       */
00272 /*        - OPAMP in mode low power                                           */
00273 /*        - OPAMP in functional mode follower                                 */
00274 /*        - load impedance of 4kOhm (min), 50pF (max)                         */
00275 /* Literal set to maximum value (refer to device datasheet,                   */
00276 /* parameter "tWAKEUP").                                                      */
00277 /* Unit: us                                                                   */
00278 #define LL_OPAMP_DELAY_STARTUP_US         ((uint32_t) 30U)  /*!< Delay for OPAMP startup time */
00279 
00280 /**
00281   * @}
00282   */
00283 
00284 /**
00285   * @}
00286   */
00287 
00288 /* Exported macro ------------------------------------------------------------*/
00289 /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
00290   * @{
00291   */
00292 /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
00293   * @{
00294   */
00295 /**
00296   * @brief  Write a value in OPAMP register
00297   * @param  __INSTANCE__ OPAMP Instance
00298   * @param  __REG__ Register to be written
00299   * @param  __VALUE__ Value to be written in the register
00300   * @retval None
00301   */
00302 #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
00303 
00304 /**
00305   * @brief  Read a value in OPAMP register
00306   * @param  __INSTANCE__ OPAMP Instance
00307   * @param  __REG__ Register to be read
00308   * @retval Register value
00309   */
00310 #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
00311 /**
00312   * @}
00313   */
00314 
00315 /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro
00316   * @{
00317   */
00318 
00319 /**
00320   * @brief  Helper macro to select the OPAMP common instance
00321   *         to which is belonging the selected OPAMP instance.
00322   * @note   OPAMP common register instance can be used to
00323   *         set parameters common to several OPAMP instances.
00324   *         Refer to functions having argument "OPAMPxy_COMMON" as parameter.
00325   * @param  __OPAMPx__ OPAMP instance
00326   * @retval OPAMP common instance
00327   */
00328 #if defined(OPAMP1) && defined(OPAMP2)
00329 #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__)                                 \
00330   (OPAMP12_COMMON)
00331 #else
00332 #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__)                                 \
00333   (OPAMP1_COMMON)
00334 #endif
00335 
00336 /**
00337   * @brief  Helper macro to check if all OPAMP instances sharing the same
00338   *         OPAMP common instance are disabled.
00339   * @note   This check is required by functions with setting conditioned to
00340   *         OPAMP state:
00341   *         All OPAMP instances of the OPAMP common group must be disabled.
00342   *         Refer to functions having argument "OPAMPxy_COMMON" as parameter.
00343   * @retval 0: All OPAMP instances sharing the same OPAMP common instance
00344   *            are disabled.
00345   *         1: At least one OPAMP instance sharing the same OPAMP common instance
00346   *            is enabled
00347   */
00348 #if defined(OPAMP1) && defined(OPAMP2)
00349 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE()                            \
00350   (LL_OPAMP_IsEnabled(OPAMP1) |                                                \
00351    LL_OPAMP_IsEnabled(OPAMP2)  )
00352 #else
00353 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE()                            \
00354   (LL_OPAMP_IsEnabled(OPAMP1))
00355 #endif
00356 
00357 /**
00358   * @}
00359   */
00360 
00361 /**
00362   * @}
00363   */
00364 
00365 /* Exported functions --------------------------------------------------------*/
00366 /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
00367   * @{
00368   */
00369 
00370 /** @defgroup OPAMP_LL_EF_Configuration_opamp_common Configuration of OPAMP hierarchical scope: common to several OPAMP instances
00371   * @{
00372   */
00373 
00374 /**
00375   * @brief  Set OPAMP power range.
00376   * @note   The OPAMP power range applies to several OPAMP instances
00377   *         (if several OPAMP instances available on the selected device).
00378   * @note   On this STM32 serie, setting of this feature is conditioned to
00379   *         OPAMP state:
00380   *         All OPAMP instances of the OPAMP common group must be disabled.
00381   *         This check can be done with function @ref LL_OPAMP_IsEnabled() for each
00382   *         OPAMP instance or by using helper macro
00383   *         @ref __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE().
00384   * @rmtoll CSR      OPARANGE       LL_OPAMP_SetCommonPowerRange
00385   * @param  OPAMPxy_COMMON OPAMP common instance
00386   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
00387   * @param  PowerRange This parameter can be one of the following values:
00388   *         @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
00389   *         @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
00390   * @retval None
00391   */
00392 __STATIC_INLINE void LL_OPAMP_SetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON, uint32_t PowerRange)
00393 {
00394   MODIFY_REG(OPAMP1->CSR, OPAMP1_CSR_OPARANGE, PowerRange);
00395 }
00396 
00397 /**
00398   * @brief  Get OPAMP power range.
00399   * @note   The OPAMP power range applies to several OPAMP instances
00400   *         (if several OPAMP instances available on the selected device).
00401   * @rmtoll CSR      OPARANGE       LL_OPAMP_GetCommonPowerRange
00402   * @param  OPAMPxy_COMMON OPAMP common instance
00403   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
00404   * @retval Returned value can be one of the following values:
00405   *         @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
00406   *         @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
00407   */
00408 __STATIC_INLINE uint32_t LL_OPAMP_GetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON)
00409 {
00410   return (uint32_t)(READ_BIT(OPAMP1->CSR, OPAMP1_CSR_OPARANGE));
00411 }
00412 
00413 /**
00414   * @}
00415   */
00416 
00417 /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
00418   * @{
00419   */
00420 
00421 /**
00422   * @brief  Set OPAMP power mode.
00423   * @note   The OPAMP must be disabled to change this configuration.
00424   * @rmtoll CSR      OPALPM         LL_OPAMP_SetPowerMode
00425   * @param  OPAMPx OPAMP instance
00426   * @param  PowerMode This parameter can be one of the following values:
00427   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
00428   *         @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
00429   * @retval None
00430   */
00431 __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
00432 {
00433   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPALPM, (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK));
00434 }
00435 
00436 /**
00437   * @brief  Get OPAMP power mode.
00438   * @rmtoll CSR      OPALPM         LL_OPAMP_GetPowerMode
00439   * @param  OPAMPx OPAMP instance
00440   * @retval Returned value can be one of the following values:
00441   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
00442   *         @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
00443   */
00444 __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
00445 {
00446   register uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPALPM));
00447   
00448   return (uint32_t)(power_mode | (power_mode >> (POSITION_VAL(OPAMP_CSR_OPALPM))));
00449 }
00450 
00451 /**
00452   * @brief  Set OPAMP mode calibration or functional.
00453   * @note   OPAMP mode corresponds to functional or calibration mode:
00454   *          - functional mode: OPAMP operation in standalone, follower, ...
00455   *            Set functional mode using function
00456   *            @ref LL_OPAMP_SetFunctionalMode().
00457   *          - calibration mode: offset calibration of the selected
00458   *            transistors differential pair NMOS or PMOS.
00459   * @note   On this STM32 serie, during calibration, OPAMP functional
00460   *         mode must be set to standalone or follower mode
00461   *         (in order to open internal connections to resistors
00462   *         of PGA mode).
00463   *         Refer to function @ref LL_OPAMP_SetFunctionalMode().
00464   * @rmtoll CSR      CALON          LL_OPAMP_SetMode
00465   * @param  OPAMPx OPAMP instance
00466   * @param  Mode This parameter can be one of the following values:
00467   *         @arg @ref LL_OPAMP_MODE_FUNCTIONAL
00468   *         @arg @ref LL_OPAMP_MODE_CALIBRATION
00469   * @retval None
00470   */
00471 __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
00472 {
00473   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
00474 }
00475 
00476 /**
00477   * @brief  Get OPAMP mode calibration or functional.
00478   * @note   OPAMP mode corresponds to functional or calibration mode:
00479   *          - functional mode: OPAMP operation in standalone, follower, ...
00480   *            Set functional mode using function
00481   *            @ref LL_OPAMP_SetFunctionalMode().
00482   *          - calibration mode: offset calibration of the selected
00483   *            transistors differential pair NMOS or PMOS.
00484   * @rmtoll CSR      CALON          LL_OPAMP_GetMode
00485   * @param  OPAMPx OPAMP instance
00486   * @retval Returned value can be one of the following values:
00487   *         @arg @ref LL_OPAMP_MODE_FUNCTIONAL
00488   *         @arg @ref LL_OPAMP_MODE_CALIBRATION
00489   */
00490 __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
00491 {
00492   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
00493 }
00494 
00495 /**
00496   * @brief  Set OPAMP functional mode by setting internal connections.
00497   *         OPAMP operation in standalone, follower, ...
00498   * @note   This function reset bit of calibration mode to ensure
00499   *         to be in functional mode, in order to have OPAMP parameters
00500   *         (inputs selection, ...) set with the corresponding OPAMP mode
00501   *         to be effective.
00502   * @rmtoll CSR      OPAMODE        LL_OPAMP_SetFunctionalMode
00503   * @param  OPAMPx OPAMP instance
00504   * @param  FunctionalMode This parameter can be one of the following values:
00505   *         @arg @ref LL_OPAMP_MODE_STANDALONE
00506   *         @arg @ref LL_OPAMP_MODE_FOLLOWER
00507   *         @arg @ref LL_OPAMP_MODE_PGA
00508   * @retval None
00509   */
00510 __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
00511 {
00512   /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
00513   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAMODE | OPAMP_CSR_CALON, FunctionalMode);
00514 }
00515 
00516 /**
00517   * @brief  Get OPAMP functional mode from setting of internal connections.
00518   *         OPAMP operation in standalone, follower, ...
00519   * @rmtoll CSR      OPAMODE        LL_OPAMP_GetFunctionalMode
00520   * @param  OPAMPx OPAMP instance
00521   * @retval Returned value can be one of the following values:
00522   *         @arg @ref LL_OPAMP_MODE_STANDALONE
00523   *         @arg @ref LL_OPAMP_MODE_FOLLOWER
00524   *         @arg @ref LL_OPAMP_MODE_PGA
00525   */
00526 __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
00527 {
00528   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMODE));
00529 }
00530 
00531 /**
00532   * @brief  Set OPAMP PGA gain.
00533   * @note   Preliminarily, OPAMP must be set in mode PGA
00534   *         using function @ref LL_OPAMP_SetFunctionalMode().
00535   * @rmtoll CSR      PGGAIN         LL_OPAMP_SetPGAGain
00536   * @param  OPAMPx OPAMP instance
00537   * @param  PGAGain This parameter can be one of the following values:
00538   *         @arg @ref LL_OPAMP_PGA_GAIN_2
00539   *         @arg @ref LL_OPAMP_PGA_GAIN_4
00540   *         @arg @ref LL_OPAMP_PGA_GAIN_8
00541   *         @arg @ref LL_OPAMP_PGA_GAIN_16
00542   * @retval None
00543   */
00544 __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
00545 {
00546   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN, PGAGain);
00547 }
00548 
00549 /**
00550   * @brief  Get OPAMP PGA gain.
00551   * @note   Preliminarily, OPAMP must be set in mode PGA
00552   *         using function @ref LL_OPAMP_SetFunctionalMode().
00553   * @rmtoll CSR      PGGAIN         LL_OPAMP_GetPGAGain
00554   * @param  OPAMPx OPAMP instance
00555   * @retval Returned value can be one of the following values:
00556   *         @arg @ref LL_OPAMP_PGA_GAIN_2
00557   *         @arg @ref LL_OPAMP_PGA_GAIN_4
00558   *         @arg @ref LL_OPAMP_PGA_GAIN_8
00559   *         @arg @ref LL_OPAMP_PGA_GAIN_16
00560   */
00561 __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
00562 {
00563   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN));
00564 }
00565 
00566 /**
00567   * @}
00568   */
00569 
00570 /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
00571   * @{
00572   */
00573 
00574 /**
00575   * @brief  Set OPAMP non-inverting input connection.
00576   * @rmtoll CSR      VPSEL          LL_OPAMP_SetInputNonInverting
00577   * @param  OPAMPx OPAMP instance
00578   * @param  InputNonInverting This parameter can be one of the following values:
00579   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
00580   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1
00581   * @retval None
00582   */
00583 __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
00584 {
00585   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
00586 }
00587 
00588 /**
00589   * @brief  Get OPAMP non-inverting input connection.
00590   * @rmtoll CSR      VPSEL          LL_OPAMP_GetInputNonInverting
00591   * @param  OPAMPx OPAMP instance
00592   * @retval Returned value can be one of the following values:
00593   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
00594   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1
00595   */
00596 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
00597 {
00598   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
00599 }
00600 
00601 /**
00602   * @brief  Set OPAMP inverting input connection.
00603   * @note   OPAMP inverting input is used with OPAMP in mode standalone
00604   *         or PGA with external capacitors for filtering circuit.
00605   *         Otherwise (OPAMP in mode follower), OPAMP inverting input
00606   *         is not used (not connected to GPIO pin).
00607   * @rmtoll CSR      VMSEL          LL_OPAMP_SetInputInverting
00608   * @param  OPAMPx OPAMP instance
00609   * @param  InputInverting This parameter can be one of the following values:
00610   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO0
00611   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO1
00612   *         @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
00613   * @retval None
00614   */
00615 __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
00616 {
00617   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VMSEL, InputInverting);
00618 }
00619 
00620 /**
00621   * @brief  Get OPAMP inverting input connection.
00622   * @rmtoll CSR      VMSEL          LL_OPAMP_GetInputInverting
00623   * @param  OPAMPx OPAMP instance
00624   * @retval Returned value can be one of the following values:
00625   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO0
00626   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO1
00627   *         @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
00628   */
00629 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
00630 {
00631   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL));
00632 }
00633 
00634 /**
00635   * @}
00636   */
00637 
00638 /** @defgroup OPAMP_LL_EF_Configuration_Legacy_Functions Configuration of OPAMP, legacy functions name
00639   * @{
00640   */
00641 /* Old functions name kept for legacy purpose, to be replaced by the          */
00642 /* current functions name.                                                    */
00643 __STATIC_INLINE void LL_OPAMP_SetNonInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t NonInvertingInput)
00644 {
00645   LL_OPAMP_SetInputNonInverting(OPAMPx, NonInvertingInput);
00646 }
00647 
00648 __STATIC_INLINE void LL_OPAMP_SetInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t InvertingInput)
00649 {
00650   LL_OPAMP_SetInputInverting(OPAMPx, InvertingInput);
00651 }
00652 
00653 /**
00654   * @}
00655   */
00656 
00657 /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
00658   * @{
00659   */
00660 
00661 /**
00662   * @brief  Set OPAMP trimming mode.
00663   * @rmtoll CSR      USERTRIM       LL_OPAMP_SetTrimmingMode
00664   * @param  OPAMPx OPAMP instance
00665   * @param  TrimmingMode This parameter can be one of the following values:
00666   *         @arg @ref LL_OPAMP_TRIMMING_FACTORY
00667   *         @arg @ref LL_OPAMP_TRIMMING_USER
00668   * @retval None
00669   */
00670 __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
00671 {
00672   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
00673 }
00674 
00675 /**
00676   * @brief  Get OPAMP trimming mode.
00677   * @rmtoll CSR      USERTRIM       LL_OPAMP_GetTrimmingMode
00678   * @param  OPAMPx OPAMP instance
00679   * @retval Returned value can be one of the following values:
00680   *         @arg @ref LL_OPAMP_TRIMMING_FACTORY
00681   *         @arg @ref LL_OPAMP_TRIMMING_USER
00682   */
00683 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx)
00684 {
00685   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
00686 }
00687 
00688 /**
00689   * @brief  Set OPAMP offset to calibrate the selected transistors
00690   *         differential pair NMOS or PMOS.
00691   * @note   Preliminarily, OPAMP must be set in mode calibration
00692   *         using function @ref LL_OPAMP_SetMode().
00693   * @rmtoll CSR      CALSEL         LL_OPAMP_SetCalibrationSelection
00694   * @param  OPAMPx OPAMP instance
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   * @retval None
00699   */
00700 __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
00701 {
00702   /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because            */
00703   /* containing other bits reserved for other purpose.                        */
00704   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, (TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK));
00705 }
00706 
00707 /**
00708   * @brief  Get OPAMP offset to calibrate the selected transistors
00709   *         differential pair NMOS or PMOS.
00710   * @note   Preliminarily, OPAMP must be set in mode calibration
00711   *         using function @ref LL_OPAMP_SetMode().
00712   * @rmtoll CSR      CALSEL         LL_OPAMP_GetCalibrationSelection
00713   * @param  OPAMPx OPAMP instance
00714   * @retval Returned value can be one of the following values:
00715   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
00716   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
00717   */
00718 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
00719 {
00720   register uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
00721   
00722   return (CalibrationSelection |
00723           ((OPAMP_OTR_TRIMOFFSETN) << (POSITION_VAL(OPAMP_OTR_TRIMOFFSETP) * (CalibrationSelection && OPAMP_CSR_CALSEL))));
00724 }
00725 
00726 /**
00727   * @brief  Get OPAMP calibration result of toggling output.
00728   * @note   This functions returns:
00729   *         0 if OPAMP calibration output is reset
00730   *         1 if OPAMP calibration output is set
00731   * @rmtoll CSR      CALOUT         LL_OPAMP_IsCalibrationOutputSet
00732   * @param  OPAMPx OPAMP instance
00733   * @retval State of bit (1 or 0).
00734   */
00735 __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
00736 {
00737   return (READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT);
00738 }
00739 
00740 /**
00741   * @brief  Set OPAMP trimming factor for the selected transistors
00742   *         differential pair NMOS or PMOS, corresponding to the selected
00743   *         power mode.
00744   * @rmtoll OTR      TRIMOFFSETN    LL_OPAMP_SetTrimmingValue\n
00745   *         OTR      TRIMOFFSETP    LL_OPAMP_SetTrimmingValue\n
00746   *         LPOTR    TRIMLPOFFSETN  LL_OPAMP_SetTrimmingValue\n
00747   *         LPOTR    TRIMLPOFFSETP  LL_OPAMP_SetTrimmingValue
00748   * @param  OPAMPx OPAMP instance
00749   * @param  PowerMode This parameter can be one of the following values:
00750   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
00751   *         @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
00752   * @param  TransistorsDiffPair This parameter can be one of the following values:
00753   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
00754   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
00755   * @param  TrimmingValue 0x00...0x1F
00756   * @retval None
00757   */
00758 __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
00759 {
00760   register uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
00761   
00762   /* Set bits with position in register depending on parameter                */
00763   /* "TransistorsDiffPair".                                                   */
00764   /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because             */
00765   /* containing other bits reserved for other purpose.                        */
00766   MODIFY_REG(*preg,
00767              (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK),
00768              TrimmingValue << (POSITION_VAL(TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK)));
00769 }
00770 
00771 /**
00772   * @brief  Get OPAMP trimming factor for the selected transistors
00773   *         differential pair NMOS or PMOS, corresponding to the selected
00774   *         power mode.
00775   * @rmtoll OTR      TRIMOFFSETN    LL_OPAMP_GetTrimmingValue\n
00776   *         OTR      TRIMOFFSETP    LL_OPAMP_GetTrimmingValue\n
00777   *         LPOTR    TRIMLPOFFSETN  LL_OPAMP_GetTrimmingValue\n
00778   *         LPOTR    TRIMLPOFFSETP  LL_OPAMP_GetTrimmingValue
00779   * @param  OPAMPx OPAMP instance
00780   * @param  PowerMode This parameter can be one of the following values:
00781   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
00782   *         @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
00783   * @param  TransistorsDiffPair This parameter can be one of the following values:
00784   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
00785   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
00786   * @retval 0x0...0x1F
00787   */
00788 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair)
00789 {
00790   register uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
00791   
00792   /* Retrieve bits with position in register depending on parameter           */
00793   /* "TransistorsDiffPair".                                                   */
00794   /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because             */
00795   /* containing other bits reserved for other purpose.                        */
00796   return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
00797                     >> (POSITION_VAL(TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
00798                    );
00799 }
00800 
00801 /**
00802   * @}
00803   */
00804 
00805 /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
00806   * @{
00807   */
00808 /**
00809   * @brief  Enable OPAMP instance.
00810   * @note   After enable from off state, OPAMP requires a delay
00811   *         to fullfill wake up time specification.
00812   *         Refer to device datasheet, parameter "tWAKEUP".
00813   * @rmtoll CSR      OPAMPXEN       LL_OPAMP_Enable
00814   * @param  OPAMPx OPAMP instance
00815   * @retval None
00816   */
00817 __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
00818 {
00819   SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
00820 }
00821 
00822 /**
00823   * @brief  Disable OPAMP instance.
00824   * @rmtoll CSR      OPAMPXEN       LL_OPAMP_Disable
00825   * @param  OPAMPx OPAMP instance
00826   * @retval None
00827   */
00828 __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
00829 {
00830   CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
00831 }
00832 
00833 /**
00834   * @brief  Get OPAMP instance enable state
00835   *         (0: OPAMP is disabled, 1: OPAMP is enabled)
00836   * @rmtoll CSR      OPAMPXEN       LL_OPAMP_IsEnabled
00837   * @param  OPAMPx OPAMP instance
00838   * @retval State of bit (1 or 0).
00839   */
00840 __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
00841 {
00842   return (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN));
00843 }
00844 
00845 /**
00846   * @}
00847   */
00848 
00849 #if defined(USE_FULL_LL_DRIVER)
00850 /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
00851   * @{
00852   */
00853 
00854 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
00855 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
00856 void        LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
00857 
00858 /**
00859   * @}
00860   */
00861 #endif /* USE_FULL_LL_DRIVER */
00862 
00863 /**
00864   * @}
00865   */
00866 
00867 /**
00868   * @}
00869   */
00870 
00871 #endif /* OPAMP1 || OPAMP2 */
00872 
00873 /**
00874   * @}
00875   */
00876 
00877 #ifdef __cplusplus
00878 }
00879 #endif
00880 
00881 #endif /* __STM32L4xx_LL_OPAMP_H */
00882 
00883 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/