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