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