source: trunk/firmware/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_hal_comp.h

Last change on this file was 6, checked in by f.jahn, 3 months ago
File size: 34.3 KB
Line 
1/**
2  ******************************************************************************
3  * @file    stm32g0xx_hal_comp.h
4  * @author  MCD Application Team
5  * @brief   Header file of COMP HAL module.
6  ******************************************************************************
7  * @attention
8  *
9  * <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
10  * All rights reserved.</center></h2>
11  *
12  * This software component is licensed by ST under BSD 3-Clause license,
13  * the "License"; You may not use this file except in compliance with the
14  * License. You may obtain a copy of the License at:
15  *                        opensource.org/licenses/BSD-3-Clause
16  *
17  ******************************************************************************
18  */
19
20/* Define to prevent recursive inclusion -------------------------------------*/
21#ifndef STM32G0xx_HAL_COMP_H
22#define STM32G0xx_HAL_COMP_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/* Includes ------------------------------------------------------------------*/
29#include "stm32g0xx_hal_def.h"
30#include "stm32g0xx_ll_exti.h"
31
32/** @addtogroup STM32G0xx_HAL_Driver
33  * @{
34  */
35#if defined (COMP1) || defined (COMP2)
36
37/** @addtogroup COMP
38  * @{
39  */
40
41/* Exported types ------------------------------------------------------------*/
42/** @defgroup COMP_Exported_Types COMP Exported Types
43  * @{
44  */
45
46/**
47  * @brief  COMP Init structure definition
48  */
49typedef struct
50{
51
52  uint32_t WindowMode;         /*!< Set window mode of a pair of comparators instances
53                                    (2 consecutive instances odd and even COMP<x> and COMP<x+1>).
54                                    Note: HAL COMP driver allows to set window mode from any COMP 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)
89typedef 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)
103typedef struct __COMP_HandleTypeDef
104#else
105typedef struct
106#endif
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  */
124typedef 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  */
134typedef  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/** @defgroup COMP_WindowMode COMP Window Mode
159  * @{
160  */
161#define COMP_WINDOWMODE_DISABLE                 (0x00000000UL)         /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */
162#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). */
163#define COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (COMP_CSR_WINMODE | COMP_WINDOWMODE_COMP2) /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP2 input plus (COMP1 input plus is no more accessible). */
164/**
165  * @}
166  */
167
168/** @defgroup COMP_WindowOutput COMP Window output
169  * @{
170  */
171#define COMP_WINDOWOUTPUT_EACH_COMP             (0x00000000UL)                            /*!< Window output default mode: Comparators output are indicating each their own state. To know window mode state: each comparator output must be read, if "((COMPx exclusive or COMPy) == 1)" then monitored signal is within comparators window.  */
172#define COMP_WINDOWOUTPUT_COMP1                 (COMP_CSR_WINOUT)                         /*!< Window output synthetized on COMP1 output: COMP1 output is no more indicating its own state, but global window mode state (logical high means monitored signal is within comparators window). */
173#define COMP_WINDOWOUTPUT_COMP2                 (COMP_CSR_WINOUT | COMP_WINDOWMODE_COMP2) /*!< Window output synthetized on COMP2 output: COMP2 output is no more indicating its own state, but global window mode state (logical high means monitored signal is within comparators window). */
174#define COMP_WINDOWOUTPUT_BOTH                  (0x00000001UL)                            /*!< Window output synthetized on both COMP1 and COMP2 output: COMP1 and COMP2 outputs are no more indicating their own state, but global window mode state (logical high means monitored signal is within comparators window). This is a specific configuraton (technically possible but not relevant from application point of view: 2 comparators output used for the same signal level), standard configuraton for window mode is one of the 3 settings above. */
175/**
176  * @}
177  */
178
179/** @defgroup COMP_PowerMode COMP power mode
180  * @{
181  */
182/* Note: For the characteristics of comparator power modes                    */
183/*       (propagation delay and power consumption),                           */
184/*       refer to device datasheet.                                           */
185#define COMP_POWERMODE_HIGHSPEED       (0x00000000UL)         /*!< High Speed */
186#define COMP_POWERMODE_MEDIUMSPEED     (COMP_CSR_PWRMODE_0)   /*!< Medium Speed */
187/**
188  * @}
189  */
190
191/** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
192  * @{
193  */
194#define COMP_INPUT_PLUS_IO1            (0x00000000UL)         /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */
195#define COMP_INPUT_PLUS_IO2            (COMP_CSR_INPSEL_0)    /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
196#define COMP_INPUT_PLUS_IO3            (COMP_CSR_INPSEL_1)    /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */
197/**
198  * @}
199  */
200
201/** @defgroup COMP_InputMinus COMP input minus (inverting input)
202  * @{
203  */
204#define COMP_INPUT_MINUS_1_4VREFINT    (0x00000000UL)                                                                  /*!< Comparator input minus connected to 1/4 VrefInt  */
205#define COMP_INPUT_MINUS_1_2VREFINT    (                                                            COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt  */
206#define COMP_INPUT_MINUS_3_4VREFINT    (                                        COMP_CSR_INMSEL_1                    ) /*!< Comparator input minus connected to 3/4 VrefInt  */
207#define COMP_INPUT_MINUS_VREFINT       (                                        COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to VrefInt */
208#define COMP_INPUT_MINUS_DAC1_CH1      (                    COMP_CSR_INMSEL_2                                        ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1)  */
209#define COMP_INPUT_MINUS_DAC1_CH2      (                    COMP_CSR_INMSEL_2                     | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2)  */
210#define COMP_INPUT_MINUS_IO1           (                    COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1                    ) /*!< Comparator input minus connected to IO1 (pin PA9 for COMP1, pin PB3 for COMP2) */
211#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) */
212#define COMP_INPUT_MINUS_IO3           (COMP_CSR_INMSEL_3                                                            ) /*!< Comparator input minus connected to IO3 (pin PA0 for COMP1, pin PA2 for COMP2) */
213/**
214  * @}
215  */
216
217/** @defgroup COMP_Hysteresis COMP hysteresis
218  * @{
219  */
220#define COMP_HYSTERESIS_NONE           (0x00000000UL)                       /*!< No hysteresis */
221#define COMP_HYSTERESIS_LOW            (                  COMP_CSR_HYST_0)  /*!< Hysteresis level low */
222#define COMP_HYSTERESIS_MEDIUM         (COMP_CSR_HYST_1                  )  /*!< Hysteresis level medium */
223#define COMP_HYSTERESIS_HIGH           (COMP_CSR_HYST_1 | COMP_CSR_HYST_0)  /*!< Hysteresis level high */
224/**
225  * @}
226  */
227
228/** @defgroup COMP_OutputPolarity COMP output Polarity
229  * @{
230  */
231#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) */
232#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) */
233/**
234  * @}
235  */
236
237/** @defgroup COMP_BlankingSrce  COMP blanking source
238  * @{
239  */
240#define COMP_BLANKINGSRC_NONE            (0x00000000UL)          /*!<Comparator output without blanking */
241/* Note: Output blanking source common to all COMP instances */
242#define COMP_BLANKINGSRC_TIM1_OC4        (COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC4 (common to all COMP instances: COMP1, COMP2) */
243#define COMP_BLANKINGSRC_TIM1_OC5        (COMP_CSR_BLANKING_1)   /*!< Comparator output blanking source TIM1 OC5 (common to all COMP instances: COMP1, COMP2) */
244#define COMP_BLANKINGSRC_TIM2_OC3        (COMP_CSR_BLANKING_2)   /*!< Comparator output blanking source TIM2 OC3 (common to all COMP instances: COMP1, COMP2) */
245#define COMP_BLANKINGSRC_TIM3_OC3        (COMP_CSR_BLANKING_3)   /*!< Comparator output blanking source TIM3 OC3 (common to all COMP instances: COMP1, COMP2) */
246#define COMP_BLANKINGSRC_TIM15_OC2       (COMP_CSR_BLANKING_4)   /*!< Comparator output blanking source TIM15 OC2 (common to all COMP instances: COMP1, COMP2) */
247/**
248  * @}
249  */
250
251/** @defgroup COMP_OutputLevel COMP Output Level
252  * @{
253  */
254/* Note: Comparator output level values are fixed to "0" and "1",             */
255/* corresponding COMP register bit is managed by HAL function to match        */
256/* with these values (independently of bit position in register).             */
257
258/* When output polarity is not inverted, comparator output is low when
259   the input plus is at a lower voltage than the input minus */
260#define COMP_OUTPUT_LEVEL_LOW              (0x00000000UL)
261/* When output polarity is not inverted, comparator output is high when
262   the input plus is at a higher voltage than the input minus */
263#define COMP_OUTPUT_LEVEL_HIGH             (0x00000001UL)
264/**
265  * @}
266  */
267
268/** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
269  * @{
270  */
271#define COMP_TRIGGERMODE_NONE                 (0x00000000UL)                                            /*!< Comparator output triggering no External Interrupt Line */
272#define COMP_TRIGGERMODE_IT_RISING            (COMP_EXTI_IT | COMP_EXTI_RISING)                         /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
273#define COMP_TRIGGERMODE_IT_FALLING           (COMP_EXTI_IT | COMP_EXTI_FALLING)                        /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
274#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 */
275#define COMP_TRIGGERMODE_EVENT_RISING         (COMP_EXTI_EVENT | COMP_EXTI_RISING)                      /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
276#define COMP_TRIGGERMODE_EVENT_FALLING        (COMP_EXTI_EVENT | COMP_EXTI_FALLING)                     /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
277#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 */
278/**
279  * @}
280  */
281
282/**
283  * @}
284  */
285
286/* Exported macro ------------------------------------------------------------*/
287/** @defgroup COMP_Exported_Macros COMP Exported Macros
288  * @{
289  */
290
291/** @defgroup COMP_Handle_Management  COMP Handle Management
292  * @{
293  */
294
295/** @brief  Reset COMP handle state.
296  * @param  __HANDLE__  COMP handle
297  * @retval None
298  */
299#if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
300#define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{                                                  \
301                                                      (__HANDLE__)->State = HAL_COMP_STATE_RESET;      \
302                                                      (__HANDLE__)->MspInitCallback = NULL;            \
303                                                      (__HANDLE__)->MspDeInitCallback = NULL;          \
304                                                    } while(0)
305#else
306#define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
307#endif
308
309/**
310  * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
311  * @param __HANDLE__ COMP handle
312  * @retval None
313  */
314#define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
315
316/**
317  * @brief  Enable the specified comparator.
318  * @param  __HANDLE__  COMP handle
319  * @retval None
320  */
321#define __HAL_COMP_ENABLE(__HANDLE__)              SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
322
323/**
324  * @brief  Disable the specified comparator.
325  * @param  __HANDLE__  COMP handle
326  * @retval None
327  */
328#define __HAL_COMP_DISABLE(__HANDLE__)             CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
329
330/**
331  * @brief  Lock the specified comparator configuration.
332  * @note   Using this macro induce HAL COMP handle state machine being no
333  *         more in line with COMP instance state.
334  *         To keep HAL COMP handle state machine updated, it is recommended
335  *         to use function "HAL_COMP_Lock')".
336  * @param  __HANDLE__  COMP handle
337  * @retval None
338  */
339#define __HAL_COMP_LOCK(__HANDLE__)                SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK)
340
341/**
342  * @brief  Check whether the specified comparator is locked.
343  * @param  __HANDLE__  COMP handle
344  * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
345  */
346#define __HAL_COMP_IS_LOCKED(__HANDLE__)           (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK)
347
348/**
349  * @}
350  */
351
352/** @defgroup COMP_Exti_Management  COMP external interrupt line management
353  * @{
354  */
355
356/**
357  * @brief  Enable the COMP1 EXTI line rising edge trigger.
358  * @retval None
359  */
360#define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
361
362/**
363  * @brief  Disable the COMP1 EXTI line rising edge trigger.
364  * @retval None
365  */
366#define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
367
368/**
369  * @brief  Enable the COMP1 EXTI line falling edge trigger.
370  * @retval None
371  */
372#define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
373
374/**
375  * @brief  Disable the COMP1 EXTI line falling edge trigger.
376  * @retval None
377  */
378#define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
379
380/**
381  * @brief  Enable the COMP1 EXTI line rising & falling edge trigger.
382  * @retval None
383  */
384#define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
385                                                               LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
386                                                               LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
387                                                             } while(0)
388
389/**
390  * @brief  Disable the COMP1 EXTI line rising & falling edge trigger.
391  * @retval None
392  */
393#define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
394                                                               LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
395                                                               LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
396                                                             } while(0)
397
398/**
399  * @brief  Enable the COMP1 EXTI line in interrupt mode.
400  * @retval None
401  */
402#define __HAL_COMP_COMP1_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP1)
403
404/**
405  * @brief  Disable the COMP1 EXTI line in interrupt mode.
406  * @retval None
407  */
408#define __HAL_COMP_COMP1_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1)
409
410/**
411  * @brief  Generate a software interrupt on the COMP1 EXTI line.
412  * @retval None
413  */
414#define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1)
415
416/**
417  * @brief  Enable the COMP1 EXTI line in event mode.
418  * @retval None
419  */
420#define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1)
421
422/**
423  * @brief  Disable the COMP1 EXTI line in event mode.
424  * @retval None
425  */
426#define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1)
427
428/**
429  * @brief  Check whether the COMP1 EXTI line rising flag is set.
430  * @retval RESET or SET
431  */
432#define __HAL_COMP_COMP1_EXTI_GET_RISING_FLAG()       LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP1)
433
434/**
435  * @brief  Clear the COMP1 EXTI rising flag.
436  * @retval None
437  */
438#define __HAL_COMP_COMP1_EXTI_CLEAR_RISING_FLAG()     LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP1)
439
440/**
441  * @brief  Check whether the COMP1 EXTI line falling flag is set.
442  * @retval RESET or SET
443  */
444#define __HAL_COMP_COMP1_EXTI_GET_FALLING_FLAG()      LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP1)
445
446/**
447  * @brief  Clear the COMP1 EXTI falling flag.
448  * @retval None
449  */
450#define __HAL_COMP_COMP1_EXTI_CLEAR_FALLING_FLAG()    LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP1)
451
452/**
453  * @brief  Enable the COMP2 EXTI line rising edge trigger.
454  * @retval None
455  */
456#define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()    LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
457
458/**
459  * @brief  Disable the COMP2 EXTI line rising edge trigger.
460  * @retval None
461  */
462#define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE()   LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
463
464/**
465  * @brief  Enable the COMP2 EXTI line falling edge trigger.
466  * @retval None
467  */
468#define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE()   LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
469
470/**
471  * @brief  Disable the COMP2 EXTI line falling edge trigger.
472  * @retval None
473  */
474#define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE()  LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
475
476/**
477  * @brief  Enable the COMP2 EXTI line rising & falling edge trigger.
478  * @retval None
479  */
480#define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
481                                                               LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
482                                                               LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
483                                                             } while(0)
484
485/**
486  * @brief  Disable the COMP2 EXTI line rising & falling edge trigger.
487  * @retval None
488  */                                         
489#define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
490                                                               LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
491                                                               LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
492                                                             } while(0)
493
494/**
495  * @brief  Enable the COMP2 EXTI line in interrupt mode.
496  * @retval None
497  */
498#define __HAL_COMP_COMP2_EXTI_ENABLE_IT()             LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2)
499
500/**
501  * @brief  Disable the COMP2 EXTI line in interrupt mode.
502  * @retval None
503  */
504#define __HAL_COMP_COMP2_EXTI_DISABLE_IT()            LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2)
505
506/**
507  * @brief  Generate a software interrupt on the COMP2 EXTI line.
508  * @retval None
509  */
510#define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT()         LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2)
511
512/**
513  * @brief  Enable the COMP2 EXTI line in event mode.
514  * @retval None
515  */
516#define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT()          LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2)
517
518/**
519  * @brief  Disable the COMP2 EXTI line in event mode.
520  * @retval None
521  */
522#define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT()         LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2)
523
524/**
525  * @brief  Check whether the COMP2 EXTI line rising flag is set.
526  * @retval RESET or SET
527  */
528#define __HAL_COMP_COMP2_EXTI_GET_RISING_FLAG()       LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP2)
529
530/**
531  * @brief  Clear the COMP2 EXTI rising flag.
532  * @retval None
533  */
534#define __HAL_COMP_COMP2_EXTI_CLEAR_RISING_FLAG()     LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP2)
535
536/**
537  * @brief  Check whether the COMP2 EXTI line falling flag is set.
538  * @retval RESET or SET
539  */
540#define __HAL_COMP_COMP2_EXTI_GET_FALLING_FLAG()      LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP2)
541
542/**
543  * @brief  Clear the COMP2 EXTI falling flag.
544  * @retval None
545  */
546#define __HAL_COMP_COMP2_EXTI_CLEAR_FALLING_FLAG()    LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP2)
547
548/**
549  * @}
550  */
551
552/**
553  * @}
554  */
555
556
557/* Private types -------------------------------------------------------------*/
558/* Private constants ---------------------------------------------------------*/
559/** @defgroup COMP_Private_Constants COMP Private Constants
560  * @{
561  */
562
563/** @defgroup COMP_WindowMode_Instance_Differentiator COMP window mode instance differentiator
564  * @{
565  */
566#define COMP_WINDOWMODE_COMP2          0x00001000U       /*!< COMP window mode using common input of COMP instance: COMP2 */
567/**
568  * @}
569  */
570
571/** @defgroup COMP_ExtiLine COMP EXTI Lines
572  * @{
573  */
574#define COMP_EXTI_LINE_COMP1           (EXTI_IMR1_IM17)  /*!< EXTI line 17 connected to COMP1 output */
575#define COMP_EXTI_LINE_COMP2           (EXTI_IMR1_IM18)  /*!< EXTI line 18 connected to COMP2 output */
576/**
577  * @}
578  */
579
580/** @defgroup COMP_ExtiLine COMP EXTI Lines
581  * @{
582  */
583#define COMP_EXTI_IT                        (0x00000001UL)  /*!< EXTI line event with interruption */
584#define COMP_EXTI_EVENT                     (0x00000002UL)  /*!< EXTI line event only (without interruption) */
585#define COMP_EXTI_RISING                    (0x00000010UL)  /*!< EXTI line event on rising edge */
586#define COMP_EXTI_FALLING                   (0x00000020UL)  /*!< EXTI line event on falling edge */
587/**
588  * @}
589  */
590
591/**
592  * @}
593  */
594
595/* Private macros ------------------------------------------------------------*/
596/** @defgroup COMP_Private_Macros COMP Private Macros
597  * @{
598  */
599
600/** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
601  * @{
602  */
603/**
604  * @brief  Get the specified EXTI line for a comparator instance.
605  * @param  __INSTANCE__  specifies the COMP instance.
606  * @retval value of @ref COMP_ExtiLine
607  */
608#define COMP_GET_EXTI_LINE(__INSTANCE__)    (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1  \
609                                             : COMP_EXTI_LINE_COMP2)
610/**
611  * @}
612  */
613
614/** @defgroup COMP_IS_COMP_Definitions COMP private macros to check input parameters
615  * @{
616  */
617#define IS_COMP_WINDOWMODE(__WINDOWMODE__)  (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE)                || \
618                                             ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)|| \
619                                             ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON)  )
620
621#define IS_COMP_WINDOWOUTPUT(__WINDOWOUTPUT__) (((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_EACH_COMP) || \
622                                                ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_COMP1)     || \
623                                                ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_COMP2)     || \
624                                                ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_BOTH)        )
625
626#define IS_COMP_POWERMODE(__POWERMODE__)    (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED)    || \
627                                             ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED)    )
628
629#define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
630                                                               ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \
631                                                               ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3))
632
633#define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)  || \
634                                                                 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)  || \
635                                                                 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)  || \
636                                                                 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)     || \
637                                                                 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)    || \
638                                                                 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2)    || \
639                                                                 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)         || \
640                                                                 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)         || \
641                                                                 ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3))
642
643#define IS_COMP_HYSTERESIS(__HYSTERESIS__)  (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE)   || \
644                                             ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW)    || \
645                                             ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
646                                             ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
647
648#define IS_COMP_OUTPUTPOL(__POL__)          (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
649                                             ((__POL__) == COMP_OUTPUTPOL_INVERTED))
650
651#define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__)                    \
652  (   ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE)               \
653   || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC4)           \
654   || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5)           \
655   || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3)           \
656   || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3)           \
657   || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC2)          \
658  )
659
660/* Note: Output blanking source common to all COMP instances */
661/*       Macro kept for compatibility with other STM32 series */
662#define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)  \
663   (IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__))
664
665
666#define IS_COMP_TRIGGERMODE(__MODE__)       (((__MODE__) == COMP_TRIGGERMODE_NONE)                 || \
667                                             ((__MODE__) == COMP_TRIGGERMODE_IT_RISING)            || \
668                                             ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING)           || \
669                                             ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING)    || \
670                                             ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING)         || \
671                                             ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING)        || \
672                                             ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
673
674#define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW)     || \
675                                                ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
676
677/**
678  * @}
679  */
680
681/**
682  * @}
683  */
684
685
686/* Exported functions --------------------------------------------------------*/
687/** @addtogroup COMP_Exported_Functions
688  * @{
689  */
690
691/** @addtogroup COMP_Exported_Functions_Group1
692  * @{
693  */
694
695/* Initialization and de-initialization functions  **********************************/
696HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
697HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp);
698void              HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
699void              HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
700
701#if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
702/* Callbacks Register/UnRegister functions  ***********************************/
703HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID,
704                                            pCOMP_CallbackTypeDef pCallback);
705HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
706#endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
707/**
708  * @}
709  */
710
711/* IO operation functions  *****************************************************/
712/** @addtogroup COMP_Exported_Functions_Group2
713  * @{
714  */
715HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
716HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
717void              HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
718/**
719  * @}
720  */
721
722/* Peripheral Control functions  ************************************************/
723/** @addtogroup COMP_Exported_Functions_Group3
724  * @{
725  */
726HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
727uint32_t          HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
728/* Callback in interrupt mode */
729void              HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
730/**
731  * @}
732  */
733
734/* Peripheral State functions  **************************************************/
735/** @addtogroup COMP_Exported_Functions_Group4
736  * @{
737  */
738HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
739uint32_t              HAL_COMP_GetError(COMP_HandleTypeDef *hcomp);
740/**
741  * @}
742  */
743
744/**
745  * @}
746  */
747
748/**
749  * @}
750  */
751#endif /* COMP1 || COMP2 */
752/**
753  * @}
754  */
755
756#ifdef __cplusplus
757}
758#endif
759
760#endif /* STM32G0xx_HAL_COMP_H */
761
762/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.