STM32L486xx 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 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 #if defined(USE_FULL_LL_DRIVER) 00036 00037 /* Includes ------------------------------------------------------------------*/ 00038 #include "stm32l4xx_ll_opamp.h" 00039 00040 #ifdef USE_FULL_ASSERT 00041 #include "stm32_assert.h" 00042 #else 00043 #define assert_param(expr) ((void)0U) 00044 #endif 00045 00046 /** @addtogroup STM32L4xx_LL_Driver 00047 * @{ 00048 */ 00049 00050 #if defined (OPAMP1) || defined (OPAMP2) 00051 00052 /** @addtogroup OPAMP_LL OPAMP 00053 * @{ 00054 */ 00055 00056 /* Private types -------------------------------------------------------------*/ 00057 /* Private variables ---------------------------------------------------------*/ 00058 /* Private constants ---------------------------------------------------------*/ 00059 /* Private macros ------------------------------------------------------------*/ 00060 00061 /** @addtogroup OPAMP_LL_Private_Macros 00062 * @{ 00063 */ 00064 00065 /* Check of parameters for configuration of OPAMP hierarchical scope: */ 00066 /* OPAMP instance. */ 00067 00068 #define IS_LL_OPAMP_POWER_MODE(__POWER_MODE__) \ 00069 ( ((__POWER_MODE__) == LL_OPAMP_POWERMODE_NORMAL) \ 00070 || ((__POWER_MODE__) == LL_OPAMP_POWERMODE_LOWPOWER)) 00071 00072 #define IS_LL_OPAMP_FUNCTIONAL_MODE(__FUNCTIONAL_MODE__) \ 00073 ( ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_STANDALONE) \ 00074 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_FOLLOWER) \ 00075 || ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA) \ 00076 ) 00077 00078 /* Note: Comparator non-inverting inputs parameters are the same on all */ 00079 /* OPAMP instances. */ 00080 /* However, comparator instance kept as macro parameter for */ 00081 /* compatibility with other STM32 families. */ 00082 #define IS_LL_OPAMP_INPUT_NONINVERTING(__OPAMPX__, __INPUT_NONINVERTING__) \ 00083 ( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \ 00084 || ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINV_DAC1_CH1) \ 00085 ) 00086 00087 /* Note: Comparator non-inverting inputs parameters are the same on all */ 00088 /* OPAMP instances. */ 00089 /* However, comparator instance kept as macro parameter for */ 00090 /* compatibility with other STM32 families. */ 00091 #define IS_LL_OPAMP_INPUT_INVERTING(__OPAMPX__, __INPUT_INVERTING__) \ 00092 ( ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0) \ 00093 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1) \ 00094 || ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO) \ 00095 ) 00096 00097 /** 00098 * @} 00099 */ 00100 00101 00102 /* Private function prototypes -----------------------------------------------*/ 00103 00104 /* Exported functions --------------------------------------------------------*/ 00105 /** @addtogroup OPAMP_LL_Exported_Functions 00106 * @{ 00107 */ 00108 00109 /** @addtogroup OPAMP_LL_EF_Init 00110 * @{ 00111 */ 00112 00113 /** 00114 * @brief De-initialize registers of the selected OPAMP instance 00115 * to their default reset values. 00116 * @param OPAMPx OPAMP instance 00117 * @retval An ErrorStatus enumeration value: 00118 * - SUCCESS: OPAMP registers are de-initialized 00119 * - ERROR: OPAMP registers are not de-initialized 00120 */ 00121 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef* OPAMPx) 00122 { 00123 ErrorStatus status = SUCCESS; 00124 00125 /* Check the parameters */ 00126 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx)); 00127 00128 LL_OPAMP_WriteReg(OPAMPx, CSR, 0x00000000U); 00129 00130 return status; 00131 } 00132 00133 /** 00134 * @brief Initialize some features of OPAMP instance. 00135 * @note This function reset bit of calibration mode to ensure 00136 * to be in functional mode, in order to have OPAMP parameters 00137 * (inputs selection, ...) set with the corresponding OPAMP mode 00138 * to be effective. 00139 * @note This function configures features of the selected OPAMP instance. 00140 * Some features are also available at scope OPAMP common instance 00141 * (common to several OPAMP instances). 00142 * Refer to functions having argument "OPAMPxy_COMMON" as parameter. 00143 * @param OPAMPx OPAMP instance 00144 * @param OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure 00145 * @retval An ErrorStatus enumeration value: 00146 * - SUCCESS: OPAMP registers are initialized 00147 * - ERROR: OPAMP registers are not initialized 00148 */ 00149 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct) 00150 { 00151 /* Check the parameters */ 00152 assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx)); 00153 assert_param(IS_LL_OPAMP_POWER_MODE(OPAMP_InitStruct->PowerMode)); 00154 assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode)); 00155 assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMPx, OPAMP_InitStruct->InputNonInverting)); 00156 00157 /* Note: OPAMP inverting input can be used with OPAMP in mode standalone */ 00158 /* or PGA with external capacitors for filtering circuit. */ 00159 /* Otherwise (OPAMP in mode follower), OPAMP inverting input is */ 00160 /* not used (not connected to GPIO pin). */ 00161 if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER) 00162 { 00163 assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMPx, OPAMP_InitStruct->InputInverting)); 00164 } 00165 00166 /* Configuration of OPAMP instance : */ 00167 /* - PowerMode */ 00168 /* - Functional mode */ 00169 /* - Input non-inverting */ 00170 /* - Input inverting */ 00171 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */ 00172 if(OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER) 00173 { 00174 MODIFY_REG(OPAMPx->CSR, 00175 OPAMP_CSR_OPALPM 00176 | OPAMP_CSR_OPAMODE 00177 | OPAMP_CSR_CALON 00178 | OPAMP_CSR_VMSEL 00179 | OPAMP_CSR_VPSEL 00180 , 00181 (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK) 00182 | OPAMP_InitStruct->FunctionalMode 00183 | OPAMP_InitStruct->InputNonInverting 00184 | OPAMP_InitStruct->InputInverting 00185 ); 00186 } 00187 else 00188 { 00189 MODIFY_REG(OPAMPx->CSR, 00190 OPAMP_CSR_OPALPM 00191 | OPAMP_CSR_OPAMODE 00192 | OPAMP_CSR_CALON 00193 | OPAMP_CSR_VMSEL 00194 | OPAMP_CSR_VPSEL 00195 , 00196 (OPAMP_InitStruct->PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK) 00197 | LL_OPAMP_MODE_FOLLOWER 00198 | OPAMP_InitStruct->InputNonInverting 00199 | LL_OPAMP_INPUT_INVERT_CONNECT_NO 00200 ); 00201 } 00202 00203 return SUCCESS; 00204 } 00205 00206 /** 00207 * @brief Set each @ref LL_OPAMP_InitTypeDef field to default value. 00208 * @param OPAMP_InitStruct pointer to a @ref LL_OPAMP_InitTypeDef structure 00209 * whose fields will be set to default values. 00210 * @retval None 00211 */ 00212 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct) 00213 { 00214 /* Set OPAMP_InitStruct fields to default values */ 00215 OPAMP_InitStruct->PowerMode = LL_OPAMP_POWERMODE_NORMAL; 00216 OPAMP_InitStruct->FunctionalMode = LL_OPAMP_MODE_FOLLOWER; 00217 OPAMP_InitStruct->InputNonInverting = LL_OPAMP_INPUT_NONINVERT_IO0; 00218 /* Note: Parameter discarded if OPAMP in functional mode follower, */ 00219 /* set anyway to its default value. */ 00220 OPAMP_InitStruct->InputInverting = LL_OPAMP_INPUT_INVERT_CONNECT_NO; 00221 } 00222 00223 /** 00224 * @} 00225 */ 00226 00227 /** 00228 * @} 00229 */ 00230 00231 /** 00232 * @} 00233 */ 00234 00235 #endif /* OPAMP1 || OPAMP2 */ 00236 00237 /** 00238 * @} 00239 */ 00240 00241 #endif /* USE_FULL_LL_DRIVER */ 00242 00243 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/