1 /** 2 ****************************************************************************** 3 * @file stm32l1xx_hal_comp.h 4 * @author MCD Application Team 5 * @brief Header file of COMP HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2017 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef __STM32L1xx_HAL_COMP_H 21 #define __STM32L1xx_HAL_COMP_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32l1xx_hal_def.h" 29 30 /** @addtogroup STM32L1xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @addtogroup COMP 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 /** @defgroup COMP_Exported_Types COMP Exported Types 40 * @{ 41 */ 42 43 /** 44 * @brief COMP Init structure definition 45 */ 46 typedef struct 47 { 48 49 uint32_t InvertingInput; /*!< Selects the inverting input of the comparator. 50 This parameter can be a value of @ref COMP_InvertingInput 51 Note: Inverting input can be changed on the fly, while comparator is running. 52 Note: This feature is available on COMP2 only. If COMP1 is selected, this parameter is discarded (On COMP1, inverting input is fixed to Vrefint). */ 53 54 uint32_t NonInvertingInput; /*!< Selects the non inverting input of the comparator. 55 This parameter can be a value of @ref COMPEx_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 Note: This feature is available on COMP2 only. If COMP1 is selected, this parameter is discarded. */ 60 61 uint32_t Mode; /*!< Selects the operating consumption mode of the comparator 62 to adjust the speed/consumption. 63 This parameter can be a value of @ref COMP_Mode 64 Note: This feature is available on COMP2 only. If COMP1 is selected, this parameter is discarded. */ 65 66 uint32_t WindowMode; /*!< Selects the window mode of the 2 comparators. 67 If enabled, non-inverting inputs of the 2 comparators are connected together and are using inputs of COMP2 only (COMP1 non-inverting input is no more accessible, even from ADC channel VCOMP). 68 This parameter can be a value of @ref COMP_WindowMode 69 Note: This feature must be enabled from COMP2 instance. If COMP1 is selected, this parameter is discarded. */ 70 71 uint32_t TriggerMode; /*!< Selects the trigger mode of the comparator when using interruption on EXTI line (interrupt mode). 72 This parameter can be a value of @ref COMP_TriggerMode 73 Note: This feature is used with function "HAL_COMP_Start_IT()". In all other functions, this parameter is discarded. */ 74 75 uint32_t NonInvertingInputPull; /*!< Selects the internal pulling resistor connected on non inverting input. 76 This parameter can be a value of @ref COMP_NonInvertingInputPull 77 Note: To avoid extra power consumption, only one resistor should be enabled at a time. 78 Note: This feature is available on COMP1 only. If COMP2 is selected, this parameter is discarded. */ 79 80 }COMP_InitTypeDef; 81 82 /** 83 * @brief HAL State structures definition 84 */ 85 typedef enum 86 { 87 HAL_COMP_STATE_RESET = 0x00, /*!< COMP not yet initialized or disabled */ 88 HAL_COMP_STATE_READY = 0x01, /*!< COMP initialized and ready for use */ 89 HAL_COMP_STATE_READY_LOCKED = 0x11, /*!< COMP initialized but the configuration is locked */ 90 HAL_COMP_STATE_BUSY = 0x02, /*!< COMP is running */ 91 HAL_COMP_STATE_BUSY_LOCKED = 0x12 /*!< COMP is running and the configuration is locked */ 92 }HAL_COMP_StateTypeDef; 93 94 /** 95 * @brief COMP Handle Structure definition 96 */ 97 typedef struct __COMP_HandleTypeDef 98 { 99 COMP_TypeDef *Instance; /*!< Register base address */ 100 COMP_InitTypeDef Init; /*!< COMP required parameters */ 101 HAL_LockTypeDef Lock; /*!< Locking object */ 102 __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */ 103 __IO uint32_t ErrorCode; /*!< COMP Error code */ 104 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 105 void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */ 106 void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */ 107 void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */ 108 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 109 } COMP_HandleTypeDef; 110 111 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 112 /** 113 * @brief HAL COMP Callback ID enumeration definition 114 */ 115 typedef enum 116 { 117 HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */ 118 HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */ 119 HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */ 120 } HAL_COMP_CallbackIDTypeDef; 121 122 /** 123 * @brief HAL COMP Callback pointer definition 124 */ 125 typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */ 126 127 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 128 129 /** 130 * @} 131 */ 132 133 /* Exported constants --------------------------------------------------------*/ 134 /** @defgroup COMP_Exported_Constants COMP Exported Constants 135 * @{ 136 */ 137 138 /** @defgroup COMP_Error_Code COMP Error Code 139 * @{ 140 */ 141 #define HAL_COMP_ERROR_NONE (0x00U) /*!< No error */ 142 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 143 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01U) /*!< Invalid Callback error */ 144 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 145 /** 146 * @} 147 */ 148 149 /** @defgroup COMP_Output COMP Output 150 * @{ 151 */ 152 #define COMP_OUTPUT_TIM2IC4 (0x00000000U) /*!< COMP2 output connected to TIM2 Input Capture 4 */ 153 #define COMP_OUTPUT_TIM2OCREFCLR ( COMP_CSR_OUTSEL_0) /*!< COMP2 output connected to TIM2 OCREF Clear */ 154 #define COMP_OUTPUT_TIM3IC4 ( COMP_CSR_OUTSEL_1 ) /*!< COMP2 output connected to TIM3 Input Capture 4 */ 155 #define COMP_OUTPUT_TIM3OCREFCLR ( COMP_CSR_OUTSEL_1 | COMP_CSR_OUTSEL_0) /*!< COMP2 output connected to TIM3 OCREF Clear */ 156 #define COMP_OUTPUT_TIM4IC4 (COMP_CSR_OUTSEL_2 ) /*!< COMP2 output connected to TIM4 Input Capture 4 */ 157 #define COMP_OUTPUT_TIM4OCREFCLR (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_0) /*!< COMP2 output connected to TIM4 OCREF Clear */ 158 #define COMP_OUTPUT_TIM10IC1 (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_1 ) /*!< COMP2 output connected to TIM10 Input Capture 1 */ 159 #define COMP_OUTPUT_NONE (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_1 | COMP_CSR_OUTSEL_0) /*!< COMP2 output is not connected to other peripherals */ 160 161 #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_OUTPUT_TIM2IC4) || \ 162 ((OUTPUT) == COMP_OUTPUT_TIM2OCREFCLR) || \ 163 ((OUTPUT) == COMP_OUTPUT_TIM3IC4) || \ 164 ((OUTPUT) == COMP_OUTPUT_TIM3OCREFCLR) || \ 165 ((OUTPUT) == COMP_OUTPUT_TIM4IC4) || \ 166 ((OUTPUT) == COMP_OUTPUT_TIM4OCREFCLR) || \ 167 ((OUTPUT) == COMP_OUTPUT_TIM10IC1) || \ 168 ((OUTPUT) == COMP_OUTPUT_NONE) ) 169 /** 170 * @} 171 */ 172 173 /** @defgroup COMP_InvertingInput COMP InvertingInput 174 * @{ 175 */ 176 /* Inverting Input specific to COMP2 */ 177 #define COMP_INVERTINGINPUT_IO ( COMP_CSR_INSEL_0) /*!< External I/O (COMP2_INM connected to pin PB3) connected to comparator 2 inverting input */ 178 #define COMP_INVERTINGINPUT_VREFINT ( COMP_CSR_INSEL_1 ) /*!< VREFINT connected to comparator 2 inverting input */ 179 #define COMP_INVERTINGINPUT_3_4VREFINT ( COMP_CSR_INSEL_1 | COMP_CSR_INSEL_0) /*!< 3/4 VREFINT connected to comparator 2 inverting input */ 180 #define COMP_INVERTINGINPUT_1_2VREFINT (COMP_CSR_INSEL_2 ) /*!< 1/2 VREFINT connected to comparator 2 inverting input */ 181 #define COMP_INVERTINGINPUT_1_4VREFINT (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_0) /*!< 1/4 VREFINT connected to comparator 2 inverting input */ 182 #define COMP_INVERTINGINPUT_DAC1 (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_1 ) /*!< DAC_OUT1 (PA4) connected to comparator 2 inverting input */ 183 #define COMP_INVERTINGINPUT_DAC2 (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_1 | COMP_CSR_INSEL_0) /*!< DAC2_OUT (PA5) connected to comparator 2 inverting input */ 184 185 #define IS_COMP_INVERTINGINPUT(INPUT) (((INPUT) == COMP_INVERTINGINPUT_IO) || \ 186 ((INPUT) == COMP_INVERTINGINPUT_VREFINT) || \ 187 ((INPUT) == COMP_INVERTINGINPUT_3_4VREFINT) || \ 188 ((INPUT) == COMP_INVERTINGINPUT_1_2VREFINT) || \ 189 ((INPUT) == COMP_INVERTINGINPUT_1_4VREFINT) || \ 190 ((INPUT) == COMP_INVERTINGINPUT_DAC1) || \ 191 ((INPUT) == COMP_INVERTINGINPUT_DAC2) ) 192 /** 193 * @} 194 */ 195 196 /** @defgroup COMP_Mode COMP Mode 197 * @{ 198 */ 199 /* Please refer to the electrical characteristics in the device datasheet for 200 the power consumption values */ 201 #define COMP_MODE_LOWSPEED (0x00000000U) /*!< Low Speed */ 202 #define COMP_MODE_HIGHSPEED COMP_CSR_SPEED /*!< High Speed */ 203 204 #define IS_COMP_MODE(SPEED) (((SPEED) == COMP_MODE_LOWSPEED) || \ 205 ((SPEED) == COMP_MODE_HIGHSPEED)) 206 /** 207 * @} 208 */ 209 210 /** @defgroup COMP_WindowMode COMP WindowMode 211 * @{ 212 */ 213 #define COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disabled: COMP1 non-inverting input is independent */ 214 #define COMP_WINDOWMODE_ENABLE COMP_CSR_WNDWE /*!< Window mode enabled: COMP1 non-inverting input is no more accessible, even from ADC channel VCOMP) (connected to COMP2 non-inverting input) */ 215 216 #define IS_COMP_WINDOWMODE(WINDOWMODE) (((WINDOWMODE) == COMP_WINDOWMODE_DISABLE) || \ 217 ((WINDOWMODE) == COMP_WINDOWMODE_ENABLE)) 218 /** 219 * @} 220 */ 221 222 /** @defgroup COMP_OutputLevel COMP OutputLevel 223 * @{ 224 */ 225 /* Comparator output is low when the non-inverting input is at a lower */ 226 /* voltage than the inverting input. */ 227 #define COMP_OUTPUTLEVEL_LOW (0x00000000U) 228 229 /* Comparator output is high when the non-inverting input is at a higher */ 230 /* voltage than the inverting input. */ 231 #define COMP_OUTPUTLEVEL_HIGH (0x00000001U) 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 244 #define IS_COMP_TRIGGERMODE(MODE) (((MODE) == COMP_TRIGGERMODE_NONE) || \ 245 ((MODE) == COMP_TRIGGERMODE_IT_RISING) || \ 246 ((MODE) == COMP_TRIGGERMODE_IT_FALLING) || \ 247 ((MODE) == COMP_TRIGGERMODE_IT_RISING_FALLING) ) 248 /** 249 * @} 250 */ 251 252 /** @defgroup COMP_ExtiLineEvent COMP ExtiLineEvent 253 * @{ 254 */ 255 #define COMP_EXTI_LINE_COMP1 EXTI_RTSR_TR21 /*!< External interrupt line 21 Connected to COMP1 */ 256 #define COMP_EXTI_LINE_COMP2 EXTI_RTSR_TR22 /*!< External interrupt line 22 Connected to COMP2 */ 257 258 /** 259 * @} 260 */ 261 262 /** @defgroup COMP_NonInvertingInputPull COMP NonInvertingInputPull 263 * @{ 264 */ 265 #define COMP_NONINVERTINGINPUT_NOPULL (0x00000000U) /*!< No internal pull-up or pull-down resistor connected to comparator non inverting input */ 266 #define COMP_NONINVERTINGINPUT_10KPU COMP_CSR_10KPU /*!< Internal 10kOhm pull-up resistor connected to comparator non inverting input */ 267 #define COMP_NONINVERTINGINPUT_10KPD COMP_CSR_10KPD /*!< Internal 10kOhm pull-down resistor connected to comparator non inverting input */ 268 #define COMP_NONINVERTINGINPUT_400KPU COMP_CSR_400KPU /*!< Internal 400kOhm pull-up resistor connected to comparator non inverting input */ 269 #define COMP_NONINVERTINGINPUT_400KPD COMP_CSR_400KPD /*!< Internal 400kOhm pull-down resistor connected to comparator non inverting input */ 270 271 #define IS_COMP_NONINVERTINGINPUTPULL(INPUT) (((INPUT) == COMP_NONINVERTINGINPUT_NOPULL) || \ 272 ((INPUT) == COMP_NONINVERTINGINPUT_10KPU) || \ 273 ((INPUT) == COMP_NONINVERTINGINPUT_10KPD) || \ 274 ((INPUT) == COMP_NONINVERTINGINPUT_400KPU) || \ 275 ((INPUT) == COMP_NONINVERTINGINPUT_400KPD) ) 276 /** 277 * @} 278 */ 279 280 /** 281 * @} 282 */ 283 284 285 /* Exported macro ------------------------------------------------------------*/ 286 287 /** @defgroup COMP_Exported_Macro COMP Exported Macro 288 * @{ 289 */ 290 291 /** @defgroup COMP_Handle_Management COMP Handle Management 292 * @{ 293 */ 294 295 /** @brief Reset COMP handle state 296 * @param __HANDLE__ COMP handle. 297 * @retval None 298 */ 299 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 300 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \ 301 (__HANDLE__)->State = HAL_COMP_STATE_RESET; \ 302 (__HANDLE__)->MspInitCallback = NULL; \ 303 (__HANDLE__)->MspDeInitCallback = NULL; \ 304 } while(0) 305 #else 306 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET) 307 #endif 308 309 /** 310 * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE"). 311 * @param __HANDLE__ COMP handle 312 * @retval None 313 */ 314 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE) 315 316 /** 317 * @brief Enables the specified comparator 318 * @param __HANDLE__ COMP handle. 319 * @retval None. 320 */ 321 #define __HAL_COMP_ENABLE(__HANDLE__) \ 322 ( ( ((__HANDLE__)->Instance == COMP1) \ 323 )? \ 324 SET_BIT(COMP->CSR, COMP_CSR_CMP1EN) \ 325 : \ 326 MODIFY_REG(COMP->CSR, COMP_CSR_INSEL, (__HANDLE__)->Init.InvertingInput ) \ 327 ) 328 329 /** 330 * @brief Disables the specified comparator 331 * @param __HANDLE__ COMP handle. 332 * @retval None. 333 */ 334 #define __HAL_COMP_DISABLE(__HANDLE__) \ 335 ( ( ((__HANDLE__)->Instance == COMP1) \ 336 )? \ 337 CLEAR_BIT(COMP->CSR, COMP_CSR_CMP1EN) \ 338 : \ 339 CLEAR_BIT(COMP->CSR, COMP_CSR_INSEL) \ 340 ) 341 342 /** @brief Checks whether the specified COMP flag is set or not. 343 * @param __HANDLE__ specifies the COMP Handle. 344 * @param __FLAG__ specifies the flag to check. 345 * This parameter can be one of the following values: 346 * @arg COMP_FLAG_LOCK: lock flag 347 * @retval The new state of __FLAG__ (TRUE or FALSE). 348 */ 349 #define __HAL_COMP_GET_FLAG(__HANDLE__, __FLAG__) (READ_BIT((__HANDLE__)->Instance->CSR, (__FLAG__)) == (__FLAG__)) 350 351 /** 352 * @brief Enable the COMP1 EXTI line rising edge trigger. 353 * @retval None 354 */ 355 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1) 356 357 /** 358 * @brief Disable the COMP1 EXTI line rising edge trigger. 359 * @retval None 360 */ 361 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1) 362 363 /** 364 * @brief Enable the COMP1 EXTI line falling edge trigger. 365 * @retval None 366 */ 367 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1) 368 369 /** 370 * @brief Disable the COMP1 EXTI line falling edge trigger. 371 * @retval None 372 */ 373 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1) 374 375 /** 376 * @brief Enable the COMP1 EXTI line rising & falling edge trigger. 377 * @retval None 378 */ 379 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 380 __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \ 381 __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \ 382 } while(0) 383 384 /** 385 * @brief Disable the COMP1 EXTI line rising & falling edge trigger. 386 * @retval None 387 */ 388 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 389 __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \ 390 __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \ 391 } while(0) 392 393 /** 394 * @brief Enable the COMP1 EXTI line in interrupt mode. 395 * @retval None 396 */ 397 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1) 398 399 /** 400 * @brief Disable the COMP1 EXTI line in interrupt mode. 401 * @retval None 402 */ 403 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1) 404 405 /** 406 * @brief Enable the COMP1 EXTI Line in event mode. 407 * @retval None 408 */ 409 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1) 410 411 /** 412 * @brief Disable the COMP1 EXTI Line in event mode. 413 * @retval None 414 */ 415 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1) 416 417 /** 418 * @brief Check whether the COMP1 EXTI line flag is set or not. 419 * @retval RESET or SET 420 */ 421 #define __HAL_COMP_COMP1_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP1) 422 423 /** 424 * @brief Clear the the COMP1 EXTI flag. 425 * @retval None 426 */ 427 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP1) 428 429 /** 430 * @brief Generates a Software interrupt on COMP1 EXTI Line. 431 * @retval None 432 */ 433 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP1) 434 435 /** 436 * @brief Enable the COMP2 EXTI line rising edge trigger. 437 * @retval None 438 */ 439 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2) 440 441 /** 442 * @brief Disable the COMP2 EXTI line rising edge trigger. 443 * @retval None 444 */ 445 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2) 446 447 /** 448 * @brief Enable the COMP2 EXTI line falling edge trigger. 449 * @retval None 450 */ 451 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2) 452 453 /** 454 * @brief Disable the COMP2 EXTI line falling edge trigger. 455 * @retval None 456 */ 457 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2) 458 459 /** 460 * @brief Enable the COMP2 EXTI line rising & falling edge trigger. 461 * @retval None 462 */ 463 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 464 __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \ 465 __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \ 466 } while(0) 467 468 /** 469 * @brief Disable the COMP2 EXTI line rising & falling edge trigger. 470 * @retval None 471 */ 472 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 473 __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \ 474 __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \ 475 } while(0) 476 477 /** 478 * @brief Enable the COMP2 EXTI line. 479 * @retval None 480 */ 481 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2) 482 483 /** 484 * @brief Disable the COMP2 EXTI line. 485 * @retval None 486 */ 487 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2) 488 489 /** 490 * @brief Enable the COMP2 EXTI Line in event mode. 491 * @retval None 492 */ 493 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2) 494 495 /** 496 * @brief Disable the COMP2 EXTI Line in event mode. 497 * @retval None 498 */ 499 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2) 500 501 /** 502 * @brief Check whether the COMP2 EXTI line flag is set or not. 503 * @retval RESET or SET 504 */ 505 #define __HAL_COMP_COMP2_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP2) 506 507 /** 508 * @brief Clear the the COMP2 EXTI flag. 509 * @retval None 510 */ 511 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP2) 512 513 /** 514 * @brief Generates a Software interrupt on COMP1 EXTI Line. 515 * @retval None 516 */ 517 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP2) 518 519 /** 520 * @} 521 */ 522 523 /* Private macro -------------------------------------------------------------*/ 524 525 /** @defgroup COMP_Private_Macro COMP Private Macro 526 * @{ 527 */ 528 529 /** 530 * @brief Get the specified EXTI line for a comparator instance 531 * @param __INSTANCE__ specifies the COMP instance. 532 * @retval value of @ref COMP_ExtiLineEvent 533 */ 534 #define COMP_GET_EXTI_LINE(__INSTANCE__) \ 535 ( ( ((__INSTANCE__) == COMP1) \ 536 )? \ 537 (COMP_EXTI_LINE_COMP1) \ 538 : \ 539 (COMP_EXTI_LINE_COMP2) \ 540 ) 541 542 /** 543 * @brief Select the COMP register CSR bit CMPxOUT corresponding to the 544 * selected COMP instance. 545 * @param __HANDLE__: COMP handle 546 * @retval Comparator register CSR bit COMP_CSR_CMP1OUT or COMP_CSR_CMP2OUT 547 */ 548 #define __COMP_CSR_CMPXOUT(__HANDLE__) \ 549 ( ( ((__HANDLE__)->Instance == COMP1) \ 550 )? \ 551 (COMP_CSR_CMP1OUT) \ 552 : \ 553 (COMP_CSR_CMP2OUT) \ 554 ) 555 556 /** 557 * @brief Verification of COMP state: enabled or disabled 558 * @param __HANDLE__: COMP handle 559 * @retval SET (COMP enabled) or RESET (COMP disabled) 560 */ 561 #define __COMP_IS_ENABLED(__HANDLE__) \ 562 ( ( ((__HANDLE__)->Instance == COMP1) \ 563 )? \ 564 (((READ_BIT(COMP->CSR , COMP_CSR_CMP1EN) == COMP_CSR_CMP1EN) \ 565 ) ? SET : RESET) \ 566 : \ 567 (((READ_BIT(COMP->CSR , COMP_CSR_INSEL) != RESET) \ 568 ) ? SET : RESET) \ 569 ) 570 571 /** 572 * @} 573 */ 574 575 576 /* Include COMP HAL Extension module */ 577 #include "stm32l1xx_hal_comp_ex.h" 578 579 /* Exported functions --------------------------------------------------------*/ 580 /** @addtogroup COMP_Exported_Functions 581 * @{ 582 */ 583 584 /* Initialization and de-initialization functions ******************************/ 585 /** @addtogroup COMP_Exported_Functions_Group1 586 * @{ 587 */ 588 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp); 589 HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp); 590 void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp); 591 void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp); 592 593 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 594 /* Callbacks Register/UnRegister functions ***********************************/ 595 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback); 596 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID); 597 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 598 599 /** 600 * @} 601 */ 602 603 /* I/O operation functions *****************************************************/ 604 /** @addtogroup COMP_Exported_Functions_Group2 605 * @{ 606 */ 607 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp); 608 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp); 609 HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp); 610 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp); 611 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp); 612 /** 613 * @} 614 */ 615 616 /* Peripheral Control functions ************************************************/ 617 /** @addtogroup COMP_Exported_Functions_Group3 618 * @{ 619 */ 620 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp); 621 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp); 622 623 /* Callback in Interrupt mode */ 624 void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp); 625 /** 626 * @} 627 */ 628 629 /* Peripheral State functions **************************************************/ 630 /** @addtogroup COMP_Exported_Functions_Group4 631 * @{ 632 */ 633 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp); 634 uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp); 635 /** 636 * @} 637 */ 638 639 /** 640 * @} 641 */ 642 643 /** 644 * @} 645 */ 646 647 /** 648 * @} 649 */ 650 651 #ifdef __cplusplus 652 } 653 #endif 654 655 #endif /* __STM32L1xx_HAL_COMP_H */ 656 657