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