Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:10

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_ll_opamp.c
0004   * @author  MCD Application Team
0005   * @brief   OPAMP LL module driver
0006   ******************************************************************************
0007   * @attention
0008   *
0009   * Copyright (c) 2017 STMicroelectronics.
0010   * All rights reserved.
0011   *
0012   * This software is licensed under terms that can be found in the LICENSE file
0013   * in the root directory of this software component.
0014   * If no LICENSE file comes with this software, it is provided AS-IS.
0015   *
0016   ******************************************************************************
0017   */
0018 #if defined(USE_FULL_LL_DRIVER) || defined(__rtems__)
0019 
0020 /* Includes ------------------------------------------------------------------*/
0021 #include "stm32h7xx_ll_opamp.h"
0022 
0023 #ifdef  USE_FULL_ASSERT
0024   #include "stm32_assert.h"
0025 #else
0026   #define assert_param(expr) ((void)0U)
0027 #endif
0028 
0029 /** @addtogroup STM32H7xx_LL_Driver
0030   * @{
0031   */
0032 
0033 #if defined (OPAMP1) || defined (OPAMP2) 
0034 /** @addtogroup OPAMP_LL OPAMP
0035   * @{
0036   */
0037 
0038 /* Private types -------------------------------------------------------------*/
0039 /* Private variables ---------------------------------------------------------*/
0040 /* Private constants ---------------------------------------------------------*/
0041 /* Private macros ------------------------------------------------------------*/
0042 
0043 /** @addtogroup OPAMP_LL_Private_Macros
0044   * @{
0045   */
0046 
0047 /* Check of parameters for configuration of OPAMP hierarchical scope:         */
0048 /* OPAMP instance.                                                            */
0049 
0050 #define IS_LL_OPAMP_POWER_MODE(__POWER_MODE__)                                 \
0051   (   ((__POWER_MODE__) == LL_OPAMP_POWERMODE_NORMAL)                          \
0052    || ((__POWER_MODE__) == LL_OPAMP_POWERMODE_HIGHSPEED))
0053 
0054 #define IS_LL_OPAMP_FUNCTIONAL_MODE(__FUNCTIONAL_MODE__)                       \
0055   (   ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_STANDALONE)                      \
0056    || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_FOLLOWER)                        \
0057    || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA)                             \
0058    || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0)                         \
0059    || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_BIAS)                    \
0060    || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_IO1_BIAS)                \
0061   )
0062 
0063 #if defined(DAC2)
0064 #define IS_LL_OPAMP_INPUT_NONINVERTING(__INPUT_NONINVERTING__)                 \
0065   (   ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0)               \
0066    || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC)               \
0067    || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC2)              \
0068   )
0069 #else
0070 #define IS_LL_OPAMP_INPUT_NONINVERTING(__INPUT_NONINVERTING__)                 \
0071   (   ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0)               \
0072    || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC)               \
0073   )
0074 #endif /* DAC2 */
0075   
0076 
0077 #define IS_LL_OPAMP_INPUT_INVERTING(__INPUT_INVERTING__)                       \
0078   (   ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0)                     \
0079    || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1)                     \
0080    || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO)              \
0081   )
0082   
0083 /**
0084   * @}
0085   */
0086 
0087 
0088 /* Private function prototypes -----------------------------------------------*/
0089 
0090 /* Exported functions --------------------------------------------------------*/
0091 /** @addtogroup OPAMP_LL_Exported_Functions
0092   * @{
0093   */
0094 
0095 /** @addtogroup OPAMP_LL_EF_Init
0096   * @{
0097   */
0098 
0099 /**
0100   * @brief  De-initialize registers of the selected OPAMP instance
0101   *         to their default reset values.
0102   * @note   If comparator is locked, de-initialization by software is
0103   *         not possible.
0104   *         The only way to unlock the comparator is a device hardware reset.
0105   * @param  OPAMPx OPAMP instance
0106   * @retval An ErrorStatus enumeration value:
0107   *          - SUCCESS: OPAMP registers are de-initialized
0108   *          - ERROR: OPAMP registers are not de-initialized
0109   */
0110 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef* OPAMPx)
0111 {
0112   ErrorStatus status = SUCCESS;
0113   
0114   /* Check the parameters */
0115   assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
0116   
0117   LL_OPAMP_WriteReg(OPAMPx, CSR, 0x00000000U);
0118  
0119   return status;
0120 }
0121 
0122 /**
0123   * @brief  Initialize some features of OPAMP instance.
0124   * @note   This function reset bit of calibration mode to ensure
0125   *         to be in functional mode, in order to have OPAMP parameters
0126   *         (inputs selection, ...) set with the corresponding OPAMP mode
0127   *         to be effective.
0128   * @param  OPAMPx OPAMP instance
0129   * @param  OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure
0130   * @retval An ErrorStatus enumeration value:
0131   *          - SUCCESS: OPAMP registers are initialized
0132   *          - ERROR: OPAMP registers are not initialized
0133   */
0134 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
0135 {
0136   ErrorStatus status = SUCCESS;
0137   
0138   /* Check the parameters */
0139   assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
0140   assert_param(IS_LL_OPAMP_POWER_MODE(OPAMP_InitStruct->PowerMode));
0141   assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode));
0142   assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMP_InitStruct->InputNonInverting));
0143   
0144   /* Note: OPAMP inverting input can be used with OPAMP in mode standalone    */
0145   /*       or PGA with external capacitors for filtering circuit.             */
0146   /*       Otherwise (OPAMP in mode follower), OPAMP inverting input is       */
0147   /*       not used (not connected to GPIO pin).                              */
0148   if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
0149   {
0150     assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMP_InitStruct->InputInverting));
0151   }
0152   
0153   /* Configuration of OPAMP instance :                                      */
0154   /*  - PowerMode                                                           */
0155   /*  - Functional mode                                                     */
0156   /*  - Input non-inverting                                                 */
0157   /*  - Input inverting                                                     */
0158   /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode.    */
0159   if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
0160   {
0161     MODIFY_REG(OPAMPx->CSR,
0162                  OPAMP_CSR_OPAHSM
0163                | OPAMP_CSR_CALON
0164                | OPAMP_CSR_VMSEL
0165                | OPAMP_CSR_VPSEL
0166                | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_1
0167               ,
0168                  (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK)
0169                | OPAMP_InitStruct->FunctionalMode
0170                | OPAMP_InitStruct->InputNonInverting
0171                | OPAMP_InitStruct->InputInverting
0172               );
0173   }
0174   else
0175   {
0176     MODIFY_REG(OPAMPx->CSR,
0177                  OPAMP_CSR_OPAHSM
0178                | OPAMP_CSR_CALON
0179                | OPAMP_CSR_VMSEL
0180                | OPAMP_CSR_VPSEL
0181                | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_1
0182               ,
0183                 (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK)
0184                | LL_OPAMP_MODE_FOLLOWER
0185                | OPAMP_InitStruct->InputNonInverting
0186               );
0187   }
0188 
0189   return status;
0190 }
0191 
0192 /**
0193   * @brief Set each @ref LL_OPAMP_InitTypeDef field to default value.
0194   * @param OPAMP_InitStruct pointer to a @ref LL_OPAMP_InitTypeDef structure
0195   *                         whose fields will be set to default values.
0196   * @retval None
0197   */
0198 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
0199 {
0200   /* Set OPAMP_InitStruct fields to default values */
0201   OPAMP_InitStruct->PowerMode         = LL_OPAMP_POWERMODE_NORMAL;
0202   OPAMP_InitStruct->FunctionalMode    = LL_OPAMP_MODE_FOLLOWER;
0203   OPAMP_InitStruct->InputNonInverting = LL_OPAMP_INPUT_NONINVERT_IO0;
0204   /* Note: Parameter discarded if OPAMP in functional mode follower,          */
0205   /*       set anyway to its default value.                                   */
0206   OPAMP_InitStruct->InputInverting    = LL_OPAMP_INPUT_INVERT_CONNECT_NO;
0207 }
0208 
0209 /**
0210   * @}
0211   */
0212 
0213 /**
0214   * @}
0215   */
0216 
0217 /**
0218   * @}
0219   */
0220 
0221 #endif /* OPAMP1 || OPAMP2 */
0222 
0223 /**
0224   * @}
0225   */
0226 
0227 #endif /* USE_FULL_LL_DRIVER */
0228