1 /** 2 ****************************************************************************** 3 * @file stm32l4xx_hal_comp.h 4 * @author MCD Application Team 5 * @brief Header file of COMP HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 10 * 11 * Redistribution and use in source and binary forms, with or without modification, 12 * are permitted provided that the following conditions are met: 13 * 1. Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 ****************************************************************************** 34 */ 35 36 /* Define to prevent recursive inclusion -------------------------------------*/ 37 #ifndef __STM32L4xx_HAL_COMP_H 38 #define __STM32L4xx_HAL_COMP_H 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /* Includes ------------------------------------------------------------------*/ 45 #include "stm32l4xx_hal_def.h" 46 #include "stm32l4xx_ll_exti.h" 47 48 /** @addtogroup STM32L4xx_HAL_Driver 49 * @{ 50 */ 51 #if defined (COMP1) || defined (COMP2) 52 53 /** @addtogroup COMP 54 * @{ 55 */ 56 57 /* Exported types ------------------------------------------------------------*/ 58 /** @defgroup COMP_Exported_Types COMP Exported Types 59 * @{ 60 */ 61 62 /** 63 * @brief COMP Init structure definition 64 */ 65 typedef struct 66 { 67 68 #if defined(COMP2) 69 uint32_t WindowMode; /*!< Set window mode of a pair of comparators instances 70 (2 consecutive instances odd and even COMP<x> and COMP<x+1>). 71 Note: HAL COMP driver allows to set window mode from any COMP instance of the pair of COMP instances composing window mode. 72 This parameter can be a value of @ref COMP_WindowMode */ 73 #endif /* COMP2 */ 74 75 uint32_t Mode; /*!< Set comparator operating mode to adjust power and speed. 76 Note: For the characteristics of comparator power modes 77 (propagation delay and power consumption), refer to device datasheet. 78 This parameter can be a value of @ref COMP_PowerMode */ 79 80 uint32_t NonInvertingInput; /*!< Set comparator input plus (non-inverting input). 81 This parameter can be a value of @ref COMP_InputPlus */ 82 83 uint32_t InvertingInput; /*!< Set comparator input minus (inverting input). 84 This parameter can be a value of @ref COMP_InputMinus */ 85 86 uint32_t Hysteresis; /*!< Set comparator hysteresis mode of the input minus. 87 This parameter can be a value of @ref COMP_Hysteresis */ 88 89 uint32_t OutputPol; /*!< Set comparator output polarity. 90 This parameter can be a value of @ref COMP_OutputPolarity */ 91 92 uint32_t BlankingSrce; /*!< Set comparator blanking source. 93 This parameter can be a value of @ref COMP_BlankingSrce */ 94 95 uint32_t TriggerMode; /*!< Set the comparator output triggering External Interrupt Line (EXTI). 96 This parameter can be a value of @ref COMP_EXTI_TriggerMode */ 97 98 }COMP_InitTypeDef; 99 100 /** 101 * @brief HAL COMP state machine: HAL COMP states definition 102 */ 103 #define COMP_STATE_BITFIELD_LOCK (0x10U) 104 typedef enum 105 { 106 HAL_COMP_STATE_RESET = 0x00U, /*!< COMP not yet initialized */ 107 HAL_COMP_STATE_RESET_LOCKED = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */ 108 HAL_COMP_STATE_READY = 0x01U, /*!< COMP initialized and ready for use */ 109 HAL_COMP_STATE_READY_LOCKED = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked */ 110 HAL_COMP_STATE_BUSY = 0x02U, /*!< COMP is running */ 111 HAL_COMP_STATE_BUSY_LOCKED = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK) /*!< COMP is running and configuration is locked */ 112 }HAL_COMP_StateTypeDef; 113 114 /** 115 * @brief COMP Handle Structure definition 116 */ 117 typedef struct __COMP_HandleTypeDef 118 { 119 COMP_TypeDef *Instance; /*!< Register base address */ 120 COMP_InitTypeDef Init; /*!< COMP required parameters */ 121 HAL_LockTypeDef Lock; /*!< Locking object */ 122 __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */ 123 __IO uint32_t ErrorCode; /*!< COMP error code */ 124 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 125 void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */ 126 void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */ 127 void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */ 128 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 129 } COMP_HandleTypeDef; 130 131 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 132 /** 133 * @brief HAL COMP Callback ID enumeration definition 134 */ 135 typedef enum 136 { 137 HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */ 138 HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */ 139 HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */ 140 } HAL_COMP_CallbackIDTypeDef; 141 142 /** 143 * @brief HAL COMP Callback pointer definition 144 */ 145 typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */ 146 147 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 148 149 /** 150 * @} 151 */ 152 153 /* Exported constants --------------------------------------------------------*/ 154 /** @defgroup COMP_Exported_Constants COMP Exported Constants 155 * @{ 156 */ 157 158 /** @defgroup COMP_Error_Code COMP Error Code 159 * @{ 160 */ 161 #define HAL_COMP_ERROR_NONE (0x00UL) /*!< No error */ 162 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 163 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01UL) /*!< Invalid Callback error */ 164 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 165 /** 166 * @} 167 */ 168 169 #if defined(COMP2) 170 /** @defgroup COMP_WindowMode COMP Window Mode 171 * @{ 172 */ 173 #define COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */ 174 #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE) /*!< 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). */ 175 /** 176 * @} 177 */ 178 #endif 179 180 /** @defgroup COMP_PowerMode COMP power mode 181 * @{ 182 */ 183 /* Note: For the characteristics of comparator power modes */ 184 /* (propagation delay and power consumption), */ 185 /* refer to device datasheet. */ 186 #define COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< High Speed */ 187 #define COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< Medium Speed */ 188 #define COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_PWRMODE) /*!< Ultra-low power mode */ 189 /** 190 * @} 191 */ 192 193 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input) 194 * @{ 195 */ 196 #define COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */ 197 #define COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */ 198 #if defined(COMP_CSR_INPSEL_1) 199 #define COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */ 200 #endif 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_DAC1_CH1 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */ 213 #if defined(DAC_CHANNEL2_SUPPORT) 214 #define COMP_INPUT_MINUS_DAC1_CH2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */ 215 #endif 216 #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) */ 217 #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, pin PB7 for COMP2) */ 218 #if defined(COMP_CSR_INMESEL_1) 219 #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) */ 220 #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) */ 221 #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) */ 222 #endif 223 /** 224 * @} 225 */ 226 227 /** @defgroup COMP_Hysteresis COMP hysteresis 228 * @{ 229 */ 230 #define COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */ 231 #define COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0) /*!< Hysteresis level low */ 232 #define COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 ) /*!< Hysteresis level medium */ 233 #define COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level high */ 234 /** 235 * @} 236 */ 237 238 /** @defgroup COMP_OutputPolarity COMP output Polarity 239 * @{ 240 */ 241 #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) */ 242 #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) */ 243 /** 244 * @} 245 */ 246 247 /** @defgroup COMP_BlankingSrce COMP blanking source 248 * @{ 249 */ 250 #define COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */ 251 #define COMP_BLANKINGSRC_TIM1_OC5_COMP1 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */ 252 #define COMP_BLANKINGSRC_TIM2_OC3_COMP1 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */ 253 #define COMP_BLANKINGSRC_TIM3_OC3_COMP1 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */ 254 #define COMP_BLANKINGSRC_TIM3_OC4_COMP2 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */ 255 #define COMP_BLANKINGSRC_TIM8_OC5_COMP2 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2) */ 256 #define COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP2) */ 257 /** 258 * @} 259 */ 260 261 /** @defgroup COMP_OutputLevel COMP Output Level 262 * @{ 263 */ 264 /* Note: Comparator output level values are fixed to "0" and "1", */ 265 /* corresponding COMP register bit is managed by HAL function to match */ 266 /* with these values (independently of bit position in register). */ 267 268 /* When output polarity is not inverted, comparator output is low when 269 the input plus is at a lower voltage than the input minus */ 270 #define COMP_OUTPUT_LEVEL_LOW (0x00000000UL) 271 /* When output polarity is not inverted, comparator output is high when 272 the input plus is at a higher voltage than the input minus */ 273 #define COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) 274 /** 275 * @} 276 */ 277 278 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI 279 * @{ 280 */ 281 #define COMP_TRIGGERMODE_NONE (0x00000000UL) /*!< Comparator output triggering no External Interrupt Line */ 282 #define COMP_TRIGGERMODE_IT_RISING (COMP_EXTI_IT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */ 283 #define COMP_TRIGGERMODE_IT_FALLING (COMP_EXTI_IT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */ 284 #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 */ 285 #define COMP_TRIGGERMODE_EVENT_RISING (COMP_EXTI_EVENT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */ 286 #define COMP_TRIGGERMODE_EVENT_FALLING (COMP_EXTI_EVENT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */ 287 #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 */ 288 /** 289 * @} 290 */ 291 292 /** 293 * @} 294 */ 295 296 /* Exported macro ------------------------------------------------------------*/ 297 /** @defgroup COMP_Exported_Macros COMP Exported Macros 298 * @{ 299 */ 300 301 /** @defgroup COMP_Handle_Management COMP Handle Management 302 * @{ 303 */ 304 305 /** @brief Reset COMP handle state. 306 * @param __HANDLE__ COMP handle 307 * @retval None 308 */ 309 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 310 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \ 311 (__HANDLE__)->State = HAL_COMP_STATE_RESET; \ 312 (__HANDLE__)->MspInitCallback = NULL; \ 313 (__HANDLE__)->MspDeInitCallback = NULL; \ 314 } while(0) 315 #else 316 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET) 317 #endif 318 319 /** 320 * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE"). 321 * @param __HANDLE__ COMP handle 322 * @retval None 323 */ 324 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE) 325 326 /** 327 * @brief Enable the specified comparator. 328 * @param __HANDLE__ COMP handle 329 * @retval None 330 */ 331 #define __HAL_COMP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN) 332 333 /** 334 * @brief Disable the specified comparator. 335 * @param __HANDLE__ COMP handle 336 * @retval None 337 */ 338 #define __HAL_COMP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN) 339 340 /** 341 * @brief Lock the specified comparator configuration. 342 * @note Using this macro induce HAL COMP handle state machine being no 343 * more in line with COMP instance state. 344 * To keep HAL COMP handle state machine updated, it is recommended 345 * to use function "HAL_COMP_Lock')". 346 * @param __HANDLE__ COMP handle 347 * @retval None 348 */ 349 #define __HAL_COMP_LOCK(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) 350 351 /** 352 * @brief Check whether the specified comparator is locked. 353 * @param __HANDLE__ COMP handle 354 * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked 355 */ 356 #define __HAL_COMP_IS_LOCKED(__HANDLE__) (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK) 357 358 /** 359 * @} 360 */ 361 362 /** @defgroup COMP_Exti_Management COMP external interrupt line management 363 * @{ 364 */ 365 366 /** 367 * @brief Enable the COMP1 EXTI line rising edge trigger. 368 * @retval None 369 */ 370 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1) 371 372 /** 373 * @brief Disable the COMP1 EXTI line rising edge trigger. 374 * @retval None 375 */ 376 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1) 377 378 /** 379 * @brief Enable the COMP1 EXTI line falling edge trigger. 380 * @retval None 381 */ 382 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1) 383 384 /** 385 * @brief Disable the COMP1 EXTI line falling edge trigger. 386 * @retval None 387 */ 388 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1) 389 390 /** 391 * @brief Enable the COMP1 EXTI line rising & falling edge trigger. 392 * @retval None 393 */ 394 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 395 LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 396 LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 397 } while(0) 398 399 /** 400 * @brief Disable the COMP1 EXTI line rising & falling edge trigger. 401 * @retval None 402 */ 403 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 404 LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 405 LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \ 406 } while(0) 407 408 /** 409 * @brief Enable the COMP1 EXTI line in interrupt mode. 410 * @retval None 411 */ 412 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP1) 413 414 /** 415 * @brief Disable the COMP1 EXTI line in interrupt mode. 416 * @retval None 417 */ 418 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1) 419 420 /** 421 * @brief Generate a software interrupt on the COMP1 EXTI line. 422 * @retval None 423 */ 424 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1) 425 426 /** 427 * @brief Enable the COMP1 EXTI line in event mode. 428 * @retval None 429 */ 430 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1) 431 432 /** 433 * @brief Disable the COMP1 EXTI line in event mode. 434 * @retval None 435 */ 436 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1) 437 438 /** 439 * @brief Check whether the COMP1 EXTI line flag is set. 440 * @retval RESET or SET 441 */ 442 #define __HAL_COMP_COMP1_EXTI_GET_FLAG() LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP1) 443 444 /** 445 * @brief Clear the COMP1 EXTI flag. 446 * @retval None 447 */ 448 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP1) 449 450 #if defined(COMP2) 451 /** 452 * @brief Enable the COMP2 EXTI line rising edge trigger. 453 * @retval None 454 */ 455 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2) 456 457 /** 458 * @brief Disable the COMP2 EXTI line rising edge trigger. 459 * @retval None 460 */ 461 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2) 462 463 /** 464 * @brief Enable the COMP2 EXTI line falling edge trigger. 465 * @retval None 466 */ 467 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2) 468 469 /** 470 * @brief Disable the COMP2 EXTI line falling edge trigger. 471 * @retval None 472 */ 473 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2) 474 475 /** 476 * @brief Enable the COMP2 EXTI line rising & falling edge trigger. 477 * @retval None 478 */ 479 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \ 480 LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 481 LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 482 } while(0) 483 484 /** 485 * @brief Disable the COMP2 EXTI line rising & falling edge trigger. 486 * @retval None 487 */ 488 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \ 489 LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 490 LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \ 491 } while(0) 492 493 /** 494 * @brief Enable the COMP2 EXTI line in interrupt mode. 495 * @retval None 496 */ 497 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2) 498 499 /** 500 * @brief Disable the COMP2 EXTI line in interrupt mode. 501 * @retval None 502 */ 503 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2) 504 505 /** 506 * @brief Generate a software interrupt on the COMP2 EXTI line. 507 * @retval None 508 */ 509 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2) 510 511 /** 512 * @brief Enable the COMP2 EXTI line in event mode. 513 * @retval None 514 */ 515 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2) 516 517 /** 518 * @brief Disable the COMP2 EXTI line in event mode. 519 * @retval None 520 */ 521 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2) 522 523 /** 524 * @brief Check whether the COMP2 EXTI line flag is set. 525 * @retval RESET or SET 526 */ 527 #define __HAL_COMP_COMP2_EXTI_GET_FLAG() LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP2) 528 529 /** 530 * @brief Clear the COMP2 EXTI flag. 531 * @retval None 532 */ 533 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP2) 534 535 #endif /* COMP2 */ 536 /** 537 * @} 538 */ 539 540 /** 541 * @} 542 */ 543 544 545 /* Private types -------------------------------------------------------------*/ 546 /* Private constants ---------------------------------------------------------*/ 547 /** @defgroup COMP_Private_Constants COMP Private Constants 548 * @{ 549 */ 550 551 /** @defgroup COMP_ExtiLine COMP EXTI Lines 552 * @{ 553 */ 554 #define COMP_EXTI_LINE_COMP1 (LL_EXTI_LINE_21) /*!< EXTI line 21 connected to COMP1 output */ 555 #if defined(COMP2) 556 #define COMP_EXTI_LINE_COMP2 (LL_EXTI_LINE_22) /*!< EXTI line 22 connected to COMP2 output */ 557 #endif /* COMP2 */ 558 /** 559 * @} 560 */ 561 562 /** @defgroup COMP_ExtiLine COMP EXTI Lines 563 * @{ 564 */ 565 #define COMP_EXTI_IT (0x00000001UL) /*!< EXTI line event with interruption */ 566 #define COMP_EXTI_EVENT (0x00000002UL) /*!< EXTI line event only (without interruption) */ 567 #define COMP_EXTI_RISING (0x00000010UL) /*!< EXTI line event on rising edge */ 568 #define COMP_EXTI_FALLING (0x00000020UL) /*!< EXTI line event on falling edge */ 569 /** 570 * @} 571 */ 572 573 /** 574 * @} 575 */ 576 577 /* Private macros ------------------------------------------------------------*/ 578 /** @defgroup COMP_Private_Macros COMP Private Macros 579 * @{ 580 */ 581 582 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators 583 * @{ 584 */ 585 /** 586 * @brief Get the specified EXTI line for a comparator instance. 587 * @param __INSTANCE__ specifies the COMP instance. 588 * @retval value of @ref COMP_ExtiLine 589 */ 590 #if defined(COMP2) 591 #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 \ 592 : COMP_EXTI_LINE_COMP2) 593 #else 594 #define COMP_GET_EXTI_LINE(__INSTANCE__) COMP_EXTI_LINE_COMP1 595 #endif /* COMP2 */ 596 /** 597 * @} 598 */ 599 600 /** @defgroup COMP_IS_COMP_Definitions COMP private macros to check input parameters 601 * @{ 602 */ 603 #if defined(COMP2) 604 #define IS_COMP_WINDOWMODE(__WINDOWMODE__) (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE) || \ 605 ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON) ) 606 #endif 607 608 #define IS_COMP_POWERMODE(__POWERMODE__) (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED) || \ 609 ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED) || \ 610 ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER) ) 611 612 #if defined(COMP_CSR_INPSEL_1) 613 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \ 614 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \ 615 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3)) 616 #else 617 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \ 618 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2)) 619 #endif 620 621 /* Note: On this STM32 serie, comparator input minus parameters are */ 622 /* the same on all COMP instances. */ 623 /* However, comparator instance kept as macro parameter for */ 624 /* compatibility with other STM32 families. */ 625 #if defined(COMP_CSR_INMESEL_1) && defined(DAC_CHANNEL2_SUPPORT) 626 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \ 627 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \ 628 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \ 629 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \ 630 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \ 631 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) || \ 632 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \ 633 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) || \ 634 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3) || \ 635 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO4) || \ 636 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO5)) 637 #elif defined(COMP_CSR_INMESEL_1) 638 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \ 639 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \ 640 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \ 641 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \ 642 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \ 643 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \ 644 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) || \ 645 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3) || \ 646 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO4) || \ 647 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO5)) 648 #elif defined(DAC_CHANNEL2_SUPPORT) 649 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \ 650 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \ 651 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \ 652 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \ 653 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \ 654 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) || \ 655 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \ 656 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)) 657 #else 658 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \ 659 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \ 660 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \ 661 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \ 662 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \ 663 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \ 664 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)) 665 #endif 666 667 #define IS_COMP_HYSTERESIS(__HYSTERESIS__) (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE) || \ 668 ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW) || \ 669 ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \ 670 ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH)) 671 672 #define IS_COMP_OUTPUTPOL(__POL__) (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \ 673 ((__POL__) == COMP_OUTPUTPOL_INVERTED)) 674 675 #if defined(COMP2) 676 #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__) \ 677 ( ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) \ 678 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) \ 679 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) \ 680 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1) \ 681 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2) \ 682 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2) \ 683 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2) \ 684 ) 685 #else 686 #if defined(TIM3) 687 #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__) \ 688 ( ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) \ 689 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) \ 690 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) \ 691 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1) \ 692 ) 693 #else 694 #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__) \ 695 ( ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) \ 696 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) \ 697 || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) \ 698 ) 699 #endif /* TIM3 */ 700 #endif /* COMP2 */ 701 702 #if defined(COMP2) 703 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \ 704 ((((__INSTANCE__) == COMP1) && \ 705 (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \ 706 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \ 707 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) || \ 708 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1))) \ 709 || \ 710 (((__INSTANCE__) == COMP2) && \ 711 (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \ 712 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2) || \ 713 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2) || \ 714 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2)))) 715 #else 716 #if defined(TIM3) 717 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \ 718 (((__INSTANCE__) == COMP1) && \ 719 (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \ 720 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \ 721 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) || \ 722 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1))) 723 #else 724 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \ 725 (((__INSTANCE__) == COMP1) && \ 726 (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \ 727 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \ 728 ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) )) 729 #endif /* TIM3 */ 730 #endif /* COMP2 */ 731 732 #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \ 733 ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \ 734 ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \ 735 ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \ 736 ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \ 737 ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \ 738 ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING)) 739 740 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW) || \ 741 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH)) 742 743 /** 744 * @} 745 */ 746 747 /** 748 * @} 749 */ 750 751 752 /* Exported functions --------------------------------------------------------*/ 753 /** @addtogroup COMP_Exported_Functions 754 * @{ 755 */ 756 757 /** @addtogroup COMP_Exported_Functions_Group1 758 * @{ 759 */ 760 761 /* Initialization and de-initialization functions **********************************/ 762 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp); 763 HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp); 764 void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp); 765 void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp); 766 767 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1) 768 /* Callbacks Register/UnRegister functions ***********************************/ 769 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback); 770 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID); 771 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */ 772 /** 773 * @} 774 */ 775 776 /* IO operation functions *****************************************************/ 777 /** @addtogroup COMP_Exported_Functions_Group2 778 * @{ 779 */ 780 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp); 781 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp); 782 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp); 783 /** 784 * @} 785 */ 786 787 /* Peripheral Control functions ************************************************/ 788 /** @addtogroup COMP_Exported_Functions_Group3 789 * @{ 790 */ 791 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp); 792 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp); 793 /* Callback in interrupt mode */ 794 void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp); 795 /** 796 * @} 797 */ 798 799 /* Peripheral State functions **************************************************/ 800 /** @addtogroup COMP_Exported_Functions_Group4 801 * @{ 802 */ 803 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp); 804 uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp); 805 /** 806 * @} 807 */ 808 809 /** 810 * @} 811 */ 812 813 /** 814 * @} 815 */ 816 #endif /* COMP1 || COMP2 */ 817 /** 818 * @} 819 */ 820 821 #ifdef __cplusplus 822 } 823 #endif 824 825 #endif /* __STM32L4xx_HAL_COMP_H */ 826 827 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 828