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