1 /** 2 ****************************************************************************** 3 * @file stm32u0xx_hal_comp.h 4 * @author MCD Application Team 5 * @brief Header file of COMP HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2023 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 STM32U0xx_HAL_COMP_H 21 #define STM32U0xx_HAL_COMP_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32u0xx_hal_def.h" 29 #include "stm32u0xx_ll_exti.h" 30 31 /** @addtogroup STM32U0xx_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 55 instance of the pair of COMP instances composing window mode. 56 This parameter can be a value of @ref COMP_WindowMode */ 57 #endif /* COMP2 */ 58 59 uint32_t WindowOutput; /*!< Set window mode output. 60 This parameter can be a value of @ref COMP_WindowOutput */ 61 62 uint32_t Mode; /*!< Set comparator operating mode to adjust power and speed. 63 Note: For the characteristics of comparator power modes 64 (propagation delay and power consumption), refer to device datasheet. 65 This parameter can be a value of @ref COMP_PowerMode */ 66 67 uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input). 68 This parameter can be a value of @ref COMP_InputPlus */ 69 70 uint32_t InputMinus; /*!< Set comparator input minus (inverting input). 71 This parameter can be a value of @ref COMP_InputMinus */ 72 73 uint32_t Hysteresis; /*!< Set comparator hysteresis mode of the input minus. 74 This parameter can be a value of @ref COMP_Hysteresis */ 75 76 uint32_t OutputPol; /*!< Set comparator output polarity. 77 This parameter can be a value of @ref COMP_OutputPolarity */ 78 79 uint32_t BlankingSrce; /*!< Set comparator blanking source. 80 This parameter can be a value of @ref COMP_BlankingSrce */ 81 82 uint32_t TriggerMode; /*!< Set the comparator output triggering External Interrupt Line (EXTI). 83 This parameter can be a value of @ref COMP_EXTI_TriggerMode */ 84 85 } COMP_InitTypeDef; 86 87 /** 88 * @brief HAL COMP state machine: HAL COMP states definition 89 */ 90 #define COMP_STATE_BITFIELD_LOCK (0x10U) 91 typedef enum 92 { 93 HAL_COMP_STATE_RESET = 0x00U, /*!< COMP not yet initialized */ 94 HAL_COMP_STATE_RESET_LOCKED = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */ 95 HAL_COMP_STATE_READY = 0x01U, /*!< COMP initialized and ready for use */ 96 HAL_COMP_STATE_READY_LOCKED = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked */ 97 HAL_COMP_STATE_BUSY = 0x02U, /*!< COMP is running */ 98 HAL_COMP_STATE_BUSY_LOCKED = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK) /*!< COMP is running and configuration is locked */ 99 } HAL_COMP_StateTypeDef; 100 101 /** 102 * @brief COMP Handle Structure definition 103 */ 104 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 105 typedef struct __COMP_HandleTypeDef 106 #else 107 typedef struct 108 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 109 { 110 COMP_TypeDef *Instance; /*!< Register base address */ 111 COMP_InitTypeDef Init; /*!< COMP required parameters */ 112 HAL_LockTypeDef Lock; /*!< Locking object */ 113 __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */ 114 __IO uint32_t ErrorCode; /*!< COMP error code */ 115 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 116 void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */ 117 void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */ 118 void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */ 119 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 120 } COMP_HandleTypeDef; 121 122 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 123 /** 124 * @brief HAL COMP Callback ID enumeration definition 125 */ 126 typedef enum 127 { 128 HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */ 129 HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */ 130 HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */ 131 } HAL_COMP_CallbackIDTypeDef; 132 133 /** 134 * @brief HAL COMP Callback pointer definition 135 */ 136 typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */ 137 138 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 139 140 /** 141 * @} 142 */ 143 144 /* Exported constants --------------------------------------------------------*/ 145 /** @defgroup COMP_Exported_Constants COMP Exported Constants 146 * @{ 147 */ 148 149 /** @defgroup COMP_Error_Code COMP Error Code 150 * @{ 151 */ 152 #define HAL_COMP_ERROR_NONE (0x00UL) /*!< No error */ 153 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 154 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01UL) /*!< Invalid Callback error */ 155 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 156 /** 157 * @} 158 */ 159 160 161 #if defined(COMP2) 162 /** @defgroup COMP_WindowMode COMP Window Mode 163 * @{ 164 */ 165 #define COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators 166 instances pair COMP1 and COMP2 are 167 independent */ 168 #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE) /*!< Window mode enable: Comparators instances 169 pair COMP1 and COMP2 have their input 170 plus connected together. 171 The common input is COMP1 input plus 172 (COMP2 input plus is no more accessible). 173 */ 174 #define COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (COMP_CSR_WINMODE \ 175 | COMP_WINDOWMODE_COMP2) /*!< Window mode enable: if used from COMP1 or 176 COMP2 instance, comparators instances 177 pair COMP1 and COMP2 have their input 178 plus connected together, the common input 179 is COMP2 input plus (COMP1 input plus is 180 no more accessible). */ 181 /** 182 * @} 183 */ 184 #endif /* COMP2 */ 185 186 /** @defgroup COMP_WindowOutput COMP Window output 187 * @{ 188 */ 189 #define COMP_WINDOWOUTPUT_EACH_COMP (0x00000000UL) /*!< Window output default mode: Comparators output are 190 indicating each their own state. 191 To know window mode state: each comparator output 192 must be read, if "((COMPx exclusive or COMPy) == 1)" 193 then monitored signal is within comparators window.*/ 194 #define COMP_WINDOWOUTPUT_COMP1 (COMP_CSR_WINOUT) /*!< Window output synthesized on COMP1 output: 195 COMP1 output is no more indicating its own state, but 196 global window mode state (logical high means 197 monitored signal is within comparators window). 198 Note: impacts only comparator output signal level 199 (COMPx_OUT propagated to GPIO, EXTI lines, 200 timers, ...), does not impact output digital state 201 of comparator (COMPx_VALUE) always reflecting each 202 comparator output state.*/ 203 #define COMP_WINDOWOUTPUT_COMP2 (COMP_CSR_WINOUT \ 204 | COMP_WINDOWMODE_COMP2) /*!< Window output synthesized on COMP2 output: 205 COMP2 output is no more indicating its own state, but 206 global window mode state (logical high means 207 monitored signal is within comparators window). 208 Note: impacts only comparator output signal level 209 (COMPx_OUT propagated to GPIO, EXTI lines, 210 timers, ...), does not impact output digital state 211 of comparator (COMPx_VALUE) always reflecting each 212 comparator output state.*/ 213 #define COMP_WINDOWOUTPUT_BOTH (0x00000001UL) /*!< Window output synthesized on both comparators output 214 of pair of comparator selected (COMP1 and COMP2: 215 both comparators outputs are no more indicating their 216 own state, but global window mode state (logical high 217 means monitored signal is within comparators window). 218 This is a specific configuration (technically 219 possible but not relevant from application 220 point of view: 221 2 comparators output used for the same signal level), 222 standard configuration for window mode is one of the 223 settings above. */ 224 /** 225 * @} 226 */ 227 228 229 /** @defgroup COMP_PowerMode COMP power mode 230 * @{ 231 */ 232 /* Note: For the characteristics of comparator power modes */ 233 /* (propagation delay and power consumption), */ 234 /* refer to device datasheet. */ 235 #define COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< High Speed */ 236 #define COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< Medium Speed */ 237 #define COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_PWRMODE_1 | COMP_CSR_PWRMODE_0) /*!< Ultra-low power */ 238 /** 239 * @} 240 */ 241 242 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input) 243 * @{ 244 */ 245 #define COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */ 246 #define COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */ 247 #define COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */ 248 #define COMP_INPUT_PLUS_IO4 (COMP_CSR_INPSEL_1 | COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO4 (pin PA9 for COMP1, pin PD10 for COMP2) */ 249 #define COMP_INPUT_PLUS_IO5 (COMP_CSR_INPSEL_2 ) /*!< Comparator input plus connected to IO5 (pin PC6 for COMP1, not applicable for COMP2) */ 250 /** 251 * @} 252 */ 253 254 /** @defgroup COMP_InputMinus COMP input minus (inverting input) 255 * @{ 256 */ 257 #define COMP_INPUT_MINUS_1_4VREFINT (0x00000000UL) /*!< Comparator input minus connected to 1/4 VrefInt */ 258 #define COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt */ 259 #define COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to 3/4 VrefInt */ 260 #define COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to VrefInt */ 261 #define COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */ 262 #define COMP_INPUT_MINUS_IO1 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO1 (pin PC4 for COMP1, pin PB7 for COMP2) */ 263 #define COMP_INPUT_MINUS_IO2 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to IO2 (pin PB1 for COMP1, pin PB3 for COMP2) */ 264 #define COMP_INPUT_MINUS_IO3 ( 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) */ 265 #define COMP_INPUT_MINUS_IO4 (COMP_CSR_INMSEL_3 ) /*!< Comparator input minus connected to IO4 (pin PA4 for COMP1, pin PA4 for COMP2) */ 266 #define COMP_INPUT_MINUS_IO5 (COMP_CSR_INMSEL_3 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO5 (pin PA5 for COMP1, pin PA5 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 /* Note: Output blanking source common to all COMP instances */ 296 #define COMP_BLANKINGSRC_TIM1_OC4 (COMP_CSR_BLANKSEL_0) /*!< Comparator output blanking source TIM1 OC4 (common to all COMP instances: COMP1, COMP2 ) */ 297 #define COMP_BLANKINGSRC_TIM1_OC5 (COMP_CSR_BLANKSEL_1) /*!< Comparator output blanking source TIM1 OC5 (common to all COMP instances: COMP1, COMP2 ) */ 298 #define COMP_BLANKINGSRC_TIM2_OC3 (COMP_CSR_BLANKSEL_2) /*!< Comparator output blanking source TIM2 OC3 (common to all COMP instances: COMP1, COMP2 ) */ 299 #define COMP_BLANKINGSRC_TIM3_OC3 (COMP_CSR_BLANKSEL_3) /*!< Comparator output blanking source TIM3 OC3 (common to all COMP instances: COMP1, COMP2 ) */ 300 #define COMP_BLANKINGSRC_TIM15_OC2 (COMP_CSR_BLANKSEL_4) /*!< Comparator output blanking source TIM15 OC2 (common to all COMP instances: COMP1, 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 * @brief Enable the COMP1 EXTI line rising edge trigger. 411 * @retval None 412 */ 413 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1) 414 415 /** 416 * @brief Disable the COMP1 EXTI line rising edge trigger. 417 * @retval None 418 */ 419 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1) 420 421 /** 422 * @brief Enable the COMP1 EXTI line falling edge trigger. 423 * @retval None 424 */ 425 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1) 426 427 /** 428 * @brief Disable the COMP1 EXTI line falling edge trigger. 429 * @retval None 430 */ 431 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1) 432 433 /** 434 * @brief Enable the COMP1 EXTI line rising & falling edge trigger. 435 * @retval None 436 */ 437 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 438 LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 439 LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 440 } while(0) 441 442 /** 443 * @brief Disable the COMP1 EXTI line rising & falling edge trigger. 444 * @retval None 445 */ 446 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 447 LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 448 LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1);\ 449 } while(0) 450 451 /** 452 * @brief Enable the COMP1 EXTI line in interrupt mode. 453 * @retval None 454 */ 455 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP1) 456 457 /** 458 * @brief Disable the COMP1 EXTI line in interrupt mode. 459 * @retval None 460 */ 461 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1) 462 463 /** 464 * @brief Generate a software interrupt on the COMP1 EXTI line. 465 * @retval None 466 */ 467 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1) 468 469 /** 470 * @brief Enable the COMP1 EXTI line in event mode. 471 * @retval None 472 */ 473 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1) 474 475 /** 476 * @brief Disable the COMP1 EXTI line in event mode. 477 * @retval None 478 */ 479 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1) 480 481 /** 482 * @brief Check whether the COMP1 EXTI line rising flag is set. 483 * @retval RESET or SET 484 */ 485 #define __HAL_COMP_COMP1_EXTI_GET_RISING_FLAG() LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP1) 486 487 /** 488 * @brief Clear the COMP1 EXTI rising flag. 489 * @retval None 490 */ 491 #define __HAL_COMP_COMP1_EXTI_CLEAR_RISING_FLAG() LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP1) 492 493 /** 494 * @brief Check whether the COMP1 EXTI line falling flag is set. 495 * @retval RESET or SET 496 */ 497 #define __HAL_COMP_COMP1_EXTI_GET_FALLING_FLAG() LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP1) 498 499 /** 500 * @brief Clear the COMP1 EXTI falling flag. 501 * @retval None 502 */ 503 #define __HAL_COMP_COMP1_EXTI_CLEAR_FALLING_FLAG() LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP1) 504 505 #if defined(COMP2) 506 /** 507 * @brief Enable the COMP2 EXTI line rising edge trigger. 508 * @retval None 509 */ 510 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2) 511 512 /** 513 * @brief Disable the COMP2 EXTI line rising edge trigger. 514 * @retval None 515 */ 516 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2) 517 518 /** 519 * @brief Enable the COMP2 EXTI line falling edge trigger. 520 * @retval None 521 */ 522 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2) 523 524 /** 525 * @brief Disable the COMP2 EXTI line falling edge trigger. 526 * @retval None 527 */ 528 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2) 529 530 /** 531 * @brief Enable the COMP2 EXTI line rising & falling edge trigger. 532 * @retval None 533 */ 534 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 535 LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 536 LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 537 } while(0) 538 539 /** 540 * @brief Disable the COMP2 EXTI line rising & falling edge trigger. 541 * @retval None 542 */ 543 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 544 LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 545 LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2);\ 546 } while(0) 547 548 /** 549 * @brief Enable the COMP2 EXTI line in interrupt mode. 550 * @retval None 551 */ 552 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2) 553 554 /** 555 * @brief Disable the COMP2 EXTI line in interrupt mode. 556 * @retval None 557 */ 558 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2) 559 560 /** 561 * @brief Generate a software interrupt on the COMP2 EXTI line. 562 * @retval None 563 */ 564 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2) 565 566 /** 567 * @brief Enable the COMP2 EXTI line in event mode. 568 * @retval None 569 */ 570 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2) 571 572 /** 573 * @brief Disable the COMP2 EXTI line in event mode. 574 * @retval None 575 */ 576 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2) 577 578 /** 579 * @brief Check whether the COMP2 EXTI line rising flag is set. 580 * @retval RESET or SET 581 */ 582 #define __HAL_COMP_COMP2_EXTI_GET_RISING_FLAG() LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP2) 583 584 /** 585 * @brief Clear the COMP2 EXTI rising flag. 586 * @retval None 587 */ 588 #define __HAL_COMP_COMP2_EXTI_CLEAR_RISING_FLAG() LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP2) 589 590 /** 591 * @brief Check whether the COMP2 EXTI line falling flag is set. 592 * @retval RESET or SET 593 */ 594 #define __HAL_COMP_COMP2_EXTI_GET_FALLING_FLAG() LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP2) 595 596 /** 597 * @brief Clear the COMP2 EXTI falling flag. 598 * @retval None 599 */ 600 #define __HAL_COMP_COMP2_EXTI_CLEAR_FALLING_FLAG() LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP2) 601 602 #endif /* COMP2 */ 603 /** 604 * @} 605 */ 606 607 /** 608 * @} 609 */ 610 611 612 /* Private types -------------------------------------------------------------*/ 613 /* Private constants ---------------------------------------------------------*/ 614 /** @defgroup COMP_Private_Constants COMP Private Constants 615 * @{ 616 */ 617 618 /** @defgroup COMP_WindowMode_Instance_Differentiator COMP window mode instance differentiator 619 * @{ 620 */ 621 #define COMP_WINDOWMODE_COMP2 0x00001000U /*!< COMP window mode using common input of COMP instance: COMP2 */ 622 /** 623 * @} 624 */ 625 626 /** @defgroup COMP_ExtiLine COMP EXTI Lines 627 * @{ 628 */ 629 #define COMP_EXTI_LINE_COMP1 (EXTI_IMR1_IM17) /*!< EXTI line 17 connected to COMP1 output */ 630 #if defined(COMP2) 631 #define COMP_EXTI_LINE_COMP2 (EXTI_IMR1_IM18) /*!< EXTI line 18 connected to COMP2 output */ 632 #endif /* COMP2 */ 633 /** 634 * @} 635 */ 636 637 /** @defgroup COMP_ExtiLine COMP EXTI Lines 638 * @{ 639 */ 640 #define COMP_EXTI_IT (0x00000001UL) /*!< EXTI line event with interruption */ 641 #define COMP_EXTI_EVENT (0x00000002UL) /*!< EXTI line event only (without interruption) */ 642 #define COMP_EXTI_RISING (0x00000010UL) /*!< EXTI line event on rising edge */ 643 #define COMP_EXTI_FALLING (0x00000020UL) /*!< EXTI line event on falling edge */ 644 /** 645 * @} 646 */ 647 648 /** 649 * @} 650 */ 651 652 /* Private macros ------------------------------------------------------------*/ 653 /** @defgroup COMP_Private_Macros COMP Private Macros 654 * @{ 655 */ 656 657 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators 658 * @{ 659 */ 660 /** 661 * @brief Get the specified EXTI line for a comparator instance. 662 * @param __INSTANCE__ specifies the COMP instance. 663 * @retval value of @ref COMP_ExtiLine 664 */ 665 #if defined(COMP2) 666 #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 \ 667 : COMP_EXTI_LINE_COMP2) 668 #else 669 #define COMP_GET_EXTI_LINE(__INSTANCE__) COMP_EXTI_LINE_COMP1 670 #endif /* COMP2 */ 671 /** 672 * @} 673 */ 674 675 /** @defgroup COMP_IS_COMP_Private_Definitions COMP private macros to check input parameters 676 * @{ 677 */ 678 #define IS_COMP_WINDOWMODE(__INSTANCE__, __WINDOWMODE__) \ 679 (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE) || \ 680 ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)|| \ 681 ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON) ) 682 683 #define IS_COMP_WINDOWOUTPUT(__WINDOWOUTPUT__) (((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_EACH_COMP) || \ 684 ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_COMP1) || \ 685 ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_COMP2) || \ 686 ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_BOTH) ) 687 688 #define IS_COMP_POWERMODE(__POWERMODE__) (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED) || \ 689 ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED) ) 690 691 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__COMP_INSTANCE__) == COMP1) \ 692 ? (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \ 693 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \ 694 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3) || \ 695 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO4) || \ 696 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO5) ) \ 697 : \ 698 (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \ 699 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \ 700 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3) || \ 701 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO4) ) \ 702 ) 703 704 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \ 705 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \ 706 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \ 707 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \ 708 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \ 709 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \ 710 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) || \ 711 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3) || \ 712 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO4) || \ 713 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO5)) 714 715 #define IS_COMP_HYSTERESIS(__HYSTERESIS__) (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE) || \ 716 ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW) || \ 717 ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \ 718 ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH)) 719 720 #define IS_COMP_OUTPUTPOL(__POL__) (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \ 721 ((__POL__) == COMP_OUTPUTPOL_INVERTED)) 722 723 #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__) \ 724 (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) \ 725 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC4) \ 726 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5) \ 727 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3) \ 728 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3) \ 729 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC2) \ 730 ) 731 732 #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \ 733 ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \ 734 ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \ 735 ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \ 736 ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \ 737 ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \ 738 ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING)) 739 740 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW) || \ 741 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH)) 742 743 /** 744 * @} 745 */ 746 747 /** 748 * @} 749 */ 750 751 752 /* Exported functions --------------------------------------------------------*/ 753 /** @addtogroup COMP_Exported_Functions 754 * @{ 755 */ 756 757 /** @addtogroup COMP_Exported_Functions_Group1 758 * @{ 759 */ 760 761 /* Initialization and de-initialization functions **********************************/ 762 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp); 763 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp); 764 void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp); 765 void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp); 766 767 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 768 /* Callbacks Register/UnRegister functions ***********************************/ 769 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, 770 pCOMP_CallbackTypeDef pCallback); 771 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID); 772 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 773 /** 774 * @} 775 */ 776 777 /* IO operation functions *****************************************************/ 778 /** @addtogroup COMP_Exported_Functions_Group2 779 * @{ 780 */ 781 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp); 782 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp); 783 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp); 784 /** 785 * @} 786 */ 787 788 /* Peripheral Control functions ************************************************/ 789 /** @addtogroup COMP_Exported_Functions_Group3 790 * @{ 791 */ 792 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp); 793 uint32_t HAL_COMP_GetOutputLevel(const COMP_HandleTypeDef *hcomp); 794 /* Callback in interrupt mode */ 795 void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp); 796 /** 797 * @} 798 */ 799 800 /* Peripheral State functions **************************************************/ 801 /** @addtogroup COMP_Exported_Functions_Group4 802 * @{ 803 */ 804 HAL_COMP_StateTypeDef HAL_COMP_GetState(const COMP_HandleTypeDef *hcomp); 805 uint32_t HAL_COMP_GetError(const COMP_HandleTypeDef *hcomp); 806 /** 807 * @} 808 */ 809 810 /** 811 * @} 812 */ 813 814 /** 815 * @} 816 */ 817 #endif /* COMP1 || COMP2 */ 818 /** 819 * @} 820 */ 821 822 #ifdef __cplusplus 823 } 824 #endif 825 826 #endif /* STM32U0xx_HAL_COMP_H */ 827