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