1 /**
2   ******************************************************************************
3   * @file    stm32wbaxx_hal_comp.h
4   * @author  MCD Application Team
5   * @brief   Header file of COMP HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 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 STM32WBAxx_HAL_COMP_H
21 #define STM32WBAxx_HAL_COMP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32wbaxx_hal_def.h"
29 #include "stm32wbaxx_ll_exti.h"
30 
31 /** @addtogroup STM32WBAxx_HAL_Driver
32   * @{
33   */
34 #if defined (COMP1) || defined (COMP2)
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 WindowMode;         /*!< Set window mode of a pair of comparators instances
52                                     (2 consecutive instances odd and even COMP<x> and COMP<x+1>).
53                                     Note: HAL COMP driver allows to set window mode from any COMP
54                                     instance of the pair of COMP instances composing window mode.
55                                     This parameter can be a value of @ref COMP_WindowMode */
56 
57   uint32_t WindowOutput;       /*!< Set window mode output.
58                                     This parameter can be a value of @ref COMP_WindowOutput */
59 
60   uint32_t Mode;               /*!< Set comparator operating mode to adjust power and speed.
61                                     Note: For the characteristics of comparator power modes
62                                           (propagation delay and power consumption), refer to device datasheet.
63                                     This parameter can be a value of @ref COMP_PowerMode */
64 
65   uint32_t InputPlus;          /*!< Set comparator input plus (non-inverting input).
66                                     This parameter can be a value of @ref COMP_InputPlus */
67 
68   uint32_t InputMinus;         /*!< Set comparator input minus (inverting input).
69                                     This parameter can be a value of @ref COMP_InputMinus */
70 
71   uint32_t Hysteresis;         /*!< Set comparator hysteresis mode of the input minus.
72                                     This parameter can be a value of @ref COMP_Hysteresis */
73 
74   uint32_t OutputPol;          /*!< Set comparator output polarity.
75                                     This parameter can be a value of @ref COMP_OutputPolarity */
76 
77   uint32_t BlankingSrce;       /*!< Set comparator blanking source.
78                                     This parameter can be a value of @ref COMP_BlankingSrce */
79 
80   uint32_t TriggerMode;        /*!< Set the comparator output triggering External Interrupt Line (EXTI).
81                                     This parameter can be a value of @ref COMP_EXTI_TriggerMode */
82 
83 } COMP_InitTypeDef;
84 
85 /**
86   * @brief  HAL COMP state machine: HAL COMP states definition
87   */
88 #define COMP_STATE_BITFIELD_LOCK  (0x10U)
89 typedef enum
90 {
91   HAL_COMP_STATE_RESET             = 0x00U,                                             /*!< COMP not yet initialized                             */
92   HAL_COMP_STATE_RESET_LOCKED      = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */
93   HAL_COMP_STATE_READY             = 0x01U,                                             /*!< COMP initialized and ready for use                   */
94   HAL_COMP_STATE_READY_LOCKED      = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked         */
95   HAL_COMP_STATE_BUSY              = 0x02U,                                             /*!< COMP is running                                      */
96   HAL_COMP_STATE_BUSY_LOCKED       = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK)   /*!< COMP is running and configuration is locked          */
97 } HAL_COMP_StateTypeDef;
98 
99 /**
100   * @brief  COMP Handle Structure definition
101   */
102 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
103 typedef struct __COMP_HandleTypeDef
104 #else
105 typedef struct
106 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
107 {
108   COMP_TypeDef       *Instance;       /*!< Register base address    */
109   COMP_InitTypeDef   Init;            /*!< COMP required parameters */
110   HAL_LockTypeDef    Lock;            /*!< Locking object           */
111   __IO HAL_COMP_StateTypeDef  State;  /*!< COMP communication state */
112   __IO uint32_t      ErrorCode;       /*!< COMP error code */
113 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
114   void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP trigger callback */
115   void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP Msp Init callback */
116   void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
117 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
118 } COMP_HandleTypeDef;
119 
120 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
121 /**
122   * @brief  HAL COMP Callback ID enumeration definition
123   */
124 typedef enum
125 {
126   HAL_COMP_TRIGGER_CB_ID                = 0x00U,  /*!< COMP trigger callback ID */
127   HAL_COMP_MSPINIT_CB_ID                = 0x01U,  /*!< COMP Msp Init callback ID */
128   HAL_COMP_MSPDEINIT_CB_ID              = 0x02U   /*!< COMP Msp DeInit callback ID */
129 } HAL_COMP_CallbackIDTypeDef;
130 
131 /**
132   * @brief  HAL COMP Callback pointer definition
133   */
134 typedef  void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
135 
136 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
137 
138 /**
139   * @}
140   */
141 
142 /* Exported constants --------------------------------------------------------*/
143 /** @defgroup COMP_Exported_Constants COMP Exported Constants
144   * @{
145   */
146 
147 /** @defgroup COMP_Error_Code COMP Error Code
148   * @{
149   */
150 #define HAL_COMP_ERROR_NONE             (0x00UL)  /*!< No error */
151 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
152 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01UL)  /*!< Invalid Callback error */
153 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
154 /**
155   * @}
156   */
157 
158 
159 /** @defgroup COMP_WindowMode COMP Window Mode
160   * @{
161   */
162 #define COMP_WINDOWMODE_DISABLE                 (0x00000000UL)            /*!< Window mode disable: Comparators
163                                                                                instances pair COMP1 and COMP2 are
164                                                                                independent */
165 #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE)        /*!< Window mode enable: Comparators instances
166                                                                                pair COMP1 and COMP2 have their input
167                                                                                plus connected together.
168                                                                                The common input is COMP1 input plus
169                                                                                (COMP2 input plus is no more accessible).
170                                                                                */
171 #define COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (COMP_CSR_WINMODE \
172                                                  | COMP_WINDOWMODE_COMP2) /*!< Window mode enable: if used from COMP1 or
173                                                                                COMP2 instance, comparators instances
174                                                                                pair COMP1 and COMP2 have their input
175                                                                                plus connected together, the common input
176                                                                                is COMP2 input plus (COMP1 input plus is
177                                                                                no more accessible). */
178 /**
179   * @}
180   */
181 
182 /** @defgroup COMP_WindowOutput COMP Window output
183   * @{
184   */
185 #define COMP_WINDOWOUTPUT_EACH_COMP (0x00000000UL)            /*!< Window output default mode: Comparators output are
186                                                                    indicating each their own state.
187                                                                    To know window mode state: each comparator output
188                                                                    must be read, if "((COMPx exclusive or COMPy) == 1)"
189                                                                    then monitored signal is within comparators window.*/
190 #define COMP_WINDOWOUTPUT_COMP1     (COMP_CSR_WINOUT)         /*!< Window output synthesized on COMP1 output:
191                                                                    COMP1 output is no more indicating its own state, but
192                                                                    global window mode state (logical high means
193                                                                    monitored signal is within comparators window).
194                                                                    Note: impacts only comparator output signal level
195                                                                    (COMPx_OUT propagated to GPIO, EXTI lines,
196                                                                    timers, ...), does not impact output digital state
197                                                                    of comparator (COMPx_VALUE) always reflecting each
198                                                                    comparator output state.*/
199 #define COMP_WINDOWOUTPUT_COMP2     (COMP_CSR_WINOUT \
200                                      | COMP_WINDOWMODE_COMP2) /*!< Window output synthesized on COMP2 output:
201                                                                    COMP2 output is no more indicating its own state, but
202                                                                    global window mode state (logical high means
203                                                                    monitored signal is within comparators window).
204                                                                    Note: impacts only comparator output signal level
205                                                                    (COMPx_OUT propagated to GPIO, EXTI lines,
206                                                                    timers, ...), does not impact output digital state
207                                                                    of comparator (COMPx_VALUE) always reflecting each
208                                                                    comparator output state.*/
209 #define COMP_WINDOWOUTPUT_BOTH      (0x00000001UL)            /*!< Window output synthesized on both comparators output
210                                                                    of pair of comparator selected (COMP1 and COMP2:
211                                                                    both comparators outputs are no more indicating their
212                                                                    own state, but global window mode state (logical high
213                                                                    means monitored signal is within comparators window).
214                                                                    This is a specific configuration (technically
215                                                                    possible but not relevant from application
216                                                                    point of view:
217                                                                    2 comparators output used for the same signal level),
218                                                                    standard configuration for window mode is one of the
219                                                                    settings above. */
220 /**
221   * @}
222   */
223 
224 
225 /** @defgroup COMP_PowerMode COMP power mode
226   * @{
227   */
228 /* Note: For the characteristics of comparator power modes                    */
229 /*       (propagation delay and power consumption),                           */
230 /*       refer to device datasheet.                                           */
231 #define COMP_POWERMODE_HIGHSPEED       (0x00000000UL)         /*!< High Speed */
232 #define COMP_POWERMODE_MEDIUMSPEED     (COMP_CSR_PWRMODE_0)   /*!< Medium Speed */
233 /**
234   * @}
235   */
236 
237 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
238   * @{
239   */
240 #define COMP_INPUT_PLUS_IO1          (0x00000000UL)           /*!< Comparator input plus connected to IO1 (pin PA2 for COMP1, pin PA0 for COMP2) */
241 /**
242   * @}
243   */
244 
245 /** @defgroup COMP_InputMinus COMP input minus (inverting input)
246   * @{
247   */
248 #define COMP_INPUT_MINUS_1_4VREFINT    (0x00000000UL)                                                                  /*!< Comparator input minus connected to 1/4 VrefInt  */
249 #define COMP_INPUT_MINUS_1_2VREFINT    (                                                            COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt  */
250 #define COMP_INPUT_MINUS_3_4VREFINT    (                                        COMP_CSR_INMSEL_1                    ) /*!< Comparator input minus connected to 3/4 VrefInt  */
251 #define COMP_INPUT_MINUS_VREFINT       (                                        COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to VrefInt */
252 #define COMP_INPUT_MINUS_IO1           (                    COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1                    ) /*!< Comparator input minus connected to IO1 (pin PA1 for COMP1, pin PB9 for COMP2) */
253 /**
254   * @}
255   */
256 
257 /** @defgroup COMP_Hysteresis COMP hysteresis
258   * @{
259   */
260 #define COMP_HYSTERESIS_NONE           (0x00000000UL)                       /*!< No hysteresis */
261 #define COMP_HYSTERESIS_LOW            (                  COMP_CSR_HYST_0)  /*!< Hysteresis level low */
262 #define COMP_HYSTERESIS_MEDIUM         (COMP_CSR_HYST_1                  )  /*!< Hysteresis level medium */
263 #define COMP_HYSTERESIS_HIGH           (COMP_CSR_HYST_1 | COMP_CSR_HYST_0)  /*!< Hysteresis level high */
264 /**
265   * @}
266   */
267 
268 /** @defgroup COMP_OutputPolarity COMP output Polarity
269   * @{
270   */
271 #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) */
272 #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) */
273 /**
274   * @}
275   */
276 
277 /** @defgroup COMP_BlankingSrce  COMP blanking source
278   * @{
279   */
280 #define COMP_BLANKINGSRC_NONE            (0x00000000UL)          /*!<Comparator output without blanking */
281 #define COMP_BLANKINGSRC_TIM1_OC5_COMP1  (COMP_CSR_BLANKSEL_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */
282 #define COMP_BLANKINGSRC_TIM2_OC3_COMP1  (COMP_CSR_BLANKSEL_1)   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */
283 #define COMP_BLANKINGSRC_TIM3_OC3_COMP1  (COMP_CSR_BLANKSEL_2)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */
284 #define COMP_BLANKINGSRC_TIM3_OC4_COMP2  (COMP_CSR_BLANKSEL_0)   /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */
285 /**
286   * @}
287   */
288 
289 /** @defgroup COMP_OutputLevel COMP Output Level
290   * @{
291   */
292 /* Note: Comparator output level values are fixed to "0" and "1",             */
293 /* corresponding COMP register bit is managed by HAL function to match        */
294 /* with these values (independently of bit position in register).             */
295 
296 /* When output polarity is not inverted, comparator output is low when
297    the input plus is at a lower voltage than the input minus */
298 #define COMP_OUTPUT_LEVEL_LOW              (0x00000000UL)
299 /* When output polarity is not inverted, comparator output is high when
300    the input plus is at a higher voltage than the input minus */
301 #define COMP_OUTPUT_LEVEL_HIGH             (0x00000001UL)
302 /**
303   * @}
304   */
305 
306 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
307   * @{
308   */
309 #define COMP_TRIGGERMODE_NONE                 (0x00000000UL)                                            /*!< Comparator output triggering no External Interrupt Line */
310 #define COMP_TRIGGERMODE_IT_RISING            (COMP_EXTI_IT | COMP_EXTI_RISING)                         /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
311 #define COMP_TRIGGERMODE_IT_FALLING           (COMP_EXTI_IT | COMP_EXTI_FALLING)                        /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
312 #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 */
313 #define COMP_TRIGGERMODE_EVENT_RISING         (COMP_EXTI_EVENT | COMP_EXTI_RISING)                      /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
314 #define COMP_TRIGGERMODE_EVENT_FALLING        (COMP_EXTI_EVENT | COMP_EXTI_FALLING)                     /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
315 #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 */
316 /**
317   * @}
318   */
319 
320 /**
321   * @}
322   */
323 
324 /* Exported macro ------------------------------------------------------------*/
325 /** @defgroup COMP_Exported_Macros COMP Exported Macros
326   * @{
327   */
328 
329 /** @defgroup COMP_Handle_Management  COMP Handle Management
330   * @{
331   */
332 
333 /** @brief  Reset COMP handle state.
334   * @param  __HANDLE__  COMP handle
335   * @retval None
336   */
337 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
338 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{                                                  \
339                                                       (__HANDLE__)->State = HAL_COMP_STATE_RESET;      \
340                                                       (__HANDLE__)->MspInitCallback = NULL;            \
341                                                       (__HANDLE__)->MspDeInitCallback = NULL;          \
342                                                     } while(0)
343 #else
344 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
345 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
346 
347 /**
348   * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
349   * @param __HANDLE__ COMP handle
350   * @retval None
351   */
352 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
353 
354 /**
355   * @brief  Enable the specified comparator.
356   * @param  __HANDLE__  COMP handle
357   * @retval None
358   */
359 #define __HAL_COMP_ENABLE(__HANDLE__)       SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
360 
361 /**
362   * @brief  Disable the specified comparator.
363   * @param  __HANDLE__  COMP handle
364   * @retval None
365   */
366 #define __HAL_COMP_DISABLE(__HANDLE__)      CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
367 
368 /**
369   * @brief  Lock the specified comparator configuration.
370   * @note   Using this macro induce HAL COMP handle state machine being no
371   *         more in line with COMP instance state.
372   *         To keep HAL COMP handle state machine updated, it is recommended
373   *         to use function "HAL_COMP_Lock')".
374   * @param  __HANDLE__  COMP handle
375   * @retval None
376   */
377 #define __HAL_COMP_LOCK(__HANDLE__)         SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK)
378 
379 /**
380   * @brief  Check whether the specified comparator is locked.
381   * @param  __HANDLE__  COMP handle
382   * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
383   */
384 #define __HAL_COMP_IS_LOCKED(__HANDLE__)    (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK)
385 
386 /**
387   * @}
388   */
389 
390 /** @defgroup COMP_Exti_Management  COMP external interrupt line management
391   * @{
392   */
393 /**
394   * @brief  Enable the COMP1 EXTI line rising edge trigger.
395   * @retval None
396   */
397 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
398 
399 /**
400   * @brief  Disable the COMP1 EXTI line rising edge trigger.
401   * @retval None
402   */
403 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
404 
405 /**
406   * @brief  Enable the COMP1 EXTI line falling edge trigger.
407   * @retval None
408   */
409 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
410 
411 /**
412   * @brief  Disable the COMP1 EXTI line falling edge trigger.
413   * @retval None
414   */
415 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
416 
417 /**
418   * @brief  Enable the COMP1 EXTI line rising & falling edge trigger.
419   * @retval None
420   */
421 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
422                                                                 LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
423                                                                 LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1);\
424                                                               } while(0)
425 
426 /**
427   * @brief  Disable the COMP1 EXTI line rising & falling edge trigger.
428   * @retval None
429   */
430 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
431                                                                  LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
432                                                                  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1);\
433                                                                } while(0)
434 
435 /**
436   * @brief  Enable the COMP1 EXTI line in interrupt mode.
437   * @retval None
438   */
439 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP1)
440 
441 /**
442   * @brief  Disable the COMP1 EXTI line in interrupt mode.
443   * @retval None
444   */
445 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1)
446 
447 /**
448   * @brief  Generate a software interrupt on the COMP1 EXTI line.
449   * @retval None
450   */
451 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1)
452 
453 /**
454   * @brief  Enable the COMP1 EXTI line in event mode.
455   * @retval None
456   */
457 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1)
458 
459 /**
460   * @brief  Disable the COMP1 EXTI line in event mode.
461   * @retval None
462   */
463 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1)
464 
465 /**
466   * @brief  Check whether the COMP1 EXTI line rising flag is set.
467   * @retval RESET or SET
468   */
469 #define __HAL_COMP_COMP1_EXTI_GET_RISING_FLAG()       LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP1)
470 
471 /**
472   * @brief  Clear the COMP1 EXTI rising flag.
473   * @retval None
474   */
475 #define __HAL_COMP_COMP1_EXTI_CLEAR_RISING_FLAG()     LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP1)
476 
477 /**
478   * @brief  Check whether the COMP1 EXTI line falling flag is set.
479   * @retval RESET or SET
480   */
481 #define __HAL_COMP_COMP1_EXTI_GET_FALLING_FLAG()      LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP1)
482 
483 /**
484   * @brief  Clear the COMP1 EXTI falling flag.
485   * @retval None
486   */
487 #define __HAL_COMP_COMP1_EXTI_CLEAR_FALLING_FLAG()    LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP1)
488 
489 /**
490   * @brief  Enable the COMP2 EXTI line rising edge trigger.
491   * @retval None
492   */
493 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
494 
495 /**
496   * @brief  Disable the COMP2 EXTI line rising edge trigger.
497   * @retval None
498   */
499 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
500 
501 /**
502   * @brief  Enable the COMP2 EXTI line falling edge trigger.
503   * @retval None
504   */
505 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
506 
507 /**
508   * @brief  Disable the COMP2 EXTI line falling edge trigger.
509   * @retval None
510   */
511 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
512 
513 /**
514   * @brief  Enable the COMP2 EXTI line rising & falling edge trigger.
515   * @retval None
516   */
517 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
518                                                                 LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2);\
519                                                                 LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2);\
520                                                               } while(0)
521 
522 /**
523   * @brief  Disable the COMP2 EXTI line rising & falling edge trigger.
524   * @retval None
525   */
526 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
527                                                                  LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2);\
528                                                                  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2);\
529                                                                } while(0)
530 
531 /**
532   * @brief  Enable the COMP2 EXTI line in interrupt mode.
533   * @retval None
534   */
535 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2)
536 
537 /**
538   * @brief  Disable the COMP2 EXTI line in interrupt mode.
539   * @retval None
540   */
541 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2)
542 
543 /**
544   * @brief  Generate a software interrupt on the COMP2 EXTI line.
545   * @retval None
546   */
547 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2)
548 
549 /**
550   * @brief  Enable the COMP2 EXTI line in event mode.
551   * @retval None
552   */
553 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2)
554 
555 /**
556   * @brief  Disable the COMP2 EXTI line in event mode.
557   * @retval None
558   */
559 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2)
560 
561 /**
562   * @brief  Check whether the COMP2 EXTI line rising flag is set.
563   * @retval RESET or SET
564   */
565 #define __HAL_COMP_COMP2_EXTI_GET_RISING_FLAG()       LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP2)
566 
567 /**
568   * @brief  Clear the COMP2 EXTI rising flag.
569   * @retval None
570   */
571 #define __HAL_COMP_COMP2_EXTI_CLEAR_RISING_FLAG()     LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP2)
572 
573 /**
574   * @brief  Check whether the COMP2 EXTI line falling flag is set.
575   * @retval RESET or SET
576   */
577 #define __HAL_COMP_COMP2_EXTI_GET_FALLING_FLAG()      LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP2)
578 
579 /**
580   * @brief  Clear the COMP2 EXTI falling flag.
581   * @retval None
582   */
583 #define __HAL_COMP_COMP2_EXTI_CLEAR_FALLING_FLAG()    LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP2)
584 
585 /**
586   * @}
587   */
588 
589 /**
590   * @}
591   */
592 
593 
594 /* Private types -------------------------------------------------------------*/
595 /* Private constants ---------------------------------------------------------*/
596 /** @defgroup COMP_Private_Constants COMP Private Constants
597   * @{
598   */
599 
600 /** @defgroup COMP_WindowMode_Instance_Differentiator COMP window mode instance differentiator
601   * @{
602   */
603 #define COMP_WINDOWMODE_COMP2          0x00001000U       /*!< COMP window mode using common input of COMP instance: COMP2 */
604 /**
605   * @}
606   */
607 
608 /** @defgroup COMP_ExtiLine COMP EXTI Lines
609   * @{
610   */
611 #define COMP_EXTI_LINE_COMP1           (EXTI_IMR1_IM17)  /*!< EXTI line 17 connected to COMP1 output */
612 #define COMP_EXTI_LINE_COMP2           (EXTI_IMR1_IM18)  /*!< EXTI line 18 connected to COMP2 output */
613 /**
614   * @}
615   */
616 
617 /** @defgroup COMP_ExtiLine COMP EXTI Lines
618   * @{
619   */
620 #define COMP_EXTI_IT                        (0x00000001UL)  /*!< EXTI line event with interruption */
621 #define COMP_EXTI_EVENT                     (0x00000002UL)  /*!< EXTI line event only (without interruption) */
622 #define COMP_EXTI_RISING                    (0x00000010UL)  /*!< EXTI line event on rising edge */
623 #define COMP_EXTI_FALLING                   (0x00000020UL)  /*!< EXTI line event on falling edge */
624 /**
625   * @}
626   */
627 
628 /**
629   * @}
630   */
631 
632 /* Private macros ------------------------------------------------------------*/
633 /** @defgroup COMP_Private_Macros COMP Private Macros
634   * @{
635   */
636 
637 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
638   * @{
639   */
640 /**
641   * @brief  Get the specified EXTI line for a comparator instance.
642   * @param  __INSTANCE__  specifies the COMP instance.
643   * @retval value of @ref COMP_ExtiLine
644   */
645 #define COMP_GET_EXTI_LINE(__INSTANCE__)    (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1  \
646                                              : COMP_EXTI_LINE_COMP2)
647 /**
648   * @}
649   */
650 
651 /** @defgroup COMP_IS_COMP_Private_Definitions COMP private macros to check input parameters
652   * @{
653   */
654 #define IS_COMP_WINDOWMODE(__INSTANCE__, __WINDOWMODE__) \
655   (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE)                || \
656    ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)|| \
657    ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON)  )
658 
659 #define IS_COMP_WINDOWOUTPUT(__WINDOWOUTPUT__) (((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_EACH_COMP) || \
660                                                 ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_COMP1)     || \
661                                                 ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_COMP2)     || \
662                                                 ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_BOTH)        )
663 
664 #define IS_COMP_POWERMODE(__POWERMODE__)    (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED)    || \
665                                              ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED)    )
666 
667 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1)
668 
669 /* Note: On this STM32 series, comparator input minus parameters are          */
670 /*       the same on all COMP instances.                                      */
671 /*       However, comparator instance kept as macro parameter for             */
672 /*       compatibility with other STM32 families.                             */
673 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)  ||\
674                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)  ||\
675                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)  ||\
676                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)     ||\
677                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1))
678 
679 #define IS_COMP_HYSTERESIS(__HYSTERESIS__)  (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE)   || \
680                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW)    || \
681                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
682                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
683 
684 #define IS_COMP_OUTPUTPOL(__POL__)          (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
685                                              ((__POL__) == COMP_OUTPUTPOL_INVERTED))
686 
687 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)  \
688   ((((__INSTANCE__) == COMP1) &&                                               \
689     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
690      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||      \
691      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||      \
692      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1)))        \
693    ||                                                                          \
694    (((__INSTANCE__) == COMP2) &&                                               \
695     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)           ||      \
696      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2))))
697 
698 
699 #define IS_COMP_TRIGGERMODE(__MODE__)       (((__MODE__) == COMP_TRIGGERMODE_NONE)                 || \
700                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING)            || \
701                                              ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING)           || \
702                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING)    || \
703                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING)         || \
704                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING)        || \
705                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
706 
707 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW)     || \
708                                                 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
709 
710 /**
711   * @}
712   */
713 
714 /**
715   * @}
716   */
717 
718 
719 /* Exported functions --------------------------------------------------------*/
720 /** @addtogroup COMP_Exported_Functions
721   * @{
722   */
723 
724 /** @addtogroup COMP_Exported_Functions_Group1
725   * @{
726   */
727 
728 /* Initialization and de-initialization functions  **********************************/
729 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
730 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp);
731 void              HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
732 void              HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
733 
734 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
735 /* Callbacks Register/UnRegister functions  ***********************************/
736 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID,
737                                             pCOMP_CallbackTypeDef pCallback);
738 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
739 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
740 /**
741   * @}
742   */
743 
744 /* IO operation functions  *****************************************************/
745 /** @addtogroup COMP_Exported_Functions_Group2
746   * @{
747   */
748 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
749 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
750 void              HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
751 /**
752   * @}
753   */
754 
755 /* Peripheral Control functions  ************************************************/
756 /** @addtogroup COMP_Exported_Functions_Group3
757   * @{
758   */
759 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
760 uint32_t          HAL_COMP_GetOutputLevel(const COMP_HandleTypeDef *hcomp);
761 /* Callback in interrupt mode */
762 void              HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
763 /**
764   * @}
765   */
766 
767 /* Peripheral State functions  **************************************************/
768 /** @addtogroup COMP_Exported_Functions_Group4
769   * @{
770   */
771 HAL_COMP_StateTypeDef HAL_COMP_GetState(const COMP_HandleTypeDef *hcomp);
772 uint32_t              HAL_COMP_GetError(const COMP_HandleTypeDef *hcomp);
773 /**
774   * @}
775   */
776 
777 /**
778   * @}
779   */
780 
781 /**
782   * @}
783   */
784 #endif /* COMP1 || COMP2 */
785 /**
786   * @}
787   */
788 
789 #ifdef __cplusplus
790 }
791 #endif
792 
793 #endif /* STM32WBAxx_HAL_COMP_H */
794