TUKS MCU Introductory course / TUKS-COURSE-THERMOMETER

Fork of TUKS-COURSE-TIMER by TUKS MCU Introductory course

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_ll_opamp.h Source File

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