STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_comp.h 00004 * @author MCD Application Team 00005 * @brief Header file of COMP LL module. 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 00019 /* Define to prevent recursive inclusion -------------------------------------*/ 00020 #ifndef STM32L4xx_LL_COMP_H 00021 #define STM32L4xx_LL_COMP_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm32l4xx.h" 00029 00030 /** @addtogroup STM32L4xx_LL_Driver 00031 * @{ 00032 */ 00033 00034 #if defined (COMP1) || defined (COMP2) 00035 00036 /** @defgroup COMP_LL COMP 00037 * @{ 00038 */ 00039 00040 /* Private types -------------------------------------------------------------*/ 00041 /* Private variables ---------------------------------------------------------*/ 00042 /* Private constants ---------------------------------------------------------*/ 00043 /** @defgroup COMP_LL_Private_Constants COMP Private Constants 00044 * @{ 00045 */ 00046 00047 /* COMP registers bits positions */ 00048 #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30UL) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */ 00049 00050 /** 00051 * @} 00052 */ 00053 00054 /* Private macros ------------------------------------------------------------*/ 00055 /** @defgroup COMP_LL_Private_Macros COMP Private Macros 00056 * @{ 00057 */ 00058 00059 /** 00060 * @} 00061 */ 00062 00063 /* Exported types ------------------------------------------------------------*/ 00064 #if defined(USE_FULL_LL_DRIVER) 00065 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure 00066 * @{ 00067 */ 00068 00069 /** 00070 * @brief Structure definition of some features of COMP instance. 00071 */ 00072 typedef struct 00073 { 00074 uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed. 00075 This parameter can be a value of @ref COMP_LL_EC_POWERMODE 00076 00077 This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */ 00078 00079 uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input). 00080 This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS 00081 00082 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */ 00083 00084 uint32_t InputMinus; /*!< Set comparator input minus (inverting input). 00085 This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS 00086 00087 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */ 00088 00089 uint32_t InputHysteresis; /*!< Set comparator hysteresis mode of the input minus. 00090 This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS 00091 00092 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputHysteresis(). */ 00093 00094 uint32_t OutputPolarity; /*!< Set comparator output polarity. 00095 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY 00096 00097 This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */ 00098 00099 uint32_t OutputBlankingSource; /*!< Set comparator blanking source. 00100 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE 00101 00102 This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputBlankingSource(). */ 00103 00104 } LL_COMP_InitTypeDef; 00105 00106 /** 00107 * @} 00108 */ 00109 #endif /* USE_FULL_LL_DRIVER */ 00110 00111 /* Exported constants --------------------------------------------------------*/ 00112 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants 00113 * @{ 00114 */ 00115 00116 /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode 00117 * @{ 00118 */ 00119 #if defined(COMP2) 00120 #define LL_COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators 1 and 2 are independent */ 00121 #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE) /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP1 input plus (COMP2 input plus is no more accessible). */ 00122 #endif /* COMP2 */ 00123 /** 00124 * @} 00125 */ 00126 00127 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode 00128 * @{ 00129 */ 00130 #define LL_COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< COMP power mode to high speed */ 00131 #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< COMP power mode to medium speed */ 00132 #define LL_COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_PWRMODE_1 | COMP_CSR_PWRMODE_0) /*!< COMP power mode to ultra-low power */ 00133 /** 00134 * @} 00135 */ 00136 00137 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection 00138 * @{ 00139 */ 00140 #define LL_COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */ 00141 #define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */ 00142 #if defined(COMP_CSR_INPSEL_1) 00143 #define LL_COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */ 00144 #endif /* COMP_CSR_INPSEL_1 */ 00145 /** 00146 * @} 00147 */ 00148 00149 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection 00150 * @{ 00151 */ 00152 #define LL_COMP_INPUT_MINUS_1_4VREFINT ( COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */ 00153 #define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/2 VrefInt */ 00154 #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 3/4 VrefInt */ 00155 #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN ) /*!< Comparator input minus connected to VrefInt */ 00156 #define LL_COMP_INPUT_MINUS_DAC1_CH1 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */ 00157 #define LL_COMP_INPUT_MINUS_DAC1_CH2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */ 00158 #define LL_COMP_INPUT_MINUS_IO1 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PB3 for COMP2) */ 00159 #define LL_COMP_INPUT_MINUS_IO2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PB7 for COMP2) */ 00160 #if defined(COMP_CSR_INMESEL_1) 00161 #define LL_COMP_INPUT_MINUS_IO3 ( COMP_CSR_INMESEL_0 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO3 (pin PA0 for COMP1, pin PA2 for COMP2) */ 00162 #define LL_COMP_INPUT_MINUS_IO4 (COMP_CSR_INMESEL_1 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO4 (pin PA4 for COMP1, pin PA4 for COMP2) */ 00163 #define LL_COMP_INPUT_MINUS_IO5 (COMP_CSR_INMESEL_1 | COMP_CSR_INMESEL_0 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO5 (pin PA5 for COMP1, pin PA5 for COMP2) */ 00164 #endif 00165 /** 00166 * @} 00167 */ 00168 00169 /** @defgroup COMP_LL_EC_INPUT_LEGACY Comparator inputs legacy literals name 00170 * @{ 00171 */ 00172 #define LL_COMP_WINDOWMODE_ENABLE LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON 00173 00174 #define LL_COMP_INVERTINGINPUT_1_4VREFINT LL_COMP_INPUT_MINUS_1_4VREFINT 00175 #define LL_COMP_INVERTINGINPUT_1_2VREFINT LL_COMP_INPUT_MINUS_1_2VREFINT 00176 #define LL_COMP_INVERTINGINPUT_3_4VREFINT LL_COMP_INPUT_MINUS_3_4VREFINT 00177 #define LL_COMP_INVERTINGINPUT_VREFINT LL_COMP_INPUT_MINUS_VREFINT 00178 #define LL_COMP_INVERTINGINPUT_DAC1 LL_COMP_INPUT_MINUS_DAC1_CH1 00179 #define LL_COMP_INVERTINGINPUT_DAC2 LL_COMP_INPUT_MINUS_DAC1_CH2 00180 #define LL_COMP_INVERTINGINPUT_IO1 LL_COMP_INPUT_MINUS_IO1 00181 #define LL_COMP_INVERTINGINPUT_IO2 LL_COMP_INPUT_MINUS_IO2 00182 #if defined(COMP_CSR_INMESEL_1) 00183 #define LL_COMP_INVERTINGINPUT_IO3 LL_COMP_INPUT_MINUS_IO3 00184 #define LL_COMP_INVERTINGINPUT_IO4 LL_COMP_INPUT_MINUS_IO4 00185 #define LL_COMP_INVERTINGINPUT_IO5 LL_COMP_INPUT_MINUS_IO5 00186 #endif /* COMP_CSR_INMESEL_1 */ 00187 00188 #define LL_COMP_NONINVERTINGINPUT_IO1 LL_COMP_INPUT_PLUS_IO1 00189 #define LL_COMP_NONINVERTINGINPUT_IO2 LL_COMP_INPUT_PLUS_IO2 00190 #if defined(COMP_CSR_INPSEL_1) 00191 #define LL_COMP_NONINVERTINGINPUT_IO3 LL_COMP_INPUT_PLUS_IO3 00192 #endif /* COMP_CSR_INPSEL_1 */ 00193 /** 00194 * @} 00195 */ 00196 00197 /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis 00198 * @{ 00199 */ 00200 #define LL_COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */ 00201 #define LL_COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0) /*!< Hysteresis level low */ 00202 #define LL_COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 ) /*!< Hysteresis level medium */ 00203 #define LL_COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level high */ 00204 /** 00205 * @} 00206 */ 00207 00208 /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity 00209 * @{ 00210 */ 00211 #define LL_COMP_OUTPUTPOL_NONINVERTED (0x00000000UL) /*!< COMP output polarity is not inverted: comparator output is high when the plus (non-inverting) input is at a higher voltage than the minus (inverting) input */ 00212 #define LL_COMP_OUTPUTPOL_INVERTED (COMP_CSR_POLARITY) /*!< COMP output polarity is inverted: comparator output is low when the plus (non-inverting) input is at a lower voltage than the minus (inverting) input */ 00213 /** 00214 * @} 00215 */ 00216 00217 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source 00218 * @{ 00219 */ 00220 #define LL_COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */ 00221 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */ 00222 #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */ 00223 #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */ 00224 #define LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */ 00225 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2) */ 00226 #define LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP2) */ 00227 /** 00228 * @} 00229 */ 00230 00231 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE_LEGACY Comparator output blanking source legacy literals name 00232 * @{ 00233 */ 00234 #define LL_COMP_BLANKINGSRC_TIM1_OC5 (LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1) 00235 #define LL_COMP_BLANKINGSRC_TIM2_OC3 (LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1) 00236 #define LL_COMP_BLANKINGSRC_TIM3_OC3 (LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1) 00237 00238 #define LL_COMP_BLANKINGSRC_TIM3_OC4 (LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2) 00239 #define LL_COMP_BLANKINGSRC_TIM8_OC5 (LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2) 00240 #define LL_COMP_BLANKINGSRC_TIM15_OC1 (LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2) 00241 /** 00242 * @} 00243 */ 00244 00245 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level 00246 * @{ 00247 */ 00248 #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000UL) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */ 00249 #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */ 00250 /** 00251 * @} 00252 */ 00253 00254 /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays 00255 * @note Only COMP peripheral HW delays are defined in COMP LL driver driver, 00256 * not timeout values. 00257 * For details on delays values, refer to descriptions in source code 00258 * above each literal definition. 00259 * @{ 00260 */ 00261 00262 /* Delay for comparator startup time. */ 00263 /* Note: Delay required to reach propagation delay specification. */ 00264 /* Literal set to maximum value (refer to device datasheet, */ 00265 /* parameter "tSTART"). */ 00266 /* Unit: us */ 00267 #define LL_COMP_DELAY_STARTUP_US ( 80UL) /*!< Delay for COMP startup time */ 00268 00269 /* Delay for comparator voltage scaler stabilization time. */ 00270 /* Note: Voltage scaler is used when selecting comparator input */ 00271 /* based on VrefInt: VrefInt or subdivision of VrefInt. */ 00272 /* Literal set to maximum value (refer to device datasheet, */ 00273 /* parameter "tSTART_SCALER"). */ 00274 /* Unit: us */ 00275 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */ 00276 00277 /** 00278 * @} 00279 */ 00280 00281 /** 00282 * @} 00283 */ 00284 00285 /* Exported macro ------------------------------------------------------------*/ 00286 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros 00287 * @{ 00288 */ 00289 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro 00290 * @{ 00291 */ 00292 00293 /** 00294 * @brief Write a value in COMP register 00295 * @param __INSTANCE__ comparator instance 00296 * @param __REG__ Register to be written 00297 * @param __VALUE__ Value to be written in the register 00298 * @retval None 00299 */ 00300 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__)) 00301 00302 /** 00303 * @brief Read a value in COMP register 00304 * @param __INSTANCE__ comparator instance 00305 * @param __REG__ Register to be read 00306 * @retval Register value 00307 */ 00308 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__) 00309 /** 00310 * @} 00311 */ 00312 00313 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro 00314 * @{ 00315 */ 00316 00317 /** 00318 * @brief Helper macro to select the COMP common instance 00319 * to which is belonging the selected COMP instance. 00320 * @note COMP common register instance can be used to 00321 * set parameters common to several COMP instances. 00322 * Refer to functions having argument "COMPxy_COMMON" as parameter. 00323 * @param __COMPx__ COMP instance 00324 * @retval COMP common instance or value "0" if there is no COMP common instance. 00325 */ 00326 #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \ 00327 (COMP12_COMMON) 00328 00329 /** 00330 * @} 00331 */ 00332 00333 /** 00334 * @} 00335 */ 00336 00337 /* Exported functions --------------------------------------------------------*/ 00338 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions 00339 * @{ 00340 */ 00341 00342 #if defined(COMP2) 00343 /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances 00344 * @{ 00345 */ 00346 00347 /** 00348 * @brief Set window mode of a pair of comparators instances 00349 * (2 consecutive COMP instances COMP<x> and COMP<x+1>). 00350 * @rmtoll CSR WINMODE LL_COMP_SetCommonWindowMode 00351 * @param COMPxy_COMMON Comparator common instance 00352 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() ) 00353 * @param WindowMode This parameter can be one of the following values: 00354 * @arg @ref LL_COMP_WINDOWMODE_DISABLE 00355 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON 00356 * @retval None 00357 */ 00358 __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode) 00359 { 00360 /* Note: On this STM32 series, window mode can be set only */ 00361 /* from COMP instance: COMP2. */ 00362 MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_WINMODE, WindowMode); 00363 } 00364 00365 /** 00366 * @brief Get window mode of a pair of comparators instances 00367 * (2 consecutive COMP instances COMP<x> and COMP<x+1>). 00368 * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowMode 00369 * @param COMPxy_COMMON Comparator common instance 00370 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() ) 00371 * @retval Returned value can be one of the following values: 00372 * @arg @ref LL_COMP_WINDOWMODE_DISABLE 00373 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON 00374 */ 00375 __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON) 00376 { 00377 return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_WINMODE)); 00378 } 00379 00380 /** 00381 * @} 00382 */ 00383 00384 #endif /* COMP2 */ 00385 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes 00386 * @{ 00387 */ 00388 00389 /** 00390 * @brief Set comparator instance operating mode to adjust power and speed. 00391 * @rmtoll CSR PWRMODE LL_COMP_SetPowerMode 00392 * @param COMPx Comparator instance 00393 * @param PowerMode This parameter can be one of the following values: 00394 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED 00395 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED 00396 * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER 00397 * @retval None 00398 */ 00399 __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode) 00400 { 00401 MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE, PowerMode); 00402 } 00403 00404 /** 00405 * @brief Get comparator instance operating mode to adjust power and speed. 00406 * @rmtoll CSR PWRMODE LL_COMP_GetPowerMode 00407 * @param COMPx Comparator instance 00408 * @retval Returned value can be one of the following values: 00409 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED 00410 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED 00411 * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER 00412 */ 00413 __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx) 00414 { 00415 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_PWRMODE)); 00416 } 00417 00418 /** 00419 * @} 00420 */ 00421 00422 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs 00423 * @{ 00424 */ 00425 00426 /** 00427 * @brief Set comparator inputs minus (inverting) and plus (non-inverting). 00428 * @note In case of comparator input selected to be connected to IO: 00429 * GPIO pins are specific to each comparator instance. 00430 * Refer to description of parameters or to reference manual. 00431 * @note On this STM32 series, scaler bridge is configurable: 00432 * to optimize power consumption, this function enables the 00433 * voltage scaler bridge only when required 00434 * (when selecting comparator input based on VrefInt: VrefInt or 00435 * subdivision of VrefInt). 00436 * - For scaler bridge power consumption values, 00437 * refer to device datasheet, parameter "IDDA(SCALER)". 00438 * - Voltage scaler requires a delay for voltage stabilization. 00439 * Refer to device datasheet, parameter "tSTART_SCALER". 00440 * - Scaler bridge is common for all comparator instances, 00441 * therefore if at least one of the comparator instance 00442 * is requiring the scaler bridge, it remains enabled. 00443 * @rmtoll CSR INMSEL LL_COMP_ConfigInputs\n 00444 * CSR INPSEL LL_COMP_ConfigInputs\n 00445 * CSR BRGEN LL_COMP_ConfigInputs\n 00446 * CSR SCALEN LL_COMP_ConfigInputs 00447 * @param COMPx Comparator instance 00448 * @param InputMinus This parameter can be one of the following values: 00449 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT 00450 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT 00451 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT 00452 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT 00453 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1 00454 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (*) 00455 * @arg @ref LL_COMP_INPUT_MINUS_IO1 00456 * @arg @ref LL_COMP_INPUT_MINUS_IO2 00457 * @arg @ref LL_COMP_INPUT_MINUS_IO3 (*) 00458 * @arg @ref LL_COMP_INPUT_MINUS_IO4 (*) 00459 * @arg @ref LL_COMP_INPUT_MINUS_IO5 (*) 00460 * 00461 * (*) Parameter not available on all devices. 00462 * @param InputPlus This parameter can be one of the following values: 00463 * @arg @ref LL_COMP_INPUT_PLUS_IO1 00464 * @arg @ref LL_COMP_INPUT_PLUS_IO2 00465 * @arg @ref LL_COMP_INPUT_PLUS_IO3 (*) 00466 * 00467 * (*) Parameter not available on all devices. 00468 * @retval None 00469 */ 00470 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus) 00471 { 00472 #if defined(COMP_CSR_INMESEL_1) 00473 MODIFY_REG(COMPx->CSR, 00474 COMP_CSR_INMESEL | COMP_CSR_INMSEL | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, 00475 InputMinus | InputPlus); 00476 #else 00477 MODIFY_REG(COMPx->CSR, 00478 COMP_CSR_INMSEL | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, 00479 InputMinus | InputPlus); 00480 #endif 00481 } 00482 00483 /** 00484 * @brief Set comparator input plus (non-inverting). 00485 * @note In case of comparator input selected to be connected to IO: 00486 * GPIO pins are specific to each comparator instance. 00487 * Refer to description of parameters or to reference manual. 00488 * @rmtoll CSR INPSEL LL_COMP_SetInputPlus 00489 * @param COMPx Comparator instance 00490 * @param InputPlus This parameter can be one of the following values: 00491 * @arg @ref LL_COMP_INPUT_PLUS_IO1 00492 * @arg @ref LL_COMP_INPUT_PLUS_IO2 00493 * @arg @ref LL_COMP_INPUT_PLUS_IO3 (*) 00494 * 00495 * (*) Parameter not available on all devices. 00496 * @retval None 00497 */ 00498 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus) 00499 { 00500 MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus); 00501 } 00502 00503 /** 00504 * @brief Get comparator input plus (non-inverting). 00505 * @note In case of comparator input selected to be connected to IO: 00506 * GPIO pins are specific to each comparator instance. 00507 * Refer to description of parameters or to reference manual. 00508 * @rmtoll CSR INPSEL LL_COMP_GetInputPlus 00509 * @param COMPx Comparator instance 00510 * @retval Returned value can be one of the following values: 00511 * @arg @ref LL_COMP_INPUT_PLUS_IO1 00512 * @arg @ref LL_COMP_INPUT_PLUS_IO2 00513 * @arg @ref LL_COMP_INPUT_PLUS_IO3 (*) 00514 * 00515 * (*) Parameter not available on all devices. 00516 */ 00517 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx) 00518 { 00519 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL)); 00520 } 00521 00522 /** 00523 * @brief Set comparator input minus (inverting). 00524 * @note In case of comparator input selected to be connected to IO: 00525 * GPIO pins are specific to each comparator instance. 00526 * Refer to description of parameters or to reference manual. 00527 * @note On this STM32 series, scaler bridge is configurable: 00528 * to optimize power consumption, this function enables the 00529 * voltage scaler bridge only when required 00530 * (when selecting comparator input based on VrefInt: VrefInt or 00531 * subdivision of VrefInt). 00532 * - For scaler bridge power consumption values, 00533 * refer to device datasheet, parameter "IDDA(SCALER)". 00534 * - Voltage scaler requires a delay for voltage stabilization. 00535 * Refer to device datasheet, parameter "tSTART_SCALER". 00536 * - Scaler bridge is common for all comparator instances, 00537 * therefore if at least one of the comparator instance 00538 * is requiring the scaler bridge, it remains enabled. 00539 * @rmtoll CSR INMSEL LL_COMP_SetInputMinus\n 00540 * CSR BRGEN LL_COMP_SetInputMinus\n 00541 * CSR SCALEN LL_COMP_SetInputMinus 00542 * @param COMPx Comparator instance 00543 * @param InputMinus This parameter can be one of the following values: 00544 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT 00545 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT 00546 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT 00547 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT 00548 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1 00549 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (*) 00550 * @arg @ref LL_COMP_INPUT_MINUS_IO1 00551 * @arg @ref LL_COMP_INPUT_MINUS_IO2 00552 * @arg @ref LL_COMP_INPUT_MINUS_IO3 (*) 00553 * @arg @ref LL_COMP_INPUT_MINUS_IO4 (*) 00554 * @arg @ref LL_COMP_INPUT_MINUS_IO5 (*) 00555 * 00556 * (*) Parameter not available on all devices. 00557 * @retval None 00558 */ 00559 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus) 00560 { 00561 #if defined(COMP_CSR_INMESEL_1) 00562 MODIFY_REG(COMPx->CSR, COMP_CSR_INMESEL | COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, InputMinus); 00563 #else 00564 MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, InputMinus); 00565 #endif /* COMP_CSR_INMESEL_1 */ 00566 } 00567 00568 /** 00569 * @brief Get comparator input minus (inverting). 00570 * @note In case of comparator input selected to be connected to IO: 00571 * GPIO pins are specific to each comparator instance. 00572 * Refer to description of parameters or to reference manual. 00573 * @rmtoll CSR INMSEL LL_COMP_GetInputMinus\n 00574 * CSR BRGEN LL_COMP_GetInputMinus\n 00575 * CSR SCALEN LL_COMP_GetInputMinus 00576 * @param COMPx Comparator instance 00577 * @retval Returned value can be one of the following values: 00578 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT 00579 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT 00580 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT 00581 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT 00582 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1 00583 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (*) 00584 * @arg @ref LL_COMP_INPUT_MINUS_IO1 00585 * @arg @ref LL_COMP_INPUT_MINUS_IO2 00586 * @arg @ref LL_COMP_INPUT_MINUS_IO3 (*) 00587 * @arg @ref LL_COMP_INPUT_MINUS_IO4 (*) 00588 * @arg @ref LL_COMP_INPUT_MINUS_IO5 (*) 00589 * 00590 * (*) Parameter not available on all devices. 00591 */ 00592 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx) 00593 { 00594 #if defined(COMP_CSR_INMESEL_1) 00595 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMESEL | COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN)); 00596 #else 00597 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN)); 00598 #endif /* COMP_CSR_INMESEL_1 */ 00599 } 00600 00601 /** 00602 * @brief Set comparator instance hysteresis mode of the input minus (inverting input). 00603 * @rmtoll CSR HYST LL_COMP_SetInputHysteresis 00604 * @param COMPx Comparator instance 00605 * @param InputHysteresis This parameter can be one of the following values: 00606 * @arg @ref LL_COMP_HYSTERESIS_NONE 00607 * @arg @ref LL_COMP_HYSTERESIS_LOW 00608 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM 00609 * @arg @ref LL_COMP_HYSTERESIS_HIGH 00610 * @retval None 00611 */ 00612 __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis) 00613 { 00614 MODIFY_REG(COMPx->CSR, COMP_CSR_HYST, InputHysteresis); 00615 } 00616 00617 /** 00618 * @brief Get comparator instance hysteresis mode of the minus (inverting) input. 00619 * @rmtoll CSR HYST LL_COMP_GetInputHysteresis 00620 * @param COMPx Comparator instance 00621 * @retval Returned value can be one of the following values: 00622 * @arg @ref LL_COMP_HYSTERESIS_NONE 00623 * @arg @ref LL_COMP_HYSTERESIS_LOW 00624 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM 00625 * @arg @ref LL_COMP_HYSTERESIS_HIGH 00626 */ 00627 __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx) 00628 { 00629 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_HYST)); 00630 } 00631 00632 /** 00633 * @} 00634 */ 00635 00636 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output 00637 * @{ 00638 */ 00639 00640 /** 00641 * @brief Set comparator instance output polarity. 00642 * @rmtoll CSR POLARITY LL_COMP_SetOutputPolarity 00643 * @param COMPx Comparator instance 00644 * @param OutputPolarity This parameter can be one of the following values: 00645 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED 00646 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED 00647 * @retval None 00648 */ 00649 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity) 00650 { 00651 MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity); 00652 } 00653 00654 /** 00655 * @brief Get comparator instance output polarity. 00656 * @rmtoll CSR POLARITY LL_COMP_GetOutputPolarity 00657 * @param COMPx Comparator instance 00658 * @retval Returned value can be one of the following values: 00659 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED 00660 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED 00661 */ 00662 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx) 00663 { 00664 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY)); 00665 } 00666 00667 /** 00668 * @brief Set comparator instance blanking source. 00669 * @note Blanking source may be specific to each comparator instance. 00670 * Refer to description of parameters or to reference manual. 00671 * @note Availability of parameters of blanking source from timer 00672 * depends on timers availability on the selected device. 00673 * @rmtoll CSR BLANKING LL_COMP_SetOutputBlankingSource 00674 * @param COMPx Comparator instance 00675 * @param BlankingSource This parameter can be one of the following values: 00676 * @arg @ref LL_COMP_BLANKINGSRC_NONE 00677 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 (1)(2) 00678 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 (1)(2) 00679 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 (1)(2) 00680 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2 (1)(3) 00681 * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (1)(3) 00682 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (1)(3) 00683 * 00684 * (1) Parameter availability depending on timer availability 00685 * on the selected device. 00686 * (2) On STM32L4, parameter available only on comparator instance: COMP1. 00687 * (3) On STM32L4, parameter available only on comparator instance: COMP2. 00688 * @retval None 00689 */ 00690 __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource) 00691 { 00692 MODIFY_REG(COMPx->CSR, COMP_CSR_BLANKING, BlankingSource); 00693 } 00694 00695 /** 00696 * @brief Get comparator instance blanking source. 00697 * @note Availability of parameters of blanking source from timer 00698 * depends on timers availability on the selected device. 00699 * @note Blanking source may be specific to each comparator instance. 00700 * Refer to description of parameters or to reference manual. 00701 * @rmtoll CSR BLANKING LL_COMP_GetOutputBlankingSource 00702 * @param COMPx Comparator instance 00703 * @retval Returned value can be one of the following values: 00704 * @arg @ref LL_COMP_BLANKINGSRC_NONE 00705 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 (1)(2) 00706 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 (1)(2) 00707 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 (1)(2) 00708 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2 (1)(3) 00709 * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (1)(3) 00710 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (1)(3) 00711 * 00712 * (1) Parameter availability depending on timer availability 00713 * on the selected device. 00714 * (2) On STM32L4, parameter available only on comparator instance: COMP1. 00715 * (3) On STM32L4, parameter available only on comparator instance: COMP2. 00716 */ 00717 __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(COMP_TypeDef *COMPx) 00718 { 00719 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_BLANKING)); 00720 } 00721 00722 /** 00723 * @} 00724 */ 00725 00726 /** @defgroup COMP_LL_EF_Configuration_Legacy_Functions Configuration of COMP, legacy functions name 00727 * @{ 00728 */ 00729 /* Old functions name kept for legacy purpose, to be replaced by the */ 00730 /* current functions name. */ 00731 __STATIC_INLINE void LL_COMP_SetInputNonInverting(COMP_TypeDef *COMPx, uint32_t InputNonInverting) 00732 { 00733 LL_COMP_SetInputPlus(COMPx, InputNonInverting); 00734 } 00735 __STATIC_INLINE uint32_t LL_COMP_GetInputNonInverting(COMP_TypeDef *COMPx) 00736 { 00737 return LL_COMP_GetInputPlus(COMPx); 00738 } 00739 00740 __STATIC_INLINE void LL_COMP_SetInputInverting(COMP_TypeDef *COMPx, uint32_t InputInverting) 00741 { 00742 LL_COMP_SetInputMinus(COMPx, InputInverting); 00743 } 00744 __STATIC_INLINE uint32_t LL_COMP_GetInputInverting(COMP_TypeDef *COMPx) 00745 { 00746 return LL_COMP_GetInputMinus(COMPx); 00747 } 00748 00749 /** 00750 * @} 00751 */ 00752 00753 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance 00754 * @{ 00755 */ 00756 00757 /** 00758 * @brief Enable comparator instance. 00759 * @note After enable from off state, comparator requires a delay 00760 * to reach reach propagation delay specification. 00761 * Refer to device datasheet, parameter "tSTART". 00762 * @rmtoll CSR EN LL_COMP_Enable 00763 * @param COMPx Comparator instance 00764 * @retval None 00765 */ 00766 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx) 00767 { 00768 SET_BIT(COMPx->CSR, COMP_CSR_EN); 00769 } 00770 00771 /** 00772 * @brief Disable comparator instance. 00773 * @rmtoll CSR EN LL_COMP_Disable 00774 * @param COMPx Comparator instance 00775 * @retval None 00776 */ 00777 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx) 00778 { 00779 CLEAR_BIT(COMPx->CSR, COMP_CSR_EN); 00780 } 00781 00782 /** 00783 * @brief Get comparator enable state 00784 * (0: COMP is disabled, 1: COMP is enabled) 00785 * @rmtoll CSR EN LL_COMP_IsEnabled 00786 * @param COMPx Comparator instance 00787 * @retval State of bit (1 or 0). 00788 */ 00789 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx) 00790 { 00791 return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1UL : 0UL); 00792 } 00793 00794 /** 00795 * @brief Lock comparator instance. 00796 * @note Once locked, comparator configuration can be accessed in read-only. 00797 * @note The only way to unlock the comparator is a device hardware reset. 00798 * @rmtoll CSR LOCK LL_COMP_Lock 00799 * @param COMPx Comparator instance 00800 * @retval None 00801 */ 00802 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx) 00803 { 00804 SET_BIT(COMPx->CSR, COMP_CSR_LOCK); 00805 } 00806 00807 /** 00808 * @brief Get comparator lock state 00809 * (0: COMP is unlocked, 1: COMP is locked). 00810 * @note Once locked, comparator configuration can be accessed in read-only. 00811 * @note The only way to unlock the comparator is a device hardware reset. 00812 * @rmtoll CSR LOCK LL_COMP_IsLocked 00813 * @param COMPx Comparator instance 00814 * @retval State of bit (1 or 0). 00815 */ 00816 __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx) 00817 { 00818 return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1UL : 0UL); 00819 } 00820 00821 /** 00822 * @brief Read comparator instance output level. 00823 * @note The comparator output level depends on the selected polarity 00824 * (Refer to function @ref LL_COMP_SetOutputPolarity()). 00825 * If the comparator polarity is not inverted: 00826 * - Comparator output is low when the input plus 00827 * is at a lower voltage than the input minus 00828 * - Comparator output is high when the input plus 00829 * is at a higher voltage than the input minus 00830 * If the comparator polarity is inverted: 00831 * - Comparator output is high when the input plus 00832 * is at a lower voltage than the input minus 00833 * - Comparator output is low when the input plus 00834 * is at a higher voltage than the input minus 00835 * @rmtoll CSR VALUE LL_COMP_ReadOutputLevel 00836 * @param COMPx Comparator instance 00837 * @retval Returned value can be one of the following values: 00838 * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW 00839 * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH 00840 */ 00841 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx) 00842 { 00843 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_VALUE) 00844 >> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS); 00845 } 00846 00847 /** 00848 * @} 00849 */ 00850 00851 #if defined(USE_FULL_LL_DRIVER) 00852 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions 00853 * @{ 00854 */ 00855 00856 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx); 00857 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct); 00858 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct); 00859 00860 /** 00861 * @} 00862 */ 00863 #endif /* USE_FULL_LL_DRIVER */ 00864 00865 /** 00866 * @} 00867 */ 00868 00869 /** 00870 * @} 00871 */ 00872 00873 /** 00874 * @} 00875 */ 00876 00877 #endif /* COMP1 || COMP2 */ 00878 00879 /** 00880 * @} 00881 */ 00882 00883 #ifdef __cplusplus 00884 } 00885 #endif 00886 00887 #endif /* STM32L4xx_LL_COMP_H */