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