1 /** 2 ****************************************************************************** 3 * @file stm32l0xx_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 __STM32L0xx_HAL_COMP_H 21 #define __STM32L0xx_HAL_COMP_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #if !defined (STM32L010xB) && !defined (STM32L010x8) && !defined (STM32L010x6) && !defined (STM32L010x4) 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32l0xx_hal_def.h" 30 31 /** @addtogroup STM32L0xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup COMP 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /** @defgroup COMP_Exported_Types COMP Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief COMP Init structure definition 46 */ 47 typedef struct 48 { 49 50 uint32_t WindowMode; /*!< Set window mode of a pair of comparators instances 51 (2 consecutive instances odd and even COMP<x> and COMP<x+1>). 52 Note: HAL COMP driver allows to set window mode from any COMP instance of the pair of COMP instances composing window mode. 53 This parameter can be a value of @ref COMP_WindowMode */ 54 55 uint32_t Mode; /*!< Set comparator operating mode to adjust power and speed. 56 Note: For the characteristics of comparator power modes 57 (propagation delay and power consumption), refer to device datasheet. 58 This parameter can be a value of @ref COMP_PowerMode */ 59 60 uint32_t NonInvertingInput; /*!< Set comparator input plus (non-inverting input). 61 This parameter can be a value of @ref COMP_InputPlus */ 62 63 uint32_t InvertingInput; /*!< Set comparator input minus (inverting input). 64 This parameter can be a value of @ref COMP_InputMinus */ 65 66 uint32_t OutputPol; /*!< Set comparator output polarity. 67 This parameter can be a value of @ref COMP_OutputPolarity */ 68 69 uint32_t LPTIMConnection; /*!< Set comparator output connection to LPTIM peripheral. 70 This parameter can be a value of @ref COMP_LPTIMConnection */ 71 72 uint32_t TriggerMode; /*!< Set the comparator output triggering External Interrupt Line (EXTI). 73 This parameter can be a value of @ref COMP_EXTI_TriggerMode */ 74 75 }COMP_InitTypeDef; 76 77 /** 78 * @brief HAL COMP state machine: HAL COMP states definition 79 */ 80 #define COMP_STATE_BITFIELD_LOCK (0x10U) 81 typedef enum 82 { 83 HAL_COMP_STATE_RESET = 0x00U, /*!< COMP not yet initialized */ 84 HAL_COMP_STATE_RESET_LOCKED = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */ 85 HAL_COMP_STATE_READY = 0x01U, /*!< COMP initialized and ready for use */ 86 HAL_COMP_STATE_READY_LOCKED = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked */ 87 HAL_COMP_STATE_BUSY = 0x02U, /*!< COMP is running */ 88 HAL_COMP_STATE_BUSY_LOCKED = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK) /*!< COMP is running and configuration is locked */ 89 }HAL_COMP_StateTypeDef; 90 91 /** 92 * @brief COMP Handle Structure definition 93 */ 94 typedef struct __COMP_HandleTypeDef 95 { 96 COMP_TypeDef *Instance; /*!< Register base address */ 97 COMP_InitTypeDef Init; /*!< COMP required parameters */ 98 HAL_LockTypeDef Lock; /*!< Locking object */ 99 __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */ 100 __IO uint32_t ErrorCode; /*!< COMP Error code */ 101 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 102 void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */ 103 void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */ 104 void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */ 105 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 106 } COMP_HandleTypeDef; 107 108 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 109 /** 110 * @brief HAL COMP Callback ID enumeration definition 111 */ 112 typedef enum 113 { 114 HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */ 115 HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */ 116 HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */ 117 } HAL_COMP_CallbackIDTypeDef; 118 119 /** 120 * @brief HAL COMP Callback pointer definition 121 */ 122 typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */ 123 124 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 125 126 /** 127 * @} 128 */ 129 130 /* Exported constants --------------------------------------------------------*/ 131 /** @defgroup COMP_Exported_Constants COMP Exported Constants 132 * @{ 133 */ 134 135 /** @defgroup COMP_Error_Code COMP Error Code 136 * @{ 137 */ 138 #define HAL_COMP_ERROR_NONE (0x00U) /*!< No error */ 139 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 140 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01U) /*!< Invalid Callback error */ 141 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 142 /** 143 * @} 144 */ 145 146 /** @defgroup COMP_WindowMode COMP Window Mode 147 * @{ 148 */ 149 #define COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */ 150 #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_COMP1WM) /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP1 input plus (COMP2 input plus is no more accessible). */ 151 /** 152 * @} 153 */ 154 155 /** @defgroup COMP_PowerMode COMP power mode 156 * @{ 157 */ 158 /* Note: For the characteristics of comparator power modes */ 159 /* (propagation delay and power consumption), */ 160 /* refer to device datasheet. */ 161 #define COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_COMP2SPEED) /*!< COMP power mode to low power (indicated as "high speed" in reference manual) (only for COMP instance: COMP2) */ 162 #define COMP_POWERMODE_ULTRALOWPOWER (0x00000000U) /*!< COMP power mode to ultra low power (indicated as "low speed" in reference manual) (only for COMP instance: COMP2) */ 163 /** 164 * @} 165 */ 166 167 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input) 168 * @{ 169 */ 170 #define COMP_INPUT_PLUS_IO1 (0x00000000U) /*!< Comparator input plus connected to IO1 (pin PA1 for COMP1, pin PA3 for COMP2) */ 171 #define COMP_INPUT_PLUS_IO2 (COMP_CSR_COMP2INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB4 for COMP2) (only for COMP instance: COMP2) */ 172 #define COMP_INPUT_PLUS_IO3 (COMP_CSR_COMP2INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA5 for COMP2) (only for COMP instance: COMP2) */ 173 #define COMP_INPUT_PLUS_IO4 (COMP_CSR_COMP2INPSEL_0 | COMP_CSR_COMP2INPSEL_1) /*!< Comparator input plus connected to IO4 (pin PB6 for COMP2) (only for COMP instance: COMP2) */ 174 #define COMP_INPUT_PLUS_IO5 (COMP_CSR_COMP2INPSEL_2) /*!< Comparator input plus connected to IO5 (pin PB7 for COMP2) (only for COMP instance: COMP2) */ 175 #if defined (STM32L011xx) || defined (STM32L021xx) 176 #define COMP_INPUT_PLUS_IO6 (COMP_CSR_COMP2INPSEL_2 | COMP_CSR_COMP2INPSEL_0) /*!< Comparator input plus connected to IO6 (pin PA7 for COMP2) (only for COMP instance: COMP2) (Available only on devices STM32L0 category 1) */ 177 #endif 178 /** 179 * @} 180 */ 181 182 /** @defgroup COMP_InputMinus COMP input minus (inverting input) 183 * @{ 184 */ 185 #define COMP_INPUT_MINUS_1_4VREFINT (COMP_CSR_COMP2INNSEL_2 ) /*!< Comparator input minus connected to 1/4 VREFINT (only for COMP instance: COMP2) */ 186 #define COMP_INPUT_MINUS_1_2VREFINT (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to 1/2 VREFINT (only for COMP instance: COMP2) */ 187 #define COMP_INPUT_MINUS_3_4VREFINT (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_1 ) /*!< Comparator input minus connected to 3/4 VREFINT (only for COMP instance: COMP2) */ 188 #define COMP_INPUT_MINUS_VREFINT (0x00000000U) /*!< Comparator input minus connected to VrefInt */ 189 #define COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CSR_COMP2INNSEL_1 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */ 190 #define COMP_INPUT_MINUS_DAC1_CH2 ( COMP_CSR_COMP2INNSEL_1 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */ 191 #define COMP_INPUT_MINUS_IO1 ( COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to IO1 (pin PA0 for COMP1, pin PA2 for COMP2) */ 192 #define COMP_INPUT_MINUS_IO2 (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_1 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to IO2 (pin PB3 for COMP2) (only for COMP instance: COMP2) */ 193 /** 194 * @} 195 */ 196 197 198 /** @defgroup COMP_LPTIMConnection COMP Low power timer connection definition 199 * @{ 200 */ 201 202 #define COMP_LPTIMCONNECTION_DISABLED (0x00000000U) /*!< COMPx signal is gated */ 203 #define COMP_LPTIMCONNECTION_IN1_ENABLED (0x00000001U) /*!< COMPx signal is connected to LPTIM input 1 */ 204 #define COMP_LPTIMCONNECTION_IN2_ENABLED (0x00000002U) /*!< COMPx signal is connected to LPTIM input 2 */ 205 /** 206 * @} 207 */ 208 209 /** @defgroup COMP_OutputPolarity COMP output Polarity 210 * @{ 211 */ 212 #define COMP_OUTPUTPOL_NONINVERTED (0x00000000U) /*!< COMP output on GPIO isn't inverted */ 213 #define COMP_OUTPUTPOL_INVERTED COMP_CSR_COMPxPOLARITY /*!< COMP output on GPIO is inverted */ 214 /** 215 * @} 216 */ 217 218 /** @defgroup COMP_OutputLevel COMP Output Level 219 * @{ 220 */ 221 /* Note: Comparator output level values are fixed to "0" and "1", */ 222 /* corresponding COMP register bit is managed by HAL function to match */ 223 /* with these values (independently of bit position in register). */ 224 225 /* When output polarity is not inverted, comparator output is low when 226 the input plus is at a lower voltage than the input minus */ 227 #define COMP_OUTPUT_LEVEL_LOW (0x00000000U) 228 /* When output polarity is not inverted, comparator output is high when 229 the input plus is at a higher voltage than the input minus */ 230 #define COMP_OUTPUT_LEVEL_HIGH (0x00000001U) 231 /** 232 * @} 233 */ 234 235 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI 236 * @{ 237 */ 238 #define COMP_TRIGGERMODE_NONE (0x00000000U) /*!< Comparator output triggering no External Interrupt Line */ 239 #define COMP_TRIGGERMODE_IT_RISING (COMP_EXTI_IT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */ 240 #define COMP_TRIGGERMODE_IT_FALLING (COMP_EXTI_IT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */ 241 #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 */ 242 #define COMP_TRIGGERMODE_EVENT_RISING (COMP_EXTI_EVENT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */ 243 #define COMP_TRIGGERMODE_EVENT_FALLING (COMP_EXTI_EVENT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */ 244 #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 */ 245 /** 246 * @} 247 */ 248 249 /** 250 * @} 251 */ 252 253 /* Exported macro ------------------------------------------------------------*/ 254 /** @defgroup COMP_Exported_Macros COMP Exported Macros 255 * @{ 256 */ 257 258 /** @defgroup COMP_Handle_Management COMP Handle Management 259 * @{ 260 */ 261 262 /** @brief Reset COMP handle state. 263 * @param __HANDLE__ COMP handle 264 * @retval None 265 */ 266 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 267 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \ 268 (__HANDLE__)->State = HAL_COMP_STATE_RESET; \ 269 (__HANDLE__)->MspInitCallback = NULL; \ 270 (__HANDLE__)->MspDeInitCallback = NULL; \ 271 } while(0) 272 #else 273 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET) 274 #endif 275 276 /** 277 * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE"). 278 * @param __HANDLE__ COMP handle 279 * @retval None 280 */ 281 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE) 282 283 /** 284 * @brief Enable the specified comparator. 285 * @param __HANDLE__ COMP handle 286 * @retval None 287 */ 288 #define __HAL_COMP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxEN) 289 290 /** 291 * @brief Disable the specified comparator. 292 * @param __HANDLE__ COMP handle 293 * @retval None 294 */ 295 #define __HAL_COMP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxEN) 296 297 /** 298 * @brief Lock the specified comparator configuration. 299 * @note Using this macro induce HAL COMP handle state machine being no 300 * more in line with COMP instance state. 301 * To keep HAL COMP handle state machine updated, it is recommended 302 * to use function "HAL_COMP_Lock')". 303 * @param __HANDLE__ COMP handle 304 * @retval None 305 */ 306 #define __HAL_COMP_LOCK(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxLOCK) 307 308 /** 309 * @brief Check whether the specified comparator is locked. 310 * @param __HANDLE__ COMP handle 311 * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked 312 */ 313 #define __HAL_COMP_IS_LOCKED(__HANDLE__) (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxLOCK) == COMP_CSR_COMPxLOCK) 314 315 /** 316 * @} 317 */ 318 319 /** @defgroup COMP_Exti_Management COMP external interrupt line management 320 * @{ 321 */ 322 323 /** 324 * @brief Enable the COMP1 EXTI line rising edge trigger. 325 * @retval None 326 */ 327 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1) 328 329 /** 330 * @brief Disable the COMP1 EXTI line rising edge trigger. 331 * @retval None 332 */ 333 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1) 334 335 /** 336 * @brief Enable the COMP1 EXTI line falling edge trigger. 337 * @retval None 338 */ 339 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1) 340 341 /** 342 * @brief Disable the COMP1 EXTI line falling edge trigger. 343 * @retval None 344 */ 345 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1) 346 347 /** 348 * @brief Enable the COMP1 EXTI line rising & falling edge trigger. 349 * @retval None 350 */ 351 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 352 __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \ 353 __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \ 354 } while(0) 355 356 /** 357 * @brief Disable the COMP1 EXTI line rising & falling edge trigger. 358 * @retval None 359 */ 360 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 361 __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \ 362 __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \ 363 } while(0) 364 365 /** 366 * @brief Enable the COMP1 EXTI line in interrupt mode. 367 * @retval None 368 */ 369 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1) 370 371 /** 372 * @brief Disable the COMP1 EXTI line in interrupt mode. 373 * @retval None 374 */ 375 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1) 376 377 /** 378 * @brief Generate a software interrupt on the COMP1 EXTI line. 379 * @retval None 380 */ 381 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP1) 382 383 /** 384 * @brief Enable the COMP1 EXTI line in event mode. 385 * @retval None 386 */ 387 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1) 388 389 /** 390 * @brief Disable the COMP1 EXTI line in event mode. 391 * @retval None 392 */ 393 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1) 394 395 /** 396 * @brief Check whether the COMP1 EXTI line flag is set. 397 * @retval RESET or SET 398 */ 399 #define __HAL_COMP_COMP1_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP1) 400 401 /** 402 * @brief Clear the COMP1 EXTI flag. 403 * @retval None 404 */ 405 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP1) 406 407 /** 408 * @brief Enable the COMP2 EXTI line rising edge trigger. 409 * @retval None 410 */ 411 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2) 412 413 /** 414 * @brief Disable the COMP2 EXTI line rising edge trigger. 415 * @retval None 416 */ 417 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2) 418 419 /** 420 * @brief Enable the COMP2 EXTI line falling edge trigger. 421 * @retval None 422 */ 423 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2) 424 425 /** 426 * @brief Disable the COMP2 EXTI line falling edge trigger. 427 * @retval None 428 */ 429 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2) 430 431 /** 432 * @brief Enable the COMP2 EXTI line rising & falling edge trigger. 433 * @retval None 434 */ 435 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 436 __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \ 437 __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \ 438 } while(0) 439 440 /** 441 * @brief Disable the COMP2 EXTI line rising & falling edge trigger. 442 * @retval None 443 */ 444 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 445 __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \ 446 __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \ 447 } while(0) 448 449 /** 450 * @brief Enable the COMP2 EXTI line in interrupt mode. 451 * @retval None 452 */ 453 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2) 454 455 /** 456 * @brief Disable the COMP2 EXTI line in interrupt mode. 457 * @retval None 458 */ 459 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2) 460 461 /** 462 * @brief Generate a software interrupt on the COMP2 EXTI line. 463 * @retval None 464 */ 465 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP2) 466 467 /** 468 * @brief Enable the COMP2 EXTI line in event mode. 469 * @retval None 470 */ 471 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2) 472 473 /** 474 * @brief Disable the COMP2 EXTI line in event mode. 475 * @retval None 476 */ 477 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2) 478 479 /** 480 * @brief Check whether the COMP2 EXTI line flag is set. 481 * @retval RESET or SET 482 */ 483 #define __HAL_COMP_COMP2_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP2) 484 485 /** 486 * @brief Clear the COMP2 EXTI flag. 487 * @retval None 488 */ 489 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP2) 490 491 /** 492 * @} 493 */ 494 495 /** 496 * @} 497 */ 498 499 500 /* Private types -------------------------------------------------------------*/ 501 /* Private constants ---------------------------------------------------------*/ 502 /** @defgroup COMP_Private_Constants COMP Private Constants 503 * @{ 504 */ 505 /** @defgroup COMP_ExtiLine COMP EXTI Lines 506 * @{ 507 */ 508 #define COMP_EXTI_LINE_COMP1 (EXTI_IMR_IM21) /*!< EXTI line 21 connected to COMP1 output */ 509 #define COMP_EXTI_LINE_COMP2 (EXTI_IMR_IM22) /*!< EXTI line 22 connected to COMP2 output */ 510 /** 511 * @} 512 */ 513 514 /** @defgroup COMP_ExtiLine COMP EXTI Lines 515 * @{ 516 */ 517 #define COMP_EXTI_IT (0x01U) /*!< EXTI line event with interruption */ 518 #define COMP_EXTI_EVENT (0x02U) /*!< EXTI line event only (without interruption) */ 519 #define COMP_EXTI_RISING (0x10U) /*!< EXTI line event on rising edge */ 520 #define COMP_EXTI_FALLING (0x20U) /*!< EXTI line event on falling edge */ 521 /** 522 * @} 523 */ 524 525 /** 526 * @} 527 */ 528 529 /* Private macros ------------------------------------------------------------*/ 530 /** @defgroup COMP_Private_Macros COMP Private Macros 531 * @{ 532 */ 533 534 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators 535 * @{ 536 */ 537 /** 538 * @brief Get the specified EXTI line for a comparator instance. 539 * @param __INSTANCE__ specifies the COMP instance. 540 * @retval value of @ref COMP_ExtiLine 541 */ 542 #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? \ 543 COMP_EXTI_LINE_COMP1 : COMP_EXTI_LINE_COMP2) 544 /** 545 * @} 546 */ 547 548 /** @defgroup COMP_IS_COMP_Definitions COMP private macros to check input parameters 549 * @{ 550 */ 551 #define IS_COMP_WINDOWMODE(__WINDOWMODE__) (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE) || \ 552 ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON) ) 553 554 #define IS_COMP_POWERMODE(__POWERMODE__) (((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED) || \ 555 ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER) ) 556 557 #define IS_COMP_WINDOWMODE_INSTANCE(INSTANCE) ((INSTANCE) == COMP1) 558 559 #if defined (STM32L011xx) || defined (STM32L021xx) 560 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \ 561 (((__COMP_INSTANCE__) == COMP1) \ 562 ? ( \ 563 (__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1 \ 564 ) \ 565 : \ 566 ( \ 567 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) \ 568 || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) \ 569 || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3) \ 570 || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO4) \ 571 || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO5) \ 572 || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO6) \ 573 ) \ 574 ) 575 #else 576 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \ 577 (((__COMP_INSTANCE__) == COMP1) \ 578 ? ( \ 579 (__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1 \ 580 ) \ 581 : \ 582 ( \ 583 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) \ 584 || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) \ 585 || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3) \ 586 || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO4) \ 587 || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO5) \ 588 ) \ 589 ) 590 #endif 591 592 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \ 593 (((__COMP_INSTANCE__) == COMP1) \ 594 ? ( \ 595 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) \ 596 || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) \ 597 || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) \ 598 || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) \ 599 ) \ 600 : \ 601 ( \ 602 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) \ 603 || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) \ 604 || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) \ 605 || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) \ 606 || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) \ 607 || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) \ 608 || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) \ 609 || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) \ 610 ) \ 611 ) 612 613 #define IS_COMP1_LPTIMCONNECTION(LPTIMCONNECTION) (((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_DISABLED) || \ 614 ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN1_ENABLED)) 615 616 #define IS_COMP2_LPTIMCONNECTION(LPTIMCONNECTION) (((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_DISABLED) || \ 617 ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN1_ENABLED) || \ 618 ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN2_ENABLED)) 619 620 #define IS_COMP2_LPTIMCONNECTION_RESTRICTED(LPTIMCONNECTION) (((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_DISABLED) || \ 621 ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN1_ENABLED)) 622 623 #define IS_COMP_OUTPUTPOL(POL) (((POL) == COMP_OUTPUTPOL_NONINVERTED) || \ 624 ((POL) == COMP_OUTPUTPOL_INVERTED)) 625 626 #define IS_COMP_TRIGGERMODE(__TRIGGERMODE__) (((__TRIGGERMODE__) == COMP_TRIGGERMODE_NONE) || \ 627 ((__TRIGGERMODE__) == COMP_TRIGGERMODE_IT_RISING) || \ 628 ((__TRIGGERMODE__) == COMP_TRIGGERMODE_IT_FALLING) || \ 629 ((__TRIGGERMODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \ 630 ((__TRIGGERMODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \ 631 ((__TRIGGERMODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \ 632 ((__TRIGGERMODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING) ) 633 634 635 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW) || \ 636 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH)) 637 638 /** 639 * @} 640 */ 641 642 /** 643 * @} 644 */ 645 646 /* Include COMP HAL Extended module */ 647 #include "stm32l0xx_hal_comp_ex.h" 648 649 /* Exported functions --------------------------------------------------------*/ 650 /** @addtogroup COMP_Exported_Functions 651 * @{ 652 */ 653 654 /** @addtogroup COMP_Exported_Functions_Group1 655 * @{ 656 */ 657 658 /* Initialization and de-initialization functions **********************************/ 659 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp); 660 HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp); 661 void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp); 662 void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp); 663 664 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 665 /* Callbacks Register/UnRegister functions ***********************************/ 666 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback); 667 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID); 668 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 669 670 /** 671 * @} 672 */ 673 674 /* IO operation functions *****************************************************/ 675 /** @addtogroup COMP_Exported_Functions_Group2 676 * @{ 677 */ 678 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp); 679 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp); 680 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp); 681 /** 682 * @} 683 */ 684 685 /* Peripheral Control functions ************************************************/ 686 /** @addtogroup COMP_Exported_Functions_Group3 687 * @{ 688 */ 689 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp); 690 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp); 691 /* Callback in interrupt mode */ 692 void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp); 693 /** 694 * @} 695 */ 696 697 /* Peripheral State functions **************************************************/ 698 /** @addtogroup COMP_Exported_Functions_Group4 699 * @{ 700 */ 701 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp); 702 uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp); 703 /** 704 * @} 705 */ 706 707 /** 708 * @} 709 */ 710 711 /** 712 * @} 713 */ 714 715 /** 716 * @} 717 */ 718 #endif /* !defined (STM32L010xB) && !defined (STM32L010x8) && !defined (STM32L010x6) && !defined (STM32L010x4) */ 719 720 #ifdef __cplusplus 721 } 722 #endif 723 724 #endif /* __STM32L0xx_HAL_COMP_H */ 725 726