STM32L486xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_comp.c 00004 * @author MCD Application Team 00005 * @brief COMP 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_comp.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 (COMP1) || defined (COMP2) 00051 00052 /** @addtogroup COMP_LL COMP 00053 * @{ 00054 */ 00055 00056 /* Private types -------------------------------------------------------------*/ 00057 /* Private variables ---------------------------------------------------------*/ 00058 /* Private constants ---------------------------------------------------------*/ 00059 /* Private macros ------------------------------------------------------------*/ 00060 00061 /** @addtogroup COMP_LL_Private_Macros 00062 * @{ 00063 */ 00064 00065 /* Check of parameters for configuration of COMP hierarchical scope: */ 00066 /* COMP instance. */ 00067 00068 #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \ 00069 ( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \ 00070 || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \ 00071 || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \ 00072 ) 00073 00074 /* Note: On this STM32 serie, comparator input plus parameters are */ 00075 /* the same on all COMP instances. */ 00076 /* However, comparator instance kept as macro parameter for */ 00077 /* compatibility with other STM32 families. */ 00078 #if defined(COMP_CSR_INPSEL_1) 00079 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \ 00080 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \ 00081 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \ 00082 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO3) \ 00083 ) 00084 #else 00085 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \ 00086 ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \ 00087 || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \ 00088 ) 00089 #endif 00090 00091 /* Note: On this STM32 serie, comparator input minus parameters are */ 00092 /* the same on all COMP instances. */ 00093 /* However, comparator instance kept as macro parameter for */ 00094 /* compatibility with other STM32 families. */ 00095 #if defined(COMP_CSR_INMESEL_1) 00096 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \ 00097 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \ 00098 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \ 00099 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \ 00100 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \ 00101 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \ 00102 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \ 00103 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \ 00104 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \ 00105 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \ 00106 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \ 00107 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO5) \ 00108 ) 00109 #else 00110 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \ 00111 ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \ 00112 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \ 00113 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \ 00114 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \ 00115 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \ 00116 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \ 00117 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \ 00118 || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \ 00119 ) 00120 #endif 00121 00122 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \ 00123 ( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \ 00124 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \ 00125 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \ 00126 || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \ 00127 ) 00128 00129 #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \ 00130 ( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \ 00131 || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \ 00132 ) 00133 00134 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \ 00135 (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \ 00136 ? ( \ 00137 (1U) \ 00138 ) \ 00139 : \ 00140 (((__COMP_INSTANCE__) == COMP1) \ 00141 ? ( \ 00142 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1) \ 00143 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1) \ 00144 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1) \ 00145 ) \ 00146 : \ 00147 ( \ 00148 ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2) \ 00149 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2) \ 00150 || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2) \ 00151 ) \ 00152 ) \ 00153 ) 00154 00155 /** 00156 * @} 00157 */ 00158 00159 00160 /* Private function prototypes -----------------------------------------------*/ 00161 00162 /* Exported functions --------------------------------------------------------*/ 00163 /** @addtogroup COMP_LL_Exported_Functions 00164 * @{ 00165 */ 00166 00167 /** @addtogroup COMP_LL_EF_Init 00168 * @{ 00169 */ 00170 00171 /** 00172 * @brief De-initialize registers of the selected COMP instance 00173 * to their default reset values. 00174 * @note If comparator is locked, de-initialization by software is 00175 * not possible. 00176 * The only way to unlock the comparator is a device hardware reset. 00177 * @param COMPx COMP instance 00178 * @retval An ErrorStatus enumeration value: 00179 * - SUCCESS: COMP registers are de-initialized 00180 * - ERROR: COMP registers are not de-initialized 00181 */ 00182 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx) 00183 { 00184 ErrorStatus status = SUCCESS; 00185 00186 /* Check the parameters */ 00187 assert_param(IS_COMP_ALL_INSTANCE(COMPx)); 00188 00189 /* Note: Hardware constraint (refer to description of this function): */ 00190 /* COMP instance must not be locked. */ 00191 if(LL_COMP_IsLocked(COMPx) == 0U) 00192 { 00193 LL_COMP_WriteReg(COMPx, CSR, 0x00000000U); 00194 00195 } 00196 else 00197 { 00198 /* Comparator instance is locked: de-initialization by software is */ 00199 /* not possible. */ 00200 /* The only way to unlock the comparator is a device hardware reset. */ 00201 status = ERROR; 00202 } 00203 00204 return status; 00205 } 00206 00207 /** 00208 * @brief Initialize some features of COMP instance. 00209 * @note This function configures features of the selected COMP instance. 00210 * Some features are also available at scope COMP common instance 00211 * (common to several COMP instances). 00212 * Refer to functions having argument "COMPxy_COMMON" as parameter. 00213 * @param COMPx COMP instance 00214 * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure 00215 * @retval An ErrorStatus enumeration value: 00216 * - SUCCESS: COMP registers are initialized 00217 * - ERROR: COMP registers are not initialized 00218 */ 00219 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct) 00220 { 00221 ErrorStatus status = SUCCESS; 00222 00223 /* Check the parameters */ 00224 assert_param(IS_COMP_ALL_INSTANCE(COMPx)); 00225 assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode)); 00226 assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus)); 00227 assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus)); 00228 assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis)); 00229 assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity)); 00230 assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMPx, COMP_InitStruct->OutputBlankingSource)); 00231 00232 /* Note: Hardware constraint (refer to description of this function) */ 00233 /* COMP instance must not be locked. */ 00234 if(LL_COMP_IsLocked(COMPx) == 0U) 00235 { 00236 /* Configuration of comparator instance : */ 00237 /* - PowerMode */ 00238 /* - InputPlus */ 00239 /* - InputMinus */ 00240 /* - InputHysteresis */ 00241 /* - OutputPolarity */ 00242 /* - OutputBlankingSource */ 00243 #if defined(COMP_CSR_INMESEL_1) 00244 MODIFY_REG(COMPx->CSR, 00245 COMP_CSR_PWRMODE 00246 | COMP_CSR_INPSEL 00247 | COMP_CSR_SCALEN 00248 | COMP_CSR_BRGEN 00249 | COMP_CSR_INMESEL 00250 | COMP_CSR_INMSEL 00251 | COMP_CSR_HYST 00252 | COMP_CSR_POLARITY 00253 | COMP_CSR_BLANKING 00254 , 00255 COMP_InitStruct->PowerMode 00256 | COMP_InitStruct->InputPlus 00257 | COMP_InitStruct->InputMinus 00258 | COMP_InitStruct->InputHysteresis 00259 | COMP_InitStruct->OutputPolarity 00260 | COMP_InitStruct->OutputBlankingSource 00261 ); 00262 #else 00263 MODIFY_REG(COMPx->CSR, 00264 COMP_CSR_PWRMODE 00265 | COMP_CSR_INPSEL 00266 | COMP_CSR_SCALEN 00267 | COMP_CSR_BRGEN 00268 | COMP_CSR_INMSEL 00269 | COMP_CSR_HYST 00270 | COMP_CSR_POLARITY 00271 | COMP_CSR_BLANKING 00272 , 00273 COMP_InitStruct->PowerMode 00274 | COMP_InitStruct->InputPlus 00275 | COMP_InitStruct->InputMinus 00276 | COMP_InitStruct->InputHysteresis 00277 | COMP_InitStruct->OutputPolarity 00278 | COMP_InitStruct->OutputBlankingSource 00279 ); 00280 #endif 00281 00282 } 00283 else 00284 { 00285 /* Initialization error: COMP instance is locked. */ 00286 status = ERROR; 00287 } 00288 00289 return status; 00290 } 00291 00292 /** 00293 * @brief Set each @ref LL_COMP_InitTypeDef field to default value. 00294 * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure 00295 * whose fields will be set to default values. 00296 * @retval None 00297 */ 00298 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct) 00299 { 00300 /* Set COMP_InitStruct fields to default values */ 00301 COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_ULTRALOWPOWER; 00302 COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1; 00303 COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT; 00304 COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE; 00305 COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED; 00306 COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE; 00307 } 00308 00309 /** 00310 * @} 00311 */ 00312 00313 /** 00314 * @} 00315 */ 00316 00317 /** 00318 * @} 00319 */ 00320 00321 #endif /* COMP1 || COMP2 */ 00322 00323 /** 00324 * @} 00325 */ 00326 00327 #endif /* USE_FULL_LL_DRIVER */ 00328 00329 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/