STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_ll_opamp.c 00004 * @author MCD Application Team 00005 * @brief OPAMP LL module driver 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 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 "stm32h7xx_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 STM32H7xx_LL_Driver 00030 * @{ 00031 */ 00032 00033 #if defined (OPAMP1) || defined (OPAMP2) 00034 /** @addtogroup OPAMP_LL OPAMP 00035 * @{ 00036 */ 00037 00038 /* Private types -------------------------------------------------------------*/ 00039 /* Private variables ---------------------------------------------------------*/ 00040 /* Private constants ---------------------------------------------------------*/ 00041 /* Private macros ------------------------------------------------------------*/ 00042 00043 /** @addtogroup OPAMP_LL_Private_Macros 00044 * @{ 00045 */ 00046 00047 /* Check of parameters for configuration of OPAMP hierarchical scope: */ 00048 /* OPAMP instance. */ 00049 00050 #define IS_LL_OPAMP_POWER_MODE(__POWER_MODE__) \ 00051 ( ((__POWER_MODE__) == LL_OPAMP_POWERMODE_NORMAL) \ 00052 || ((__POWER_MODE__) == LL_OPAMP_POWERMODE_HIGHSPEED)) 00053 00054 #define IS_LL_OPAMP_FUNCTIONAL_MODE(__FUNCTIONAL_MODE__) \ 00055 ( ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_STANDALONE) \ 00056 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_FOLLOWER) \ 00057 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA) \ 00058 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0) \ 00059 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_BIAS) \ 00060 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_IO1_BIAS) \ 00061 ) 00062 00063 #if defined(DAC2) 00064 #define IS_LL_OPAMP_INPUT_NONINVERTING(__INPUT_NONINVERTING__) \ 00065 ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \ 00066 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC) \ 00067 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC2) \ 00068 ) 00069 #else 00070 #define IS_LL_OPAMP_INPUT_NONINVERTING(__INPUT_NONINVERTING__) \ 00071 ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \ 00072 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC) \ 00073 ) 00074 #endif /* DAC2 */ 00075 00076 00077 #define IS_LL_OPAMP_INPUT_INVERTING(__INPUT_INVERTING__) \ 00078 ( ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0) \ 00079 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1) \ 00080 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO) \ 00081 ) 00082 00083 /** 00084 * @} 00085 */ 00086 00087 00088 /* Private function prototypes -----------------------------------------------*/ 00089 00090 /* Exported functions --------------------------------------------------------*/ 00091 /** @addtogroup OPAMP_LL_Exported_Functions 00092 * @{ 00093 */ 00094 00095 /** @addtogroup OPAMP_LL_EF_Init 00096 * @{ 00097 */ 00098 00099 /** 00100 * @brief De-initialize registers of the selected OPAMP instance 00101 * to their default reset values. 00102 * @note If comparator is locked, de-initialization by software is 00103 * not possible. 00104 * The only way to unlock the comparator is a device hardware reset. 00105 * @param OPAMPx OPAMP instance 00106 * @retval An ErrorStatus enumeration value: 00107 * - SUCCESS: OPAMP registers are de-initialized 00108 * - ERROR: OPAMP registers are not de-initialized 00109 */ 00110 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef* OPAMPx) 00111 { 00112 ErrorStatus status = SUCCESS; 00113 00114 /* Check the parameters */ 00115 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx)); 00116 00117 LL_OPAMP_WriteReg(OPAMPx, CSR, 0x00000000U); 00118 00119 return status; 00120 } 00121 00122 /** 00123 * @brief Initialize some features of OPAMP instance. 00124 * @note This function reset bit of calibration mode to ensure 00125 * to be in functional mode, in order to have OPAMP parameters 00126 * (inputs selection, ...) set with the corresponding OPAMP mode 00127 * to be effective. 00128 * @param OPAMPx OPAMP instance 00129 * @param OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure 00130 * @retval An ErrorStatus enumeration value: 00131 * - SUCCESS: OPAMP registers are initialized 00132 * - ERROR: OPAMP registers are not initialized 00133 */ 00134 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct) 00135 { 00136 ErrorStatus status = SUCCESS; 00137 00138 /* Check the parameters */ 00139 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx)); 00140 assert_param(IS_LL_OPAMP_POWER_MODE(OPAMP_InitStruct->PowerMode)); 00141 assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode)); 00142 assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMP_InitStruct->InputNonInverting)); 00143 00144 /* Note: OPAMP inverting input can be used with OPAMP in mode standalone */ 00145 /* or PGA with external capacitors for filtering circuit. */ 00146 /* Otherwise (OPAMP in mode follower), OPAMP inverting input is */ 00147 /* not used (not connected to GPIO pin). */ 00148 if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER) 00149 { 00150 assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMP_InitStruct->InputInverting)); 00151 } 00152 00153 /* Configuration of OPAMP instance : */ 00154 /* - PowerMode */ 00155 /* - Functional mode */ 00156 /* - Input non-inverting */ 00157 /* - Input inverting */ 00158 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */ 00159 if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER) 00160 { 00161 MODIFY_REG(OPAMPx->CSR, 00162 OPAMP_CSR_OPAHSM 00163 | OPAMP_CSR_CALON 00164 | OPAMP_CSR_VMSEL 00165 | OPAMP_CSR_VPSEL 00166 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_1 00167 , 00168 (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK) 00169 | OPAMP_InitStruct->FunctionalMode 00170 | OPAMP_InitStruct->InputNonInverting 00171 | OPAMP_InitStruct->InputInverting 00172 ); 00173 } 00174 else 00175 { 00176 MODIFY_REG(OPAMPx->CSR, 00177 OPAMP_CSR_OPAHSM 00178 | OPAMP_CSR_CALON 00179 | OPAMP_CSR_VMSEL 00180 | OPAMP_CSR_VPSEL 00181 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_1 00182 , 00183 (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK) 00184 | LL_OPAMP_MODE_FOLLOWER 00185 | OPAMP_InitStruct->InputNonInverting 00186 ); 00187 } 00188 00189 return status; 00190 } 00191 00192 /** 00193 * @brief Set each @ref LL_OPAMP_InitTypeDef field to default value. 00194 * @param OPAMP_InitStruct pointer to a @ref LL_OPAMP_InitTypeDef structure 00195 * whose fields will be set to default values. 00196 * @retval None 00197 */ 00198 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct) 00199 { 00200 /* Set OPAMP_InitStruct fields to default values */ 00201 OPAMP_InitStruct->PowerMode = LL_OPAMP_POWERMODE_NORMAL; 00202 OPAMP_InitStruct->FunctionalMode = LL_OPAMP_MODE_FOLLOWER; 00203 OPAMP_InitStruct->InputNonInverting = LL_OPAMP_INPUT_NONINVERT_IO0; 00204 /* Note: Parameter discarded if OPAMP in functional mode follower, */ 00205 /* set anyway to its default value. */ 00206 OPAMP_InitStruct->InputInverting = LL_OPAMP_INPUT_INVERT_CONNECT_NO; 00207 } 00208 00209 /** 00210 * @} 00211 */ 00212 00213 /** 00214 * @} 00215 */ 00216 00217 /** 00218 * @} 00219 */ 00220 00221 #endif /* OPAMP1 || OPAMP2 */ 00222 00223 /** 00224 * @} 00225 */ 00226 00227 #endif /* USE_FULL_LL_DRIVER */ 00228