2 ******************************************************************************
3 * @file stm32h7xx_hal_comp.h
4 * @author MCD Application Team
5 * @brief Header file of COMP HAL module.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32H7xx_HAL_COMP_H
22 #define STM32H7xx_HAL_COMP_H
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx_hal_def.h"
31 /** @addtogroup STM32H7xx_HAL_Driver
39 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup COMP_Exported_Types COMP Exported Types
45 * @brief COMP Init structure definition
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 */
55 uint32_t Mode
; /*!< Set comparator operating mode to adjust power and speed.
56 Note: For the characteritics 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 */
60 uint32_t NonInvertingInput
; /*!< Set comparator input plus (non-inverting input).
61 This parameter can be a value of @ref COMP_InputPlus */
63 uint32_t InvertingInput
; /*!< Set comparator input minus (inverting input).
64 This parameter can be a value of @ref COMP_InputMinus */
66 uint32_t Hysteresis
; /*!< Set comparator hysteresis mode of the input minus.
67 This parameter can be a value of @ref COMP_Hysteresis */
69 uint32_t OutputPol
; /*!< Set comparator output polarity.
70 This parameter can be a value of @ref COMP_OutputPolarity */
72 uint32_t BlankingSrce
; /*!< Set comparator blanking source.
73 This parameter can be a value of @ref COMP_BlankingSrce */
75 uint32_t TriggerMode
; /*!< Set the comparator output triggering External Interrupt Line (EXTI).
76 This parameter can be a value of @ref COMP_EXTI_TriggerMode */
81 * @brief HAL COMP state machine: HAL COMP states definition
83 #define COMP_STATE_BITFIELD_LOCK ((uint32_t)0x10)
86 HAL_COMP_STATE_RESET
= 0x00, /*!< COMP not yet initialized */
87 HAL_COMP_STATE_RESET_LOCKED
= (HAL_COMP_STATE_RESET
| COMP_STATE_BITFIELD_LOCK
), /*!< COMP not yet initialized and configuration is locked */
88 HAL_COMP_STATE_READY
= 0x01, /*!< COMP initialized and ready for use */
89 HAL_COMP_STATE_READY_LOCKED
= (HAL_COMP_STATE_READY
| COMP_STATE_BITFIELD_LOCK
), /*!< COMP initialized but configuration is locked */
90 HAL_COMP_STATE_BUSY
= 0x02, /*!< COMP is running */
91 HAL_COMP_STATE_BUSY_LOCKED
= (HAL_COMP_STATE_BUSY
| COMP_STATE_BITFIELD_LOCK
) /*!< COMP is running and configuration is locked */
92 }HAL_COMP_StateTypeDef
;
95 * @brief COMP Handle Structure definition
97 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
98 typedef struct __COMP_HandleTypeDef
101 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
103 COMP_TypeDef
*Instance
; /*!< Register base address */
104 COMP_InitTypeDef Init
; /*!< COMP required parameters */
105 HAL_LockTypeDef Lock
; /*!< Locking object */
106 __IO HAL_COMP_StateTypeDef State
; /*!< COMP communication state */
107 __IO
uint32_t ErrorCode
; /*!< COMP error code */
108 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
109 void (* TriggerCallback
)(struct __COMP_HandleTypeDef
*hcomp
); /*!< COMP trigger callback */
110 void (* MspInitCallback
)(struct __COMP_HandleTypeDef
*hcomp
); /*!< COMP Msp Init callback */
111 void (* MspDeInitCallback
)(struct __COMP_HandleTypeDef
*hcomp
); /*!< COMP Msp DeInit callback */
112 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
114 } COMP_HandleTypeDef
;
116 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
118 * @brief HAL COMP Callback ID enumeration definition
122 HAL_COMP_TRIGGER_CB_ID
= 0x00U
, /*!< COMP trigger callback ID */
123 HAL_COMP_MSPINIT_CB_ID
= 0x01U
, /*!< COMP Msp Init callback ID */
124 HAL_COMP_MSPDEINIT_CB_ID
= 0x02U
/*!< COMP Msp DeInit callback ID */
125 } HAL_COMP_CallbackIDTypeDef
;
128 * @brief HAL COMP Callback pointer definition
130 typedef void (*pCOMP_CallbackTypeDef
)(COMP_HandleTypeDef
*hcomp
); /*!< pointer to a COMP callback function */
132 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
137 /* Exported constants --------------------------------------------------------*/
138 /** @defgroup COMP_Exported_Constants COMP Exported Constants
142 /** @defgroup COMP_Error_Code COMP Error Code
145 #define HAL_COMP_ERROR_NONE (0x00U) /*!< No error */
146 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
147 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01U) /*!< Invalid Callback error */
148 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
153 /** @defgroup COMP_WindowMode COMP Window Mode
156 #define COMP_WINDOWMODE_DISABLE ((uint32_t)0x00000000) /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */
157 #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CFGRx_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). */
163 /** @defgroup COMP_PowerMode COMP power mode
166 /* Note: For the characteritics of comparator power modes */
167 /* (propagation delay and power consumption), */
168 /* refer to device datasheet. */
169 #define COMP_POWERMODE_HIGHSPEED ((uint32_t)0x00000000) /*!< High Speed */
170 #define COMP_POWERMODE_MEDIUMSPEED (COMP_CFGRx_PWRMODE_0) /*!< Medium Speed */
171 #define COMP_POWERMODE_ULTRALOWPOWER (COMP_CFGRx_PWRMODE) /*!< Ultra-low power mode */
176 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
179 #define COMP_INPUT_PLUS_IO1 ((uint32_t)0x00000000) /*!< Comparator input plus connected to IO1 (pin PB0 for COMP1, pin PE9 for COMP2) */
180 #define COMP_INPUT_PLUS_IO2 (COMP_CFGRx_INPSEL) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PE11 for COMP2) */
181 #if defined (COMP_CFGRx_INP2SEL)
182 #define COMP_INPUT_PLUS_DAC2_CH1 (COMP_CFGRx_INP2SEL) /*!< Comparator input plus 2 connected to (DAC2_CH1 for COMP1) */
188 /** @defgroup COMP_InputMinus COMP input minus (inverting input)
191 #define COMP_INPUT_MINUS_1_4VREFINT ( COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */
192 #define COMP_INPUT_MINUS_1_2VREFINT ( COMP_CFGRx_INMSEL_0 | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 1/2 VrefInt */
193 #define COMP_INPUT_MINUS_3_4VREFINT ( COMP_CFGRx_INMSEL_1 | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 3/4 VrefInt */
194 #define COMP_INPUT_MINUS_VREFINT ( COMP_CFGRx_INMSEL_1 | COMP_CFGRx_INMSEL_0 | COMP_CFGRx_SCALEN ) /*!< Comparator input minus connected to VrefInt */
195 #define COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CFGRx_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
196 #define COMP_INPUT_MINUS_DAC1_CH2 ( COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_0 ) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
197 #define COMP_INPUT_MINUS_IO1 ( COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PE10 for COMP2) */
198 #define COMP_INPUT_MINUS_IO2 ( COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_1 | COMP_CFGRx_INMSEL_0 ) /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PE7 for COMP2) */
199 #if defined (COMP_CFGRx_INMSEL_3)
200 #define COMP_INPUT_MINUS_TPSENS_DAC2CH1 (COMP_CFGRx_INMSEL_3 ) /*!< Comparator input minus connected to (temp sensor which is exist in ADC for COMP1, DAC2_CH1 for COMP2) */
201 #define COMP_INPUT_MINUS_VBAT_VDDAP (COMP_CFGRx_INMSEL_3 | COMP_CFGRx_INMSEL_0 ) /*!< Comparator input minus connected to (VBAT/4 for COMP1, VDDAP for COMP2) */
207 /** @defgroup COMP_Hysteresis COMP hysteresis
210 #define COMP_HYSTERESIS_NONE ((uint32_t)0x00000000) /*!< No hysteresis */
211 #define COMP_HYSTERESIS_LOW (COMP_CFGRx_HYST_0) /*!< Hysteresis level low */
212 #define COMP_HYSTERESIS_MEDIUM (COMP_CFGRx_HYST_1) /*!< Hysteresis level medium */
213 #define COMP_HYSTERESIS_HIGH (COMP_CFGRx_HYST) /*!< Hysteresis level high */
218 /** @defgroup COMP_OutputPolarity COMP Output Polarity
221 #define COMP_OUTPUTPOL_NONINVERTED ((uint32_t)0x00000000) /*!< COMP output level is not inverted (comparator output is high when the input plus is at a higher voltage than the input minus) */
222 #define COMP_OUTPUTPOL_INVERTED (COMP_CFGRx_POLARITY) /*!< COMP output level is inverted (comparator output is low when the input plus is at a higher voltage than the input minus) */
228 /** @defgroup COMP_BlankingSrce COMP Blanking Source
231 /* Any blanking source can be selected for all comparators */
232 #define COMP_BLANKINGSRC_NONE ((uint32_t)0x00000000) /*!< No blanking source */
233 #define COMP_BLANKINGSRC_TIM1_OC5 (COMP_CFGRx_BLANKING_0) /*!< TIM1 OC5 selected as blanking source for comparator */
234 #define COMP_BLANKINGSRC_TIM2_OC3 (COMP_CFGRx_BLANKING_1) /*!< TIM2 OC3 selected as blanking source for comparator */
235 #define COMP_BLANKINGSRC_TIM3_OC3 (COMP_CFGRx_BLANKING_0 |COMP_CFGRx_BLANKING_1) /*!< TIM3 OC3 selected as blanking source for compartor */
236 #define COMP_BLANKINGSRC_TIM3_OC4 (COMP_CFGRx_BLANKING_2) /*!< TIM3 OC4 selected as blanking source for comparator */
237 #define COMP_BLANKINGSRC_TIM8_OC5 (COMP_CFGRx_BLANKING_2|COMP_CFGRx_BLANKING_0) /*!< TIM8 OC5 selected as blanking source for comparator */
238 #define COMP_BLANKINGSRC_TIM15_OC1 (COMP_CFGRx_BLANKING_2|COMP_CFGRx_BLANKING_1) /*!< TIM15 OC1 selected as blanking source for comparator */
246 /** @defgroup COMP_OutputLevel COMP Output Level
250 /* Note: Comparator output level values are fixed to "0" and "1", */
251 /* corresponding COMP register bit is managed by HAL function to match */
252 /* with these values (independently of bit position in register). */
254 /* When output polarity is not inverted, comparator output is low when
255 the input plus is at a lower voltage than the input minus */
256 #define COMP_OUTPUT_LEVEL_LOW ((uint32_t)0x00000000)
257 /* When output polarity is not inverted, comparator output is high when
258 the input plus is at a higher voltage than the input minus */
259 #define COMP_OUTPUT_LEVEL_HIGH ((uint32_t)0x00000001)
265 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
268 #define COMP_TRIGGERMODE_NONE ((uint32_t)0x00000000) /*!< Comparator output triggering no External Interrupt Line */
269 #define COMP_TRIGGERMODE_IT_RISING (COMP_EXTI_IT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
270 #define COMP_TRIGGERMODE_IT_FALLING (COMP_EXTI_IT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
271 #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 */
272 #define COMP_TRIGGERMODE_EVENT_RISING (COMP_EXTI_EVENT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
273 #define COMP_TRIGGERMODE_EVENT_FALLING (COMP_EXTI_EVENT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
274 #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 */
280 /** @defgroup COMP_Flag COMP Flag
283 #define COMP_FLAG_C1I COMP_SR_C1IF /*!< Comparator 1 Interrupt Flag */
284 #define COMP_FLAG_C2I COMP_SR_C2IF /*!< Comparator 2 Interrupt Flag */
285 #define COMP_FLAG_LOCK COMP_CFGRx_LOCK /*!< Lock flag */
289 /** @defgroup COMP_IT_CLEAR_Flags COMP Interruption Clear Flags
292 #define COMP_CLEAR_C1IF COMP_ICFR_C1IF /*!< Clear Comparator 1 Interrupt Flag */
293 #define COMP_CLEAR_C2IF COMP_ICFR_C2IF /*!< Clear Comparator 2 Interrupt Flag */
297 /** @defgroup COMP_Interrupts_Definitions COMP Interrupts Definitions
300 #define COMP_IT_EN COMP_CFGRx_ITEN
311 /* Exported macros -----------------------------------------------------------*/
312 /** @defgroup COMP_Exported_Macros COMP Exported Macros
315 /** @defgroup COMP_Handle_Management COMP Handle Management
319 /** @brief Reset COMP handle state.
320 * @param __HANDLE__ COMP handle
323 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
324 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \
325 (__HANDLE__)->State = HAL_COMP_STATE_RESET; \
326 (__HANDLE__)->MspInitCallback = NULL; \
327 (__HANDLE__)->MspDeInitCallback = NULL; \
330 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
334 * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
335 * @param __HANDLE__ COMP handle
338 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
341 * @brief Enable the specified comparator.
342 * @param __HANDLE__ COMP handle
345 #define __HAL_COMP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CFGR, COMP_CFGRx_EN)
348 * @brief Disable the specified comparator.
349 * @param __HANDLE__ COMP handle
352 #define __HAL_COMP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CFGR, COMP_CFGRx_EN)
355 * @brief Lock the specified comparator configuration.
356 * @note Using this macro induce HAL COMP handle state machine being no
357 * more in line with COMP instance state.
358 * To keep HAL COMP handle state machine updated, it is recommended
359 * to use function "HAL_COMP_Lock')".
360 * @param __HANDLE__ COMP handle
363 #define __HAL_COMP_LOCK(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CFGR, COMP_CFGRx_LOCK)
366 * @brief Check whether the specified comparator is locked.
367 * @param __HANDLE__ COMP handle
368 * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
370 #define __HAL_COMP_IS_LOCKED(__HANDLE__) (READ_BIT((__HANDLE__)->Instance->CFGR, COMP_CFGRx_LOCK) == COMP_CFGRx_LOCK)
376 /** @defgroup COMP_Exti_Management COMP external interrupt line management
381 * @brief Enable the COMP1 EXTI line rising edge trigger.
384 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, COMP_EXTI_LINE_COMP1)
388 * @brief Disable the COMP1 EXTI line rising edge trigger.
391 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, COMP_EXTI_LINE_COMP1)
394 * @brief Enable the COMP1 EXTI line falling edge trigger.
397 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, COMP_EXTI_LINE_COMP1)
400 * @brief Disable the COMP1 EXTI line falling edge trigger.
403 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, COMP_EXTI_LINE_COMP1)
407 * @brief Enable the COMP1 EXTI line rising & falling edge trigger.
410 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
411 __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \
412 __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \
417 * @brief Disable the COMP1 EXTI line rising & falling edge trigger.
420 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
421 __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \
422 __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \
427 * @brief Enable the COMP1 EXTI line in interrupt mode.
430 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() SET_BIT(EXTI_D1->IMR1, COMP_EXTI_LINE_COMP1)
433 * @brief Disable the COMP1 EXTI line in interrupt mode.
436 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() CLEAR_BIT(EXTI_D1->IMR1, COMP_EXTI_LINE_COMP1)
439 * @brief Enable the COMP1 EXTI Line in event mode.
442 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() SET_BIT(EXTI_D1->EMR1, COMP_EXTI_LINE_COMP1)
445 * @brief Disable the COMP1 EXTI Line in event mode.
448 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI_D1->EMR1, COMP_EXTI_LINE_COMP1)
451 * @brief Check whether the COMP1 EXTI line flag is set or not.
452 * @retval RESET or SET
454 #define __HAL_COMP_COMP1_EXTI_GET_FLAG() READ_BIT(EXTI_D1->PR1, COMP_EXTI_LINE_COMP1)
456 * @brief Clear the COMP1 EXTI flag.
459 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() WRITE_REG(EXTI_D1->PR1, COMP_EXTI_LINE_COMP1)
462 * @brief Generate a software interrupt on the COMP1 EXTI line.
465 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, COMP_EXTI_LINE_COMP1)
468 * @brief Enable the COMP1 D3 EXTI Line in event mode.
471 #define __HAL_COMP_COMP1_EXTID3_ENABLE_EVENT() SET_BIT(EXTI->D3PMR1, COMP_EXTI_LINE_COMP1)
474 * @brief Disable the COMP1 D3 EXTI Line in event mode.
477 #define __HAL_COMP_COMP1_EXTID3_DISABLE_EVENT() CLEAR_BIT(EXTI->D3PMR1, COMP_EXTI_LINE_COMP1)
479 #if defined(DUAL_CORE)
481 * @brief Enable the COMP1 D2 EXTI line in interrupt mode.
484 #define __HAL_COMP_COMP1_EXTID2_ENABLE_IT() SET_BIT(EXTI_D2->IMR1, COMP_EXTI_LINE_COMP1)
487 * @brief Disable the COMP1 D2 EXTI line in interrupt mode.
490 #define __HAL_COMP_COMP1_EXTID2_DISABLE_IT() CLEAR_BIT(EXTI_D2->IMR1, COMP_EXTI_LINE_COMP1)
493 * @brief Enable the COMP1 D2 EXTI Line in event mode.
496 #define __HAL_COMP_COMP1_EXTID2_ENABLE_EVENT() SET_BIT(EXTI_D2->EMR1, COMP_EXTI_LINE_COMP1)
499 * @brief Disable the COMP1 D2 EXTI Line in event mode.
502 #define __HAL_COMP_COMP1_EXTID2_DISABLE_EVENT() CLEAR_BIT(EXTI_D2->EMR1, COMP_EXTI_LINE_COMP1)
505 * @brief Check whether the COMP1 D2 EXTI line flag is set or not.
506 * @retval RESET or SET
508 #define __HAL_COMP_COMP1_EXTID2_GET_FLAG() READ_BIT(EXTI_D2->PR1, COMP_EXTI_LINE_COMP1)
511 * @brief Clear the COMP1 D2 EXTI flag.
514 #define __HAL_COMP_COMP1_EXTID2_CLEAR_FLAG() WRITE_REG(EXTI_D2->PR1, COMP_EXTI_LINE_COMP1)
519 * @brief Enable the COMP2 EXTI line rising edge trigger.
522 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, COMP_EXTI_LINE_COMP2)
525 * @brief Disable the COMP2 EXTI line rising edge trigger.
528 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, COMP_EXTI_LINE_COMP2)
531 * @brief Enable the COMP2 EXTI line falling edge trigger.
534 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, COMP_EXTI_LINE_COMP2)
537 * @brief Disable the COMP2 EXTI line falling edge trigger.
540 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, COMP_EXTI_LINE_COMP2)
543 * @brief Enable the COMP2 EXTI line rising & falling edge trigger.
546 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
547 __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \
548 __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \
552 * @brief Disable the COMP2 EXTI line rising & falling edge trigger.
555 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
556 __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \
557 __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \
560 * @brief Enable the COMP2 EXTI line.
563 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() SET_BIT(EXTI_D1->IMR1, COMP_EXTI_LINE_COMP2)
566 * @brief Disable the COMP2 EXTI line.
569 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() CLEAR_BIT(EXTI_D1->IMR1, COMP_EXTI_LINE_COMP2)
572 * @brief Enable the COMP2 EXTI Line in event mode.
575 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() SET_BIT(EXTI_D1->EMR1, COMP_EXTI_LINE_COMP2)
578 * @brief Disable the COMP2 EXTI Line in event mode.
581 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI_D1->EMR1, COMP_EXTI_LINE_COMP2)
584 * @brief Check whether the COMP2 EXTI line flag is set or not.
585 * @retval RESET or SET
587 #define __HAL_COMP_COMP2_EXTI_GET_FLAG() READ_BIT(EXTI_D1->PR1, COMP_EXTI_LINE_COMP2)
590 * @brief Clear the the COMP2 EXTI flag.
593 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() WRITE_REG(EXTI_D1->PR1, COMP_EXTI_LINE_COMP2)
596 * @brief Enable the COMP2 D3 EXTI Line in event mode.
599 #define __HAL_COMP_COMP2_EXTID3_ENABLE_EVENT() SET_BIT(EXTI->D3PMR1, COMP_EXTI_LINE_COMP2)
602 * @brief Disable the COMP2 D3 EXTI Line in event mode.
605 #define __HAL_COMP_COMP2_EXTID3_DISABLE_EVENT() CLEAR_BIT(EXTI->D3PMR1, COMP_EXTI_LINE_COMP2)
608 * @brief Generate a software interrupt on the COMP2 EXTI line.
611 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, COMP_EXTI_LINE_COMP2)
613 #if defined(DUAL_CORE)
615 * @brief Enable the COMP2 D2 EXTI line
618 #define __HAL_COMP_COMP2_EXTID2_ENABLE_IT() SET_BIT(EXTI_D2->IMR1, COMP_EXTI_LINE_COMP2)
622 * @brief Disable the COMP2 D2 EXTI line.
625 #define __HAL_COMP_COMP2_EXTID2_DISABLE_IT() CLEAR_BIT(EXTI_D2->IMR1, COMP_EXTI_LINE_COMP2)
630 * @brief Enable the COMP2 D2 EXTI Line in event mode.
633 #define __HAL_COMP_COMP2_EXTID2_ENABLE_EVENT() SET_BIT(EXTI_D2->EMR1, COMP_EXTI_LINE_COMP2)
638 * @brief Disable the COMP2 D2 EXTI Line in event mode.
641 #define __HAL_COMP_COMP2_EXTID2_DISABLE_EVENT() CLEAR_BIT(EXTI_D2->EMR1, COMP_EXTI_LINE_COMP2)
645 * @brief Check whether the COMP2 D2 EXTI line flag is set or not.
646 * @retval RESET or SET
648 #define __HAL_COMP_COMP2_EXTID2_GET_FLAG() READ_BIT(EXTI_D2->PR1, COMP_EXTI_LINE_COMP2)
651 * @brief Clear the the COMP2 D2 EXTI flag.
654 #define __HAL_COMP_COMP2_EXTID2_CLEAR_FLAG() WRITE_REG(EXTI_D2->PR1, COMP_EXTI_LINE_COMP2)
657 /** @brief Checks if the specified COMP interrupt source is enabled or disabled.
658 * @param __HANDLE__: specifies the COMP Handle.
659 * This parameter can be COMP1 where x: 1 or 2 to select the COMP peripheral.
660 * @param __INTERRUPT__: specifies the COMP interrupt source to check.
661 * This parameter can be one of the following values:
662 * @arg COMP_IT_EN: Comparator interrupt enable
664 * @retval The new state of __IT__ (TRUE or FALSE)
666 #define __HAL_COMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CFGR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
668 /** @brief Checks whether the specified COMP flag is set or not.
669 * @param __FLAG__: specifies the flag to check.
670 * This parameter can be one of the following values:
671 * @arg COMP_FLAG_C1I: Comparator 1 Interrupt Flag
672 * @arg COMP_FLAG_C2I: Comparator 2 Interrupt Flag
673 * @retval The new state of __FLAG__ (TRUE or FALSE)
675 #define __HAL_COMP_GET_FLAG(__FLAG__) ((COMP12->SR & (__FLAG__)) == (__FLAG__))
677 /** @brief Clears the specified COMP pending flag.
678 * @param __FLAG__: specifies the flag to check.
679 * This parameter can be any combination of the following values:
680 * @arg COMP_CLEAR_C1IF : Clear Comparator 1 Interrupt Flag
681 * @arg COMP_CLEAR_C2IF : Clear Comparator 2 Interrupt Flag
684 #define __HAL_COMP_CLEAR_FLAG(__FLAG__) (COMP12->ICFR = (__FLAG__))
686 /** @brief Clear the COMP C1I flag.
689 #define __HAL_COMP_CLEAR_C1IFLAG() __HAL_COMP_CLEAR_FLAG( COMP_CLEAR_C1IF)
691 /** @brief Clear the COMP C2I flag.
694 #define __HAL_COMP_CLEAR_C2IFLAG() __HAL_COMP_CLEAR_FLAG( COMP_CLEAR_C2IF)
696 /** @brief Enable the specified COMP interrupt.
697 * @param __HANDLE__: specifies the COMP Handle.
698 * @param __INTERRUPT__: specifies the COMP interrupt source to enable.
699 * This parameter can be one of the following values:
700 * @arg COMP_CFGRx_ITEN : Comparator interrupt
703 #define __HAL_COMP_ENABLE_IT(__HANDLE__, __INTERRUPT__) ( ((__HANDLE__)->Instance->CFGR) |= (__INTERRUPT__) )
705 /** @brief Disable the specified COMP interrupt.
706 * @param __HANDLE__: specifies the COMP Handle.
707 * @param __INTERRUPT__: specifies the COMP interrupt source to enable.
708 * This parameter can be one of the following values:
709 * @arg COMP_CFGRx_ITEN : Comparator interrupt
712 #define __HAL_COMP_DISABLE_IT(__HANDLE__,__INTERRUPT__) (((__HANDLE__)->Instance->CFGR) &= ~(__INTERRUPT__))
717 /** @brief Enable the specified bit in the Option register.
718 * @param __AF__: specifies the Alternate Function source selection .
719 * This parameter can be one of the following values:
720 * @arg COMP_OR_AFOPA6 : Alternate Function PA6 source selection
721 * @arg COMP_OR_AFOPA8 : Alternate Function PA8 source selection
722 * @arg COMP_OR_AFOPB12 : Alternate Function PB12 source selection
723 * @arg COMP_OR_AFOPE6 : Alternate Function PE6 source selection
724 * @arg COMP_OR_AFOPE15 : Alternate Function PE15 source selection
725 * @arg COMP_OR_AFOPG2 : Alternate Function PG2 source selection
726 * @arg COMP_OR_AFOPG3 : Alternate Function PG3 source selection
727 * @arg COMP_OR_AFOPG4 : Alternate Function PG4 source selection
728 * @arg COMP_OR_AFOPI1 : Alternate Function PI1 source selection
729 * @arg COMP_OR_AFOPI4 : Alternate Function PI4 source selection
730 * @arg COMP_OR_AFOPK2 : Alternate Function PK2 source selection
733 #define __HAL_COMP_ENABLE_OR(__AF__) SET_BIT(COMP12->OR, (__AF__))
735 /** @brief Disable the specified bit in the Option register.
736 * @param __AF__: specifies the Alternate Function source selection .
737 * This parameter can be one of the following values:
738 * @arg COMP_OR_AFOPA6 : Alternate Function PA6 source selection
739 * @arg COMP_OR_AFOPA8 : Alternate Function PA8 source selection
740 * @arg COMP_OR_AFOPB12 : Alternate Function PB12 source selection
741 * @arg COMP_OR_AFOPE6 : Alternate Function PE6 source selection
742 * @arg COMP_OR_AFOPE15 : Alternate Function PE15 source selection
743 * @arg COMP_OR_AFOPG2 : Alternate Function PG2 source selection
744 * @arg COMP_OR_AFOPG3 : Alternate Function PG3 source selection
745 * @arg COMP_OR_AFOPG4 : Alternate Function PG4 source selection
746 * @arg COMP_OR_AFOPI1 : Alternate Function PI1 source selection
747 * @arg COMP_OR_AFOPI4 : Alternate Function PI4 source selection
748 * @arg COMP_OR_AFOPK2 : Alternate Function PK2 source selection
751 #define __HAL_COMP_DISABLE_OR(__AF__) CLEAR_BIT(COMP12->OR, (__AF__))
756 /* Private types -------------------------------------------------------------*/
757 /* Private constants ---------------------------------------------------------*/
758 /** @defgroup COMP_Private_Constants COMP Private Constants
761 /** @defgroup COMP_ExtiLine COMP EXTI Lines
764 #define COMP_EXTI_LINE_COMP1 (EXTI_IMR1_IM20) /*!< EXTI line 20 connected to COMP1 output */
765 #define COMP_EXTI_LINE_COMP2 (EXTI_IMR1_IM21) /*!< EXTI line 21 connected to COMP2 output */
769 /** @defgroup COMP_ExtiLine COMP EXTI Lines
772 #define COMP_EXTI_IT ((uint32_t) 0x01) /*!< EXTI line event with interruption */
773 #define COMP_EXTI_EVENT ((uint32_t) 0x02) /*!< EXTI line event only (without interruption) */
774 #define COMP_EXTI_RISING ((uint32_t) 0x10) /*!< EXTI line event on rising edge */
775 #define COMP_EXTI_FALLING ((uint32_t) 0x20) /*!< EXTI line event on falling edge */
783 /* Private macros ------------------------------------------------------------*/
784 /** @defgroup COMP_Private_Macros COMP Private Macros
787 /** @defgroup COMP_GET_EXTI_LINE COMP Private macros to get EXTI line associated with Comparators
791 * @brief Get the specified EXTI line for a comparator instance.
792 * @param __INSTANCE__: specifies the COMP instance.
793 * @retval value of @ref COMP_ExtiLine
795 #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 : \
796 COMP_EXTI_LINE_COMP2)
800 /** @defgroup COMP_IS_COMP_Definitions COMP private macros to check input parameters
803 #define IS_COMP_WINDOWMODE(__WINDOWMODE__) (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE) || \
804 ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON) )
806 #define IS_COMP_POWERMODE(__POWERMODE__) (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED) || \
807 ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED) || \
808 ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER) )
810 #if defined (COMP_CFGRx_INP2SEL)
811 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
812 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \
813 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_DAC2_CH1))
815 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
816 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2))
820 #if defined (COMP_CFGRx_INMSEL_3)
821 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
822 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
823 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
824 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \
825 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \
826 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) || \
827 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \
828 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) || \
829 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_TPSENS_DAC2CH1) || \
830 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VBAT_VDDAP))
832 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
833 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
834 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
835 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \
836 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \
837 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) || \
838 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \
839 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2))
842 #define IS_COMP_HYSTERESIS(__HYSTERESIS__) (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE) || \
843 ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW) || \
844 ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
845 ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
847 #define IS_COMP_OUTPUTPOL(__POL__) (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
848 ((__POL__) == COMP_OUTPUTPOL_INVERTED))
850 #define IS_COMP_BLANKINGSRCE(__SOURCE__) (((__SOURCE__) == COMP_BLANKINGSRC_NONE) || \
851 ((__SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5) || \
852 ((__SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3) || \
853 ((__SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3) || \
854 ((__SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4) || \
855 ((__SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5) || \
856 ((__SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1))
859 #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \
860 ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \
861 ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \
862 ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \
863 ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \
864 ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \
865 ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
867 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW) || \
868 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
878 /* Exported functions --------------------------------------------------------*/
879 /** @addtogroup COMP_Exported_Functions
883 /** @addtogroup COMP_Exported_Functions_Group1
886 /* Initialization and de-initialization functions **********************************/
887 HAL_StatusTypeDef
HAL_COMP_Init(COMP_HandleTypeDef
*hcomp
);
888 HAL_StatusTypeDef
HAL_COMP_DeInit (COMP_HandleTypeDef
*hcomp
);
889 void HAL_COMP_MspInit(COMP_HandleTypeDef
*hcomp
);
890 void HAL_COMP_MspDeInit(COMP_HandleTypeDef
*hcomp
);
891 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
892 /* Callbacks Register/UnRegister functions ***********************************/
893 HAL_StatusTypeDef
HAL_COMP_RegisterCallback(COMP_HandleTypeDef
*hcomp
, HAL_COMP_CallbackIDTypeDef CallbackID
, pCOMP_CallbackTypeDef pCallback
);
894 HAL_StatusTypeDef
HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef
*hcomp
, HAL_COMP_CallbackIDTypeDef CallbackID
);
895 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
900 /* IO operation functions *****************************************************/
901 /** @addtogroup COMP_Exported_Functions_Group2
904 HAL_StatusTypeDef
HAL_COMP_Start(COMP_HandleTypeDef
*hcomp
);
905 HAL_StatusTypeDef
HAL_COMP_Stop(COMP_HandleTypeDef
*hcomp
);
906 HAL_StatusTypeDef
HAL_COMP_Start_IT(COMP_HandleTypeDef
*hcomp
);
907 HAL_StatusTypeDef
HAL_COMP_Stop_IT(COMP_HandleTypeDef
*hcomp
);
908 void HAL_COMP_IRQHandler(COMP_HandleTypeDef
*hcomp
);
914 /* Peripheral Control functions ************************************************/
915 /** @addtogroup COMP_Exported_Functions_Group3
918 HAL_StatusTypeDef
HAL_COMP_Lock(COMP_HandleTypeDef
*hcomp
);
919 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef
*hcomp
);
920 /* Callback in Interrupt mode */
921 void HAL_COMP_TriggerCallback(COMP_HandleTypeDef
*hcomp
);
926 /* Peripheral State functions **************************************************/
927 /** @addtogroup COMP_Exported_Functions_Group4
930 HAL_COMP_StateTypeDef
HAL_COMP_GetState(COMP_HandleTypeDef
*hcomp
);
931 uint32_t HAL_COMP_GetError(COMP_HandleTypeDef
*hcomp
);
952 #endif /* STM32H7xx_HAL_COMP_H */
954 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/