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