STM32G474xx HAL 用户手册
stm32g4xx_ll_opamp.c
转到此文件的文档。
00001 /**
00002   ******************************************************************************
00003   * @file    stm32g4xx_ll_opamp.c
00004   * @author  MCD Application Team
00005   * @brief   OPAMP LL模块驱动
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * Copyright (c) 2019 STMicroelectronics.
00010   * All rights reserved.
00011   *
00012   * This software is licensed under terms that can be found in the LICENSE file
00013   * in the root directory of this software component.
00014   * If no LICENSE file comes with this software, it is provided AS-IS.
00015   *
00016   ******************************************************************************
00017   */
00018 #if defined(USE_FULL_LL_DRIVER)
00019 
00020 /* Includes ------------------------------------------------------------------*/
00021 #include "stm32g4xx_ll_opamp.h"
00022 
00023 #ifdef  USE_FULL_ASSERT
00024 #include "stm32_assert.h"
00025 #else
00026 #define assert_param(expr) ((void)0U)
00027 #endif
00028 
00029 /** @addtogroup STM32G4xx_LL_Driver
00030   * @{
00031   */
00032 
00033 #if defined (OPAMP1) || defined (OPAMP2) || defined (OPAMP3) || defined (OPAMP4) || defined (OPAMP5) || defined (OPAMP6)
00034 
00035 /** @addtogroup OPAMP_LL OPAMP
00036   * @{
00037   */
00038 
00039 /* Private types -------------------------------------------------------------*/
00040 /* Private variables ---------------------------------------------------------*/
00041 /* Private constants ---------------------------------------------------------*/
00042 /* Private macros ------------------------------------------------------------*/
00043 
00044 /** @addtogroup OPAMP_LL_Private_Macros
00045   * @{
00046   */
00047 
00048 /* Check of parameters for configuration of OPAMP hierarchical scope:         */
00049 /* OPAMP instance.                                                            */
00050 
00051 #define IS_LL_OPAMP_POWER_MODE(__POWER_MODE__)                                 \
00052   (   ((__POWER_MODE__) == LL_OPAMP_POWERMODE_NORMALSPEED)                     \
00053    || ((__POWER_MODE__) == LL_OPAMP_POWERMODE_HIGHSPEED))
00054 
00055 #define IS_LL_OPAMP_FUNCTIONAL_MODE(__FUNCTIONAL_MODE__)                       \
00056   (   ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_STANDALONE)                      \
00057    || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_FOLLOWER)                        \
00058    || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA)                             \
00059    || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0)                         \
00060    || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_BIAS)                    \
00061    || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_IO1_BIAS)                \
00062   )
00063 
00064 #define IS_LL_OPAMP_INPUT_NONINVERTING(__INPUT_NONINVERTING__)                 \
00065   (   ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0)               \
00066    || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO1)               \
00067    || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO2)               \
00068    || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO3)               \
00069    || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC)               \
00070   )
00071 
00072 #define IS_LL_OPAMP_INPUT_INVERTING(__INPUT_INVERTING__)                       \
00073   (   ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0)                     \
00074    || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1)                     \
00075    || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO)              \
00076   )
00077 
00078 /**
00079   * @}
00080   */
00081 
00082 
00083 /* Private function prototypes -----------------------------------------------*/
00084 
00085 /* Exported functions --------------------------------------------------------*/
00086 /** @addtogroup OPAMP_LL_Exported_Functions
00087   * @{
00088   */
00089 
00090 /** @addtogroup OPAMP_LL_EF_Init
00091   * @{
00092   */
00093 
00094 /**
00095   * @brief  将选定OPAMP实例的寄存器反初始化
00096   *         至其默认复位值。
00097   * @note   如果比较器被锁定,则无法通过软件进行反初始化。
00098   *         唯一的解锁比较器的方法是设备硬件复位。
00099   * @param  OPAMPx OPAMP实例
00100   * @retval 一个ErrorStatus枚举值:
00101   *          - SUCCESS: OPAMP寄存器已反初始化
00102   *          - ERROR: OPAMP寄存器未反初始化
00103   */
00104   */
00105 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx)
00106 {
00107   ErrorStatus status = SUCCESS;
00108 
00109   /* Check the parameters */
00110   assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
00111 
00112   /* Note: Hardware constraint (refer to description of this function):       */
00113   /*       OPAMP instance must not be locked.                                 */
00114   if (LL_OPAMP_IsLocked(OPAMPx) == 0UL)
00115   {
00116     LL_OPAMP_WriteReg(OPAMPx, CSR, 0x00000000UL);
00117   }
00118   else
00119   {
00120     /* OPAMP instance is locked: de-initialization by software is              */
00121     /* not possible.                                                           */
00122     /* The only way to unlock the OPAMP is a device hardware reset.            */
00123     status = ERROR;
00124   }
00125 
00126   /* Timer controlled mux mode register reset                                  */
00127   if (LL_OPAMP_IsTimerMuxLocked(OPAMPx) == 0UL)
00128   {
00129     LL_OPAMP_WriteReg(OPAMPx, TCMR, 0x00000000UL);
00130   }
00131   else if (LL_OPAMP_ReadReg(OPAMPx, TCMR) != 0x80000000UL)
00132   {
00133     /* OPAMP instance timer controlled mux is locked configured, deinit error  */
00134     /* The only way to unlock the OPAMP is a device hardware reset.            */
00135     status = ERROR;
00136   }
00137   else
00138   {
00139     /* OPAMP instance timer controlled mux is locked unconfigured, deinit OK */
00140   }
00141 
00142   return status;
00143 }
00144 
00145 /**
00146   * @brief  初始化OPAMP实例的某些特性。
00147   * @note   此函数重置校准模式位以确保处于功能模式,
00148   *         以便设置的OPAMP参数(输入选择等)
00149   *         能够在相应的OPAMP模式下生效。
00150   * @param  OPAMPx OPAMP实例
00151   * @param  OPAMP_InitStruct 指向 @ref LL_OPAMP_InitTypeDef 结构体的指针
00152   * @retval 一个ErrorStatus枚举值:
00153   *          - SUCCESS: OPAMP寄存器已初始化
00154   *          - ERROR: OPAMP寄存器未初始化
00155   */
00156   */
00157 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, const LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
00158 {
00159   ErrorStatus status = SUCCESS;
00160 
00161   /* Check the parameters */
00162   assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
00163   assert_param(IS_LL_OPAMP_POWER_MODE(OPAMP_InitStruct->PowerMode));
00164   assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode));
00165   assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMP_InitStruct-&