1 /**
2   ******************************************************************************
3   * @file    stm32g4xx_hal_comp.h
4   * @author  MCD Application Team
5   * @brief   Header file of COMP HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2019 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 STM32G4xx_HAL_COMP_H
21 #define STM32G4xx_HAL_COMP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g4xx_hal_def.h"
29 #include "stm32g4xx_ll_exti.h"
30 
31 /** @addtogroup STM32G4xx_HAL_Driver
32   * @{
33   */
34 
35 
36 /** @addtogroup COMP
37   * @{
38   */
39 
40 /* Exported types ------------------------------------------------------------*/
41 /** @defgroup COMP_Exported_Types COMP Exported Types
42   * @{
43   */
44 
45 /**
46   * @brief  COMP Init structure definition
47   */
48 typedef struct
49 {
50 
51   uint32_t InputPlus;          /*!< Set comparator input plus (non-inverting input).
52                                     This parameter can be a value of @ref COMP_InputPlus */
53 
54   uint32_t InputMinus;         /*!< Set comparator input minus (inverting input).
55                                     This parameter can be a value of @ref COMP_InputMinus */
56 
57   uint32_t Hysteresis;         /*!< Set comparator hysteresis mode of the input minus.
58                                     This parameter can be a value of @ref COMP_Hysteresis */
59 
60   uint32_t OutputPol;          /*!< Set comparator output polarity.
61                                     This parameter can be a value of @ref COMP_OutputPolarity */
62 
63   uint32_t BlankingSrce;       /*!< Set comparator blanking source.
64                                     This parameter can be a value of @ref COMP_BlankingSrce */
65 
66   uint32_t TriggerMode;        /*!< Set the comparator output triggering External Interrupt Line (EXTI).
67                                     This parameter can be a value of @ref COMP_EXTI_TriggerMode */
68 
69 } COMP_InitTypeDef;
70 
71 /**
72   * @brief  HAL COMP state machine: HAL COMP states definition
73   */
74 #define COMP_STATE_BITFIELD_LOCK  (0x10U)
75 typedef enum
76 {
77   HAL_COMP_STATE_RESET             = 0x00U,                                             /*!< COMP not yet initialized                             */
78   HAL_COMP_STATE_RESET_LOCKED      = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */
79   HAL_COMP_STATE_READY             = 0x01U,                                             /*!< COMP initialized and ready for use                   */
80   HAL_COMP_STATE_READY_LOCKED      = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked         */
81   HAL_COMP_STATE_BUSY              = 0x02U,                                             /*!< COMP is running                                      */
82   HAL_COMP_STATE_BUSY_LOCKED       = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK)   /*!< COMP is running and configuration is locked          */
83 } HAL_COMP_StateTypeDef;
84 
85 /**
86   * @brief  COMP Handle Structure definition
87   */
88 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
89 typedef struct __COMP_HandleTypeDef
90 #else
91 typedef struct
92 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
93 {
94   COMP_TypeDef       *Instance;       /*!< Register base address    */
95   COMP_InitTypeDef   Init;            /*!< COMP required parameters */
96   HAL_LockTypeDef    Lock;            /*!< Locking object           */
97   __IO HAL_COMP_StateTypeDef  State;  /*!< COMP communication state */
98   __IO uint32_t      ErrorCode;       /*!< COMP error code */
99 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
100   void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP trigger callback */
101   void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP Msp Init callback */
102   void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
103 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
104 } COMP_HandleTypeDef;
105 
106 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
107 /**
108   * @brief  HAL COMP Callback ID enumeration definition
109   */
110 typedef enum
111 {
112   HAL_COMP_TRIGGER_CB_ID                = 0x00U,  /*!< COMP trigger callback ID */
113   HAL_COMP_MSPINIT_CB_ID                = 0x01U,  /*!< COMP Msp Init callback ID */
114   HAL_COMP_MSPDEINIT_CB_ID              = 0x02U   /*!< COMP Msp DeInit callback ID */
115 } HAL_COMP_CallbackIDTypeDef;
116 
117 /**
118   * @brief  HAL COMP Callback pointer definition
119   */
120 typedef  void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
121 
122 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
123 
124 /**
125   * @}
126   */
127 
128 /* Exported constants --------------------------------------------------------*/
129 /** @defgroup COMP_Exported_Constants COMP Exported Constants
130   * @{
131   */
132 
133 /** @defgroup COMP_Error_Code COMP Error Code
134   * @{
135   */
136 #define HAL_COMP_ERROR_NONE             (0x00UL)  /*!< No error */
137 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
138 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01UL)  /*!< Invalid Callback error */
139 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
140 /**
141   * @}
142   */
143 
144 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
145   * @{
146   */
147 #define COMP_INPUT_PLUS_IO1            (0x00000000UL)         /*!< Comparator input plus connected to IO1 (pin PA1 for COMP1, pin PA7 for COMP2, pin PA0 for COMP3, pin PB0 for COMP4, pin PB13 for COMP5, pin PB11 for COMP6, pin PB14 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
148 #define COMP_INPUT_PLUS_IO2            (COMP_CSR_INPSEL)      /*!< Comparator input plus connected to IO2 (pin PB1 for COMP1, pin PA3 for COMP2, pin PC1 for COMP3, pin PE7 for COMP4, pin PD12 for COMP5, pin PD11 for COMP6, pin PD14 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
149 /**
150   * @}
151   */
152 
153 /** @defgroup COMP_InputMinus COMP input minus (inverting input)
154   * @{
155   */
156 #define COMP_INPUT_MINUS_1_4VREFINT    (                                                            COMP_CSR_SCALEN | COMP_CSR_BRGEN)        /*!< Comparator input minus connected to 1/4 VrefInt */
157 #define COMP_INPUT_MINUS_1_2VREFINT    (                                        COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN | COMP_CSR_BRGEN)        /*!< Comparator input minus connected to 1/2 VrefInt */
158 #define COMP_INPUT_MINUS_3_4VREFINT    (                    COMP_CSR_INMSEL_1                     | COMP_CSR_SCALEN | COMP_CSR_BRGEN)        /*!< Comparator input minus connected to 3/4 VrefInt */
159 #define COMP_INPUT_MINUS_VREFINT       (                    COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN                 )        /*!< Comparator input minus connected to VrefInt */
160 #define COMP_INPUT_MINUS_DAC1_CH1      (COMP_CSR_INMSEL_2                     | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to DAC1 Channel 1 for COMP1/3/4. Note: For COMPx & DACx instances availability, please refer to datasheet */
161 #define COMP_INPUT_MINUS_DAC1_CH2      (COMP_CSR_INMSEL_2                     | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to DAC1 Channel 2 for COMP2/5. Note: For COMPx & DACx instances availability, please refer to datasheet */
162 #define COMP_INPUT_MINUS_DAC2_CH1      (COMP_CSR_INMSEL_2                     | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to DAC2 Channel 1 for COMP6/7. Note: For COMPx & DACx instances availability, please refer to datasheet */
163 #define COMP_INPUT_MINUS_DAC3_CH1      (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC3 Channel 1 for COMP1/3. Note: For COMPx & DACx instances availability, please refer to datasheet */
164 #define COMP_INPUT_MINUS_DAC3_CH2      (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC3 Channel 2 for COMP2/4. Note: For COMPx & DACx instances availability, please refer to datasheet */
165 #define COMP_INPUT_MINUS_DAC4_CH1      (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC4 Channel 1 for COMP5/7. Note: For COMPx & DACx instances availability, please refer to datasheet */
166 #define COMP_INPUT_MINUS_DAC4_CH2      (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC4 Channel 2 for COMP6. Note: For COMPx & DACx instances availability, please refer to datasheet */
167 #define COMP_INPUT_MINUS_IO1           (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1                    )                                           /*!< Comparator input minus connected to IO1 (pin PA4 for COMP1, pin PA5 for COMP2, pin PF1 for COMP3, pin PE8 for COMP4, pin PB10 for COMP5, pin PD10 for COMP6, pin PD15 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
168 #define COMP_INPUT_MINUS_IO2           (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to IO2 (pin PA0 for COMP1, pin PA2 for COMP2, pin PC0 for COMP3, pin PB2 for COMP4, pin PD13 for COMP5, pin PB15 for COMP6, pin PB12 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
169 /**
170   * @}
171   */
172 
173 /** @defgroup COMP_Hysteresis COMP hysteresis
174   * @{
175   */
176 #define COMP_HYSTERESIS_NONE           (0x00000000UL)                                        /*!< No hysteresis */
177 #define COMP_HYSTERESIS_10MV           (                                    COMP_CSR_HYST_0) /*!< Hysteresis level 10mV */
178 #define COMP_HYSTERESIS_20MV           (                  COMP_CSR_HYST_1                  ) /*!< Hysteresis level 20mV */
179 #define COMP_HYSTERESIS_30MV           (                  COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level 30mV */
180 #define COMP_HYSTERESIS_40MV           (COMP_CSR_HYST_2                                    ) /*!< Hysteresis level 40mV */
181 #define COMP_HYSTERESIS_50MV           (COMP_CSR_HYST_2                   | COMP_CSR_HYST_0) /*!< Hysteresis level 50mV */
182 #define COMP_HYSTERESIS_60MV           (COMP_CSR_HYST_2 | COMP_CSR_HYST_1                  ) /*!< Hysteresis level 60mV */
183 #define COMP_HYSTERESIS_70MV           (COMP_CSR_HYST_2 | COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level 70mV */
184 #define COMP_HYSTERESIS_LOW            COMP_HYSTERESIS_10MV  /*!< Hysteresis level low */
185 #define COMP_HYSTERESIS_MEDIUM         COMP_HYSTERESIS_40MV  /*!< Hysteresis level medium */
186 #define COMP_HYSTERESIS_HIGH           COMP_HYSTERESIS_70MV  /*!< Hysteresis level high */
187 /**
188   * @}
189   */
190 
191 /** @defgroup COMP_OutputPolarity COMP output Polarity
192   * @{
193   */
194 #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) */
195 #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) */
196 /**
197   * @}
198   */
199 
200 /** @defgroup COMP_BlankingSrce  COMP blanking source
201   * @{
202   */
203 #define COMP_BLANKINGSRC_NONE            (0x00000000UL)          /*!<Comparator output without blanking */
204 #define COMP_BLANKINGSRC_TIM1_OC5_COMP1  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1). Note: For COMPx & TIMx instances availability, please refer to datasheet */
205 #define COMP_BLANKINGSRC_TIM1_OC5_COMP2  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP2). Note: For COMPx & TIMx instances availability, please refer to datasheet */
206 #define COMP_BLANKINGSRC_TIM1_OC5_COMP3  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP3). Note: For COMPx & TIMx instances availability, please refer to datasheet */
207 #define COMP_BLANKINGSRC_TIM1_OC5_COMP4  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP4). Note: For COMPx & TIMx instances availability, please refer to datasheet */
208 #define COMP_BLANKINGSRC_TIM1_OC5_COMP5  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP5). Note: For COMPx & TIMx instances availability, please refer to datasheet */
209 #define COMP_BLANKINGSRC_TIM1_OC5_COMP6  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP6). Note: For COMPx & TIMx instances availability, please refer to datasheet */
210 #define COMP_BLANKINGSRC_TIM1_OC5_COMP7  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP7). Note: For COMPx & TIMx instances availability, please refer to datasheet */
211 #define COMP_BLANKINGSRC_TIM2_OC3_COMP1  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1). Note: For COMPx & TIMx instances availability, please refer to datasheet */
212 #define COMP_BLANKINGSRC_TIM2_OC3_COMP2  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP2). Note: For COMPx & TIMx instances availability, please refer to datasheet */
213 #define COMP_BLANKINGSRC_TIM2_OC3_COMP5  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP5). Note: For COMPx & TIMx instances availability, please refer to datasheet */
214 #define COMP_BLANKINGSRC_TIM2_OC4_COMP3  (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM2 OC4 (specific to COMP instance: COMP3). Note: For COMPx & TIMx instances availability, please refer to datasheet */
215 #define COMP_BLANKINGSRC_TIM2_OC4_COMP6  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM2 OC4 (specific to COMP instance: COMP6). Note: For COMPx & TIMx instances availability, please refer to datasheet */
216 #define COMP_BLANKINGSRC_TIM3_OC3_COMP1  (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1). Note: For COMPx & TIMx instances availability, please refer to datasheet */
217 #define COMP_BLANKINGSRC_TIM3_OC3_COMP2  (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP2). Note: For COMPx & TIMx instances availability, please refer to datasheet */
218 #define COMP_BLANKINGSRC_TIM3_OC3_COMP3  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP3). Note: For COMPx & TIMx instances availability, please refer to datasheet */
219 #define COMP_BLANKINGSRC_TIM3_OC3_COMP5  (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP5). Note: For COMPx & TIMx instances availability, please refer to datasheet */
220 #define COMP_BLANKINGSRC_TIM3_OC3_COMP7  (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP7). Note: For COMPx & TIMx instances availability, please refer to datasheet */
221 #define COMP_BLANKINGSRC_TIM3_OC4_COMP4  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP4). Note: For COMPx & TIMx instances availability, please refer to datasheet */
222 #define COMP_BLANKINGSRC_TIM8_OC5_COMP1  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP1). Note: For COMPx & TIMx instances availability, please refer to datasheet */
223 #define COMP_BLANKINGSRC_TIM8_OC5_COMP2  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2). Note: For COMPx & TIMx instances availability, please refer to datasheet */
224 #define COMP_BLANKINGSRC_TIM8_OC5_COMP3  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP3). Note: For COMPx & TIMx instances availability, please refer to datasheet */
225 #define COMP_BLANKINGSRC_TIM8_OC5_COMP4  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP4). Note: For COMPx & TIMx instances availability, please refer to datasheet */
226 #define COMP_BLANKINGSRC_TIM8_OC5_COMP5  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP5). Note: For COMPx & TIMx instances availability, please refer to datasheet */
227 #define COMP_BLANKINGSRC_TIM8_OC5_COMP6  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP6). Note: For COMPx & TIMx instances availability, please refer to datasheet */
228 #define COMP_BLANKINGSRC_TIM8_OC5_COMP7  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP7). Note: For COMPx & TIMx instances availability, please refer to datasheet */
229 #define COMP_BLANKINGSRC_TIM15_OC1_COMP4 (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP4). Note: For COMPx & TIMx instances availability, please refer to datasheet */
230 #define COMP_BLANKINGSRC_TIM15_OC2_COMP6 (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM15 OC2 (specific to COMP instance: COMP6). Note: For COMPx & TIMx instances availability, please refer to datasheet */
231 #define COMP_BLANKINGSRC_TIM15_OC2_COMP7 (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM15 OC3 (specific to COMP instance: COMP7). Note: For COMPx & TIMx instances availability, please refer to datasheet */
232 #define COMP_BLANKINGSRC_TIM20_OC5       (COMP_CSR_BLANKING_2 |                       COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM20 OC5 (Common to all COMP instances) */
233 #define COMP_BLANKINGSRC_TIM15_OC1       (COMP_CSR_BLANKING_2 | COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM15 OC1 (Common to all COMP instances) */
234 #define COMP_BLANKINGSRC_TIM4_OC3        (COMP_CSR_BLANKING_2 | COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM4 OC3 (Common to all COMP instances) */
235 
236 /**
237   * @}
238   */
239 
240 /** @defgroup COMP_OutputLevel COMP Output Level
241   * @{
242   */
243 /* Note: Comparator output level values are fixed to "0" and "1",             */
244 /* corresponding COMP register bit is managed by HAL function to match        */
245 /* with these values (independently of bit position in register).             */
246 
247 /* When output polarity is not inverted, comparator output is low when
248    the input plus is at a lower voltage than the input minus */
249 #define COMP_OUTPUT_LEVEL_LOW              (0x00000000UL)
250 /* When output polarity is not inverted, comparator output is high when
251    the input plus is at a higher voltage than the input minus */
252 #define COMP_OUTPUT_LEVEL_HIGH             (0x00000001UL)
253 /**
254   * @}
255   */
256 
257 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
258   * @{
259   */
260 #define COMP_TRIGGERMODE_NONE                 (0x00000000UL)                                            /*!< Comparator output triggering no External Interrupt Line */
261 #define COMP_TRIGGERMODE_IT_RISING            (COMP_EXTI_IT | COMP_EXTI_RISING)                         /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
262 #define COMP_TRIGGERMODE_IT_FALLING           (COMP_EXTI_IT | COMP_EXTI_FALLING)                        /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
263 #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 */
264 #define COMP_TRIGGERMODE_EVENT_RISING         (COMP_EXTI_EVENT | COMP_EXTI_RISING)                      /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
265 #define COMP_TRIGGERMODE_EVENT_FALLING        (COMP_EXTI_EVENT | COMP_EXTI_FALLING)                     /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
266 #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 */
267 /**
268   * @}
269   */
270 
271 /**
272   * @}
273   */
274 
275 /* Exported macro ------------------------------------------------------------*/
276 /** @defgroup COMP_Exported_Macros COMP Exported Macros
277   * @{
278   */
279 
280 /** @defgroup COMP_Handle_Management  COMP Handle Management
281   * @{
282   */
283 
284 /** @brief  Reset COMP handle state.
285   * @param  __HANDLE__  COMP handle
286   * @retval None
287   */
288 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
289 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{                                                  \
290                                                       (__HANDLE__)->State = HAL_COMP_STATE_RESET;      \
291                                                       (__HANDLE__)->MspInitCallback = NULL;            \
292                                                       (__HANDLE__)->MspDeInitCallback = NULL;          \
293                                                     } while(0)
294 #else
295 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
296 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
297 
298 /**
299   * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
300   * @param __HANDLE__ COMP handle
301   * @retval None
302   */
303 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
304 
305 /**
306   * @brief  Enable the specified comparator.
307   * @param  __HANDLE__  COMP handle
308   * @retval None
309   */
310 #define __HAL_COMP_ENABLE(__HANDLE__)              SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
311 
312 /**
313   * @brief  Disable the specified comparator.
314   * @param  __HANDLE__  COMP handle
315   * @retval None
316   */
317 #define __HAL_COMP_DISABLE(__HANDLE__)             CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
318 
319 /**
320   * @brief  Lock the specified comparator configuration.
321   * @note   Using this macro induce HAL COMP handle state machine being no
322   *         more in line with COMP instance state.
323   *         To keep HAL COMP handle state machine updated, it is recommended
324   *         to use function "HAL_COMP_Lock')".
325   * @param  __HANDLE__  COMP handle
326   * @retval None
327   */
328 #define __HAL_COMP_LOCK(__HANDLE__)                SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK)
329 
330 /**
331   * @brief  Check whether the specified comparator is locked.
332   * @param  __HANDLE__  COMP handle
333   * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
334   */
335 #define __HAL_COMP_IS_LOCKED(__HANDLE__)           (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK)
336 
337 /**
338   * @}
339   */
340 
341 /** @defgroup COMP_Exti_Management  COMP external interrupt line management
342   * @{
343   */
344 
345 /**
346   * @brief  Enable the COMP1 EXTI line rising edge trigger.
347   * @retval None
348   */
349 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
350 
351 /**
352   * @brief  Disable the COMP1 EXTI line rising edge trigger.
353   * @retval None
354   */
355 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
356 
357 /**
358   * @brief  Enable the COMP1 EXTI line falling edge trigger.
359   * @retval None
360   */
361 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
362 
363 /**
364   * @brief  Disable the COMP1 EXTI line falling edge trigger.
365   * @retval None
366   */
367 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
368 
369 /**
370   * @brief  Enable the COMP1 EXTI line rising & falling edge trigger.
371   * @retval None
372   */
373 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
374                                                                LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
375                                                                LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
376                                                              } while(0)
377 
378 /**
379   * @brief  Disable the COMP1 EXTI line rising & falling edge trigger.
380   * @retval None
381   */
382 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
383                                                                LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
384                                                                LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
385                                                              } while(0)
386 
387 /**
388   * @brief  Enable the COMP1 EXTI line in interrupt mode.
389   * @retval None
390   */
391 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP1)
392 
393 /**
394   * @brief  Disable the COMP1 EXTI line in interrupt mode.
395   * @retval None
396   */
397 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1)
398 
399 /**
400   * @brief  Generate a software interrupt on the COMP1 EXTI line.
401   * @retval None
402   */
403 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1)
404 
405 /**
406   * @brief  Enable the COMP1 EXTI line in event mode.
407   * @retval None
408   */
409 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1)
410 
411 /**
412   * @brief  Disable the COMP1 EXTI line in event mode.
413   * @retval None
414   */
415 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1)
416 
417 /**
418   * @brief  Check whether the COMP1 EXTI line flag is set.
419   * @retval RESET or SET
420   */
421 #define __HAL_COMP_COMP1_EXTI_GET_FLAG()              LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP1)
422 
423 /**
424   * @brief  Clear the COMP1 EXTI flag.
425   * @retval None
426   */
427 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG()            LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP1)
428 
429 /**
430   * @brief  Enable the COMP2 EXTI line rising edge trigger.
431   * @retval None
432   */
433 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
434 
435 /**
436   * @brief  Disable the COMP2 EXTI line rising edge trigger.
437   * @retval None
438   */
439 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
440 
441 /**
442   * @brief  Enable the COMP2 EXTI line falling edge trigger.
443   * @retval None
444   */
445 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
446 
447 /**
448   * @brief  Disable the COMP2 EXTI line falling edge trigger.
449   * @retval None
450   */
451 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
452 
453 /**
454   * @brief  Enable the COMP2 EXTI line rising & falling edge trigger.
455   * @retval None
456   */
457 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
458                                                                LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
459                                                                LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
460                                                              } while(0)
461 
462 /**
463   * @brief  Disable the COMP2 EXTI line rising & falling edge trigger.
464   * @retval None
465   */
466 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
467                                                                LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
468                                                                LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
469                                                              } while(0)
470 
471 /**
472   * @brief  Enable the COMP2 EXTI line in interrupt mode.
473   * @retval None
474   */
475 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2)
476 
477 /**
478   * @brief  Disable the COMP2 EXTI line in interrupt mode.
479   * @retval None
480   */
481 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2)
482 
483 /**
484   * @brief  Generate a software interrupt on the COMP2 EXTI line.
485   * @retval None
486   */
487 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2)
488 
489 /**
490   * @brief  Enable the COMP2 EXTI line in event mode.
491   * @retval None
492   */
493 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2)
494 
495 /**
496   * @brief  Disable the COMP2 EXTI line in event mode.
497   * @retval None
498   */
499 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2)
500 
501 /**
502   * @brief  Check whether the COMP2 EXTI line flag is set.
503   * @retval RESET or SET
504   */
505 #define __HAL_COMP_COMP2_EXTI_GET_FLAG()              LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP2)
506 
507 /**
508   * @brief  Clear the COMP2 EXTI flag.
509   * @retval None
510   */
511 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG()            LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP2)
512 
513 /**
514   * @brief  Enable the COMP3 EXTI line rising edge trigger.
515   * @retval None
516   */
517 #define __HAL_COMP_COMP3_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP3)
518 
519 /**
520   * @brief  Disable the COMP3 EXTI line rising edge trigger.
521   * @retval None
522   */
523 #define __HAL_COMP_COMP3_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP3)
524 
525 /**
526   * @brief  Enable the COMP3 EXTI line falling edge trigger.
527   * @retval None
528   */
529 #define __HAL_COMP_COMP3_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP3)
530 
531 /**
532   * @brief  Disable the COMP3 EXTI line falling edge trigger.
533   * @retval None
534   */
535 #define __HAL_COMP_COMP3_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP3)
536 
537 /**
538   * @brief  Enable the COMP3 EXTI line rising & falling edge trigger.
539   * @retval None
540   */
541 #define __HAL_COMP_COMP3_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
542                                                                LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP3); \
543                                                                LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP3); \
544                                                              } while(0)
545 
546 /**
547   * @brief  Disable the COMP3 EXTI line rising & falling edge trigger.
548   * @retval None
549   */
550 #define __HAL_COMP_COMP3_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
551                                                                LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP3); \
552                                                                LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP3); \
553                                                              } while(0)
554 
555 /**
556   * @brief  Enable the COMP3 EXTI line in interrupt mode.
557   * @retval None
558   */
559 #define __HAL_COMP_COMP3_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP3)
560 
561 /**
562   * @brief  Disable the COMP3 EXTI line in interrupt mode.
563   * @retval None
564   */
565 #define __HAL_COMP_COMP3_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP3)
566 
567 /**
568   * @brief  Generate a software interrupt on the COMP3 EXTI line.
569   * @retval None
570   */
571 #define __HAL_COMP_COMP3_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP3)
572 
573 /**
574   * @brief  Enable the COMP3 EXTI line in event mode.
575   * @retval None
576   */
577 #define __HAL_COMP_COMP3_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP3)
578 
579 /**
580   * @brief  Disable the COMP3 EXTI line in event mode.
581   * @retval None
582   */
583 #define __HAL_COMP_COMP3_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP3)
584 
585 /**
586   * @brief  Check whether the COMP3 EXTI line flag is set.
587   * @retval RESET or SET
588   */
589 #define __HAL_COMP_COMP3_EXTI_GET_FLAG()              LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP3)
590 
591 /**
592   * @brief  Clear the COMP3 EXTI flag.
593   * @retval None
594   */
595 #define __HAL_COMP_COMP3_EXTI_CLEAR_FLAG()            LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP3)
596 
597 /**
598   * @brief  Enable the COMP4 EXTI line rising edge trigger.
599   * @retval None
600   */
601 #define __HAL_COMP_COMP4_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP4)
602 
603 /**
604   * @brief  Disable the COMP4 EXTI line rising edge trigger.
605   * @retval None
606   */
607 #define __HAL_COMP_COMP4_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP4)
608 
609 /**
610   * @brief  Enable the COMP4 EXTI line falling edge trigger.
611   * @retval None
612   */
613 #define __HAL_COMP_COMP4_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP4)
614 
615 /**
616   * @brief  Disable the COMP4 EXTI line falling edge trigger.
617   * @retval None
618   */
619 #define __HAL_COMP_COMP4_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP4)
620 
621 /**
622   * @brief  Enable the COMP4 EXTI line rising & falling edge trigger.
623   * @retval None
624   */
625 #define __HAL_COMP_COMP4_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
626                                                                LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP4); \
627                                                                LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP4); \
628                                                              } while(0)
629 
630 /**
631   * @brief  Disable the COMP4 EXTI line rising & falling edge trigger.
632   * @retval None
633   */
634 #define __HAL_COMP_COMP4_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
635                                                                LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP4); \
636                                                                LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP4); \
637                                                              } while(0)
638 
639 /**
640   * @brief  Enable the COMP4 EXTI line in interrupt mode.
641   * @retval None
642   */
643 #define __HAL_COMP_COMP4_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP4)
644 
645 /**
646   * @brief  Disable the COMP4 EXTI line in interrupt mode.
647   * @retval None
648   */
649 #define __HAL_COMP_COMP4_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP4)
650 
651 /**
652   * @brief  Generate a software interrupt on the COMP4 EXTI line.
653   * @retval None
654   */
655 #define __HAL_COMP_COMP4_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP4)
656 
657 /**
658   * @brief  Enable the COMP4 EXTI line in event mode.
659   * @retval None
660   */
661 #define __HAL_COMP_COMP4_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP4)
662 
663 /**
664   * @brief  Disable the COMP4 EXTI line in event mode.
665   * @retval None
666   */
667 #define __HAL_COMP_COMP4_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP4)
668 
669 /**
670   * @brief  Check whether the COMP4 EXTI line flag is set.
671   * @retval RESET or SET
672   */
673 #define __HAL_COMP_COMP4_EXTI_GET_FLAG()              LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP4)
674 
675 /**
676   * @brief  Clear the COMP4 EXTI flag.
677   * @retval None
678   */
679 #define __HAL_COMP_COMP4_EXTI_CLEAR_FLAG()            LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP4)
680 
681 #if  defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
682 /**
683   * @brief  Enable the COMP5 EXTI line rising edge trigger.
684   * @retval None
685   */
686 #define __HAL_COMP_COMP5_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP5)
687 
688 /**
689   * @brief  Disable the COMP5 EXTI line rising edge trigger.
690   * @retval None
691   */
692 #define __HAL_COMP_COMP5_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP5)
693 
694 /**
695   * @brief  Enable the COMP5 EXTI line falling edge trigger.
696   * @retval None
697   */
698 #define __HAL_COMP_COMP5_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP5)
699 
700 /**
701   * @brief  Disable the COMP5 EXTI line falling edge trigger.
702   * @retval None
703   */
704 #define __HAL_COMP_COMP5_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP5)
705 
706 /**
707   * @brief  Enable the COMP5 EXTI line rising & falling edge trigger.
708   * @retval None
709   */
710 #define __HAL_COMP_COMP5_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
711                                                                LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP5); \
712                                                                LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP5); \
713                                                              } while(0)
714 
715 /**
716   * @brief  Disable the COMP5 EXTI line rising & falling edge trigger.
717   * @retval None
718   */
719 #define __HAL_COMP_COMP5_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
720                                                                LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP5); \
721                                                                LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP5); \
722                                                              } while(0)
723 
724 /**
725   * @brief  Enable the COMP5 EXTI line in interrupt mode.
726   * @retval None
727   */
728 #define __HAL_COMP_COMP5_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP5)
729 
730 /**
731   * @brief  Disable the COMP5 EXTI line in interrupt mode.
732   * @retval None
733   */
734 #define __HAL_COMP_COMP5_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP5)
735 
736 /**
737   * @brief  Generate a software interrupt on the COMP5 EXTI line.
738   * @retval None
739   */
740 #define __HAL_COMP_COMP5_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP5)
741 
742 /**
743   * @brief  Enable the COMP5 EXTI line in event mode.
744   * @retval None
745   */
746 #define __HAL_COMP_COMP5_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP5)
747 
748 /**
749   * @brief  Disable the COMP5 EXTI line in event mode.
750   * @retval None
751   */
752 #define __HAL_COMP_COMP5_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP5)
753 
754 /**
755   * @brief  Check whether the COMP5 EXTI line flag is set.
756   * @retval RESET or SET
757   */
758 #define __HAL_COMP_COMP5_EXTI_GET_FLAG()              LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP5)
759 
760 /**
761   * @brief  Clear the COMP5 EXTI flag.
762   * @retval None
763   */
764 #define __HAL_COMP_COMP5_EXTI_CLEAR_FLAG()            LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP5)
765 
766 #endif /* STM32G474xx || STM32G484xx || STM32G473xx || STM32G483xx*/
767 #if  defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
768 /**
769   * @brief  Enable the COMP6 EXTI line rising edge trigger.
770   * @retval None
771   */
772 #define __HAL_COMP_COMP6_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_32_63(COMP_EXTI_LINE_COMP6)
773 
774 /**
775   * @brief  Disable the COMP6 EXTI line rising edge trigger.
776   * @retval None
777   */
778 #define __HAL_COMP_COMP6_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_32_63(COMP_EXTI_LINE_COMP6)
779 
780 /**
781   * @brief  Enable the COMP6 EXTI line falling edge trigger.
782   * @retval None
783   */
784 #define __HAL_COMP_COMP6_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_32_63(COMP_EXTI_LINE_COMP6)
785 
786 /**
787   * @brief  Disable the COMP6 EXTI line falling edge trigger.
788   * @retval None
789   */
790 #define __HAL_COMP_COMP6_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_32_63(COMP_EXTI_LINE_COMP6)
791 
792 /**
793   * @brief  Enable the COMP6 EXTI line rising & falling edge trigger.
794   * @retval None
795   */
796 #define __HAL_COMP_COMP6_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
797                                                                LL_EXTI_EnableRisingTrig_32_63(COMP_EXTI_LINE_COMP6); \
798                                                                LL_EXTI_EnableFallingTrig_32_63(COMP_EXTI_LINE_COMP6); \
799                                                              } while(0)
800 
801 /**
802   * @brief  Disable the COMP6 EXTI line rising & falling edge trigger.
803   * @retval None
804   */
805 #define __HAL_COMP_COMP6_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
806                                                                LL_EXTI_DisableRisingTrig_32_63(COMP_EXTI_LINE_COMP6); \
807                                                                LL_EXTI_DisableFallingTrig_32_63(COMP_EXTI_LINE_COMP6); \
808                                                              } while(0)
809 
810 /**
811   * @brief  Enable the COMP6 EXTI line in interrupt mode.
812   * @retval None
813   */
814 #define __HAL_COMP_COMP6_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_32_63(COMP_EXTI_LINE_COMP6)
815 
816 /**
817   * @brief  Disable the COMP6 EXTI line in interrupt mode.
818   * @retval None
819   */
820 #define __HAL_COMP_COMP6_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_32_63(COMP_EXTI_LINE_COMP6)
821 
822 /**
823   * @brief  Generate a software interrupt on the COMP6 EXTI line.
824   * @retval None
825   */
826 #define __HAL_COMP_COMP6_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_32_63(COMP_EXTI_LINE_COMP6)
827 
828 /**
829   * @brief  Enable the COMP6 EXTI line in event mode.
830   * @retval None
831   */
832 #define __HAL_COMP_COMP6_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_32_63(COMP_EXTI_LINE_COMP6)
833 
834 /**
835   * @brief  Disable the COMP6 EXTI line in event mode.
836   * @retval None
837   */
838 #define __HAL_COMP_COMP6_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_32_63(COMP_EXTI_LINE_COMP6)
839 
840 /**
841   * @brief  Check whether the COMP6 EXTI line flag is set.
842   * @retval RESET or SET
843   */
844 #define __HAL_COMP_COMP6_EXTI_GET_FLAG()              LL_EXTI_IsActiveFlag_32_63(COMP_EXTI_LINE_COMP6)
845 
846 /**
847   * @brief  Clear the COMP6 EXTI flag.
848   * @retval None
849   */
850 #define __HAL_COMP_COMP6_EXTI_CLEAR_FLAG()            LL_EXTI_ClearFlag_32_63(COMP_EXTI_LINE_COMP6)
851 
852 #endif /* STM32G474xx || STM32G484xx || STM32G473xx || STM32G483xx*/
853 #if  defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
854 /**
855   * @brief  Enable the COMP7 EXTI line rising edge trigger.
856   * @retval None
857   */
858 #define __HAL_COMP_COMP7_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_32_63(COMP_EXTI_LINE_COMP7)
859 
860 /**
861   * @brief  Disable the COMP7 EXTI line rising edge trigger.
862   * @retval None
863   */
864 #define __HAL_COMP_COMP7_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_32_63(COMP_EXTI_LINE_COMP7)
865 
866 /**
867   * @brief  Enable the COMP7 EXTI line falling edge trigger.
868   * @retval None
869   */
870 #define __HAL_COMP_COMP7_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_32_63(COMP_EXTI_LINE_COMP7)
871 
872 /**
873   * @brief  Disable the COMP7 EXTI line falling edge trigger.
874   * @retval None
875   */
876 #define __HAL_COMP_COMP7_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_32_63(COMP_EXTI_LINE_COMP7)
877 
878 /**
879   * @brief  Enable the COMP7 EXTI line rising & falling edge trigger.
880   * @retval None
881   */
882 #define __HAL_COMP_COMP7_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
883                                                                LL_EXTI_EnableRisingTrig_32_63(COMP_EXTI_LINE_COMP7); \
884                                                                LL_EXTI_EnableFallingTrig_32_63(COMP_EXTI_LINE_COMP7); \
885                                                              } while(0)
886 
887 /**
888   * @brief  Disable the COMP7 EXTI line rising & falling edge trigger.
889   * @retval None
890   */
891 #define __HAL_COMP_COMP7_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
892                                                                LL_EXTI_DisableRisingTrig_32_63(COMP_EXTI_LINE_COMP7); \
893                                                                LL_EXTI_DisableFallingTrig_32_63(COMP_EXTI_LINE_COMP7); \
894                                                              } while(0)
895 
896 /**
897   * @brief  Enable the COMP7 EXTI line in interrupt mode.
898   * @retval None
899   */
900 #define __HAL_COMP_COMP7_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_32_63(COMP_EXTI_LINE_COMP7)
901 
902 /**
903   * @brief  Disable the COMP7 EXTI line in interrupt mode.
904   * @retval None
905   */
906 #define __HAL_COMP_COMP7_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_32_63(COMP_EXTI_LINE_COMP7)
907 
908 /**
909   * @brief  Generate a software interrupt on the COMP7 EXTI line.
910   * @retval None
911   */
912 #define __HAL_COMP_COMP7_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_32_63(COMP_EXTI_LINE_COMP7)
913 
914 /**
915   * @brief  Enable the COMP7 EXTI line in event mode.
916   * @retval None
917   */
918 #define __HAL_COMP_COMP7_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_32_63(COMP_EXTI_LINE_COMP7)
919 
920 /**
921   * @brief  Disable the COMP7 EXTI line in event mode.
922   * @retval None
923   */
924 #define __HAL_COMP_COMP7_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_32_63(COMP_EXTI_LINE_COMP7)
925 
926 /**
927   * @brief  Check whether the COMP7 EXTI line flag is set.
928   * @retval RESET or SET
929   */
930 #define __HAL_COMP_COMP7_EXTI_GET_FLAG()              LL_EXTI_IsActiveFlag_32_63(COMP_EXTI_LINE_COMP7)
931 
932 /**
933   * @brief  Clear the COMP7 EXTI flag.
934   * @retval None
935   */
936 #define __HAL_COMP_COMP7_EXTI_CLEAR_FLAG()            LL_EXTI_ClearFlag_32_63(COMP_EXTI_LINE_COMP7)
937 
938 #endif /* STM32G474xx || STM32G484xx || STM32G473xx || STM32G483xx */
939 /**
940   * @}
941   */
942 
943 /**
944   * @}
945   */
946 
947 
948 /* Private types -------------------------------------------------------------*/
949 /* Private constants ---------------------------------------------------------*/
950 /** @defgroup COMP_Private_Constants COMP Private Constants
951   * @{
952   */
953 
954 /** @defgroup COMP_ExtiLine COMP EXTI Lines
955   * @{
956   */
957 #define COMP_EXTI_LINE_COMP1           (LL_EXTI_LINE_21)  /*!< EXTI line 21 connected to COMP1 output. Note: For COMPx instance availability, please refer to datasheet */
958 #define COMP_EXTI_LINE_COMP2           (LL_EXTI_LINE_22)  /*!< EXTI line 22 connected to COMP2 output. Note: For COMPx instance availability, please refer to datasheet */
959 #define COMP_EXTI_LINE_COMP3           (LL_EXTI_LINE_29)  /*!< EXTI line 29 connected to COMP3 output. Note: For COMPx instance availability, please refer to datasheet */
960 #define COMP_EXTI_LINE_COMP4           (LL_EXTI_LINE_30)  /*!< EXTI line 30 connected to COMP4 output. Note: For COMPx instance availability, please refer to datasheet */
961 #if defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
962 #define COMP_EXTI_LINE_COMP5           (LL_EXTI_LINE_31)  /*!< EXTI line 31 connected to COMP5 output. Note: For COMPx instance availability, please refer to datasheet */
963 #define COMP_EXTI_LINE_COMP6           (LL_EXTI_LINE_32)  /*!< EXTI line 32 connected to COMP6 output. Note: For COMPx instance availability, please refer to datasheet */
964 #define COMP_EXTI_LINE_COMP7           (LL_EXTI_LINE_33)  /*!< EXTI line 33 connected to COMP7 output. Note: For COMPx instance availability, please refer to datasheet */
965 #endif /* STM32G474xx || STM32G484xx || STM32G473xx || STM32G483xx */
966 /**
967   * @}
968   */
969 
970 /** @defgroup COMP_ExtiLine COMP EXTI Lines
971   * @{
972   */
973 #define COMP_EXTI_IT                        (0x00000001UL)  /*!< EXTI line event with interruption */
974 #define COMP_EXTI_EVENT                     (0x00000002UL)  /*!< EXTI line event only (without interruption) */
975 #define COMP_EXTI_RISING                    (0x00000010UL)  /*!< EXTI line event on rising edge */
976 #define COMP_EXTI_FALLING                   (0x00000020UL)  /*!< EXTI line event on falling edge */
977 /**
978   * @}
979   */
980 
981 /**
982   * @}
983   */
984 
985 /* Private macros ------------------------------------------------------------*/
986 /** @defgroup COMP_Private_Macros COMP Private Macros
987   * @{
988   */
989 
990 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
991   * @{
992   */
993 /**
994   * @brief  Get the specified EXTI line for a comparator instance.
995   * @param  __INSTANCE__  specifies the COMP instance.
996   * @retval value of @ref COMP_ExtiLine
997   */
998 #if defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
999 #define COMP_GET_EXTI_LINE(__INSTANCE__)    (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1  \
1000                                              :((__INSTANCE__) == COMP2) ? COMP_EXTI_LINE_COMP2 \
1001                                              :((__INSTANCE__) == COMP3) ? COMP_EXTI_LINE_COMP3 \
1002                                              :((__INSTANCE__) == COMP4) ? COMP_EXTI_LINE_COMP4 \
1003                                              :((__INSTANCE__) == COMP5) ? COMP_EXTI_LINE_COMP5 \
1004                                              :((__INSTANCE__) == COMP6) ? COMP_EXTI_LINE_COMP6 \
1005                                              : COMP_EXTI_LINE_COMP7)
1006 #elif defined(STM32GBK1CB) || defined(STM32G431xx) || defined(STM32G441xx) || defined(STM32G471xx) || defined(STM32G491xx) || defined(STM32G4A1xx)
1007 #define COMP_GET_EXTI_LINE(__INSTANCE__)    (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1  \
1008                                              :((__INSTANCE__) == COMP2) ? COMP_EXTI_LINE_COMP2 \
1009                                              :((__INSTANCE__) == COMP3) ? COMP_EXTI_LINE_COMP3 \
1010                                              : COMP_EXTI_LINE_COMP4)
1011 #endif /* STM32G474xx || STM32G484xx || STM32G473xx || STM32G483xx */
1012 /**
1013   * @}
1014   */
1015 
1016 /** @defgroup COMP_IS_COMP_Private_Definitions COMP private macros to check input parameters
1017   * @{
1018   */
1019 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
1020                                                                ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2))
1021 
1022 #if defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
1023 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)  || \
1024                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)  || \
1025                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)  || \
1026                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)     || \
1027                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)         || \
1028                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)         || \
1029                                                                  (((__COMP_INSTANCE__) == COMP1)                        && \
1030                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)  || \
1031                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC3_CH1))    \
1032                                                                  )                                                      || \
1033                                                                  (((__COMP_INSTANCE__) == COMP2)                        && \
1034                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2)  || \
1035                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC3_CH2))    \
1036                                                                  )                                                      || \
1037                                                                  (((__COMP_INSTANCE__) == COMP3)                        && \
1038                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)  || \
1039                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC3_CH1))    \
1040                                                                  )                                                      || \
1041                                                                  (((__COMP_INSTANCE__) == COMP4)                        && \
1042                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)  || \
1043                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC3_CH2))    \
1044                                                                  )                                                      || \
1045                                                                  (((__COMP_INSTANCE__) == COMP5)                        && \
1046                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2)  || \
1047                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC4_CH1))    \
1048                                                                  )                                                      || \
1049                                                                  (((__COMP_INSTANCE__) == COMP6)                        && \
1050                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC2_CH1)  || \
1051                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC4_CH2))    \
1052                                                                  )                                                      || \
1053                                                                  (((__COMP_INSTANCE__) == COMP7)                        && \
1054                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC2_CH1)  || \
1055                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC4_CH1))    \
1056                                                                  ))
1057 #elif defined(STM32GBK1CB) || defined(STM32G431xx) || defined(STM32G441xx) || defined(STM32G471xx) || defined(STM32G491xx) || defined(STM32G4A1xx)
1058 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)  || \
1059                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)  || \
1060                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)  || \
1061                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)     || \
1062                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)         || \
1063                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)         || \
1064                                                                  (((__COMP_INSTANCE__) == COMP1)                        && \
1065                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)  || \
1066                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC3_CH1))    \
1067                                                                  )                                                      || \
1068                                                                  (((__COMP_INSTANCE__) == COMP2)                        && \
1069                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2)  || \
1070                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC3_CH2))    \
1071                                                                  )                                                      || \
1072                                                                  (((__COMP_INSTANCE__) == COMP3)                        && \
1073                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)  || \
1074                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC3_CH1))    \
1075                                                                  )                                                      || \
1076                                                                  (((__COMP_INSTANCE__) == COMP4)                        && \
1077                                                                   (((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)  || \
1078                                                                    ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC3_CH2))    \
1079                                                                  ))
1080 #endif
1081 
1082 
1083 #define IS_COMP_HYSTERESIS(__HYSTERESIS__)  (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE)   || \
1084                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_10MV)   || \
1085                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_20MV)   || \
1086                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_30MV)   || \
1087                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_40MV)   || \
1088                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_50MV)   || \
1089                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_60MV)   || \
1090                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_70MV)   || \
1091                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW)    || \
1092                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
1093                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
1094 
1095 #define IS_COMP_OUTPUTPOL(__POL__)          (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
1096                                              ((__POL__) == COMP_OUTPUTPOL_INVERTED))
1097 
1098 /* Note: Output blanking source depends on COMP instances     */
1099 /*       Better use IS_COMP_BLANKINGSRC_INSTANCE instead      */
1100 /*       Macro kept for compatibility with other STM32 series */
1101 #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__)                    \
1102   (   ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)               \
1103    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1)     \
1104    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP2)     \
1105    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP3)     \
1106    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP4)     \
1107    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP5)     \
1108    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP6)     \
1109    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP7)     \
1110    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1)     \
1111    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP2)     \
1112    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP5)     \
1113    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC4_COMP3)     \
1114    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC4_COMP6)     \
1115    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1)     \
1116    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP2)     \
1117    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP3)     \
1118    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP5)     \
1119    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP7)     \
1120    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP4)     \
1121    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP1)     \
1122    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2)     \
1123    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP3)     \
1124    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP4)     \
1125    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP5)     \
1126    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP6)     \
1127    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP7)     \
1128    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP4)    \
1129    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC2_COMP6)    \
1130    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC2_COMP7)    \
1131    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM20_OC5)          \
1132    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1)          \
1133    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM4_OC3)           \
1134   )
1135 #if defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
1136 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)  \
1137    ((((__INSTANCE__) == COMP1) &&                                               \
1138     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1139      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||      \
1140      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||      \
1141      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1)  ||      \
1142      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP1)))        \
1143     ||                                                                          \
1144     (((__INSTANCE__) == COMP2) &&                                               \
1145     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1146      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP2)  ||      \
1147      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP2)  ||      \
1148      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP2)  ||      \
1149      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2)))        \
1150     ||                                                                          \
1151     (((__INSTANCE__) == COMP3) &&                                               \
1152     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1153      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP3)  ||      \
1154      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC4_COMP3)  ||      \
1155      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP3)  ||      \
1156      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP3)))        \
1157     ||                                                                          \
1158     (((__INSTANCE__) == COMP4) &&                                               \
1159     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1160      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP4)  ||      \
1161      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP4)  ||      \
1162      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP4)  ||      \
1163      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP4)))       \
1164     ||                                                                          \
1165     (((__INSTANCE__) == COMP5) &&                                               \
1166     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1167      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP5)  ||      \
1168      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP5)  ||      \
1169      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP5)  ||      \
1170      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP5)))        \
1171     ||                                                                          \
1172     (((__INSTANCE__) == COMP6) &&                                               \
1173     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1174      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP6)  ||      \
1175      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC4_COMP6)  ||      \
1176      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP6)  ||      \
1177      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC2_COMP6)))       \
1178     ||                                                                          \
1179     (((__INSTANCE__) == COMP7) &&                                               \
1180     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1181      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP7)  ||      \
1182      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP7)  ||      \
1183      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP7)  ||      \
1184      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC2_COMP7)))       \
1185     || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM20_OC5)             \
1186     || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1)             \
1187     || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM4_OC3)              \
1188     )
1189 #elif defined(STM32GBK1CB) || defined(STM32G431xx) || defined(STM32G441xx) || defined(STM32G471xx)
1190 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)  \
1191    ((((__INSTANCE__) == COMP1) &&                                               \
1192     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1193      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||      \
1194      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||      \
1195      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1)  ||      \
1196      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP1)))        \
1197     ||                                                                          \
1198     (((__INSTANCE__) == COMP2) &&                                               \
1199     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1200      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP2)  ||      \
1201      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP2)  ||      \
1202      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP2)  ||      \
1203      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2)))        \
1204     ||                                                                          \
1205     (((__INSTANCE__) == COMP3) &&                                               \
1206     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1207      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP3)  ||      \
1208      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC4_COMP3)  ||      \
1209      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP3)  ||      \
1210      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP3)))        \
1211     ||                                                                          \
1212     (((__INSTANCE__) == COMP4) &&                                               \
1213     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1214      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP4)  ||      \
1215      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP4)  ||      \
1216      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP4)  ||      \
1217      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP4)))       \
1218     || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1)             \
1219     || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM4_OC3)              \
1220     )
1221 #elif defined(STM32G491xx) || defined(STM32G4A1xx)
1222 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)  \
1223    ((((__INSTANCE__) == COMP1) &&                                               \
1224     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1225      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||      \
1226      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||      \
1227      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1)  ||      \
1228      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP1)))        \
1229     ||                                                                          \
1230     (((__INSTANCE__) == COMP2) &&                                               \
1231     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1232      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP2)  ||      \
1233      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP2)  ||      \
1234      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP2)  ||      \
1235      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2)))        \
1236     ||                                                                          \
1237     (((__INSTANCE__) == COMP3) &&                                               \
1238     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1239      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP3)  ||      \
1240      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC4_COMP3)  ||      \
1241      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP3)  ||      \
1242      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP3)))        \
1243     ||                                                                          \
1244     (((__INSTANCE__) == COMP4) &&                                               \
1245     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
1246      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP4)  ||      \
1247      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP4)  ||      \
1248      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP4)  ||      \
1249      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP4)))       \
1250     || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM20_OC5)             \
1251     || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1)             \
1252     || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM4_OC3)              \
1253     )
1254 #endif /* STM32G474xx || STM32G484xx || STM32G473xx || STM32G483xx */
1255 
1256 #define IS_COMP_TRIGGERMODE(__MODE__)       (((__MODE__) == COMP_TRIGGERMODE_NONE)                 || \
1257                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING)            || \
1258                                              ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING)           || \
1259                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING)    || \
1260                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING)         || \
1261                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING)        || \
1262                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
1263 
1264 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW)     || \
1265                                                 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
1266 
1267 /**
1268   * @}
1269   */
1270 
1271 /**
1272   * @}
1273   */
1274 
1275 
1276 /* Exported functions --------------------------------------------------------*/
1277 /** @addtogroup COMP_Exported_Functions
1278   * @{
1279   */
1280 
1281 /** @addtogroup COMP_Exported_Functions_Group1
1282   * @{
1283   */
1284 
1285 /* Initialization and de-initialization functions  **********************************/
1286 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
1287 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp);
1288 void              HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
1289 void              HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
1290 
1291 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
1292 /* Callbacks Register/UnRegister functions  ***********************************/
1293 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID,
1294                                             pCOMP_CallbackTypeDef pCallback);
1295 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
1296 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
1297 /**
1298   * @}
1299   */
1300 
1301 /* IO operation functions  *****************************************************/
1302 /** @addtogroup COMP_Exported_Functions_Group2
1303   * @{
1304   */
1305 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
1306 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
1307 void              HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
1308 /**
1309   * @}
1310   */
1311 
1312 /* Peripheral Control functions  ************************************************/
1313 /** @addtogroup COMP_Exported_Functions_Group3
1314   * @{
1315   */
1316 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
1317 uint32_t          HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
1318 /* Callback in interrupt mode */
1319 void              HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
1320 /**
1321   * @}
1322   */
1323 
1324 /* Peripheral State functions  **************************************************/
1325 /** @addtogroup COMP_Exported_Functions_Group4
1326   * @{
1327   */
1328 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
1329 uint32_t              HAL_COMP_GetError(COMP_HandleTypeDef *hcomp);
1330 /**
1331   * @}
1332   */
1333 
1334 /**
1335   * @}
1336   */
1337 
1338 /**
1339   * @}
1340   */
1341 
1342 /**
1343   * @}
1344   */
1345 
1346 #ifdef __cplusplus
1347 }
1348 #endif
1349 
1350 #endif /* STM32G4xx_HAL_COMP_H */
1351