1 /** 2 ****************************************************************************** 3 * @file stm32l4xx_hal_comp.h 4 * @author MCD Application Team 5 * @brief Header file of COMP HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2017 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32L4xx_HAL_COMP_H 21 #define STM32L4xx_HAL_COMP_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32l4xx_hal_def.h" 29 #include "stm32l4xx_ll_exti.h" 30 31 /** @addtogroup STM32L4xx_HAL_Driver 32 * @{ 33 */ 34 #if defined (COMP1) || defined (COMP2) 35 36 /** @addtogroup COMP 37 * @{ 38 */ 39 40 /* Exported types ------------------------------------------------------------*/ 41 /** @defgroup COMP_Exported_Types COMP Exported Types 42 * @{ 43 */ 44 45 /** 46 * @brief COMP Init structure definition 47 */ 48 typedef struct 49 { 50 51 #if defined(COMP2) 52 uint32_t WindowMode; /*!< Set window mode of a pair of comparators instances 53 (2 consecutive instances odd and even COMP<x> and COMP<x+1>). 54 Note: HAL COMP driver allows to set window mode from any COMP instance of the pair of COMP instances composing window mode. 55 This parameter can be a value of @ref COMP_WindowMode */ 56 #endif /* COMP2 */ 57 58 uint32_t Mode; /*!< Set comparator operating mode to adjust power and speed. 59 Note: For the characteristics of comparator power modes 60 (propagation delay and power consumption), refer to device datasheet. 61 This parameter can be a value of @ref COMP_PowerMode */ 62 63 uint32_t NonInvertingInput; /*!< Set comparator input plus (non-inverting input). 64 This parameter can be a value of @ref COMP_InputPlus */ 65 66 uint32_t InvertingInput; /*!< Set comparator input minus (inverting input). 67 This parameter can be a value of @ref COMP_InputMinus */ 68 69 uint32_t Hysteresis; /*!< Set comparator hysteresis mode of the input minus. 70 This parameter can be a value of @ref COMP_Hysteresis */ 71 72 uint32_t OutputPol; /*!< Set comparator output polarity. 73 This parameter can be a value of @ref COMP_OutputPolarity */ 74 75 uint32_t BlankingSrce; /*!< Set comparator blanking source. 76 This parameter can be a value of @ref COMP_BlankingSrce */ 77 78 uint32_t TriggerMode; /*!< Set the comparator output triggering External Interrupt Line (EXTI). 79 This parameter can be a value of @ref COMP_EXTI_TriggerMode */ 80 81 } COMP_InitTypeDef; 82 83 /** 84 * @brief HAL COMP state machine: HAL COMP states definition 85 */ 86 #define COMP_STATE_BITFIELD_LOCK (0x10U) 87 typedef enum 88 { 89 HAL_COMP_STATE_RESET = 0x00U, /*!< COMP not yet initialized */ 90 HAL_COMP_STATE_RESET_LOCKED = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */ 91 HAL_COMP_STATE_READY = 0x01U, /*!< COMP initialized and ready for use */ 92 HAL_COMP_STATE_READY_LOCKED = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked */ 93 HAL_COMP_STATE_BUSY = 0x02U, /*!< COMP is running */ 94 HAL_COMP_STATE_BUSY_LOCKED = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK) /*!< COMP is running and configuration is locked */ 95 } HAL_COMP_StateTypeDef; 96 97 /** 98 * @brief COMP Handle Structure definition 99 */ 100 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 101 typedef struct __COMP_HandleTypeDef 102 #else 103 typedef struct 104 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 105 { 106 COMP_TypeDef *Instance; /*!< Register base address */ 107 COMP_InitTypeDef Init; /*!< COMP required parameters */ 108 HAL_LockTypeDef Lock; /*!< Locking object */ 109 __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */ 110 __IO uint32_t ErrorCode; /*!< COMP error code */ 111 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 112 void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */ 113 void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */ 114 void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */ 115 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 116 } COMP_HandleTypeDef; 117 118 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 119 /** 120 * @brief HAL COMP Callback ID enumeration definition 121 */ 122 typedef enum 123 { 124 HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */ 125 HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */ 126 HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */ 127 } HAL_COMP_CallbackIDTypeDef; 128 129 /** 130 * @brief HAL COMP Callback pointer definition 131 */ 132 typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */ 133 134 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 135 136 /** 137 * @} 138 */ 139 140 /* Exported constants --------------------------------------------------------*/ 141 /** @defgroup COMP_Exported_Constants COMP Exported Constants 142 * @{ 143 */ 144 145 /** @defgroup COMP_Error_Code COMP Error Code 146 * @{ 147 */ 148 #define HAL_COMP_ERROR_NONE (0x00UL) /*!< No error */ 149 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 150 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01UL) /*!< Invalid Callback error */ 151 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 152 /** 153 * @} 154 */ 155 156 #if defined(COMP2) 157 /** @defgroup COMP_WindowMode COMP Window Mode 158 * @{ 159 */ 160 #define COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */ 161 #define 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). */ 162 /** 163 * @} 164 */ 165 #endif /* COMP2 */ 166 167 /** @defgroup COMP_PowerMode COMP power mode 168 * @{ 169 */ 170 /* Note: For the characteristics of comparator power modes */ 171 /* (propagation delay and power consumption), */ 172 /* refer to device datasheet. */ 173 #define COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< High Speed */ 174 #define COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< Medium Speed */ 175 #define COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_PWRMODE) /*!< Ultra-low power mode */ 176 /** 177 * @} 178 */ 179 180 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input) 181 * @{ 182 */ 183 #define COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */ 184 #define COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */ 185 #if defined(COMP_CSR_INPSEL_1) 186 #define COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */ 187 #endif 188 /** 189 * @} 190 */ 191 192 /** @defgroup COMP_InputMinus COMP input minus (inverting input) 193 * @{ 194 */ 195 #define COMP_INPUT_MINUS_1_4VREFINT ( COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */ 196 #define COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/2 VrefInt */ 197 #define COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 3/4 VrefInt */ 198 #define COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN ) /*!< Comparator input minus connected to VrefInt */ 199 #define COMP_INPUT_MINUS_DAC1_CH1 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */ 200 #if defined(DAC_CHANNEL2_SUPPORT) 201 #define COMP_INPUT_MINUS_DAC1_CH2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */ 202 #endif /* DAC_CHANNEL2_SUPPORT */ 203 #define 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) */ 204 #define 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) */ 205 #if defined(COMP_CSR_INMESEL_1) 206 #define 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) */ 207 #define 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) */ 208 #define 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) */ 209 #endif /* COMP_CSR_INMESEL_1 */ 210 /** 211 * @} 212 */ 213 214 /** @defgroup COMP_Hysteresis COMP hysteresis 215 * @{ 216 */ 217 #define COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */ 218 #define COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0) /*!< Hysteresis level low */ 219 #define COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 ) /*!< Hysteresis level medium */ 220 #define COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level high */ 221 /** 222 * @} 223 */ 224 225 /** @defgroup COMP_OutputPolarity COMP output Polarity 226 * @{ 227 */ 228 #define COMP_OUTPUTPOL_NONINVERTED (0x00000000UL) /*!< COMP output level is not inverted (comparator output is high when the input plus is at a higher voltage than the input minus) */ 229 #define COMP_OUTPUTPOL_INVERTED (COMP_CSR_POLARITY) /*!< COMP output level is inverted (comparator output is low when the input plus is at a higher voltage than the input minus) */ 230 /** 231 * @} 232 */ 233 234 /** @defgroup COMP_BlankingSrce COMP blanking source 235 * @{ 236 */ 237 #define COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */ 238 #define COMP_BLANKINGSRC_TIM1_OC5_COMP1 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */ 239 #define COMP_BLANKINGSRC_TIM2_OC3_COMP1 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */ 240 #define COMP_BLANKINGSRC_TIM3_OC3_COMP1 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */ 241 #define COMP_BLANKINGSRC_TIM3_OC4_COMP2 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */ 242 #define COMP_BLANKINGSRC_TIM8_OC5_COMP2 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2) */ 243 #define COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP2) */ 244 /** 245 * @} 246 */ 247 248 /** @defgroup COMP_OutputLevel COMP Output Level 249 * @{ 250 */ 251 /* Note: Comparator output level values are fixed to "0" and "1", */ 252 /* corresponding COMP register bit is managed by HAL function to match */ 253 /* with these values (independently of bit position in register). */ 254 255 /* When output polarity is not inverted, comparator output is low when 256 the input plus is at a lower voltage than the input minus */ 257 #define COMP_OUTPUT_LEVEL_LOW (0x00000000UL) 258 /* When output polarity is not inverted, comparator output is high when 259 the input plus is at a higher voltage than the input minus */ 260 #define COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) 261 /** 262 * @} 263 */ 264 265 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI 266 * @{ 267 */ 268 #define COMP_TRIGGERMODE_NONE (0x00000000UL) /*!< Comparator output triggering no External Interrupt Line */ 269 #define COMP_TRIGGERMODE_IT_RISING (COMP_EXTI_IT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */ 270 #define COMP_TRIGGERMODE_IT_FALLING (COMP_EXTI_IT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */ 271 #define COMP_TRIGGERMODE_IT_RISING_FALLING (COMP_EXTI_IT | COMP_EXTI_RISING | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on both rising and falling edges */ 272 #define COMP_TRIGGERMODE_EVENT_RISING (COMP_EXTI_EVENT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */ 273 #define COMP_TRIGGERMODE_EVENT_FALLING (COMP_EXTI_EVENT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */ 274 #define COMP_TRIGGERMODE_EVENT_RISING_FALLING (COMP_EXTI_EVENT | COMP_EXTI_RISING | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on both rising and falling edges */ 275 /** 276 * @} 277 */ 278 279 /** 280 * @} 281 */ 282 283 /* Exported macro ------------------------------------------------------------*/ 284 /** @defgroup COMP_Exported_Macros COMP Exported Macros 285 * @{ 286 */ 287 288 /** @defgroup COMP_Handle_Management COMP Handle Management 289 * @{ 290 */ 291 292 /** @brief Reset COMP handle state. 293 * @param __HANDLE__ COMP handle 294 * @retval None 295 */ 296 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 297 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \ 298 (__HANDLE__)->State = HAL_COMP_STATE_RESET; \ 299 (__HANDLE__)->MspInitCallback = NULL; \ 300 (__HANDLE__)->MspDeInitCallback = NULL; \ 301 } while(0) 302 #else 303 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET) 304 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 305 306 /** 307 * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE"). 308 * @param __HANDLE__ COMP handle 309 * @retval None 310 */ 311 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE) 312 313 /** 314 * @brief Enable the specified comparator. 315 * @param __HANDLE__ COMP handle 316 * @retval None 317 */ 318 #define __HAL_COMP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN) 319 320 /** 321 * @brief Disable the specified comparator. 322 * @param __HANDLE__ COMP handle 323 * @retval None 324 */ 325 #define __HAL_COMP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN) 326 327 /** 328 * @brief Lock the specified comparator configuration. 329 * @note Using this macro induce HAL COMP handle state machine being no 330 * more in line with COMP instance state. 331 * To keep HAL COMP handle state machine updated, it is recommended 332 * to use function "HAL_COMP_Lock')". 333 * @param __HANDLE__ COMP handle 334 * @retval None 335 */ 336 #define __HAL_COMP_LOCK(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) 337 338 /** 339 * @brief Check whether the specified comparator is locked. 340 * @param __HANDLE__ COMP handle 341 * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked 342 */ 343 #define __HAL_COMP_IS_LOCKED(__HANDLE__) (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK) 344 345 /** 346 * @} 347 */ 348 349 /** @defgroup COMP_Exti_Management COMP external interrupt line management 350 * @{ 351 */ 352 353 /** 354 * @brief Enable the COMP1 EXTI line rising edge trigger. 355 * @retval None 356 */ 357 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1) 358 359 /** 360 * @brief Disable the COMP1 EXTI line rising edge trigger. 361 * @retval None 362 */ 363 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1) 364 365 /** 366 * @brief Enable the COMP1 EXTI line falling edge trigger. 367 * @retval None 368 */ 369 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1) 370 371 /** 372 * @brief Disable the COMP1 EXTI line falling edge trigger. 373 * @retval None 374 */ 375 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1) 376 377 /** 378 * @brief Enable the COMP1 EXTI line rising & falling edge trigger. 379 * @retval None 380 */ 381 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 382 LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 383 LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 384 } while(0) 385 386 /** 387 * @brief Disable the COMP1 EXTI line rising & falling edge trigger. 388 * @retval None 389 */ 390 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 391 LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 392 LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 393 } while(0) 394 395 /** 396 * @brief Enable the COMP1 EXTI line in interrupt mode. 397 * @retval None 398 */ 399 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP1) 400 401 /** 402 * @brief Disable the COMP1 EXTI line in interrupt mode. 403 * @retval None 404 */ 405 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1) 406 407 /** 408 * @brief Generate a software interrupt on the COMP1 EXTI line. 409 * @retval None 410 */ 411 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1) 412 413 /** 414 * @brief Enable the COMP1 EXTI line in event mode. 415 * @retval None 416 */ 417 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1) 418 419 /** 420 * @brief Disable the COMP1 EXTI line in event mode. 421 * @retval None 422 */ 423 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1) 424 425 /** 426 * @brief Check whether the COMP1 EXTI line flag is set. 427 * @retval RESET or SET 428 */ 429 #define __HAL_COMP_COMP1_EXTI_GET_FLAG() LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP1) 430 431 /** 432 * @brief Clear the COMP1 EXTI flag. 433 * @retval None 434 */ 435 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP1) 436 437 #if defined(COMP2) 438 /** 439 * @brief Enable the COMP2 EXTI line rising edge trigger. 440 * @retval None 441 */ 442 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2) 443 444 /** 445 * @brief Disable the COMP2 EXTI line rising edge trigger. 446 * @retval None 447 */ 448 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2) 449 450 /** 451 * @brief Enable the COMP2 EXTI line falling edge trigger. 452 * @retval None 453 */ 454 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2) 455 456 /** 457 * @brief Disable the COMP2 EXTI line falling edge trigger. 458 * @retval None 459 */ 460 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2) 461 462 /** 463 * @brief Enable the COMP2 EXTI line rising & falling edge trigger. 464 * @retval None 465 */ 466 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 467 LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 468 LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 469 } while(0) 470 471 /** 472 * @brief Disable the COMP2 EXTI line rising & falling edge trigger. 473 * @retval None 474 */ 475 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 476 LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 477 LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 478 } while(0) 479 480 /** 481 * @brief Enable the COMP2 EXTI line in interrupt mode. 482 * @retval None 483 */ 484 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2) 485 486 /** 487 * @brief Disable the COMP2 EXTI line in interrupt mode. 488 * @retval None 489 */ 490 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2) 491 492 /** 493 * @brief Generate a software interrupt on the COMP2 EXTI line. 494 * @retval None 495 */ 496 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2) 497 498 /** 499 * @brief Enable the COMP2 EXTI line in event mode. 500 * @retval None 501 */ 502 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2) 503 504 /** 505 * @brief Disable the COMP2 EXTI line in event mode. 506 * @retval None 507 */ 508 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2) 509 510 /** 511 * @brief Check whether the COMP2 EXTI line flag is set. 512 * @retval RESET or SET 513 */ 514 #define __HAL_COMP_COMP2_EXTI_GET_FLAG() LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP2) 515 516 /** 517 * @brief Clear the COMP2 EXTI flag. 518 * @retval None 519 */ 520 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP2) 521 522 #endif /* COMP2 */ 523 /** 524 * @} 525 */ 526 527 /** 528 * @} 529 */ 530 531 532 /* Private types -------------------------------------------------------------*/ 533 /* Private constants ---------------------------------------------------------*/ 534 /** @defgroup COMP_Private_Constants COMP Private Constants 535 * @{ 536 */ 537 538 /** @defgroup COMP_ExtiLine COMP EXTI Lines 539 * @{ 540 */ 541 #define COMP_EXTI_LINE_COMP1 (LL_EXTI_LINE_21) /*!< EXTI line 21 connected to COMP1 output */ 542 #if defined(COMP2) 543 #define COMP_EXTI_LINE_COMP2 (LL_EXTI_LINE_22) /*!< EXTI line 22 connected to COMP2 output */ 544 #endif /* COMP2 */ 545 /** 546 * @} 547 */ 548 549 /** @defgroup COMP_ExtiLine COMP EXTI Lines 550 * @{ 551 */ 552 #define COMP_EXTI_IT (0x00000001UL) /*!< EXTI line event with interruption */ 553 #define COMP_EXTI_EVENT (0x00000002UL) /*!< EXTI line event only (without interruption) */ 554 #define COMP_EXTI_RISING (0x00000010UL) /*!< EXTI line event on rising edge */ 555 #define COMP_EXTI_FALLING (0x00000020UL) /*!< EXTI line event on falling edge */ 556 /** 557 * @} 558 */ 559 560 /** 561 * @} 562 */ 563 564 /* Private macros ------------------------------------------------------------*/ 565 /** @defgroup COMP_Private_Macros COMP Private Macros 566 * @{ 567 */ 568 569 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators 570 * @{ 571 */ 572 /** 573 * @brief Get the specified EXTI line for a comparator instance. 574 * @param __INSTANCE__ specifies the COMP instance. 575 * @retval value of @ref COMP_ExtiLine 576 */ 577 #if defined(COMP2) 578 #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 \ 579 : COMP_EXTI_LINE_COMP2) 580 #else 581 #define COMP_GET_EXTI_LINE(__INSTANCE__) COMP_EXTI_LINE_COMP1 582 #endif /* COMP2 */ 583 /** 584 * @} 585 */ 586 587 /** @defgroup COMP_IS_COMP_Private_Definitions COMP private macros to check input parameters 588 * @{ 589 */ 590 #if defined(COMP2) 591 #define IS_COMP_WINDOWMODE(__WINDOWMODE__) (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE) || \ 592 ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON) ) 593 #endif /* COMP2 */ 594 595 #define IS_COMP_POWERMODE(__POWERMODE__) (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED) || \ 596 ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED) || \ 597 ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER) ) 598 599 #if defined(COMP_CSR_INPSEL_1) 600 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \ 601 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \ 602 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3)) 603 #else 604 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \ 605 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2)) 606 #endif 607 608 /* Note: On this STM32 series, comparator input minus parameters are */ 609 /* the same on all COMP instances. */ 610 /* However, comparator instance kept as macro parameter for */ 611 /* compatibility with other STM32 families. */ 612 #if defined(COMP_CSR_INMESEL_1) && defined(DAC_CHANNEL2_SUPPORT) 613 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \ 614 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \ 615 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \ 616 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \ 617 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \ 618 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) || \ 619 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \ 620 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) || \ 621 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3) || \ 622 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO4) || \ 623 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO5)) 624 #elif defined(COMP_CSR_INMESEL_1) 625 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \ 626 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \ 627 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \ 628 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \ 629 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \ 630 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \ 631 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) || \ 632 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3) || \ 633 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO4) || \ 634 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO5)) 635 #elif defined(DAC_CHANNEL2_SUPPORT) 636 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \ 637 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \ 638 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \ 639 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \ 640 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \ 641 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) || \ 642 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \ 643 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)) 644 #else 645 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \ 646 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \ 647 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \ 648 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \ 649 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \ 650 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \ 651 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)) 652 #endif /* COMP_CSR_INMESEL_1 && DAC_CHANNEL2_SUPPORT */ 653 654 #define IS_COMP_HYSTERESIS(__HYSTERESIS__) (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE) || \ 655 ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW) || \ 656 ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \ 657 ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH)) 658 659 #define IS_COMP_OUTPUTPOL(__POL__) (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \ 660 ((__POL__) == COMP_OUTPUTPOL_INVERTED)) 661 662 #if defined(COMP2) 663 #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__) \ 664 ( ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) \ 665 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) \ 666 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) \ 667 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1) \ 668 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2) \ 669 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2) \ 670 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2) \ 671 ) 672 #else 673 #if defined(TIM3) 674 #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__) \ 675 ( ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) \ 676 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) \ 677 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) \ 678 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1) \ 679 ) 680 #else 681 #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__) \ 682 ( ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) \ 683 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) \ 684 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) \ 685 ) 686 #endif /* TIM3 */ 687 #endif /* COMP2 */ 688 689 #if defined(COMP2) 690 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \ 691 ((((__INSTANCE__) == COMP1) && \ 692 (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \ 693 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \ 694 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) || \ 695 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1))) \ 696 || \ 697 (((__INSTANCE__) == COMP2) && \ 698 (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \ 699 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2) || \ 700 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2) || \ 701 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2)))) 702 #else 703 #if defined(TIM3) 704 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \ 705 (((__INSTANCE__) == COMP1) && \ 706 (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \ 707 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \ 708 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) || \ 709 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1))) 710 #else 711 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \ 712 (((__INSTANCE__) == COMP1) && \ 713 (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \ 714 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \ 715 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) )) 716 #endif /* TIM3 */ 717 #endif /* COMP2 */ 718 719 #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \ 720 ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \ 721 ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \ 722 ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \ 723 ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \ 724 ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \ 725 ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING)) 726 727 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW) || \ 728 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH)) 729 730 /** 731 * @} 732 */ 733 734 /** 735 * @} 736 */ 737 738 739 /* Exported functions --------------------------------------------------------*/ 740 /** @addtogroup COMP_Exported_Functions 741 * @{ 742 */ 743 744 /** @addtogroup COMP_Exported_Functions_Group1 745 * @{ 746 */ 747 748 /* Initialization and de-initialization functions **********************************/ 749 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp); 750 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp); 751 void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp); 752 void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp); 753 754 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 755 /* Callbacks Register/UnRegister functions ***********************************/ 756 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, 757 pCOMP_CallbackTypeDef pCallback); 758 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID); 759 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 760 /** 761 * @} 762 */ 763 764 /* IO operation functions *****************************************************/ 765 /** @addtogroup COMP_Exported_Functions_Group2 766 * @{ 767 */ 768 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp); 769 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp); 770 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp); 771 /** 772 * @} 773 */ 774 775 /* Peripheral Control functions ************************************************/ 776 /** @addtogroup COMP_Exported_Functions_Group3 777 * @{ 778 */ 779 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp); 780 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp); 781 /* Callback in interrupt mode */ 782 void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp); 783 /** 784 * @} 785 */ 786 787 /* Peripheral State functions **************************************************/ 788 /** @addtogroup COMP_Exported_Functions_Group4 789 * @{ 790 */ 791 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp); 792 uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp); 793 /** 794 * @} 795 */ 796 797 /** 798 * @} 799 */ 800 801 /** 802 * @} 803 */ 804 #endif /* COMP1 || COMP2 */ 805 /** 806 * @} 807 */ 808 809 #ifdef __cplusplus 810 } 811 #endif 812 813 #endif /* STM32L4xx_HAL_COMP_H */ 814