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