1 /**
2   ******************************************************************************
3   * @file    stm32l5xx_hal_comp.h
4   * @author  MCD Application Team
5   * @brief   Header file of COMP HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2019 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32L5xx_HAL_COMP_H
21 #define STM32L5xx_HAL_COMP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l5xx_hal_def.h"
29 #include "stm32l5xx_ll_exti.h"
30 
31 /** @addtogroup STM32L5xx_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 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 PC5 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 PB6 for COMP2) */
181 #define COMP_INPUT_PLUS_IO3            (COMP_CSR_INPSEL_1)    /*!< Comparator input plus connected to IO3 (pin PA2 for COMP1, not available 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_DAC1_CH1      (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
194 #define COMP_INPUT_MINUS_DAC1_CH2      (COMP_CSR_INMSEL_2                     | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
195 #define COMP_INPUT_MINUS_IO1           (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1                    )                                           /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PB3 for COMP2) */
196 #define COMP_INPUT_MINUS_IO2           (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PB7 for COMP2) */
197 /**
198   * @}
199   */
200 
201 /** @defgroup COMP_Hysteresis COMP hysteresis
202   * @{
203   */
204 #define COMP_HYSTERESIS_NONE           (0x00000000UL)                       /*!< No hysteresis */
205 #define COMP_HYSTERESIS_LOW            (                  COMP_CSR_HYST_0)  /*!< Hysteresis level low */
206 #define COMP_HYSTERESIS_MEDIUM         (COMP_CSR_HYST_1                  )  /*!< Hysteresis level medium */
207 #define COMP_HYSTERESIS_HIGH           (COMP_CSR_HYST_1 | COMP_CSR_HYST_0)  /*!< Hysteresis level high */
208 /**
209   * @}
210   */
211 
212 /** @defgroup COMP_OutputPolarity COMP output Polarity
213   * @{
214   */
215 #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) */
216 #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) */
217 /**
218   * @}
219   */
220 
221 /** @defgroup COMP_BlankingSrce  COMP blanking source
222   * @{
223   */
224 #define COMP_BLANKINGSRC_NONE            (0x00000000UL)          /*!<Comparator output without blanking */
225 #define COMP_BLANKINGSRC_TIM1_OC5_COMP1  (COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */
226 #define COMP_BLANKINGSRC_TIM2_OC3_COMP1  (COMP_CSR_BLANKING_1)   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */
227 #define COMP_BLANKINGSRC_TIM3_OC3_COMP1  (COMP_CSR_BLANKING_2)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */
228 #define COMP_BLANKINGSRC_TIM3_OC4_COMP2  (COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */
229 #define COMP_BLANKINGSRC_TIM8_OC5_COMP2  (COMP_CSR_BLANKING_1)   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2) */
230 #define COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2)   /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP2) */
231 /**
232   * @}
233   */
234 
235 /** @defgroup COMP_OutputLevel COMP Output Level
236   * @{
237   */
238 /* Note: Comparator output level values are fixed to "0" and "1",             */
239 /* corresponding COMP register bit is managed by HAL function to match        */
240 /* with these values (independently of bit position in register).             */
241 
242 /* When output polarity is not inverted, comparator output is low when
243    the input plus is at a lower voltage than the input minus */
244 #define COMP_OUTPUT_LEVEL_LOW              (0x00000000UL)
245 /* When output polarity is not inverted, comparator output is high when
246    the input plus is at a higher voltage than the input minus */
247 #define COMP_OUTPUT_LEVEL_HIGH             (0x00000001UL)
248 /**
249   * @}
250   */
251 
252 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
253   * @{
254   */
255 #define COMP_TRIGGERMODE_NONE                 (0x00000000UL)                                            /*!< Comparator output triggering no External Interrupt Line */
256 #define COMP_TRIGGERMODE_IT_RISING            (COMP_EXTI_IT | COMP_EXTI_RISING)                         /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
257 #define COMP_TRIGGERMODE_IT_FALLING           (COMP_EXTI_IT | COMP_EXTI_FALLING)                        /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
258 #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 */
259 #define COMP_TRIGGERMODE_EVENT_RISING         (COMP_EXTI_EVENT | COMP_EXTI_RISING)                      /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
260 #define COMP_TRIGGERMODE_EVENT_FALLING        (COMP_EXTI_EVENT | COMP_EXTI_FALLING)                     /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
261 #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 */
262 /**
263   * @}
264   */
265 
266 /**
267   * @}
268   */
269 
270 /* Exported macro ------------------------------------------------------------*/
271 /** @defgroup COMP_Exported_Macros COMP Exported Macros
272   * @{
273   */
274 
275 /** @defgroup COMP_Handle_Management  COMP Handle Management
276   * @{
277   */
278 
279 /** @brief  Reset COMP handle state.
280   * @param  __HANDLE__  COMP handle
281   * @retval None
282   */
283 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
284 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{                                                  \
285                                                       (__HANDLE__)->State = HAL_COMP_STATE_RESET;      \
286                                                       (__HANDLE__)->MspInitCallback = NULL;            \
287                                                       (__HANDLE__)->MspDeInitCallback = NULL;          \
288                                                     } while(0)
289 #else
290 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
291 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
292 
293 /**
294   * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
295   * @param __HANDLE__ COMP handle
296   * @retval None
297   */
298 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
299 
300 /**
301   * @brief  Enable the specified comparator.
302   * @param  __HANDLE__  COMP handle
303   * @retval None
304   */
305 #define __HAL_COMP_ENABLE(__HANDLE__)              SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
306 
307 /**
308   * @brief  Disable the specified comparator.
309   * @param  __HANDLE__  COMP handle
310   * @retval None
311   */
312 #define __HAL_COMP_DISABLE(__HANDLE__)             CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
313 
314 /**
315   * @brief  Lock the specified comparator configuration.
316   * @note   Using this macro induce HAL COMP handle state machine being no
317   *         more in line with COMP instance state.
318   *         To keep HAL COMP handle state machine updated, it is recommended
319   *         to use function "HAL_COMP_Lock')".
320   * @param  __HANDLE__  COMP handle
321   * @retval None
322   */
323 #define __HAL_COMP_LOCK(__HANDLE__)                SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK)
324 
325 /**
326   * @brief  Check whether the specified comparator is locked.
327   * @param  __HANDLE__  COMP handle
328   * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
329   */
330 #define __HAL_COMP_IS_LOCKED(__HANDLE__)           (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK)
331 
332 /**
333   * @}
334   */
335 
336 /** @defgroup COMP_Exti_Management  COMP external interrupt line management
337   * @{
338   */
339 
340 /**
341   * @brief  Enable the COMP1 EXTI line rising edge trigger.
342   * @retval None
343   */
344 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
345 
346 /**
347   * @brief  Disable the COMP1 EXTI line rising edge trigger.
348   * @retval None
349   */
350 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
351 
352 /**
353   * @brief  Enable the COMP1 EXTI line falling edge trigger.
354   * @retval None
355   */
356 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
357 
358 /**
359   * @brief  Disable the COMP1 EXTI line falling edge trigger.
360   * @retval None
361   */
362 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
363 
364 /**
365   * @brief  Enable the COMP1 EXTI line rising & falling edge trigger.
366   * @retval None
367   */
368 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
369                                                                LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
370                                                                LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
371                                                              } while(0)
372 
373 /**
374   * @brief  Disable the COMP1 EXTI line rising & falling edge trigger.
375   * @retval None
376   */
377 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
378                                                                LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
379                                                                LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
380                                                              } while(0)
381 
382 /**
383   * @brief  Enable the COMP1 EXTI line in interrupt mode.
384   * @retval None
385   */
386 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP1)
387 
388 /**
389   * @brief  Disable the COMP1 EXTI line in interrupt mode.
390   * @retval None
391   */
392 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1)
393 
394 /**
395   * @brief  Generate a software interrupt on the COMP1 EXTI line.
396   * @retval None
397   */
398 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1)
399 
400 /**
401   * @brief  Enable the COMP1 EXTI line in event mode.
402   * @retval None
403   */
404 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1)
405 
406 /**
407   * @brief  Disable the COMP1 EXTI line in event mode.
408   * @retval None
409   */
410 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1)
411 
412 /**
413   * @brief  Check whether the COMP1 EXTI line rising flag is set.
414   * @retval RESET or SET
415   */
416 #define __HAL_COMP_COMP1_EXTI_GET_RISING_FLAG()       LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP1)
417 
418 /**
419   * @brief  Clear the COMP1 EXTI rising flag.
420   * @retval None
421   */
422 #define __HAL_COMP_COMP1_EXTI_CLEAR_RISING_FLAG()     LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP1)
423 
424 /**
425   * @brief  Check whether the COMP1 EXTI line falling flag is set.
426   * @retval RESET or SET
427   */
428 #define __HAL_COMP_COMP1_EXTI_GET_FALLING_FLAG()      LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP1)
429 
430 /**
431   * @brief  Clear the COMP1 EXTI falling flag.
432   * @retval None
433   */
434 #define __HAL_COMP_COMP1_EXTI_CLEAR_FALLING_FLAG()    LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP1)
435 
436 /**
437   * @brief  Enable the COMP2 EXTI line rising edge trigger.
438   * @retval None
439   */
440 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
441 
442 /**
443   * @brief  Disable the COMP2 EXTI line rising edge trigger.
444   * @retval None
445   */
446 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
447 
448 /**
449   * @brief  Enable the COMP2 EXTI line falling edge trigger.
450   * @retval None
451   */
452 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
453 
454 /**
455   * @brief  Disable the COMP2 EXTI line falling edge trigger.
456   * @retval None
457   */
458 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
459 
460 /**
461   * @brief  Enable the COMP2 EXTI line rising & falling edge trigger.
462   * @retval None
463   */
464 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
465                                                                LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
466                                                                LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
467                                                              } while(0)
468 
469 /**
470   * @brief  Disable the COMP2 EXTI line rising & falling edge trigger.
471   * @retval None
472   */
473 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
474                                                                LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
475                                                                LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
476                                                              } while(0)
477 
478 /**
479   * @brief  Enable the COMP2 EXTI line in interrupt mode.
480   * @retval None
481   */
482 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2)
483 
484 /**
485   * @brief  Disable the COMP2 EXTI line in interrupt mode.
486   * @retval None
487   */
488 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2)
489 
490 /**
491   * @brief  Generate a software interrupt on the COMP2 EXTI line.
492   * @retval None
493   */
494 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2)
495 
496 /**
497   * @brief  Enable the COMP2 EXTI line in event mode.
498   * @retval None
499   */
500 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2)
501 
502 /**
503   * @brief  Disable the COMP2 EXTI line in event mode.
504   * @retval None
505   */
506 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2)
507 
508 /**
509   * @brief  Check whether the COMP2 EXTI line rising flag is set.
510   * @retval RESET or SET
511   */
512 #define __HAL_COMP_COMP2_EXTI_GET_RISING_FLAG()       LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP2)
513 
514 /**
515   * @brief  Clear the COMP2 EXTI rising flag.
516   * @retval None
517   */
518 #define __HAL_COMP_COMP2_EXTI_CLEAR_RISING_FLAG()     LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP2)
519 
520 /**
521   * @brief  Check whether the COMP2 EXTI line falling flag is set.
522   * @retval RESET or SET
523   */
524 #define __HAL_COMP_COMP2_EXTI_GET_FALLING_FLAG()      LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP2)
525 
526 /**
527   * @brief  Clear the COMP2 EXTI falling flag.
528   * @retval None
529   */
530 #define __HAL_COMP_COMP2_EXTI_CLEAR_FALLING_FLAG()    LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP2)
531 
532 /**
533   * @}
534   */
535 
536 /**
537   * @}
538   */
539 
540 
541 /* Private types -------------------------------------------------------------*/
542 /* Private constants ---------------------------------------------------------*/
543 /** @defgroup COMP_Private_Constants COMP Private Constants
544   * @{
545   */
546 
547 /** @defgroup COMP_ExtiLine COMP EXTI Lines
548   * @{
549   */
550 #define COMP_EXTI_LINE_COMP1           (LL_EXTI_LINE_21)  /*!< EXTI line 21 connected to COMP1 output */
551 #define COMP_EXTI_LINE_COMP2           (LL_EXTI_LINE_22)  /*!< EXTI line 22 connected to COMP2 output */
552 /**
553   * @}
554   */
555 
556 /** @defgroup COMP_ExtiLine COMP EXTI Lines
557   * @{
558   */
559 #define COMP_EXTI_IT                        (0x00000001UL)  /*!< EXTI line event with interruption */
560 #define COMP_EXTI_EVENT                     (0x00000002UL)  /*!< EXTI line event only (without interruption) */
561 #define COMP_EXTI_RISING                    (0x00000010UL)  /*!< EXTI line event on rising edge */
562 #define COMP_EXTI_FALLING                   (0x00000020UL)  /*!< EXTI line event on falling edge */
563 /**
564   * @}
565   */
566 
567 /**
568   * @}
569   */
570 
571 /* Private macros ------------------------------------------------------------*/
572 /** @defgroup COMP_Private_Macros COMP Private Macros
573   * @{
574   */
575 
576 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
577   * @{
578   */
579 /**
580   * @brief  Get the specified EXTI line for a comparator instance.
581   * @param  __INSTANCE__  specifies the COMP instance.
582   * @retval value of @ref COMP_ExtiLine
583   */
584 #define COMP_GET_EXTI_LINE(__INSTANCE__)    (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1  \
585                                              : COMP_EXTI_LINE_COMP2)
586 /**
587   * @}
588   */
589 
590 /** @defgroup COMP_IS_COMP_Private_Definitions COMP private macros to check input parameters
591   * @{
592   */
593 #define IS_COMP_WINDOWMODE(__WINDOWMODE__)  (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE)                || \
594                                              ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)  )
595 
596 #define IS_COMP_POWERMODE(__POWERMODE__)    (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED)    || \
597                                              ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED)  || \
598                                              ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER)  )
599 
600 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) ((__COMP_INSTANCE__ == COMP1)                     \
601                                                                ? (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) ||  \
602                                                                   ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) ||  \
603                                                                   ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3)   ) \
604                                                                :                                                \
605                                                                (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) ||    \
606                                                                 ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2)   )   \
607                                                               )
608 
609 /* Note: On this STM32 series, comparator input minus parameters are          */
610 /*       the same on all COMP instances.                                      */
611 /*       However, comparator instance kept as macro parameter for             */
612 /*       compatibility with other STM32 families.                             */
613 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)  || \
614                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)  || \
615                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)  || \
616                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)     || \
617                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)    || \
618                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2)    || \
619                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)         || \
620                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2))
621 
622 #define IS_COMP_HYSTERESIS(__HYSTERESIS__)  (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE)   || \
623                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW)    || \
624                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
625                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
626 
627 #define IS_COMP_OUTPUTPOL(__POL__)          (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
628                                              ((__POL__) == COMP_OUTPUTPOL_INVERTED))
629 
630 #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__)                    \
631   (   ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)               \
632    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1)     \
633    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1)     \
634    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1)     \
635    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2)     \
636    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2)     \
637    || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2)    \
638   )
639 
640 #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)  \
641    ((((__INSTANCE__) == COMP1) &&                                               \
642     (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)            ||      \
643      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||      \
644      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||      \
645      ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1)))        \
646     ||                                                                          \
647     (((__INSTANCE__) == COMP2) &&                                               \
648      (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)           ||      \
649       ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2) ||      \
650       ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2) ||      \
651       ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2))))
652 
653 
654 #define IS_COMP_TRIGGERMODE(__MODE__)       (((__MODE__) == COMP_TRIGGERMODE_NONE)                 || \
655                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING)            || \
656                                              ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING)           || \
657                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING)    || \
658                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING)         || \
659                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING)        || \
660                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
661 
662 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW)     || \
663                                                 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
664 
665 /**
666   * @}
667   */
668 
669 /**
670   * @}
671   */
672 
673 
674 /* Exported functions --------------------------------------------------------*/
675 /** @addtogroup COMP_Exported_Functions
676   * @{
677   */
678 
679 /** @addtogroup COMP_Exported_Functions_Group1
680   * @{
681   */
682 
683 /* Initialization and de-initialization functions  **********************************/
684 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
685 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp);
686 void              HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
687 void              HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
688 
689 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
690 /* Callbacks Register/UnRegister functions  ***********************************/
691 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID,
692                                             pCOMP_CallbackTypeDef pCallback);
693 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
694 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
695 /**
696   * @}
697   */
698 
699 /* IO operation functions  *****************************************************/
700 /** @addtogroup COMP_Exported_Functions_Group2
701   * @{
702   */
703 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
704 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
705 void              HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
706 /**
707   * @}
708   */
709 
710 /* Peripheral Control functions  ************************************************/
711 /** @addtogroup COMP_Exported_Functions_Group3
712   * @{
713   */
714 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
715 uint32_t          HAL_COMP_GetOutputLevel(const COMP_HandleTypeDef *hcomp);
716 /* Callback in interrupt mode */
717 void              HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
718 /**
719   * @}
720   */
721 
722 /* Peripheral State functions  **************************************************/
723 /** @addtogroup COMP_Exported_Functions_Group4
724   * @{
725   */
726 HAL_COMP_StateTypeDef HAL_COMP_GetState(const COMP_HandleTypeDef *hcomp);
727 uint32_t              HAL_COMP_GetError(const COMP_HandleTypeDef *hcomp);
728 /**
729   * @}
730   */
731 
732 /**
733   * @}
734   */
735 
736 /**
737   * @}
738   */
739 #endif /* COMP1 || COMP2 */
740 /**
741   * @}
742   */
743 
744 #ifdef __cplusplus
745 }
746 #endif
747 
748 #endif /* STM32L5xx_HAL_COMP_H */
749