1 /**
2   **********************************************************************************************************************
3   * @file    stm32h5xx_hal_comp.h
4   * @author  MCD Application Team
5   * @brief   Header file of COMP HAL module.
6   **********************************************************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   **********************************************************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -----------------------------------------------------------------------------*/
20 #ifndef STM32H5xx_HAL_COMP_H
21 #define STM32H5xx_HAL_COMP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ----------------------------------------------------------------------------------------------------------*/
28 #include "stm32h5xx_hal_def.h"
29 #include "stm32h5xx_ll_exti.h"
30 
31 /** @addtogroup STM32H5xx_HAL_Driver
32   * @{
33   */
34 #if defined (COMP1)
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   uint32_t Mode;               /*!< Set comparator operating mode to adjust power and speed.
51                                     Note: For the characteristics of comparator power modes
52                                           (propagation delay and power consumption), refer to device datasheet.
53                                     This parameter can be a value of @ref COMP_PowerMode */
54 
55   uint32_t InputPlus;          /*!< Set comparator input plus (non-inverting input).
56                                     This parameter can be a value of @ref COMP_InputPlus */
57 
58   uint32_t InputMinus;         /*!< Set comparator input minus (inverting input).
59                                     This parameter can be a value of @ref COMP_InputMinus */
60 
61   uint32_t Hysteresis;         /*!< Set comparator hysteresis mode of the input minus.
62                                     This parameter can be a value of @ref COMP_Hysteresis */
63 
64   uint32_t OutputPol;          /*!< Set comparator output polarity.
65                                     This parameter can be a value of @ref COMP_OutputPolarity
66                                     Note: Specific to comparator of this STM32 series: comparator output
67                                           triggers interruption on high level. HAL_COMP_Start_x functions
68                                           can change output polarity depending on initial output level. */
69 
70   uint32_t BlankingSrce;       /*!< Set comparator blanking source.
71                                     This parameter can be a value of @ref COMP_BlankingSrce */
72 
73   uint32_t TriggerMode;        /*!< Set the comparator output triggering External Interrupt Line (EXTI).
74                                     This parameter can be a value of @ref COMP_EXTI_TriggerMode */
75 
76 } COMP_InitTypeDef;
77 
78 /**
79   * @brief  HAL COMP state machine: HAL COMP states definition
80   */
81 #define COMP_STATE_BITFIELD_LOCK  (0x10U)
82 typedef enum
83 {
84   HAL_COMP_STATE_RESET        = 0x00,                       /*!< COMP not yet initialized                             */
85   HAL_COMP_STATE_RESET_LOCKED = (HAL_COMP_STATE_RESET | \
86                                  COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */
87   HAL_COMP_STATE_READY        = 0x01,                       /*!< COMP initialized and ready for use                   */
88   HAL_COMP_STATE_READY_LOCKED = (HAL_COMP_STATE_READY | \
89                                  COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked         */
90   HAL_COMP_STATE_BUSY         = 0x02,                       /*!< COMP is running                                      */
91   HAL_COMP_STATE_BUSY_LOCKED  = (HAL_COMP_STATE_BUSY | \
92                                  COMP_STATE_BITFIELD_LOCK)  /*!< COMP is running and configuration is locked          */
93 
94 } HAL_COMP_StateTypeDef;
95 
96 /**
97   * @brief  COMP Handle Structure definition
98   */
99 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1U)
100 typedef struct __COMP_HandleTypeDef
101 #else
102 typedef struct
103 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
104 {
105   COMP_TypeDef       *Instance;                                   /*!< Register base address    */
106   COMP_InitTypeDef   Init;                                        /*!< COMP required parameters */
107   HAL_LockTypeDef    Lock;                                        /*!< Locking object           */
108   __IO HAL_COMP_StateTypeDef  State;                              /*!< COMP communication state */
109   __IO uint32_t      ErrorCode;                                   /*!< COMP error code          */
110 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1U)
111   void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP trigger callback    */
112   void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP Msp Init callback   */
113   void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
114 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
115   uint8_t            InterruptAutoRearm;                          /*!< COMP interrupt auto rearm setting */
116 } COMP_HandleTypeDef;
117 
118 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1U)
119 /**
120   * @brief  HAL COMP Callback ID enumeration definition
121   */
122 typedef enum
123 {
124   HAL_COMP_TRIGGER_CB_ID   = 0x00U,  /*!< COMP trigger callback ID */
125   HAL_COMP_MSPINIT_CB_ID   = 0x01U,  /*!< COMP Msp Init callback ID */
126   HAL_COMP_MSPDEINIT_CB_ID = 0x02U   /*!< COMP Msp DeInit callback ID */
127 
128 } HAL_COMP_CallbackIDTypeDef;
129 
130 /**
131   * @brief  HAL COMP Callback pointer definition
132   */
133 typedef  void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
134 
135 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
136 
137 /**
138   * @}
139   */
140 
141 /* Exported constants ------------------------------------------------------------------------------------------------*/
142 /** @defgroup COMP_Exported_Constants COMP Exported Constants
143   * @{
144   */
145 
146 /** @defgroup COMP_Error_Code COMP Error Code
147   * @{
148   */
149 #define HAL_COMP_ERROR_NONE             (0x00UL)   /*!< No error */
150 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1U)
151 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01U)   /*!< Invalid Callback error */
152 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
153 /**
154   * @}
155   */
156 
157 /** @defgroup COMP_PowerMode COMP power mode
158   * @{
159   */
160 /* Note: For the characteristics of comparator power modes                    */
161 /*       (propagation delay and power consumption),                           */
162 /*       refer to device datasheet.                                           */
163 #define COMP_POWERMODE_HIGHSPEED       (0x00000000UL)         /*!< High Speed */
164 #define COMP_POWERMODE_MEDIUMSPEED     (COMP_CFGR1_PWRMODE_0) /*!< Medium Speed */
165 #define COMP_POWERMODE_ULTRALOWPOWER   (COMP_CFGR1_PWRMODE)   /*!< Ultra-low power mode */
166 /**
167   * @}
168   */
169 
170 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
171   * @{
172   */
173 #define COMP_INPUT_PLUS_IO1            (0x00000000UL)         /*!< Comparator input plus connected to IO1 (pin PB0) */
174 #define COMP_INPUT_PLUS_IO2            (COMP_CFGR2_INPSEL0)   /*!< Comparator input plus connected to IO2 (pin PA0) */
175 #define COMP_INPUT_PLUS_IO3            (COMP_CFGR1_INPSEL1)   /*!< Comparator input plus connected to IO3 (pin PB2) */
176 #define COMP_INPUT_PLUS_DAC1_CH1       (COMP_CFGR1_INPSEL2)   /*!< Comparator input plus connected to (DAC1_CH1) */
177 /**
178   * @}
179   */
180 
181 /** @defgroup COMP_InputMinus COMP input minus (inverting input)
182   * @{
183   */
184 #define COMP_INPUT_MINUS_1_4VREFINT  (COMP_CFGR1_SCALEN |\
185                                       COMP_CFGR1_BRGEN)       /*!< Comparator input minus connected to 1/4 VrefInt    */
186 #define COMP_INPUT_MINUS_1_2VREFINT  (COMP_CFGR1_INMSEL_0 |\
187                                       COMP_CFGR1_SCALEN |\
188                                       COMP_CFGR1_BRGEN)       /*!< Comparator input minus connected to 1/2 VrefInt    */
189 #define COMP_INPUT_MINUS_3_4VREFINT  (COMP_CFGR1_INMSEL_1 |\
190                                       COMP_CFGR1_SCALEN |\
191                                       COMP_CFGR1_BRGEN)       /*!< Comparator input minus connected to 3/4 VrefInt    */
192 #define COMP_INPUT_MINUS_VREFINT     (COMP_CFGR1_INMSEL_1 |\
193                                       COMP_CFGR1_INMSEL_0 |\
194                                       COMP_CFGR1_SCALEN)      /*!< Comparator input minus connected to VrefInt        */
195 #define COMP_INPUT_MINUS_DAC1_CH1    (COMP_CFGR1_INMSEL_2)    /*!< Comparator input minus connected to DAC1 channel 1 */
196 #define COMP_INPUT_MINUS_IO1         (COMP_CFGR1_INMSEL_2 |\
197                                       COMP_CFGR1_INMSEL_0)    /*!< Comparator input minus connected to IO1 (pin PC4)  */
198 #define COMP_INPUT_MINUS_IO2         (COMP_CFGR1_INMSEL_2 |\
199                                       COMP_CFGR1_INMSEL_1)    /*!< Comparator input minus connected to IO2 (pin PB1)  */
200 #define COMP_INPUT_MINUS_IO3         (COMP_CFGR1_INMSEL_2 |\
201                                       COMP_CFGR1_INMSEL_1 |\
202                                       COMP_CFGR1_INMSEL_0)    /*!< Comparator input minus connected to IO3 (pin PA5)  */
203 #define COMP_INPUT_MINUS_TEMPSENSOR  (COMP_CFGR1_INMSEL_3)    /*!< Comparator input minus connected to internal
204                                      temperature sensor (also accessible through ADC peripheral) */
205 #define COMP_INPUT_MINUS_VBAT        (COMP_CFGR1_INMSEL_3 |\
206                                       COMP_CFGR1_INMSEL_0)    /*!< Comparator input minus connected to Vbat/4:
207                                      Vbat voltage through a divider ladder of factor 1/4 to have input voltage
208                                      always below Vdda. */
209 
210 /**
211   * @}
212   */
213 
214 /** @defgroup COMP_Hysteresis COMP hysteresis
215   * @{
216   */
217 #define COMP_HYSTERESIS_NONE           (0x00000000UL)                       /*!< No hysteresis */
218 #define COMP_HYSTERESIS_LOW            (COMP_CFGR1_HYST_0)                  /*!< Hysteresis level low */
219 #define COMP_HYSTERESIS_MEDIUM         (COMP_CFGR1_HYST_1)                  /*!< Hysteresis level medium */
220 #define COMP_HYSTERESIS_HIGH           (COMP_CFGR1_HYST_0 | COMP_CFGR1_HYST_1) /*!< Hysteresis level high */
221 /**
222   * @}
223   */
224 
225 /** @defgroup COMP_OutputPolarity COMP output Polarity
226   * @{
227   */
228 #define COMP_OUTPUTPOL_NONINVERTED     (0x00000000UL)          /*!< COMP output level is not inverted (comparator output
229                                                                     is high when the input plus is at a higher voltage
230                                                                     than the input minus) */
231 #define COMP_OUTPUTPOL_INVERTED        (COMP_CFGR1_POLARITY)   /*!< COMP output level is inverted (comparator output is
232                                                                     low when the input plus is at a higher voltage than
233                                                                     the input minus) */
234 /**
235   * @}
236   */
237 
238 /** @defgroup COMP_BlankingSrce  COMP blanking source
239   * @{
240   */
241 #define COMP_BLANKINGSRC_NONE            (0x00000000UL)           /*!< Comparator output without blanking */
242 #define COMP_BLANKINGSRC_TIM1_OC5        (COMP_CFGR1_BLANKING_0)  /*!< TIM1 OC5 selected as blanking source */
243 #define COMP_BLANKINGSRC_TIM2_OC3        (COMP_CFGR1_BLANKING_1)  /*!< TIM2 OC3 selected as blanking source */
244 #define COMP_BLANKINGSRC_TIM3_OC3        (COMP_CFGR1_BLANKING_0 |\
245                                           COMP_CFGR1_BLANKING_1)  /*!< TIM3 OC3 selected as blanking source */
246 #define COMP_BLANKINGSRC_TIM3_OC4        (COMP_CFGR1_BLANKING_2)  /*!< TIM3 OC4 selected as blanking source */
247 #define COMP_BLANKINGSRC_LPTIM1_OC2      (COMP_CFGR1_BLANKING_2 |\
248                                           COMP_CFGR1_BLANKING_0)  /*!< LPTIM1 OC2 selected as blanking source */
249 #define COMP_BLANKINGSRC_LPTIM2_OC2      (COMP_CFGR1_BLANKING_2 |\
250                                           COMP_CFGR1_BLANKING_1)  /*!< LPTIM2 OC2 selected as blanking source */
251 /**
252   * @}
253   */
254 
255 /** @defgroup COMP_OutputLevel COMP Output Level
256   * @{
257   */
258 /* Note: Comparator output level values are fixed to "0" and "1",             */
259 /* corresponding COMP register bit is managed by HAL function to match        */
260 /* with these values (independently of bit position in register).             */
261 
262 /* When output polarity is not inverted, comparator output is low when
263    the input plus is at a lower voltage than the input minus */
264 #define COMP_OUTPUT_LEVEL_LOW              (0x00000000UL)
265 /* When output polarity is not inverted, comparator output is high when
266    the input plus is at a higher voltage than the input minus */
267 #define COMP_OUTPUT_LEVEL_HIGH             (0x00000001UL)
268 /**
269   * @}
270   */
271 
272 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
273   * @{
274   */
275 #define COMP_TRIGGERMODE_NONE                 (0x00000000UL)          /*!< Comparator output triggering no External
276                                                                            Interrupt Line */
277 #define COMP_TRIGGERMODE_IT_RISING_FALLING    (COMP_EXTI_IT |\
278                                                COMP_EXTI_RISING |\
279                                                COMP_EXTI_FALLING)     /*!< Comparator output triggering interrupt
280                                               on rising and falling edges.
281                                               Note: Specific to comparator of this STM32 series: comparator output
282                                                     triggers interruption on high level. HAL_COMP_Start_x functions
283                                                     can change output polarity depending on initial output level. */
284 /**
285   * @}
286   */
287 
288 /** @defgroup COMP_Flag COMP Flag
289   * @{
290   */
291 #define COMP_FLAG_C1I           COMP_SR_C1IF           /*!< Comparator 1 Interrupt Flag */
292 #define COMP_FLAG_LOCK          COMP_CFGR1_LOCK        /*!< Lock flag                   */
293 /**
294   * @}
295   */
296 
297 /** @defgroup COMP_IT_CLEAR_Flags  COMP Interruption Clear Flags
298   * @{
299   */
300 #define COMP_CLEAR_C1IF          COMP_ICFR_CC1IF     /*!< Clear Comparator 1 Interrupt Flag */
301 /**
302   * @}
303   */
304 
305 /** @defgroup COMP_Interrupts_Definitions COMP Interrupts Definitions
306   * @{
307   */
308 #define COMP_IT_EN               COMP_CFGR1_ITEN
309 /**
310   * @}
311   */
312 
313 /**
314   * @}
315   */
316 
317 /* Exported macro ----------------------------------------------------------------------------------------------------*/
318 /** @defgroup COMP_Exported_Macros COMP Exported Macros
319   * @{
320   */
321 
322 /** @defgroup COMP_Handle_Management  COMP Handle Management
323   * @{
324   */
325 
326 /** @brief  Reset COMP handle state.
327   * @param  __HANDLE__  COMP handle
328   * @retval None
329   */
330 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1U)
331 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{                                                  \
332                                                       (__HANDLE__)->State = HAL_COMP_STATE_RESET;      \
333                                                       (__HANDLE__)->MspInitCallback = NULL;            \
334                                                       (__HANDLE__)->MspDeInitCallback = NULL;          \
335                                                     } while(0)
336 #else
337 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
338 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
339 
340 /**
341   * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
342   * @param __HANDLE__ COMP handle
343   * @retval None
344   */
345 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
346 
347 /**
348   * @brief  Enable the specified comparator.
349   * @param  __HANDLE__ COMP handle
350   * @retval None
351   */
352 #define __HAL_COMP_ENABLE(__HANDLE__)        SET_BIT((__HANDLE__)->Instance->CFGR1, COMP_CFGR1_EN)
353 
354 /**
355   * @brief  Disable the specified comparator.
356   * @param  __HANDLE__ COMP handle
357   * @retval None
358   */
359 #define __HAL_COMP_DISABLE(__HANDLE__)       CLEAR_BIT((__HANDLE__)->Instance->CFGR1, COMP_CFGR1_EN)
360 
361 /**
362   * @brief  Lock the specified comparator configuration.
363   * @note   Using this macro induce HAL COMP handle state machine being no
364   *         more in line with COMP instance state.
365   *         To keep HAL COMP handle state machine updated, it is recommended
366   *         to use function "HAL_COMP_Lock')".
367   * @param  __HANDLE__ COMP handle
368   * @retval None
369   */
370 #define __HAL_COMP_LOCK(__HANDLE__)         SET_BIT((__HANDLE__)->Instance->CFGR1, COMP_CFGR1_LOCK)
371 
372 /**
373   * @brief  Check whether the specified comparator is locked.
374   * @param  __HANDLE__  COMP handle
375   * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
376   */
377 #define __HAL_COMP_IS_LOCKED(__HANDLE__)   (READ_BIT((__HANDLE__)->Instance->CFGR1, COMP_CFGR1_LOCK) == COMP_CFGR1_LOCK)
378 
379 /**
380   * @}
381   */
382 
383 /** @defgroup COMP_Exti_Management  COMP external interrupt line management
384   * @{
385   */
386 
387 /** @brief  Checks if the specified COMP interrupt source is enabled or disabled.
388   * @param  __HANDLE__ specifies the COMP Handle.
389   *         This parameter can be COMP1.
390   * @param  __INTERRUPT__ specifies the COMP interrupt source to check.
391   *          This parameter can be one of the following values:
392   *            @arg COMP_IT_EN Comparator interrupt enable
393   *
394   * @retval State of interruption (TRUE or FALSE)
395   */
396 #define __HAL_COMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
397   ((((__HANDLE__)->Instance->CFGR1 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
398 
399 /** @brief  Checks whether the specified COMP flag is set or not.
400   * @param  __FLAG__ specifies the flag to check.
401   *        This parameter can be one of the following values:
402   *            @arg COMP_FLAG_C1I Comparator 1 Interrupt Flag
403   *            @retval State of flag (TRUE or FALSE)
404   */
405 #define __HAL_COMP_GET_FLAG(__FLAG__)     ((COMP1->SR & (__FLAG__)) == (__FLAG__))
406 
407 /** @brief  Clears the specified COMP pending flag.
408   * @param  __FLAG__ specifies the flag to check.
409   *          This parameter can be any combination of the following values:
410   *            @arg COMP_CLEAR_C1IF Clear Comparator 1 Interrupt Flag
411   * @retval None
412   */
413 #define __HAL_COMP_CLEAR_FLAG(__FLAG__)   (COMP1->ICFR = (__FLAG__))
414 
415 /** @brief  Clear the COMP C1I  flag.
416   * @retval None
417   */
418 #define __HAL_COMP_CLEAR_C1IFLAG()   __HAL_COMP_CLEAR_FLAG( COMP_CLEAR_C1IF)
419 
420 /** @brief  Enable the specified COMP interrupt.
421   * @param  __HANDLE__ specifies the COMP Handle.
422   * @param  __INTERRUPT__ specifies the COMP interrupt source to enable.
423   *          This parameter can be one of the following values:
424   *            @arg COMP_CFGR1_ITEN Comparator  interrupt
425   * @retval None
426   */
427 #define __HAL_COMP_ENABLE_IT(__HANDLE__, __INTERRUPT__)   (((__HANDLE__)->Instance->CFGR1) |= (__INTERRUPT__) )
428 
429 /** @brief  Disable the specified COMP interrupt.
430   * @param  __HANDLE__ specifies the COMP Handle.
431   * @param  __INTERRUPT__ specifies the COMP interrupt source to enable.
432   *          This parameter can be one of the following values:
433   *            @arg COMP_CFGR1_ITEN Comparator  interrupt
434   * @retval None
435   */
436 #define __HAL_COMP_DISABLE_IT(__HANDLE__,__INTERRUPT__) (((__HANDLE__)->Instance->CFGR1) &= ~(__INTERRUPT__))
437 
438 /**
439   * @}
440   */
441 
442 /**
443   * @}
444   */
445 
446 /* Private types -----------------------------------------------------------------------------------------------------*/
447 /* Private constants -------------------------------------------------------------------------------------------------*/
448 /** @defgroup COMP_Private_Constants COMP Private Constants
449   * @{
450   */
451 
452 /** @defgroup COMP_ExtiLine COMP EXTI Lines
453   * @{
454   */
455 #define COMP_EXTI_LINE_COMP1           (EXTI_IMR1_IM29)  /*!< EXTI line 29 connected to COMP1 output */
456 /**
457   * @}
458   */
459 
460 /** @defgroup COMP_ExtiLine COMP EXTI Lines
461   * @{
462   */
463 #define COMP_EXTI_IT                        (0x00000001UL)  /*!< EXTI line event with interruption */
464 #define COMP_EXTI_RISING                    (0x00000010UL)  /*!< EXTI line event on rising edge */
465 #define COMP_EXTI_FALLING                   (0x00000020UL)  /*!< EXTI line event on falling edge */
466 /**
467   * @}
468   */
469 
470 /**
471   * @}
472   */
473 
474 /* Private macros ----------------------------------------------------------------------------------------------------*/
475 /** @defgroup COMP_Private_Macros COMP Private Macros
476   * @{
477   */
478 
479 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
480   * @{
481   */
482 /**
483   * @brief  Get the specified EXTI line for a comparator instance.
484   * @param  __INSTANCE__  specifies the COMP instance.
485   * @retval value of @ref COMP_ExtiLine
486   */
487 #define COMP_GET_EXTI_LINE(__INSTANCE__)    (COMP_EXTI_LINE_COMP1)
488 /**
489   * @}
490   */
491 
492 /** @defgroup COMP_IS_COMP_Private_Definitions COMP private macros to check input parameters
493   * @{
494   */
495 #define IS_COMP_POWERMODE(__POWERMODE__)    (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED)    || \
496                                              ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED)  || \
497                                              ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER)  )
498 
499 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
500                                                                ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \
501                                                                ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3) || \
502                                                                ((__INPUT_PLUS__) == COMP_INPUT_PLUS_DAC1_CH1))
503 
504 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
505                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
506                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
507                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)    || \
508                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)   || \
509                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)        || \
510                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)        || \
511                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3)        || \
512                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_TEMPSENSOR) || \
513                                                                  ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VBAT))
514 
515 #define IS_COMP_HYSTERESIS(__HYSTERESIS__)  (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE)   || \
516                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW)    || \
517                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
518                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
519 
520 #define IS_COMP_OUTPUTPOL(__POL__)          (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
521                                              ((__POL__) == COMP_OUTPUTPOL_INVERTED))
522 
523 #define IS_COMP_BLANKINGSRCE(__SOURCE__)    (((__SOURCE__) == COMP_BLANKINGSRC_NONE)       || \
524                                              ((__SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5)   || \
525                                              ((__SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3)   || \
526                                              ((__SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3)   || \
527                                              ((__SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4)   || \
528                                              ((__SOURCE__) == COMP_BLANKINGSRC_LPTIM1_OC2) || \
529                                              ((__SOURCE__) == COMP_BLANKINGSRC_LPTIM2_OC2))
530 
531 
532 #define IS_COMP_TRIGGERMODE(__MODE__)       (((__MODE__) == COMP_TRIGGERMODE_NONE)                 || \
533                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING))
534 
535 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW)     || \
536                                                 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
537 
538 /**
539   * @}
540   */
541 
542 /**
543   * @}
544   */
545 
546 /* Exported functions ------------------------------------------------------------------------------------------------*/
547 /** @addtogroup COMP_Exported_Functions
548   * @{
549   */
550 
551 /** @addtogroup COMP_Exported_Functions_Group1
552   * @{
553   */
554 /* Initialization and de-initialization functions */
555 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
556 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp);
557 void              HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
558 void              HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
559 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1U)
560 /* Callbacks Register/UnRegister functions */
561 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID,
562                                             pCOMP_CallbackTypeDef pCallback);
563 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
564 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
565 /**
566   * @}
567   */
568 
569 /* IO operation functions */
570 /** @addtogroup COMP_Exported_Functions_Group2
571   * @{
572   */
573 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
574 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
575 HAL_StatusTypeDef HAL_COMP_Start_IT_OneShot(COMP_HandleTypeDef *hcomp);
576 HAL_StatusTypeDef HAL_COMP_Start_IT_AutoRearm(COMP_HandleTypeDef *hcomp);
577 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp);
578 void              HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
579 
580 /**
581   * @}
582   */
583 
584 /* Peripheral Control functions */
585 /** @addtogroup COMP_Exported_Functions_Group3
586   * @{
587   */
588 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
589 uint32_t          HAL_COMP_GetOutputLevel(const COMP_HandleTypeDef *hcomp);
590 /* Callback in interrupt mode */
591 void              HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
592 /**
593   * @}
594   */
595 
596 /* Peripheral State functions */
597 /** @addtogroup COMP_Exported_Functions_Group4
598   * @{
599   */
600 HAL_COMP_StateTypeDef HAL_COMP_GetState(const COMP_HandleTypeDef *hcomp);
601 uint32_t              HAL_COMP_GetError(const COMP_HandleTypeDef *hcomp);
602 /**
603   * @}
604   */
605 
606 /**
607   * @}
608   */
609 
610 /**
611   * @}
612   */
613 #endif /* COMP1 */
614 /**
615   * @}
616   */
617 
618 #ifdef __cplusplus
619 }
620 #endif
621 
622 #endif /* STM32H5xx_HAL_COMP_H */
623