Subversion Repositories DashDisplay

Rev

Rev 56 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32l1xx_ll_opamp.h
  4.   * @author  MCD Application Team
  5.   * @brief   Header file of OPAMP LL module.
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10.   * All rights reserved.</center></h2>
  11.   *
  12.   * This software component is licensed by ST under BSD 3-Clause license,
  13.   * the "License"; You may not use this file except in compliance with the
  14.   * License. You may obtain a copy of the License at:
  15.   *                        opensource.org/licenses/BSD-3-Clause
  16.   *
  17.   ******************************************************************************
  18.   */
  19.  
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef __STM32L1xx_LL_OPAMP_H
  22. #define __STM32L1xx_LL_OPAMP_H
  23.  
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27.  
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32l1xx.h"
  30.  
  31. /** @addtogroup STM32L1xx_LL_Driver
  32.   * @{
  33.   */
  34.  
  35. #if defined (OPAMP1) || defined (OPAMP2) || defined (OPAMP3)
  36.  
  37. /** @defgroup OPAMP_LL OPAMP
  38.   * @{
  39.   */
  40.  
  41. /* Private types -------------------------------------------------------------*/
  42. /* Private variables ---------------------------------------------------------*/
  43.  
  44. /* Private constants ---------------------------------------------------------*/
  45. /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants
  46.   * @{
  47.   */
  48.  
  49. /* Internal mask for OPAMP power mode:                                        */
  50. /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for:         */
  51. /* - OPAMP power mode into control register                                   */
  52. /* - OPAMP trimming register offset                                           */
  53.  
  54. /* Internal register offset for OPAMP trimming configuration */
  55. #define OPAMP_POWERMODE_OTR_REGOFFSET       (0x00000000U)
  56. #define OPAMP_POWERMODE_LPOTR_REGOFFSET     (0x00000001U)
  57. #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK  (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_LPOTR_REGOFFSET)
  58.  
  59. /* Mask for OPAMP power mode into control register */
  60. #define OPAMP_POWERMODE_CSR_BIT_MASK        (OPAMP_CSR_OPA1LPM)
  61.  
  62. /* Internal mask for OPAMP trimming of transistors differential pair NMOS     */
  63. /* or PMOS.                                                                   */
  64. /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for:          */
  65. /* - OPAMP trimming selection of transistors differential pair                */
  66. /* - OPAMP trimming values of transistors differential pair                   */
  67. #define OPAMP_TRIMMING_SELECT_SW_OFFSET     (16U)
  68. #define OPAMP_TRIMMING_SELECT_MASK          ((OPAMP_CSR_OPA1CAL_H | OPAMP_CSR_OPA1CAL_L) << OPAMP_TRIMMING_SELECT_SW_OFFSET)
  69. #define OPAMP_TRIMMING_VALUE_MASK           (OPAMP_OTR_AO1_OPT_OFFSET_TRIM_HIGH | OPAMP_OTR_AO1_OPT_OFFSET_TRIM_LOW)
  70.  
  71. /**
  72.   * @}
  73.   */
  74.  
  75.  
  76. /* Private macros ------------------------------------------------------------*/
  77. /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
  78.   * @{
  79.   */
  80.  
  81. /**
  82.   * @brief  Driver macro reserved for internal use: set a pointer to
  83.   *         a register from a register basis from which an offset
  84.   *         is applied.
  85.   * @param  __REG__ Register basis from which the offset is applied.
  86.   * @param  __REG_OFFSET__ Offset to be applied (unit: number of registers).
  87.   * @retval Register address
  88. */
  89. #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__)                        \
  90.  ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
  91.  
  92. /**
  93.   * @brief  Driver macro reserved for internal use: from OPAMP instance
  94.   *         selected, return the instance number in decimal format.
  95.   * @param  __OPAMP_INSTANCE__ OPAMP instance
  96.   * @retval Instance number in decimal format: value "0" for OPAMP1,
  97.   *         value "1" for OPAMP2, value "2" for OPAMP3.
  98. */
  99. #define __OPAMP_INSTANCE_DECIMAL(__OPAMP_INSTANCE__)                           \
  100.   ((uint32_t)(__OPAMP_INSTANCE__) - OPAMP_BASE)
  101.  
  102. /**
  103.   * @brief  Driver macro reserved for internal use: from OPAMP instance
  104.   *         selected, set offset of bits into OPAMP register.
  105.   * @note   Since all OPAMP instances are sharing the same register
  106.   *         with 3 area of bits with an offset of 8 bits (except bits
  107.   *         OPAxCALOUT, OPARANGE, S7SEL2), this function
  108.   *         returns .
  109.   * @param  __OPAMP_INSTANCE__ OPAMP instance
  110.   * @retval Bits offset in register 32 bits: value "0" for OPAMP1,
  111.   *         value "8" for OPAMP2, value "16" for OPAMP3
  112. */
  113. #define __OPAMP_INSTANCE_BITOFFSET(__OPAMP_INSTANCE__)                         \
  114.   (((uint32_t)(__OPAMP_INSTANCE__) - OPAMP_BASE) << 3U)
  115.  
  116. /**
  117.   * @brief  Driver macro reserved for internal use: from OPAMP instance
  118.   *         selected, return whether it corresponds to instance OPAMP2.
  119.   * @param  __OPAMP_INSTANCE__ OPAMP instance
  120.   * @retval Instance number in decimal format: value "0" for OPAMP1 or OPAMP3,
  121.   *         value "1" for OPAMP2.
  122. */
  123. #define __OPAMP_IS_INSTANCE_OPAMP2(__OPAMP_INSTANCE__)                         \
  124.   (((uint32_t)(__OPAMP_INSTANCE__) - OPAMP_BASE) % 2)
  125.  
  126. /**
  127.   * @}
  128.   */
  129.  
  130.  
  131. /* Exported types ------------------------------------------------------------*/
  132. #if defined(USE_FULL_LL_DRIVER)
  133. /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
  134.   * @{
  135.   */
  136.  
  137. /**
  138.   * @brief  Structure definition of some features of OPAMP instance.
  139.   */
  140. typedef struct
  141. {
  142.   uint32_t PowerMode;                   /*!< Set OPAMP power mode.
  143.                                              This parameter can be a value of @ref OPAMP_LL_EC_POWERMODE
  144.                                              
  145.                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
  146.  
  147.   uint32_t FunctionalMode;              /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
  148.                                              This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
  149.                                              
  150.                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
  151.  
  152.   uint32_t InputNonInverting;           /*!< Set OPAMP input non-inverting connection.
  153.                                              This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
  154.                                              
  155.                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
  156.  
  157.   uint32_t InputInverting;              /*!< Set OPAMP inverting input connection.
  158.                                              This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
  159.                                              @note OPAMP inverting input is used with OPAMP in mode standalone. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin), this parameter is discarded.
  160.                                              
  161.                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
  162.  
  163. } LL_OPAMP_InitTypeDef;
  164.  
  165. /**
  166.   * @}
  167.   */
  168. #endif /* USE_FULL_LL_DRIVER */
  169.  
  170. /* Exported constants --------------------------------------------------------*/
  171. /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
  172.   * @{
  173.   */
  174.  
  175. /** @defgroup OPAMP_LL_EC_POWERSUPPLY_RANGE OPAMP power supply range
  176.   * @{
  177.   */
  178. #define LL_OPAMP_POWERSUPPLY_RANGE_LOW  (0x00000000U)           /*!< Power supply range low. On STM32L1 serie: Vdda lower than 2.4V. */
  179. #define LL_OPAMP_POWERSUPPLY_RANGE_HIGH (OPAMP_CSR_AOP_RANGE)   /*!< Power supply range high. On STM32L1 serie: Vdda higher than 2.4V. */
  180. /**
  181.   * @}
  182.   */
  183.  
  184. /** @defgroup OPAMP_LL_EC_POWERMODE OPAMP power mode
  185.   * @{
  186.   */
  187. #define LL_OPAMP_POWERMODE_NORMAL       (OPAMP_POWERMODE_OTR_REGOFFSET)                       /*!< OPAMP power mode normal */
  188. #define LL_OPAMP_POWERMODE_LOWPOWER     (OPAMP_POWERMODE_LPOTR_REGOFFSET | OPAMP_CSR_OPA1LPM) /*!< OPAMP power mode low-power */
  189. /**
  190.   * @}
  191.   */
  192.  
  193. /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
  194.   * @{
  195.   */
  196. #define LL_OPAMP_MODE_FUNCTIONAL        (0x00000000U)                                                                                  /*!< OPAMP functional mode */
  197. #define LL_OPAMP_MODE_CALIBRATION       (OPAMP_CSR_S3SEL1 | OPAMP_CSR_S4SEL1 | OPAMP_CSR_S5SEL1 | OPAMP_CSR_S6SEL1 | OPAMP_CSR_S7SEL2) /*!< OPAMP calibration mode (on STM32L1 serie, it corresponds to all OPAMP input internal switches opened) */
  198. /**
  199.   * @}
  200.   */
  201.  
  202. /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
  203.   * @{
  204.   */
  205. #define LL_OPAMP_MODE_STANDALONE        (0x00000000U)           /*!< OPAMP functional mode, OPAMP operation in standalone (on STM32L1 serie, it corresponds to OPAMP internal switches S3 opened (switch SanB state depends on switch S4 state)) */
  206. #define LL_OPAMP_MODE_FOLLOWER          (OPAMP_CSR_S3SEL1)      /*!< OPAMP functional mode, OPAMP operation in follower (on STM32L1 serie, it corresponds to OPAMP internal switches S3 and SanB closed) */
  207. /**
  208.   * @}
  209.   */
  210.  
  211. /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
  212.   * @{
  213.   */
  214. #define LL_OPAMP_INPUT_NONINVERT_IO0      (OPAMP_CSR_S5SEL1)      /*!< OPAMP non inverting input connected to GPIO pin (low leakage input) */
  215. #define LL_OPAMP_INPUT_NONINV_DAC1_CH1    (OPAMP_CSR_S6SEL1)      /*!< OPAMP non inverting input connected to DAC1 channel1 output (specific to OPAMP instances: OPAMP1, OPAMP2) */
  216. #define LL_OPAMP_INPUT_NONINV_DAC1_CH2    (OPAMP_CSR_S7SEL2)      /*!< OPAMP non inverting input connected to DAC1 channel2 output (specific to OPAMP instances: OPAMP2, OPAMP3) */
  217. #if defined(OPAMP3)
  218. #define LL_OPAMP_INPUT_NONINV_DAC1_CH2_OPAMP3 (OPAMP_CSR_S6SEL1)  /*!< OPAMP non inverting input connected to DAC1 channel2 output (specific to OPAMP instances: OPAMP3) */
  219. #endif
  220. /**
  221.   * @}
  222.   */
  223.  
  224. /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
  225.   * @{
  226.   */
  227. #define LL_OPAMP_INPUT_INVERT_IO0        (OPAMP_CSR_S4SEL1)      /*!< OPAMP inverting input connected to GPIO pin (low leakage input). Note: OPAMP inverting input is used with OPAMP in mode standalone. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
  228. #define LL_OPAMP_INPUT_INVERT_IO1        (OPAMP_CSR_ANAWSEL1)    /*!< OPAMP inverting input connected to GPIO pin (alternative IO pin, not low leakage, availability depends on STM32L1 serie devices packages). Note: OPAMP inverting input is used with OPAMP in mode standalone. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
  229. #define LL_OPAMP_INPUT_INVERT_CONNECT_NO (0x00000000U)           /*!< OPAMP inverting input not externally connected (intended for OPAMP in mode follower) */
  230. /**
  231.   * @}
  232.   */
  233.  
  234. /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
  235.   * @{
  236.   */
  237. #define LL_OPAMP_TRIMMING_FACTORY       (0x00000000U)           /*!< OPAMP trimming factors set to factory values */
  238. #define LL_OPAMP_TRIMMING_USER          (OPAMP_OTR_OT_USER)     /*!< OPAMP trimming factors set to user values */
  239. /**
  240.   * @}
  241.   */
  242.  
  243. /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
  244.   * @{
  245.   */
  246. #define LL_OPAMP_TRIMMING_NMOS          (OPAMP_OTR_AO1_OPT_OFFSET_TRIM_HIGH | (OPAMP_CSR_OPA1CAL_H << OPAMP_TRIMMING_SELECT_SW_OFFSET)) /*!< OPAMP trimming of transistors differential pair NMOS */
  247. #define LL_OPAMP_TRIMMING_PMOS          (OPAMP_OTR_AO1_OPT_OFFSET_TRIM_LOW  | (OPAMP_CSR_OPA1CAL_L << OPAMP_TRIMMING_SELECT_SW_OFFSET)) /*!< OPAMP trimming of transistors differential pair PMOS */
  248. #define LL_OPAMP_TRIMMING_NONE          (0x00000000U)                                                                                   /*!< OPAMP trimming unselect transistors differential pair NMOS and PMOs */
  249. /**
  250.   * @}
  251.   */
  252.  
  253. /** @defgroup OPAMP_LL_EC_HW_DELAYS  Definitions of OPAMP hardware constraints delays
  254.   * @note   Only OPAMP IP HW delays are defined in OPAMP LL driver driver,
  255.   *         not timeout values.
  256.   *         For details on delays values, refer to descriptions in source code
  257.   *         above each literal definition.
  258.   * @{
  259.   */
  260.  
  261. /* Delay for OPAMP startup time (transition from state disable to enable).    */
  262. /* Note: OPAMP startup time depends on board application environment:         */
  263. /*       impedance connected to OPAMP output.                                 */
  264. /*       The delay below is specified under conditions:                       */
  265. /*        - OPAMP in mode low power                                           */
  266. /*        - load impedance of 4kOhm (min), 50pF (max)                         */
  267. /* Literal set to maximum value (refer to device datasheet,                   */
  268. /* parameter "tWAKEUP").                                                      */
  269. /* Unit: us                                                                   */
  270. #define LL_OPAMP_DELAY_STARTUP_US         (30U)  /*!< Delay for OPAMP startup time */
  271.  
  272. /**
  273.   * @}
  274.   */
  275.  
  276. /**
  277.   * @}
  278.   */
  279.  
  280. /* Exported macro ------------------------------------------------------------*/
  281. /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
  282.   * @{
  283.   */
  284. /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
  285.   * @{
  286.   */
  287. /**
  288.   * @brief  Write a value in OPAMP register
  289.   * @param  __INSTANCE__ OPAMP Instance
  290.   * @param  __REG__ Register to be written
  291.   * @param  __VALUE__ Value to be written in the register
  292.   * @retval None
  293.   */
  294. #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  295.  
  296. /**
  297.   * @brief  Read a value in OPAMP register
  298.   * @param  __INSTANCE__ OPAMP Instance
  299.   * @param  __REG__ Register to be read
  300.   * @retval Register value
  301.   */
  302. #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  303. /**
  304.   * @}
  305.   */
  306.  
  307. /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro
  308.   * @{
  309.   */
  310.  
  311. /**
  312.   * @brief  Helper macro to select the OPAMP common instance
  313.   *         to which is belonging the selected OPAMP instance.
  314.   * @note   OPAMP common register instance can be used to
  315.   *         set parameters common to several OPAMP instances.
  316.   *         Refer to functions having argument "OPAMPxy_COMMON" as parameter.
  317.   * @param  __OPAMPx__ OPAMP instance
  318.   * @retval OPAMP common instance
  319.   */
  320. #if defined(OPAMP1) && defined(OPAMP2) && defined(OPAMP3)
  321. #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__)                                 \
  322.   (OPAMP123_COMMON)
  323. #else
  324. #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__)                                 \
  325.   (OPAMP12_COMMON)
  326. #endif
  327.  
  328. /**
  329.   * @brief  Helper macro to check if all OPAMP instances sharing the same
  330.   *         OPAMP common instance are disabled.
  331.   * @note   This check is required by functions with setting conditioned to
  332.   *         OPAMP state:
  333.   *         All OPAMP instances of the OPAMP common group must be disabled.
  334.   *         Refer to functions having argument "OPAMPxy_COMMON" as parameter.
  335.   * @retval 0: All OPAMP instances sharing the same OPAMP common instance
  336.   *            are disabled.
  337.   *         1: At least one OPAMP instance sharing the same OPAMP common instance
  338.   *            is enabled
  339.   */
  340. #if defined(OPAMP1) && defined(OPAMP2) && defined(OPAMP3)
  341. #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE()                            \
  342.   (LL_OPAMP_IsEnabled(OPAMP1) |                                                \
  343.    LL_OPAMP_IsEnabled(OPAMP2) |                                                \
  344.    LL_OPAMP_IsEnabled(OPAMP3)  )
  345. #else
  346. #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE()                            \
  347.   (LL_OPAMP_IsEnabled(OPAMP1) |                                                \
  348.    LL_OPAMP_IsEnabled(OPAMP2)  )
  349. #endif
  350.  
  351. /**
  352.   * @}
  353.   */
  354.  
  355. /**
  356.   * @}
  357.   */
  358.  
  359. /* Exported functions --------------------------------------------------------*/
  360. /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
  361.   * @{
  362.   */
  363.  
  364. /** @defgroup OPAMP_LL_EF_Configuration_opamp_common Configuration of OPAMP hierarchical scope: common to several OPAMP instances
  365.   * @{
  366.   */
  367.  
  368. /**
  369.   * @brief  Set OPAMP power range.
  370.   * @note   The OPAMP power range applies to several OPAMP instances
  371.   *         (if several OPAMP instances available on the selected device).
  372.   * @note   On this STM32 serie, setting of this feature is conditioned to
  373.   *         OPAMP state:
  374.   *         All OPAMP instances of the OPAMP common group must be disabled.
  375.   *         This check can be done with function @ref LL_OPAMP_IsEnabled() for each
  376.   *         OPAMP instance or by using helper macro
  377.   *         @ref __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE().
  378.   * @rmtoll CSR      AOP_RANGE      LL_OPAMP_SetCommonPowerRange
  379.   * @param  OPAMPxy_COMMON OPAMP common instance
  380.   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  381.   * @param  PowerRange This parameter can be one of the following values:
  382.   *         @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
  383.   *         @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
  384.   * @retval None
  385.   */
  386. __STATIC_INLINE void LL_OPAMP_SetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON, uint32_t PowerRange)
  387. {
  388.   /* Prevent unused parameter warning */
  389.   (void)(OPAMPxy_COMMON);
  390.    
  391.   MODIFY_REG(OPAMP->CSR, OPAMP_CSR_AOP_RANGE, PowerRange);
  392. }
  393.  
  394. /**
  395.   * @brief  Get OPAMP power range.
  396.   * @note   The OPAMP power range applies to several OPAMP instances
  397.   *         (if several OPAMP instances available on the selected device).
  398.   * @rmtoll CSR      AOP_RANGE      LL_OPAMP_GetCommonPowerRange
  399.   * @param  OPAMPxy_COMMON OPAMP common instance
  400.   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  401.   * @retval Returned value can be one of the following values:
  402.   *         @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
  403.   *         @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
  404.   */
  405. __STATIC_INLINE uint32_t LL_OPAMP_GetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON)
  406. {
  407.   /* Prevent unused parameter warning */
  408.   (void)(OPAMPxy_COMMON);
  409.  
  410.   return (uint32_t)(READ_BIT(OPAMP->CSR, OPAMP_CSR_AOP_RANGE));
  411. }
  412.  
  413. /**
  414.   * @}
  415.   */
  416.  
  417. /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
  418.   * @{
  419.   */
  420.  
  421. /**
  422.   * @brief  Set OPAMP power mode.
  423.   * @note   The OPAMP must be disabled to change this configuration.
  424.   * @rmtoll CSR      OPA1LPM        LL_OPAMP_SetPowerMode\n
  425.   *         CSR      OPA2LPM        LL_OPAMP_SetPowerMode\n
  426.   *         CSR      OPA3LPM        LL_OPAMP_SetPowerMode
  427.   * @param  OPAMPx OPAMP instance
  428.   * @param  PowerMode This parameter can be one of the following values:
  429.   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
  430.   *         @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  431.   * @retval None
  432.   */
  433. __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
  434. {
  435.   MODIFY_REG(OPAMP->CSR,
  436.              OPAMP_CSR_OPA1LPM << __OPAMP_INSTANCE_BITOFFSET(OPAMPx),
  437.              (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx));
  438. }
  439.  
  440. /**
  441.   * @brief  Get OPAMP power mode.
  442.   * @rmtoll CSR      OPA1LPM        LL_OPAMP_GetPowerMode\n
  443.   *         CSR      OPA2LPM        LL_OPAMP_GetPowerMode\n
  444.   *         CSR      OPA3LPM        LL_OPAMP_GetPowerMode
  445.   * @param  OPAMPx OPAMP instance
  446.   * @retval Returned value can be one of the following values:
  447.   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
  448.   *         @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  449.   */
  450. __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
  451. {
  452.   uint32_t power_mode = (READ_BIT(OPAMP->CSR, OPAMP_CSR_OPA1LPM << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)));
  453.  
  454.   /* Shift variable to position corresponding to bitfield of OPAMP1 */
  455.   power_mode >>= __OPAMP_INSTANCE_BITOFFSET(OPAMPx);
  456.  
  457.   /* Construct data corresponding to literal LL_OPAMP_POWERMODE_x */
  458.   return (uint32_t)(power_mode | (power_mode >> (POSITION_VAL(OPAMP_CSR_OPA1LPM))));
  459. }
  460.  
  461. /**
  462.   * @brief  Set OPAMP mode calibration or functional.
  463.   * @note   OPAMP mode corresponds to functional or calibration mode:
  464.   *          - functional mode: OPAMP operation in standalone, follower, ...
  465.   *            Set functional mode using function
  466.   *            @ref LL_OPAMP_SetFunctionalMode().
  467.   *          - calibration mode: offset calibration of the selected
  468.   *            transistors differential pair NMOS or PMOS.
  469.   * @note   On this STM32 serie, entering in calibration mode makes
  470.   *         loosing OPAMP internal switches configuration.
  471.   *         Therefore, when going back to functional mode,
  472.   *         functional mode must be set again using
  473.   *         @ref LL_OPAMP_SetFunctionalMode().
  474.   * @rmtoll CSR      S3SELx         LL_OPAMP_SetMode\n
  475.   * @rmtoll CSR      S4SELx         LL_OPAMP_SetMode\n
  476.   * @rmtoll CSR      S5SELx         LL_OPAMP_SetMode\n
  477.   * @rmtoll CSR      S6SELx         LL_OPAMP_SetMode\n
  478.   * @rmtoll CSR      S7SEL2         LL_OPAMP_SetMode
  479.   * @param  OPAMPx OPAMP instance
  480.   * @param  Mode This parameter can be one of the following values:
  481.   *         @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  482.   *         @arg @ref LL_OPAMP_MODE_CALIBRATION
  483.   * @retval None
  484.   */
  485. __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
  486. {
  487.   CLEAR_BIT(OPAMP->CSR,
  488.             ((Mode & ~OPAMP_CSR_S7SEL2) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | ((Mode & OPAMP_CSR_S7SEL2) * __OPAMP_IS_INSTANCE_OPAMP2(OPAMPx)));
  489. }
  490.  
  491. /**
  492.   * @brief  Get OPAMP mode calibration or functional.
  493.   * @note   OPAMP mode corresponds to functional or calibration mode:
  494.   *          - functional mode: OPAMP operation in standalone, follower, ...
  495.   *            Set functional mode using function
  496.   *            @ref LL_OPAMP_SetFunctionalMode().
  497.   *          - calibration mode: offset calibration of the selected
  498.   *            transistors differential pair NMOS or PMOS.
  499.   * @rmtoll CSR      S3SELx         LL_OPAMP_SetMode\n
  500.   * @rmtoll CSR      S4SELx         LL_OPAMP_SetMode\n
  501.   * @rmtoll CSR      S5SELx         LL_OPAMP_SetMode\n
  502.   * @rmtoll CSR      S6SELx         LL_OPAMP_SetMode\n
  503.   * @rmtoll CSR      S7SEL2         LL_OPAMP_SetMode
  504.   * @param  OPAMPx OPAMP instance
  505.   * @retval Returned value can be one of the following values:
  506.   *         @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  507.   *         @arg @ref LL_OPAMP_MODE_CALIBRATION
  508.   */
  509. __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
  510. {
  511.   return (uint32_t)(((READ_BIT(OPAMP->CSR,
  512.                                ((LL_OPAMP_MODE_CALIBRATION & ~OPAMP_CSR_S7SEL2) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | (OPAMP_CSR_S7SEL2 * __OPAMP_IS_INSTANCE_OPAMP2(OPAMPx)))
  513.                      ) == 0U) * LL_OPAMP_MODE_CALIBRATION);
  514. }
  515.  
  516. /**
  517.   * @brief  Set OPAMP functional mode by setting internal connections.
  518.   *         OPAMP operation in standalone, follower, ...
  519.   * @note   This function reset bit of calibration mode to ensure
  520.   *         to be in functional mode, in order to have OPAMP parameters
  521.   *         (inputs selection, ...) set with the corresponding OPAMP mode
  522.   *         to be effective.
  523.   * @rmtoll CSR      S3SELx        LL_OPAMP_SetFunctionalMode
  524.   * @param  OPAMPx OPAMP instance
  525.   * @param  FunctionalMode This parameter can be one of the following values:
  526.   *         @arg @ref LL_OPAMP_MODE_STANDALONE
  527.   *         @arg @ref LL_OPAMP_MODE_FOLLOWER
  528.   * @retval None
  529.   */
  530. __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
  531. {
  532.   /* Note: Bits OPAMP_CSR_OPAxCAL_y reset to ensure to be in functional mode */
  533.   MODIFY_REG(OPAMP->CSR,
  534.              (OPAMP_CSR_S3SEL1 | OPAMP_CSR_OPA1CAL_H | OPAMP_CSR_OPA1CAL_L) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx),
  535.              FunctionalMode << __OPAMP_INSTANCE_BITOFFSET(OPAMPx));
  536. }
  537.  
  538. /**
  539.   * @brief  Get OPAMP functional mode from setting of internal connections.
  540.   *         OPAMP operation in standalone, follower, ...
  541.   * @rmtoll CSR      S3SELx        LL_OPAMP_GetFunctionalMode
  542.   * @param  OPAMPx OPAMP instance
  543.   * @retval Returned value can be one of the following values:
  544.   *         @arg @ref LL_OPAMP_MODE_STANDALONE
  545.   *         @arg @ref LL_OPAMP_MODE_FOLLOWER
  546.   */
  547. __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
  548. {
  549.   return (uint32_t)(READ_BIT(OPAMP->CSR, OPAMP_CSR_S3SEL1 << __OPAMP_INSTANCE_BITOFFSET(OPAMPx))
  550.                     >> __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  551.                    );
  552. }
  553.  
  554. /**
  555.   * @}
  556.   */
  557.  
  558. /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
  559.   * @{
  560.   */
  561.  
  562. /**
  563.   * @brief  Set OPAMP non-inverting input connection.
  564.   * @rmtoll CSR      S5SELx         LL_OPAMP_SetInputNonInverting\n
  565.   * @rmtoll CSR      S6SELx         LL_OPAMP_SetInputNonInverting\n
  566.   * @rmtoll CSR      S7SEL2         LL_OPAMP_SetInputNonInverting
  567.   * @param  OPAMPx OPAMP instance
  568.   * @param  InputNonInverting This parameter can be one of the following values:
  569.   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  570.   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1 (1)
  571.   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2 (2)
  572.   *        
  573.   *         (1) Parameter specific to OPAMP instances: OPAMP1, OPAMP2.\n
  574.   *         (2) Parameter specific to OPAMP instances: OPAMP2, OPAMP3.
  575.   * @retval None
  576.   */
  577. __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
  578. {
  579.   MODIFY_REG(OPAMP->CSR,
  580.              ((OPAMP_CSR_S5SEL1 | OPAMP_CSR_S6SEL1) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | (OPAMP_CSR_S7SEL2 * __OPAMP_IS_INSTANCE_OPAMP2(OPAMPx)),
  581.              (InputNonInverting << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | ((InputNonInverting & OPAMP_CSR_S7SEL2) * __OPAMP_IS_INSTANCE_OPAMP2(OPAMPx))
  582.             );
  583. }
  584.  
  585. /**
  586.   * @brief  Get OPAMP non-inverting input connection.
  587.   * @rmtoll CSR      S5SELx         LL_OPAMP_GetInputNonInverting\n
  588.   * @rmtoll CSR      S6SELx         LL_OPAMP_GetInputNonInverting\n
  589.   * @rmtoll CSR      S7SEL2         LL_OPAMP_GetInputNonInverting
  590.   * @param  OPAMPx OPAMP instance
  591.   * @retval Returned value can be one of the following values:
  592.   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  593.   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1 (1)
  594.   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2 (2)
  595.   *        
  596.   *         (1) Parameter specific to OPAMP instances: OPAMP1, OPAMP2.\n
  597.   *         (2) Parameter specific to OPAMP instances: OPAMP2, OPAMP3.
  598.   */
  599. __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
  600. {
  601.   uint32_t input_non_inverting_opamp_x = READ_BIT(OPAMP->CSR,
  602.                                                   (OPAMP_CSR_S5SEL1 | OPAMP_CSR_S6SEL1) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  603.                                                   | (OPAMP_CSR_S7SEL2 * __OPAMP_IS_INSTANCE_OPAMP2(OPAMPx))
  604.                                                  );
  605.  
  606.   return (((input_non_inverting_opamp_x & ~OPAMP_CSR_S7SEL2) >> __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | (input_non_inverting_opamp_x & OPAMP_CSR_S7SEL2));
  607. }
  608.  
  609. /**
  610.   * @brief  Set OPAMP inverting input connection.
  611.   * @note   OPAMP inverting input is used with OPAMP in mode standalone.
  612.   *         Otherwise (OPAMP in mode follower), OPAMP inverting input
  613.   *         is not used (not connected to GPIO pin).
  614.   * @rmtoll CSR      S4SELx         LL_OPAMP_SetInputInverting\n
  615.   * @rmtoll CSR      ANAWSELx        LL_OPAMP_SetInputInverting
  616.   * @param  OPAMPx OPAMP instance
  617.   * @param  InputInverting This parameter can be one of the following values:
  618.   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  619.   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO1        (1)
  620.   *         @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  621.   *        
  622.   *         (1) Alternative IO pin, not low leakage, availability depends on STM32L1 serie devices packages.
  623.   * @retval None
  624.   */
  625. __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
  626. {
  627.   MODIFY_REG(OPAMP->CSR,
  628.              ((OPAMP_CSR_S4SEL1) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | ((OPAMP_CSR_ANAWSEL1) << __OPAMP_INSTANCE_DECIMAL(OPAMPx)),
  629.              ((InputInverting & OPAMP_CSR_S4SEL1) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | ((InputInverting & OPAMP_CSR_ANAWSEL1) << __OPAMP_INSTANCE_DECIMAL(OPAMPx))
  630.             );
  631. }
  632.  
  633. /**
  634.   * @brief  Get OPAMP inverting input connection.
  635.   * @rmtoll CSR      S4SELx         LL_OPAMP_SetInputInverting\n
  636.   * @rmtoll CSR      ANAWSELx        LL_OPAMP_SetInputInverting
  637.   * @param  OPAMPx OPAMP instance
  638.   * @retval Returned value can be one of the following values:
  639.   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  640.   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO1        (1)
  641.   *         @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  642.   *        
  643.   *         (1) Alternative IO pin, not low leakage, availability depends on STM32L1 serie devices packages.
  644.   */
  645. __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
  646. {
  647.   uint32_t input_inverting_opamp_x = READ_BIT(OPAMP->CSR,
  648.                                                 (OPAMP_CSR_S4SEL1) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  649.                                               | (OPAMP_CSR_ANAWSEL1) << __OPAMP_INSTANCE_DECIMAL(OPAMPx)
  650.                                              );
  651.  
  652. #if defined(OPAMP3)
  653.   return (  ((input_inverting_opamp_x & (OPAMP_CSR_S4SEL1 | OPAMP_CSR_S4SEL2 | OPAMP_CSR_S4SEL3)) >> __OPAMP_INSTANCE_BITOFFSET(OPAMPx))
  654.           | ((input_inverting_opamp_x & (OPAMP_CSR_ANAWSEL1 | OPAMP_CSR_ANAWSEL2 | OPAMP_CSR_ANAWSEL3)) >> __OPAMP_INSTANCE_DECIMAL(OPAMPx)));
  655. #else
  656.   return (  ((input_inverting_opamp_x & (OPAMP_CSR_S4SEL1 | OPAMP_CSR_S4SEL2)) >> __OPAMP_INSTANCE_BITOFFSET(OPAMPx))
  657.           | ((input_inverting_opamp_x & (OPAMP_CSR_ANAWSEL1 | OPAMP_CSR_ANAWSEL2)) >> __OPAMP_INSTANCE_DECIMAL(OPAMPx)));
  658. #endif
  659. }
  660.  
  661. /**
  662.   * @}
  663.   */
  664.  
  665. /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
  666.   * @{
  667.   */
  668.  
  669. /**
  670.   * @brief  Set OPAMP trimming mode.
  671.   * @note   The OPAMP trimming mode applies to several OPAMP instances
  672.   *         (if several OPAMP instances available on the selected device).
  673.   * @rmtoll OTR      OT_USER        LL_OPAMP_SetCommonTrimmingMode
  674.   * @param  OPAMPxy_COMMON OPAMP common instance
  675.   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  676.   * @param  TrimmingMode This parameter can be one of the following values:
  677.   *         @arg @ref LL_OPAMP_TRIMMING_FACTORY
  678.   *         @arg @ref LL_OPAMP_TRIMMING_USER
  679.   * @retval None
  680.   */
  681. __STATIC_INLINE void LL_OPAMP_SetCommonTrimmingMode(OPAMP_Common_TypeDef *OPAMPxy_COMMON, uint32_t TrimmingMode)
  682. {
  683.   /* Note: On STM32L1 serie, OPAMP trimming mode bit "OPAMP_OTR_OT_USER" is   */
  684.   /*       write only, cannot be read.                                        */
  685.   MODIFY_REG(OPAMPxy_COMMON->OTR,
  686.              OPAMP_OTR_OT_USER,
  687.              TrimmingMode);
  688. }
  689.  
  690. /**
  691.   * @brief  Get OPAMP trimming mode.
  692.   * @note   The OPAMP trimming mode applies to several OPAMP instances
  693.   *         (if several OPAMP instances available on the selected device).
  694.   * @rmtoll OTR      OT_USER        LL_OPAMP_GetCommonTrimmingMode
  695.   * @param  OPAMPxy_COMMON OPAMP common instance
  696.   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  697.   * @retval Returned value can be one of the following values:
  698.   *         @arg @ref LL_OPAMP_TRIMMING_FACTORY
  699.   *         @arg @ref LL_OPAMP_TRIMMING_USER
  700.   */
  701. __STATIC_INLINE uint32_t LL_OPAMP_GetCommonTrimmingMode(OPAMP_Common_TypeDef *OPAMPxy_COMMON)
  702. {
  703.   return (uint32_t)(READ_BIT(OPAMPxy_COMMON->OTR, OPAMP_OTR_OT_USER));
  704. }
  705.  
  706. /**
  707.   * @brief  Set OPAMP offset to calibrate the selected transistors
  708.   *         differential pair NMOS or PMOS.
  709.   * @note   Preliminarily, OPAMP must be set in mode calibration
  710.   *         using function @ref LL_OPAMP_SetMode().
  711.   * @rmtoll CSR      OPA1CAL_H      LL_OPAMP_SetCalibrationSelection\n
  712.   *         CSR      OPA1CAL_L      LL_OPAMP_SetCalibrationSelection
  713.   * @param  OPAMPx OPAMP instance
  714.   * @param  TransistorsDiffPair This parameter can be one of the following values:
  715.   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
  716.   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
  717.   *         @arg @ref LL_OPAMP_TRIMMING_NONE
  718.   * @retval None
  719.   */
  720. __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
  721. {
  722.   /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because            */
  723.   /* containing other bits reserved for other purpose.                        */
  724.   MODIFY_REG(OPAMP->CSR,
  725.              (OPAMP_CSR_OPA1CAL_H | OPAMP_CSR_OPA1CAL_L) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx),
  726.              ((TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK) >> OPAMP_TRIMMING_SELECT_SW_OFFSET) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  727.             );
  728. }
  729.  
  730. /**
  731.   * @brief  Get OPAMP offset to calibrate the selected transistors
  732.   *         differential pair NMOS or PMOS.
  733.   * @note   Preliminarily, OPAMP must be set in mode calibration
  734.   *         using function @ref LL_OPAMP_SetMode().
  735.   * @rmtoll CSR      OPA1CAL_H      LL_OPAMP_SetCalibrationSelection\n
  736.   *         CSR      OPA1CAL_L      LL_OPAMP_SetCalibrationSelection
  737.   * @param  OPAMPx OPAMP instance
  738.   * @retval Returned value can be one of the following values:
  739.   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
  740.   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
  741.   *         @arg @ref LL_OPAMP_TRIMMING_NONE
  742.   */
  743. __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
  744. {
  745.   uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMP->CSR,
  746.                                                       (OPAMP_CSR_OPA1CAL_H | OPAMP_CSR_OPA1CAL_L) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  747.                                                      )
  748.                                              >> __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  749.                                             );
  750.  
  751.   return ((CalibrationSelection << OPAMP_TRIMMING_SELECT_SW_OFFSET) |
  752.           ((OPAMP_OTR_AO1_OPT_OFFSET_TRIM_LOW) << (OPAMP_OTR_AO1_OPT_OFFSET_TRIM_HIGH_Pos * ((CalibrationSelection & OPAMP_CSR_OPA1CAL_H) != 0U))));
  753. }
  754.  
  755. /**
  756.   * @brief  Get OPAMP calibration result of toggling output.
  757.   * @note   This functions returns:
  758.   *         0 if OPAMP calibration output is reset
  759.   *         1 if OPAMP calibration output is set
  760.   * @rmtoll CSR      OPAxCALOUT     LL_OPAMP_IsCalibrationOutputSet
  761.   * @param  OPAMPx OPAMP instance
  762.   * @retval State of bit (1 or 0).
  763.   */
  764. __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
  765. {
  766.   return (READ_BIT(OPAMP->CSR, (OPAMP_CSR_OPA1CALOUT << __OPAMP_INSTANCE_DECIMAL(OPAMPx)))
  767.           == (OPAMP_CSR_OPA1CALOUT << __OPAMP_INSTANCE_DECIMAL(OPAMPx)));
  768. }
  769.  
  770. /**
  771.   * @brief  Set OPAMP trimming factor for the selected transistors
  772.   *         differential pair NMOS or PMOS, corresponding to the selected
  773.   *         power mode.
  774.   * @note   On STM32L1 serie, OPAMP trimming mode must be re-configured
  775.   *         at each update of trimming values in power mode normal.
  776.   *         Refer to function @ref LL_OPAMP_SetCommonTrimmingMode().
  777.   * @rmtoll OTR      AOx_OPT_OFFSET_TRIM_HIGH    LL_OPAMP_SetTrimmingValue\n
  778.   *         OTR      AOx_OPT_OFFSET_TRIM_LOW     LL_OPAMP_SetTrimmingValue\n
  779.   *         LPOTR    AOx_OPT_OFFSET_TRIM_LP_HIGH LL_OPAMP_SetTrimmingValue\n
  780.   *         LPOTR    AOx_OPT_OFFSET_TRIM_LP_LOW  LL_OPAMP_SetTrimmingValue
  781.   * @param  OPAMPx OPAMP instance
  782.   * @param  PowerMode This parameter can be one of the following values:
  783.   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
  784.   *         @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  785.   * @param  TransistorsDiffPair This parameter can be one of the following values:
  786.   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
  787.   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
  788.   * @param  TrimmingValue 0x00...0x1F
  789.   * @retval None
  790.   */
  791. __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
  792. {
  793.   uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMP->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
  794.  
  795.   /* Set bits with position in register depending on parameter                */
  796.   /* "TransistorsDiffPair".                                                   */
  797.   /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because             */
  798.   /* containing other bits reserved for other purpose.                        */
  799.   MODIFY_REG(*preg,
  800.              (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) << (OPAMP_OTR_AO2_OPT_OFFSET_TRIM_LOW_Pos * __OPAMP_INSTANCE_DECIMAL(OPAMPx)),
  801.              TrimmingValue << (POSITION_VAL(TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) + (OPAMP_OTR_AO2_OPT_OFFSET_TRIM_LOW_Pos * __OPAMP_INSTANCE_DECIMAL(OPAMPx))));
  802. }
  803.  
  804. /**
  805.   * @brief  Get OPAMP trimming factor for the selected transistors
  806.   *         differential pair NMOS or PMOS, corresponding to the selected
  807.   *         power mode.
  808.   * @rmtoll OTR      AOx_OPT_OFFSET_TRIM_HIGH    LL_OPAMP_GetTrimmingValue\n
  809.   *         OTR      AOx_OPT_OFFSET_TRIM_LOW     LL_OPAMP_GetTrimmingValue\n
  810.   *         LPOTR    AOx_OPT_OFFSET_TRIM_LP_HIGH LL_OPAMP_GetTrimmingValue\n
  811.   *         LPOTR    AOx_OPT_OFFSET_TRIM_LP_LOW  LL_OPAMP_GetTrimmingValue
  812.   * @param  OPAMPx OPAMP instance
  813.   * @param  PowerMode This parameter can be one of the following values:
  814.   *         @arg @ref LL_OPAMP_POWERMODE_NORMAL
  815.   *         @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  816.   * @param  TransistorsDiffPair This parameter can be one of the following values:
  817.   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
  818.   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
  819.   * @retval 0x0...0x1F
  820.   */
  821. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair)
  822. {
  823.   uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMP->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
  824.  
  825.   /* Retrieve bits with position in register depending on parameter           */
  826.   /* "TransistorsDiffPair".                                                   */
  827.   /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because             */
  828.   /* containing other bits reserved for other purpose.                        */
  829.   return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) << (OPAMP_OTR_AO2_OPT_OFFSET_TRIM_LOW_Pos * __OPAMP_INSTANCE_DECIMAL(OPAMPx)))
  830.                     >> (POSITION_VAL(TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) + (OPAMP_OTR_AO2_OPT_OFFSET_TRIM_LOW_Pos * __OPAMP_INSTANCE_DECIMAL(OPAMPx)))
  831.                    );
  832. }
  833.  
  834. /**
  835.   * @}
  836.   */
  837.  
  838. /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
  839.   * @{
  840.   */
  841. /**
  842.   * @brief  Enable OPAMP instance.
  843.   * @note   After enable from off state, OPAMP requires a delay
  844.   *         to fullfill wake up time specification.
  845.   *         Refer to device datasheet, parameter "tWAKEUP".
  846.   * @rmtoll CSR      OPAxPD         LL_OPAMP_Enable
  847.   * @param  OPAMPx OPAMP instance
  848.   * @retval None
  849.   */
  850. __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
  851. {
  852.   CLEAR_BIT(OPAMP->CSR, OPAMP_CSR_OPA1PD << __OPAMP_INSTANCE_BITOFFSET(OPAMPx));
  853. }
  854.  
  855. /**
  856.   * @brief  Disable OPAMP instance.
  857.   * @rmtoll CSR      OPAxPD         LL_OPAMP_Disable
  858.   * @param  OPAMPx OPAMP instance
  859.   * @retval None
  860.   */
  861. __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
  862. {
  863.   SET_BIT(OPAMP->CSR, OPAMP_CSR_OPA1PD << __OPAMP_INSTANCE_BITOFFSET(OPAMPx));
  864. }
  865.  
  866. /**
  867.   * @brief  Get OPAMP instance enable state
  868.   *         (0: OPAMP is disabled, 1: OPAMP is enabled)
  869.   * @rmtoll CSR      OPAxPD         LL_OPAMP_IsEnabled
  870.   * @param  OPAMPx OPAMP instance
  871.   * @retval State of bit (1 or 0).
  872.   */
  873. __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
  874. {
  875.   return (READ_BIT(OPAMP->CSR, OPAMP_CSR_OPA1PD << __OPAMP_INSTANCE_BITOFFSET(OPAMPx))
  876.           != (OPAMP_CSR_OPA1PD << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)));
  877. }
  878.  
  879. /**
  880.   * @}
  881.   */
  882.  
  883. #if defined(USE_FULL_LL_DRIVER)
  884. /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
  885.   * @{
  886.   */
  887.  
  888. ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
  889. ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  890. void        LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  891.  
  892. /**
  893.   * @}
  894.   */
  895. #endif /* USE_FULL_LL_DRIVER */
  896.  
  897. /**
  898.   * @}
  899.   */
  900.  
  901. /**
  902.   * @}
  903.   */
  904.  
  905. #endif /* OPAMP1 || OPAMP2 || OPAMP3 */
  906.  
  907. /**
  908.   * @}
  909.   */
  910.  
  911. #ifdef __cplusplus
  912. }
  913. #endif
  914.  
  915. #endif /* __STM32L1xx_LL_OPAMP_H */
  916.  
  917. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  918.