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_INTERMSPEED     (COMP_CSR_PWRMODE_0)   /*!< Intermediate speed */
233 #define COMP_POWERMODE_MEDIUMSPEED     (COMP_CSR_PWRMODE_1)   /*!< Medium speed */
234 #define COMP_POWERMODE_ULTRALOWPOWER   (COMP_CSR_PWRMODE_1 | COMP_CSR_PWRMODE_0) /*!< Ultra-low power */
235 /**
236   * @}
237   */
238 
239 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
240   * @{
241   */
242 #define COMP_INPUT_PLUS_IO1          (0x00000000UL)           /*!< Comparator input plus connected to IO1 (pin PA2 for COMP1, pin PA0 for COMP2) */
243 /**
244   * @}
245   */
246 
247 /** @defgroup COMP_InputMinus COMP input minus (inverting input)
248   * @{
249   */
250 #define COMP_INPUT_MINUS_1_4VREFINT    (0x00000000UL)                                                                  /*!< Comparator input minus connected to 1/4 VrefInt  */
251 #define COMP_INPUT_MINUS_1_2VREFINT    (                                                            COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt  */
252 #define COMP_INPUT_MINUS_3_4VREFINT    (                                        COMP_CSR_INMSEL_1                    ) /*!< Comparator input minus connected to 3/4 VrefInt  */
253 #define COMP_INPUT_MINUS_VREFINT       (                                        COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to VrefInt */
254 #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) */
255 /**
256   * @}
257   */
258 
259 /** @defgroup COMP_Hysteresis COMP hysteresis
260   * @{
261   */
262 #define COMP_HYSTERESIS_NONE           (0x00000000UL)                       /*!< No hysteresis */
263 #define COMP_HYSTERESIS_LOW            (                  COMP_CSR_HYST_0)  /*!< Hysteresis level low */
264 #define COMP_HYSTERESIS_MEDIUM         (COMP_CSR_HYST_1                  )  /*!< Hysteresis level medium */
265 #define COMP_HYSTERESIS_HIGH           (COMP_CSR_HYST_1 | COMP_CSR_HYST_0)  /*!< Hysteresis level high */
266 /**
267   * @}
268   */
269 
270 /** @defgroup COMP_OutputPolarity COMP output Polarity
271   * @{
272   */
273 #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) */
274 #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) */
275 /**
276   * @}
277   */
278 
279 /** @defgroup COMP_BlankingSrce  COMP blanking source
280   * @{
281   */
282 #define COMP_BLANKINGSRC_NONE            (0x00000000UL)          /*!<Comparator output without blanking */
283 #define COMP_BLANKINGSRC_TIM1_OC5_COMP1  (COMP_CSR_BLANKSEL_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */
284 #define COMP_BLANKINGSRC_TIM2_OC3_COMP1  (COMP_CSR_BLANKSEL_1)   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */
285 #define COMP_BLANKINGSRC_TIM3_OC3_COMP1  (COMP_CSR_BLANKSEL_2)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */
286 #define COMP_BLANKINGSRC_TIM3_OC4_COMP2  (COMP_CSR_BLANKSEL_0)   /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */
287 /**
288   * @}
289   */
290 
291 /** @defgroup COMP_OutputLevel COMP Output Level
292   * @{
293   */
294 /* Note: Comparator output level values are fixed to "0" and "1",             */
295 /* corresponding COMP register bit is managed by HAL function to match        */
296 /* with these values (independently of bit position in register).             */
297 
298 /* When output polarity is not inverted, comparator output is low when
299    the input plus is at a lower voltage than the input minus */
300 #define COMP_OUTPUT_LEVEL_LOW              (0x00000000UL)
301 /* When output polarity is not inverted, comparator output is high when
302    the input plus is at a higher voltage than the input minus */
303 #define COMP_OUTPUT_LEVEL_HIGH             (0x00000001UL)
304 /**
305   * @}
306   */
307 
308 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
309   * @{
310   */
311 #define COMP_TRIGGERMODE_NONE                 (0x00000000UL)                                            /*!< Comparator output triggering no External Interrupt Line */
312 #define COMP_TRIGGERMODE_IT_RISING            (COMP_EXTI_IT | COMP_EXTI_RISING)                         /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
313 #define COMP_TRIGGERMODE_IT_FALLING           (COMP_EXTI_IT | COMP_EXTI_FALLING)                        /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
314 #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 */
315 #define COMP_TRIGGERMODE_EVENT_RISING         (COMP_EXTI_EVENT | COMP_EXTI_RISING)                      /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
316 #define COMP_TRIGGERMODE_EVENT_FALLING        (COMP_EXTI_EVENT | COMP_EXTI_FALLING)                     /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
317 #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 */
318 /**
319   * @}
320   */
321 
322 /**
323   * @}
324   */
325 
326 /* Exported macro ------------------------------------------------------------*/
327 /** @defgroup COMP_Exported_Macros COMP Exported Macros
328   * @{
329   */
330 
331 /** @defgroup COMP_Handle_Management  COMP Handle Management
332   * @{
333   */
334 
335 /** @brief  Reset COMP handle state.
336   * @param  __HANDLE__  COMP handle
337   * @retval None
338   */
339 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
340 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{                                                  \
341                                                       (__HANDLE__)->State = HAL_COMP_STATE_RESET;      \
342                                                       (__HANDLE__)->MspInitCallback = NULL;            \
343                                                       (__HANDLE__)->MspDeInitCallback = NULL;          \
344                                                     } while(0)
345 #else
346 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
347 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
348 
349 /**
350   * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
351   * @param __HANDLE__ COMP handle
352   * @retval None
353   */
354 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
355 
356 /**
357   * @brief  Enable the specified comparator.
358   * @param  __HANDLE__  COMP handle
359   * @retval None
360   */
361 #define __HAL_COMP_ENABLE(__HANDLE__)       SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
362 
363 /**
364   * @brief  Disable the specified comparator.
365   * @param  __HANDLE__  COMP handle
366   * @retval None
367   */
368 #define __HAL_COMP_DISABLE(__HANDLE__)      CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
369 
370 /**
371   * @brief  Lock the specified comparator configuration.
372   * @note   Using this macro induce HAL COMP handle state machine being no
373   *         more in line with COMP instance state.
374   *         To keep HAL COMP handle state machine updated, it is recommended
375   *         to use function "HAL_COMP_Lock')".
376   * @param  __HANDLE__  COMP handle
377   * @retval None
378   */
379 #define __HAL_COMP_LOCK(__HANDLE__)         SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK)
380 
381 /**
382   * @brief  Check whether the specified comparator is locked.
383   * @param  __HANDLE__  COMP handle
384   * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
385   */
386 #define __HAL_COMP_IS_LOCKED(__HANDLE__)    (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK)
387 
388 /**
389   * @}
390   */
391 
392 /** @defgroup COMP_Exti_Management  COMP external interrupt line management
393   * @{
394   */
395 /**
396   * @brief  Enable the COMP1 EXTI line rising edge trigger.
397   * @retval None
398   */
399 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
400 
401 /**
402   * @brief  Disable the COMP1 EXTI line rising edge trigger.
403   * @retval None
404   */
405 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
406 
407 /**
408   * @brief  Enable the COMP1 EXTI line falling edge trigger.
409   * @retval None
410   */
411 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
412 
413 /**
414   * @brief  Disable the COMP1 EXTI line falling edge trigger.
415   * @retval None
416   */
417 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
418 
419 /**
420   * @brief  Enable the COMP1 EXTI line rising & falling edge trigger.
421   * @retval None
422   */
423 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do {                                                        \
424                                                                 LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1);   \
425                                                                 LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1);  \
426                                                               } while(0)
427 
428 /**
429   * @brief  Disable the COMP1 EXTI line rising & falling edge trigger.
430   * @retval None
431   */
432 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do {                                                       \
433                                                                  LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
434                                                                  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1);\
435                                                                } while(0)
436 
437 /**
438   * @brief  Enable the COMP1 EXTI line in interrupt mode.
439   * @retval None
440   */
441 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP1)
442 
443 /**
444   * @brief  Disable the COMP1 EXTI line in interrupt mode.
445   * @retval None
446   */
447 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1)
448 
449 /**
450   * @brief  Generate a software interrupt on the COMP1 EXTI line.
451   * @retval None
452   */
453 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1)
454 
455 /**
456   * @brief  Enable the COMP1 EXTI line in event mode.
457   * @retval None
458   */
459 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1)
460 
461 /**
462   * @brief  Disable the COMP1 EXTI line in event mode.
463   * @retval None
464   */
465 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1)
466 
467 /**
468   * @brief  Check whether the COMP1 EXTI line rising flag is set.
469   * @retval RESET or SET
470   */
471 #define __HAL_COMP_COMP1_EXTI_GET_RISING_FLAG()       LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP1)
472 
473 /**
474   * @brief  Clear the COMP1 EXTI rising flag.
475   * @retval None
476   */
477 #define __HAL_COMP_COMP1_EXTI_CLEAR_RISING_FLAG()     LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP1)
478 
479 /**
480   * @brief  Check whether the COMP1 EXTI line falling flag is set.
481   * @retval RESET or SET
482   */
483 #define __HAL_COMP_COMP1_EXTI_GET_FALLING_FLAG()      LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP1)
484 
485 /**
486   * @brief  Clear the COMP1 EXTI falling flag.
487   * @retval None
488   */
489 #define __HAL_COMP_COMP1_EXTI_CLEAR_FALLING_FLAG()    LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP1)
490 
491 /**
492   * @brief  Enable the COMP2 EXTI line rising edge trigger.
493   * @retval None
494   */
495 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
496 
497 /**
498   * @brief  Disable the COMP2 EXTI line rising edge trigger.
499   * @retval None
500   */
501 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
502 
503 /**
504   * @brief  Enable the COMP2 EXTI line falling edge trigger.
505   * @retval None
506   */
507 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
508 
509 /**
510   * @brief  Disable the COMP2 EXTI line falling edge trigger.
511   * @retval None
512   */
513 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
514 
515 /**
516   * @brief  Enable the COMP2 EXTI line rising & falling edge trigger.
517   * @retval None
518   */
519 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do {                                                        \
520                                                                 LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2);   \
521                                                                 LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2);  \
522                                                               } while(0)
523 
524 /**
525   * @brief  Disable the COMP2 EXTI line rising & falling edge trigger.
526   * @retval None
527   */
528 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do {                                                       \
529                                                                  LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
530                                                                  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2);\
531                                                                } while(0)
532 
533 /**
534   * @brief  Enable the COMP2 EXTI line in interrupt mode.
535   * @retval None
536   */
537 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2)
538 
539 /**
540   * @brief  Disable the COMP2 EXTI line in interrupt mode.
541   * @retval None
542   */
543 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2)
544 
545 /**
546   * @brief  Generate a software interrupt on the COMP2 EXTI line.
547   * @retval None
548   */
549 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2)
550 
551 /**
552   * @brief  Enable the COMP2 EXTI line in event mode.
553   * @retval None
554   */
555 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2)
556 
557 /**
558   * @brief  Disable the COMP2 EXTI line in event mode.
559   * @retval None
560   */
561 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2)
562 
563 /**
564   * @brief  Check whether the COMP2 EXTI line rising flag is set.
565   * @retval RESET or SET
566   */
567 #define __HAL_COMP_COMP2_EXTI_GET_RISING_FLAG()       LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP2)
568 
569 /**
570   * @brief  Clear the COMP2 EXTI rising flag.
571   * @retval None
572   */
573 #define __HAL_COMP_COMP2_EXTI_CLEAR_RISING_FLAG()     LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP2)
574 
575 /**
576   * @brief  Check whether the COMP2 EXTI line falling flag is set.
577   * @retval RESET or SET
578   */
579 #define __HAL_COMP_COMP2_EXTI_GET_FALLING_FLAG()      LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP2)
580 
581 /**
582   * @brief  Clear the COMP2 EXTI falling flag.
583   * @retval None
584   */
585 #define __HAL_COMP_COMP2_EXTI_CLEAR_FALLING_FLAG()    LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP2)
586 
587 /**
588   * @}
589   */
590 
591 /**
592   * @}
593   */
594 
595 
596 /* Private types -------------------------------------------------------------*/
597 /* Private constants ---------------------------------------------------------*/
598 /** @defgroup COMP_Private_Constants COMP Private Constants
599   * @{
600   */
601 
602 /** @defgroup COMP_WindowMode_Instance_Differentiator COMP window mode instance differentiator
603   * @{
604   */
605 #define COMP_WINDOWMODE_COMP2          0x00001000U       /*!< COMP window mode using common input of COMP instance: COMP2 */
606 /**
607   * @}
608   */
609 
610 /** @defgroup COMP_ExtiLine COMP EXTI Lines
611   * @{
612   */
613 #define COMP_EXTI_LINE_COMP1           (EXTI_IMR1_IM17)  /*!< EXTI line 17 connected to COMP1 output */
614 #define COMP_EXTI_LINE_COMP2           (EXTI_IMR1_IM18)  /*!< EXTI line 18 connected to COMP2 output */
615 /**
616   * @}
617   */
618 
619 /** @defgroup COMP_ExtiLine COMP EXTI Lines
620   * @{
621   */
622 #define COMP_EXTI_IT                        (0x00000001UL)  /*!< EXTI line event with interruption */
623 #define COMP_EXTI_EVENT                     (0x00000002UL)  /*!< EXTI line event only (without interruption) */
624 #define COMP_EXTI_RISING                    (0x00000010UL)  /*!< EXTI line event on rising edge */
625 #define COMP_EXTI_FALLING                   (0x00000020UL)  /*!< EXTI line event on falling edge */
626 /**
627   * @}
628   */
629 
630 /**
631   * @}
632   */
633 
634 /* Private macros ------------------------------------------------------------*/
635 /** @defgroup COMP_Private_Macros COMP Private Macros
636   * @{
637   */
638 
639 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
640   * @{
641   */
642 /**
643   * @brief  Get the specified EXTI line for a comparator instance.
644   * @param  __INSTANCE__  specifies the COMP instance.
645   * @retval value of @ref COMP_ExtiLine
646   */
647 #define COMP_GET_EXTI_LINE(__INSTANCE__)    (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1  \
648                                              : COMP_EXTI_LINE_COMP2)
649 /**
650   * @}
651   */
652 
653 /** @defgroup COMP_IS_COMP_Private_Definitions COMP private macros to check input parameters
654   * @{
655   */
656 #define IS_COMP_WINDOWMODE(__INSTANCE__, __WINDOWMODE__) \
657   (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE)                || \
658    ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)|| \
659    ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON)  )
660 
661 #define IS_COMP_WINDOWOUTPUT(__WINDOWOUTPUT__) (((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_EACH_COMP) || \
662                                                 ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_COMP1)     || \
663                                                 ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_COMP2)     || \
664                                                 ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_BOTH)        )
665 
666 #define IS_COMP_POWERMODE(__POWERMODE__)    (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED)    || \
667                                              ((__POWERMODE__) == COMP_POWERMODE_INTERMSPEED)  || \
668                                              ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED)  || \
669                                              ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER)  )
670 
671 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1)
672 
673 /* Note: On this STM32 series, comparator input minus parameters are          */
674 /*       the same on all COMP instances.                                      */
675 /*       However, comparator instance kept as macro parameter for             */
676 /*       compatibility with other STM32 series.                               */
677 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)  || \
678                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)  || \
679                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)  || \
680                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)     || \
681                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1))
682 
683 #define IS_COMP_HYSTERESIS(__HYSTERESIS__)  (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE)   || \
684                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW)    || \
685                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
686                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
687 
688 #define IS_COMP_OUTPUTPOL(__POL__)          (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
689                                              ((__POL__) == COMP_OUTPUTPOL_INVERTED))
690 
691 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)  \
692   ((((__INSTANCE__) == COMP1) &&                                                \
693     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
694      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||      \
695      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||      \
696      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1)))        \
697    ||                                                                           \
698    (((__INSTANCE__) == COMP2) &&                                                \
699     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
700      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2))))
701 
702 
703 #define IS_COMP_TRIGGERMODE(__MODE__)       (((__MODE__) == COMP_TRIGGERMODE_NONE)                 || \
704                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING)            || \
705                                              ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING)           || \
706                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING)    || \
707                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING)         || \
708                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING)        || \
709                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
710 
711 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW)     || \
712                                                 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
713 
714 /**
715   * @}
716   */
717 
718 /**
719   * @}
720   */
721 
722 
723 /* Exported functions --------------------------------------------------------*/
724 /** @addtogroup COMP_Exported_Functions
725   * @{
726   */
727 
728 /** @addtogroup COMP_Exported_Functions_Group1
729   * @{
730   */
731 
732 /* Initialization and de-initialization functions  **********************************/
733 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
734 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp);
735 void              HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
736 void              HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
737 
738 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
739 /* Callbacks Register/UnRegister functions  ***********************************/
740 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID,
741                                             pCOMP_CallbackTypeDef pCallback);
742 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
743 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
744 /**
745   * @}
746   */
747 
748 /* IO operation functions  *****************************************************/
749 /** @addtogroup COMP_Exported_Functions_Group2
750   * @{
751   */
752 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
753 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
754 void              HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
755 /**
756   * @}
757   */
758 
759 /* Peripheral Control functions  ************************************************/
760 /** @addtogroup COMP_Exported_Functions_Group3
761   * @{
762   */
763 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
764 uint32_t          HAL_COMP_GetOutputLevel(const COMP_HandleTypeDef *hcomp);
765 /* Callback in interrupt mode */
766 void              HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
767 /**
768   * @}
769   */
770 
771 /* Peripheral State functions  **************************************************/
772 /** @addtogroup COMP_Exported_Functions_Group4
773   * @{
774   */
775 HAL_COMP_StateTypeDef HAL_COMP_GetState(const COMP_HandleTypeDef *hcomp);
776 uint32_t              HAL_COMP_GetError(const COMP_HandleTypeDef *hcomp);
777 /**
778   * @}
779   */
780 
781 /**
782   * @}
783   */
784 
785 /**
786   * @}
787   */
788 #endif /* COMP1 || COMP2 */
789 /**
790   * @}
791   */
792 
793 #ifdef __cplusplus
794 }
795 #endif
796 
797 #endif /* STM32WBAxx_HAL_COMP_H */
798