1 /** 2 ****************************************************************************** 3 * @file stm32f0xx_hal_comp.h 4 * @author MCD Application Team 5 * @brief Header file of COMP HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2016 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 STM32F0xx_HAL_COMP_H 21 #define STM32F0xx_HAL_COMP_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #if defined (COMP1) || defined (COMP2) 28 29 /* Includes ------------------------------------------------------------------*/ 30 #include "stm32f0xx_hal_def.h" 31 32 /** @addtogroup STM32F0xx_HAL_Driver 33 * @{ 34 */ 35 36 /** @addtogroup COMP 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 uint32_t InvertingInput; /*!< Selects the inverting input of the comparator. 52 This parameter can be a value of @ref COMP_InvertingInput */ 53 54 uint32_t NonInvertingInput; /*!< Selects the non inverting input of the comparator. 55 This parameter can be a value of @ref COMP_NonInvertingInput */ 56 57 uint32_t Output; /*!< Selects the output redirection of the comparator. 58 This parameter can be a value of @ref COMP_Output */ 59 60 uint32_t OutputPol; /*!< Selects the output polarity of the comparator. 61 This parameter can be a value of @ref COMP_OutputPolarity */ 62 63 uint32_t Hysteresis; /*!< Selects the hysteresis voltage of the comparator. 64 This parameter can be a value of @ref COMP_Hysteresis */ 65 66 uint32_t Mode; /*!< Selects the operating consumption mode of the comparator 67 to adjust the speed/consumption. 68 This parameter can be a value of @ref COMP_Mode */ 69 70 uint32_t WindowMode; /*!< Selects the window mode of the comparator 1 & 2. 71 This parameter can be a value of @ref COMP_WindowMode */ 72 73 uint32_t TriggerMode; /*!< Selects the trigger mode of the comparator (interrupt mode). 74 This parameter can be a value of @ref COMP_TriggerMode */ 75 76 }COMP_InitTypeDef; 77 78 /** 79 * @brief COMP Handle Structure definition 80 */ 81 typedef struct __COMP_HandleTypeDef 82 { 83 COMP_TypeDef *Instance; /*!< Register base address */ 84 COMP_InitTypeDef Init; /*!< COMP required parameters */ 85 HAL_LockTypeDef Lock; /*!< Locking object */ 86 __IO uint32_t State; /*!< COMP communication state 87 This parameter can be a value of @ref COMP_State */ 88 __IO uint32_t ErrorCode; /*!< COMP Error code */ 89 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 90 void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */ 91 void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */ 92 void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */ 93 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 94 }COMP_HandleTypeDef; 95 96 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 97 /** 98 * @brief HAL COMP Callback ID enumeration definition 99 */ 100 typedef enum 101 { 102 HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */ 103 HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */ 104 HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */ 105 } HAL_COMP_CallbackIDTypeDef; 106 107 /** 108 * @brief HAL COMP Callback pointer definition 109 */ 110 typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */ 111 112 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 113 114 /** 115 * @} 116 */ 117 118 /* Exported constants --------------------------------------------------------*/ 119 /** @defgroup COMP_Exported_Constants COMP Exported Constants 120 * @{ 121 */ 122 123 /** @defgroup COMP_Error_Code COMP Error Code 124 * @{ 125 */ 126 #define HAL_COMP_ERROR_NONE (0x00U) /*!< No error */ 127 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 128 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01U) /*!< Invalid Callback error */ 129 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 130 /** 131 * @} 132 */ 133 134 /** @defgroup COMP_State COMP State 135 * @{ 136 */ 137 #define HAL_COMP_STATE_RESET (0x00000000U) /*!< COMP not yet initialized or disabled */ 138 #define HAL_COMP_STATE_READY (0x00000001U) /*!< COMP initialized and ready for use */ 139 #define HAL_COMP_STATE_READY_LOCKED (0x00000011U) /*!< COMP initialized but the configuration is locked */ 140 #define HAL_COMP_STATE_BUSY (0x00000002U) /*!< COMP is running */ 141 #define HAL_COMP_STATE_BUSY_LOCKED (0x00000012U) /*!< COMP is running and the configuration is locked */ 142 /** 143 * @} 144 */ 145 146 /** @defgroup COMP_OutputPolarity COMP OutputPolarity 147 * @{ 148 */ 149 #define COMP_OUTPUTPOL_NONINVERTED (0x00000000U) /*!< COMP output on GPIO isn't inverted */ 150 #define COMP_OUTPUTPOL_INVERTED COMP_CSR_COMP1POL /*!< COMP output on GPIO is inverted */ 151 /** 152 * @} 153 */ 154 155 /** @defgroup COMP_Hysteresis COMP Hysteresis 156 * @{ 157 */ 158 #define COMP_HYSTERESIS_NONE (0x00000000U) /*!< No hysteresis */ 159 #define COMP_HYSTERESIS_LOW COMP_CSR_COMP1HYST_0 /*!< Hysteresis level low */ 160 #define COMP_HYSTERESIS_MEDIUM COMP_CSR_COMP1HYST_1 /*!< Hysteresis level medium */ 161 #define COMP_HYSTERESIS_HIGH COMP_CSR_COMP1HYST /*!< Hysteresis level high */ 162 /** 163 * @} 164 */ 165 166 /** @defgroup COMP_Mode COMP Mode 167 * @{ 168 */ 169 /* Please refer to the electrical characteristics in the device datasheet for 170 the power consumption values */ 171 #define COMP_MODE_HIGHSPEED (0x00000000U) /*!< High Speed */ 172 #define COMP_MODE_MEDIUMSPEED COMP_CSR_COMP1MODE_0 /*!< Medium Speed */ 173 #define COMP_MODE_LOWPOWER COMP_CSR_COMP1MODE_1 /*!< Low power mode */ 174 #define COMP_MODE_ULTRALOWPOWER COMP_CSR_COMP1MODE /*!< Ultra-low power mode */ 175 /** 176 * @} 177 */ 178 179 /** @defgroup COMP_InvertingInput COMP InvertingInput 180 * @{ 181 */ 182 183 #define COMP_INVERTINGINPUT_1_4VREFINT (0x00000000U) /*!< 1/4 VREFINT connected to comparator inverting input */ 184 #define COMP_INVERTINGINPUT_1_2VREFINT COMP_CSR_COMP1INSEL_0 /*!< 1/2 VREFINT connected to comparator inverting input */ 185 #define COMP_INVERTINGINPUT_3_4VREFINT COMP_CSR_COMP1INSEL_1 /*!< 3/4 VREFINT connected to comparator inverting input */ 186 #define COMP_INVERTINGINPUT_VREFINT (COMP_CSR_COMP1INSEL_1|COMP_CSR_COMP1INSEL_0) /*!< VREFINT connected to comparator inverting input */ 187 #define COMP_INVERTINGINPUT_DAC1 COMP_CSR_COMP1INSEL_2 /*!< DAC_OUT1 (PA4) connected to comparator inverting input */ 188 #define COMP_INVERTINGINPUT_DAC1SWITCHCLOSED (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1SW1) /*!< DAC_OUT1 (PA4) connected to comparator inverting input 189 and close switch (PA0 for COMP1 only) */ 190 #define COMP_INVERTINGINPUT_DAC2 (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1INSEL_0) /*!< DAC_OUT2 (PA5) connected to comparator inverting input */ 191 #define COMP_INVERTINGINPUT_IO1 (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1INSEL_1) /*!< IO (PA0 for COMP1 and PA2 for COMP2) connected to comparator inverting input */ 192 /** 193 * @} 194 */ 195 196 /** @defgroup COMP_NonInvertingInput COMP NonInvertingInput 197 * @{ 198 */ 199 #define COMP_NONINVERTINGINPUT_IO1 (0x00000000U) /*!< I/O1 (PA1 for COMP1, PA3 for COMP2) 200 connected to comparator non inverting input */ 201 #define COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED COMP_CSR_COMP1SW1 /*!< DAC output connected to comparator COMP1 non inverting input */ 202 /** 203 * @} 204 */ 205 206 /** @defgroup COMP_Output COMP Output 207 * @{ 208 */ 209 210 /* Output Redirection common for COMP1 and COMP2 */ 211 #define COMP_OUTPUT_NONE (0x00000000U) /*!< COMP output isn't connected to other peripherals */ 212 #define COMP_OUTPUT_TIM1BKIN COMP_CSR_COMP1OUTSEL_0 /*!< COMP output connected to TIM1 Break Input (BKIN) */ 213 #define COMP_OUTPUT_TIM1IC1 COMP_CSR_COMP1OUTSEL_1 /*!< COMP output connected to TIM1 Input Capture 1 */ 214 #define COMP_OUTPUT_TIM1OCREFCLR (COMP_CSR_COMP1OUTSEL_1|COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM1 OCREF Clear */ 215 #define COMP_OUTPUT_TIM2IC4 COMP_CSR_COMP1OUTSEL_2 /*!< COMP output connected to TIM2 Input Capture 4 */ 216 #define COMP_OUTPUT_TIM2OCREFCLR (COMP_CSR_COMP1OUTSEL_2|COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM2 OCREF Clear */ 217 #define COMP_OUTPUT_TIM3IC1 (COMP_CSR_COMP1OUTSEL_2|COMP_CSR_COMP1OUTSEL_1) /*!< COMP output connected to TIM3 Input Capture 1 */ 218 #define COMP_OUTPUT_TIM3OCREFCLR COMP_CSR_COMP1OUTSEL /*!< COMP output connected to TIM3 OCREF Clear */ 219 /** 220 * @} 221 */ 222 223 /** @defgroup COMP_OutputLevel COMP OutputLevel 224 * @{ 225 */ 226 /* When output polarity is not inverted, comparator output is low when 227 the non-inverting input is at a lower voltage than the inverting input*/ 228 #define COMP_OUTPUTLEVEL_LOW (0x00000000U) 229 /* When output polarity is not inverted, comparator output is high when 230 the non-inverting input is at a higher voltage than the inverting input */ 231 #define COMP_OUTPUTLEVEL_HIGH COMP_CSR_COMP1OUT 232 /** 233 * @} 234 */ 235 236 /** @defgroup COMP_TriggerMode COMP TriggerMode 237 * @{ 238 */ 239 #define COMP_TRIGGERMODE_NONE (0x00000000U) /*!< No External Interrupt trigger detection */ 240 #define COMP_TRIGGERMODE_IT_RISING (0x00000001U) /*!< External Interrupt Mode with Rising edge trigger detection */ 241 #define COMP_TRIGGERMODE_IT_FALLING (0x00000002U) /*!< External Interrupt Mode with Falling edge trigger detection */ 242 #define COMP_TRIGGERMODE_IT_RISING_FALLING (0x00000003U) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ 243 #define COMP_TRIGGERMODE_EVENT_RISING (0x00000010U) /*!< Event Mode with Rising edge trigger detection */ 244 #define COMP_TRIGGERMODE_EVENT_FALLING (0x00000020U) /*!< Event Mode with Falling edge trigger detection */ 245 #define COMP_TRIGGERMODE_EVENT_RISING_FALLING (0x00000030U) /*!< Event Mode with Rising/Falling edge trigger detection */ 246 /** 247 * @} 248 */ 249 250 /** @defgroup COMP_WindowMode COMP WindowMode 251 * @{ 252 */ 253 #define COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disabled */ 254 #define COMP_WINDOWMODE_ENABLE COMP_CSR_WNDWEN /*!< Window mode enabled: non inverting input of comparator 2 255 is connected to the non inverting input of comparator 1 (PA1) */ 256 /** 257 * @} 258 */ 259 260 /** @defgroup COMP_Flag COMP Flag 261 * @{ 262 */ 263 #define COMP_FLAG_LOCK ((uint32_t)COMP_CSR_COMPxLOCK) /*!< Lock flag */ 264 265 /** 266 * @} 267 */ 268 269 /** 270 * @} 271 */ 272 273 /* Exported macros -----------------------------------------------------------*/ 274 /** @defgroup COMP_Exported_Macros COMP Exported Macros 275 * @{ 276 */ 277 278 /** @brief Reset COMP handle state 279 * @param __HANDLE__ COMP handle. 280 * @retval None 281 */ 282 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 283 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \ 284 (__HANDLE__)->State = HAL_COMP_STATE_RESET; \ 285 (__HANDLE__)->MspInitCallback = NULL; \ 286 (__HANDLE__)->MspDeInitCallback = NULL; \ 287 } while(0) 288 #else 289 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET) 290 #endif 291 292 /** 293 * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE"). 294 * @param __HANDLE__ COMP handle 295 * @retval None 296 */ 297 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE) 298 299 /** 300 * @brief Enable the specified comparator. 301 * @param __HANDLE__ COMP handle. 302 * @retval None 303 */ 304 #define __HAL_COMP_ENABLE(__HANDLE__) (((__HANDLE__)->Instance == COMP1) ? \ 305 SET_BIT(COMP->CSR, COMP_CSR_COMP1EN) : \ 306 SET_BIT(COMP->CSR, COMP_CSR_COMP2EN)) 307 308 /** 309 * @brief Disable the specified comparator. 310 * @param __HANDLE__ COMP handle. 311 * @retval None 312 */ 313 #define __HAL_COMP_DISABLE(__HANDLE__) (((__HANDLE__)->Instance == COMP1) ? \ 314 CLEAR_BIT(COMP->CSR, COMP_CSR_COMP1EN) : \ 315 CLEAR_BIT(COMP->CSR, COMP_CSR_COMP2EN)) 316 317 /** 318 * @brief Lock the specified comparator configuration. 319 * @param __HANDLE__ COMP handle. 320 * @retval None 321 */ 322 #define __HAL_COMP_LOCK(__HANDLE__) (((__HANDLE__)->Instance == COMP1) ? \ 323 SET_BIT(COMP->CSR, COMP_CSR_COMP1LOCK) : \ 324 SET_BIT(COMP->CSR, COMP_CSR_COMP2LOCK)) 325 326 /** 327 * @brief Enable the COMP1 EXTI line rising edge trigger. 328 * @retval None 329 */ 330 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1) 331 332 /** 333 * @brief Disable the COMP1 EXTI line rising edge trigger. 334 * @retval None 335 */ 336 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1) 337 338 /** 339 * @brief Enable the COMP1 EXTI line falling edge trigger. 340 * @retval None 341 */ 342 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1) 343 344 /** 345 * @brief Disable the COMP1 EXTI line falling edge trigger. 346 * @retval None 347 */ 348 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1) 349 350 /** 351 * @brief Enable the COMP1 EXTI line rising & falling edge trigger. 352 * @retval None 353 */ 354 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 355 __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \ 356 __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \ 357 } while(0) 358 359 /** 360 * @brief Disable the COMP1 EXTI line rising & falling edge trigger. 361 * @retval None 362 */ 363 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 364 __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \ 365 __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \ 366 } while(0) 367 368 /** 369 * @brief Enable the COMP1 EXTI line in interrupt mode. 370 * @retval None 371 */ 372 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1) 373 374 /** 375 * @brief Disable the COMP1 EXTI line in interrupt mode. 376 * @retval None 377 */ 378 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1) 379 380 /** 381 * @brief Generate a software interrupt on the COMP1 EXTI line. 382 * @retval None 383 */ 384 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP1) 385 386 /** 387 * @brief Enable the COMP1 EXTI Line in event mode. 388 * @retval None 389 */ 390 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1) 391 392 /** 393 * @brief Disable the COMP1 EXTI Line in event mode. 394 * @retval None 395 */ 396 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1) 397 398 /** 399 * @brief Check whether the COMP1 EXTI line flag is set or not. 400 * @retval RESET or SET 401 */ 402 #define __HAL_COMP_COMP1_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP1) 403 404 /** 405 * @brief Clear the COMP1 EXTI flag. 406 * @retval None 407 */ 408 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP1) 409 410 /** 411 * @brief Enable the COMP2 EXTI line rising edge trigger. 412 * @retval None 413 */ 414 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2) 415 416 /** 417 * @brief Disable the COMP2 EXTI line rising edge trigger. 418 * @retval None 419 */ 420 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2) 421 422 /** 423 * @brief Enable the COMP2 EXTI line falling edge trigger. 424 * @retval None 425 */ 426 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2) 427 428 /** 429 * @brief Disable the COMP2 EXTI line falling edge trigger. 430 * @retval None 431 */ 432 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2) 433 434 /** 435 * @brief Enable the COMP2 EXTI line rising & falling edge trigger. 436 * @retval None 437 */ 438 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 439 __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \ 440 __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \ 441 } while(0) 442 443 /** 444 * @brief Disable the COMP2 EXTI line rising & falling edge trigger. 445 * @retval None 446 */ 447 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 448 __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \ 449 __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \ 450 } while(0) 451 452 /** 453 * @brief Enable the COMP2 EXTI line in interrupt mode. 454 * @retval None 455 */ 456 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2) 457 458 /** 459 * @brief Disable the COMP2 EXTI line in interrupt mode. 460 * @retval None 461 */ 462 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2) 463 464 /** 465 * @brief Generate a software interrupt on the COMP2 EXTI line. 466 * @retval None 467 */ 468 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP2) 469 470 /** 471 * @brief Enable the COMP2 EXTI Line in event mode. 472 * @retval None 473 */ 474 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2) 475 476 /** 477 * @brief Disable the COMP2 EXTI Line in event mode. 478 * @retval None 479 */ 480 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2) 481 482 /** 483 * @brief Check whether the COMP2 EXTI line flag is set or not. 484 * @retval RESET or SET 485 */ 486 #define __HAL_COMP_COMP2_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP2) 487 488 /** 489 * @brief Clear the COMP2 EXTI flag. 490 * @retval None 491 */ 492 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP2) 493 494 /** @brief Check whether the specified COMP flag is set or not. 495 * @param __HANDLE__ specifies the COMP Handle. 496 * @param __FLAG__ specifies the flag to check. 497 * This parameter can be one of the following values: 498 * @arg COMP_FLAG_LOCK: lock flag 499 * @retval The new state of __FLAG__ (TRUE or FALSE). 500 */ 501 #define __HAL_COMP_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->CSR & (__FLAG__)) == (__FLAG__)) 502 503 /** 504 * @} 505 */ 506 507 /* Exported functions --------------------------------------------------------*/ 508 /** @addtogroup COMP_Exported_Functions COMP Exported Functions 509 * @{ 510 */ 511 /** @addtogroup COMP_Exported_Functions_Group1 Initialization/de-initialization functions 512 * @brief Initialization and Configuration functions 513 * @{ 514 */ 515 /* Initialization and de-initialization functions ****************************/ 516 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp); 517 HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp); 518 void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp); 519 void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp); 520 521 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 522 /* Callbacks Register/UnRegister functions ***********************************/ 523 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback); 524 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID); 525 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 526 527 /** 528 * @} 529 */ 530 531 /** @addtogroup COMP_Exported_Functions_Group2 I/O operation functions 532 * @brief Data transfers functions 533 * @{ 534 */ 535 /* IO operation functions *****************************************************/ 536 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp); 537 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp); 538 HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp); 539 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp); 540 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp); 541 /** 542 * @} 543 */ 544 545 /** @addtogroup COMP_Exported_Functions_Group3 Peripheral Control functions 546 * @brief management functions 547 * @{ 548 */ 549 /* Peripheral Control functions ***********************************************/ 550 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp); 551 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp); 552 553 /* Callback in Interrupt mode */ 554 void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp); 555 /** 556 * @} 557 */ 558 559 /** @addtogroup COMP_Exported_Functions_Group4 Peripheral State functions 560 * @brief Peripheral State functions 561 * @{ 562 */ 563 /* Peripheral State and Error functions ***************************************/ 564 uint32_t HAL_COMP_GetState(COMP_HandleTypeDef *hcomp); 565 uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp); 566 /** 567 * @} 568 */ 569 570 /** 571 * @} 572 */ 573 574 /* Private types -------------------------------------------------------------*/ 575 /* Private constants ---------------------------------------------------------*/ 576 /** @defgroup COMP_Private_Constants COMP Private Constants 577 * @{ 578 */ 579 /** @defgroup COMP_ExtiLine COMP EXTI Lines 580 * Elements values convention: XXXX0000 581 * - XXXX : Interrupt mask in the EMR/IMR/RTSR/FTSR register 582 * @{ 583 */ 584 #define COMP_EXTI_LINE_COMP1 ((uint32_t)EXTI_IMR_MR21) /*!< EXTI line 21 connected to COMP1 output */ 585 #define COMP_EXTI_LINE_COMP2 ((uint32_t)EXTI_IMR_MR22) /*!< EXTI line 22 connected to COMP2 output */ 586 587 /** 588 * @} 589 */ 590 591 /** 592 * @} 593 */ 594 595 /* Private macros ------------------------------------------------------------*/ 596 /** @defgroup COMP_Private_Macros COMP Private Macros 597 * @{ 598 */ 599 /** @defgroup COMP_GET_EXTI_LINE COMP Private macros to get EXTI line associated with Comparators 600 * @{ 601 */ 602 /** 603 * @brief Get the specified EXTI line for a comparator instance. 604 * @param __INSTANCE__ specifies the COMP instance. 605 * @retval value of @ref COMP_ExtiLine 606 */ 607 #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 : \ 608 COMP_EXTI_LINE_COMP2) 609 /** 610 * @} 611 */ 612 613 /** @defgroup COMP_IS_COMP_Definitions COMP Private macros to check input parameters 614 * @{ 615 */ 616 617 #define IS_COMP_OUTPUTPOL(POL) (((POL) == COMP_OUTPUTPOL_NONINVERTED) || \ 618 ((POL) == COMP_OUTPUTPOL_INVERTED)) 619 620 #define IS_COMP_HYSTERESIS(HYSTERESIS) (((HYSTERESIS) == COMP_HYSTERESIS_NONE) || \ 621 ((HYSTERESIS) == COMP_HYSTERESIS_LOW) || \ 622 ((HYSTERESIS) == COMP_HYSTERESIS_MEDIUM) || \ 623 ((HYSTERESIS) == COMP_HYSTERESIS_HIGH)) 624 625 #define IS_COMP_MODE(MODE) (((MODE) == COMP_MODE_HIGHSPEED) || \ 626 ((MODE) == COMP_MODE_MEDIUMSPEED) || \ 627 ((MODE) == COMP_MODE_LOWPOWER) || \ 628 ((MODE) == COMP_MODE_ULTRALOWPOWER)) 629 630 #define IS_COMP_INVERTINGINPUT(INPUT) (((INPUT) == COMP_INVERTINGINPUT_1_4VREFINT) || \ 631 ((INPUT) == COMP_INVERTINGINPUT_1_2VREFINT) || \ 632 ((INPUT) == COMP_INVERTINGINPUT_3_4VREFINT) || \ 633 ((INPUT) == COMP_INVERTINGINPUT_VREFINT) || \ 634 ((INPUT) == COMP_INVERTINGINPUT_DAC1) || \ 635 ((INPUT) == COMP_INVERTINGINPUT_DAC1SWITCHCLOSED) || \ 636 ((INPUT) == COMP_INVERTINGINPUT_DAC2) || \ 637 ((INPUT) == COMP_INVERTINGINPUT_IO1)) 638 639 #define IS_COMP_NONINVERTINGINPUT(INPUT) (((INPUT) == COMP_NONINVERTINGINPUT_IO1) || \ 640 ((INPUT) == COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED)) 641 642 #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_OUTPUT_NONE) || \ 643 ((OUTPUT) == COMP_OUTPUT_TIM1BKIN) || \ 644 ((OUTPUT) == COMP_OUTPUT_TIM1IC1) || \ 645 ((OUTPUT) == COMP_OUTPUT_TIM1OCREFCLR) || \ 646 ((OUTPUT) == COMP_OUTPUT_TIM2IC4) || \ 647 ((OUTPUT) == COMP_OUTPUT_TIM2OCREFCLR) || \ 648 ((OUTPUT) == COMP_OUTPUT_TIM3IC1) || \ 649 ((OUTPUT) == COMP_OUTPUT_TIM3OCREFCLR)) 650 651 #define IS_COMP_WINDOWMODE(WINDOWMODE) (((WINDOWMODE) == COMP_WINDOWMODE_DISABLE) || \ 652 ((WINDOWMODE) == COMP_WINDOWMODE_ENABLE)) 653 654 #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \ 655 ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \ 656 ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \ 657 ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \ 658 ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \ 659 ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \ 660 ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING)) 661 /** 662 * @} 663 */ 664 665 /** @defgroup COMP_Lock COMP Lock 666 * @{ 667 */ 668 #define COMP_LOCK_DISABLE (0x00000000U) 669 #define COMP_LOCK_ENABLE COMP_CSR_COMP1LOCK 670 671 #define COMP_STATE_BIT_LOCK (0x10U) 672 /** 673 * @} 674 */ 675 676 /** 677 * @} 678 */ 679 680 /* Private functions ---------------------------------------------------------*/ 681 682 /** 683 * @} 684 */ 685 686 /** 687 * @} 688 */ 689 690 #endif /* COMP1 || COMP2 */ 691 692 #ifdef __cplusplus 693 } 694 #endif 695 696 #endif /* STM32F0xx_HAL_COMP_H */ 697 698 699