STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_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 "stm32l4xx_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 STM32L4xx_LL_Driver 00030 * @{ 00031 */ 00032 00033 #if defined (OPAMP1) || defined (OPAMP2) 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_NORMALPOWER) \ 00053 || ((__POWER_MODE__) == LL_OPAMP_POWERMODE_LOWPOWER)) 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 ) 00060 00061 /* Note: Comparator non-inverting inputs parameters are the same on all */ 00062 /* OPAMP instances. */ 00063 /* However, comparator instance kept as macro parameter for */ 00064 /* compatibility with other STM32 families. */ 00065 #define IS_LL_OPAMP_INPUT_NONINVERTING(__OPAMPX__, __INPUT_NONINVERTING__) \ 00066 ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \ 00067 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINV_DAC1_CH1) \ 00068 ) 00069 00070 /* Note: Comparator non-inverting inputs parameters are the same on all */ 00071 /* OPAMP instances. */ 00072 /* However, comparator instance kept as macro parameter for */ 00073 /* compatibility with other STM32 families. */ 00074 #define IS_LL_OPAMP_INPUT_INVERTING(__OPAMPX__, __INPUT_INVERTING__) \ 00075 ( ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0) \ 00076 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1) \ 00077 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO) \ 00078 ) 00079 00080 /** 00081 * @} 00082 */ 00083 00084 00085 /* Private function prototypes -----------------------------------------------*/ 00086 00087 /* Exported functions --------------------------------------------------------*/ 00088 /** @addtogroup OPAMP_LL_Exported_Functions 00089 * @{ 00090 */ 00091 00092 /** @addtogroup OPAMP_LL_EF_Init 00093 * @{ 00094 */ 00095 00096 /** 00097 * @brief De-initialize registers of the selected OPAMP instance 00098 * to their default reset values. 00099 * @param OPAMPx OPAMP instance 00100 * @retval An ErrorStatus enumeration value: 00101 * - SUCCESS: OPAMP registers are de-initialized 00102 * - ERROR: OPAMP registers are not de-initialized 00103 */ 00104 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef* OPAMPx) 00105 { 00106 ErrorStatus status = SUCCESS; 00107 00108 /* Check the parameters */ 00109 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx)); 00110 00111 LL_OPAMP_WriteReg(OPAMPx, CSR, 0x00000000U); 00112 00113 return status; 00114 } 00115 00116 /** 00117 * @brief Initialize some features of OPAMP instance. 00118 * @note This function reset bit of calibration mode to ensure 00119 * to be in functional mode, in order to have OPAMP parameters 00120 * (inputs selection, ...) set with the corresponding OPAMP mode 00121 * to be effective. 00122 * @note This function configures features of the selected OPAMP instance. 00123 * Some features are also available at scope OPAMP common instance 00124 * (common to several OPAMP instances). 00125 * Refer to functions having argument "OPAMPxy_COMMON" as parameter. 00126 * @param OPAMPx OPAMP instance 00127 * @param OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure 00128 * @retval An ErrorStatus enumeration value: 00129 * - SUCCESS: OPAMP registers are initialized 00130 * - ERROR: OPAMP registers are not initialized 00131 */ 00132 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct) 00133 { 00134 /* Check the parameters */ 00135 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx)); 00136 assert_param(IS_LL_OPAMP_POWER_MODE(OPAMP_InitStruct->PowerMode)); 00137 assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode)); 00138 assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMPx, OPAMP_InitStruct->InputNonInverting)); 00139 00140 /* Note: OPAMP inverting input can be used with OPAMP in mode standalone */ 00141 /* or PGA with external capacitors for filtering circuit. */ 00142 /* Otherwise (OPAMP in mode follower), OPAMP inverting input is */ 00143 /* not used (not connected to GPIO pin). */ 00144 if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER) 00145 { 00146 assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMPx, OPAMP_InitStruct->InputInverting)); 00147 } 00148 00149 /* Configuration of OPAMP instance : */ 00150 /* - PowerMode */ 00151 /* - Functional mode */ 00152 /* - Input non-inverting */ 00153 /* - Input inverting */ 00154 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */ 00155 if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER) 00156 { 00157 MODIFY_REG(OPAMPx->CSR, 00158 OPAMP_CSR_OPALPM 00159 | OPAMP_CSR_OPAMODE 00160 | OPAMP_CSR_CALON 00161 | OPAMP_CSR_VMSEL 00162 | OPAMP_CSR_VPSEL 00163 , 00164 (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK) 00165 | OPAMP_InitStruct->FunctionalMode 00166 | OPAMP_InitStruct->InputNonInverting 00167 | OPAMP_InitStruct->InputInverting 00168 ); 00169 } 00170 else 00171 { 00172 MODIFY_REG(OPAMPx->CSR, 00173 OPAMP_CSR_OPALPM 00174 | OPAMP_CSR_OPAMODE 00175 | OPAMP_CSR_CALON 00176 | OPAMP_CSR_VMSEL 00177 | OPAMP_CSR_VPSEL 00178 , 00179 (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK) 00180 | LL_OPAMP_MODE_FOLLOWER 00181 | OPAMP_InitStruct->InputNonInverting 00182 | LL_OPAMP_INPUT_INVERT_CONNECT_NO 00183 ); 00184 } 00185 00186 return SUCCESS; 00187 } 00188 00189 /** 00190 * @brief Set each @ref LL_OPAMP_InitTypeDef field to default value. 00191 * @param OPAMP_InitStruct pointer to a @ref LL_OPAMP_InitTypeDef structure 00192 * whose fields will be set to default values. 00193 * @retval None 00194 */ 00195 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct) 00196 { 00197 /* Set OPAMP_InitStruct fields to default values */ 00198 OPAMP_InitStruct->PowerMode = LL_OPAMP_POWERMODE_NORMALPOWER; 00199 OPAMP_InitStruct->FunctionalMode = LL_OPAMP_MODE_FOLLOWER; 00200 OPAMP_InitStruct->InputNonInverting = LL_OPAMP_INPUT_NONINVERT_IO0; 00201 /* Note: Parameter discarded if OPAMP in functional mode follower, */ 00202 /* set anyway to its default value. */ 00203 OPAMP_InitStruct->InputInverting = LL_OPAMP_INPUT_INVERT_CONNECT_NO; 00204 } 00205 00206 /** 00207 * @} 00208 */ 00209 00210 /** 00211 * @} 00212 */ 00213 00214 /** 00215 * @} 00216 */ 00217 00218 #endif /* OPAMP1 || OPAMP2 */ 00219 00220 /** 00221 * @} 00222 */ 00223 00224 #endif /* USE_FULL_LL_DRIVER */