1 /*
2  * SPDX-FileCopyrightText: 2016 STMicroelectronics
3  * SPDX-FileCopyrightText: 2019-2025 SiFli Technologies(Nanjing) Co., Ltd
4  *
5  * SPDX-License-Identifier: BSD-3-Clause AND Apache-2.0
6  */
7 
8 /* Define to prevent recursive inclusion -------------------------------------*/
9 #ifndef BF0_HAL_LPCOMP_H
10 #define BF0_HAL_LPCOMP_H
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /* Includes ------------------------------------------------------------------*/
17 #include "bf0_hal_def.h"
18 
19 
20 /** @addtogroup BF0_HAL_Driver
21   * @{
22   */
23 
24 /** @addtogroup COMP
25   * @{
26   */
27 
28 /* Exported types ------------------------------------------------------------*/
29 /** @defgroup COMP_Exported_Types COMP Exported Types
30   * @{
31   */
32 
33 /**
34   * @brief  COMP Init structure definition
35   */
36 typedef struct
37 {
38     uint32_t Mode;               /*!< Set comparator operating mode to adjust power and speed.
39                                     Note: For the characteristics of comparator power modes
40                                           (propagation delay and power consumption), refer to device datasheet.
41                                     This parameter can be a value of @ref COMP_PowerMode */
42 
43     uint32_t NonInvertingInput;  /*!< Set comparator input plus (non-inverting input).
44                                     This parameter can be a value of @ref COMP_InputPlus */
45 
46     uint32_t InvertingInput;     /*!< Set comparator input minus (inverting input).
47                                     This parameter can be a value of @ref COMP_InputMinus */
48 
49     uint32_t Hysteresis;         /*!< Set comparator hysteresis mode of the input minus.
50                                     This parameter can be a value of @ref COMP_Hysteresis */
51 
52     uint32_t TriggerMode;        /*!< Set the comparator output triggering External Interrupt Line (EXTI).
53                                     This parameter can be a value of @ref COMP_EXTI_TriggerMode */
54 
55     uint32_t InternalVRef;        /*!< Set the comparator internal voltage refrence.
56                                 This parameter can be a value of @ref COMP_Internal_VRefMode */
57 
58     uint32_t WorkingPin;        /*!<  There are 2 comparator, they can not work seperate, need use one instance.
59                                 Use a flag to check whichi one used , bit 0 for comp0 ,bit 1 for comp1, 2 for composite*/
60 } COMP_InitTypeDef;
61 
62 typedef struct
63 {
64     uint32_t Mode;               /*!< Set comparator operating mode to adjust power and speed.
65                                     Note: For the characteristics of comparator power modes
66                                           (propagation delay and power consumption), refer to device datasheet.
67                                     This parameter can be a value of @ref COMP_PowerMode */
68 
69     uint32_t InvertingInput;     /*!< Set comparator input minus (inverting input).
70                                     This parameter can be a value of @ref COMP_InputMinus */
71 
72     uint32_t TriggerMode;        /*!< Set the comparator output triggering External Interrupt Line (EXTI).
73                                     This parameter can be a value of @ref COMP_EXTI_TriggerMode */
74 
75     uint32_t InternalVRef;        /*!< Set the comparator internal voltage refrence.
76                                 This parameter can be a value of @ref COMP_Internal_VRefMode */
77 
78     uint32_t WorkingPin;        /*!<  There are 2 comparator, they can not work seperate, need use one instance.
79                                 Use a flag to check whichi one used , bit 0 for comp0 ,bit 1 for comp1, 2 for composite*/
80 } COMP_ConfigTypeDef;
81 
82 
83 /**
84   * @brief  HAL COMP state machine: HAL COMP states definition
85   */
86 #define COMP_STATE_BITFIELD_LOCK  (0x10U)
87 typedef enum
88 {
89     HAL_COMP_STATE_RESET             = 0x00U,                                             /*!< COMP not yet initialized                             */
90     HAL_COMP_STATE_RESET_LOCKED      = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */
91     HAL_COMP_STATE_READY             = 0x01U,                                             /*!< COMP initialized and ready for use                   */
92     HAL_COMP_STATE_READY_LOCKED      = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked         */
93     HAL_COMP_STATE_BUSY              = 0x02U,                                             /*!< COMP is running                                      */
94     HAL_COMP_STATE_BUSY_LOCKED       = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK)   /*!< COMP is running and configuration is locked          */
95 } HAL_COMP_StateTypeDef;
96 
97 /**
98   * @brief  COMP Handle Structure definition
99   */
100 typedef struct __COMP_HandleTypeDef
101 {
102     LPCOMP_TypeDef     *Instance;       /*!< Register base address    */
103     COMP_InitTypeDef   Init;            /*!< COMP required parameters */
104     HAL_LockTypeDef    Lock;            /*!< Locking object           */
105     __IO HAL_COMP_StateTypeDef  State;  /*!< COMP communication state */
106     __IO uint32_t      ErrorCode;       /*!< COMP error code */
107 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
108     void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP trigger callback */
109     void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp);   /*!< COMP Msp Init callback */
110     void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
111 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
112 } COMP_HandleTypeDef;
113 
114 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
115 /**
116   * @brief  HAL COMP Callback ID enumeration definition
117   */
118 typedef enum
119 {
120     HAL_COMP_TRIGGER_CB_ID                = 0x00U,  /*!< COMP trigger callback ID */
121     HAL_COMP_MSPINIT_CB_ID                = 0x01U,  /*!< COMP Msp Init callback ID */
122     HAL_COMP_MSPDEINIT_CB_ID              = 0x02U   /*!< COMP Msp DeInit callback ID */
123 } HAL_COMP_CallbackIDTypeDef;
124 
125 /**
126   * @brief  HAL COMP Callback pointer definition
127   */
128 typedef  void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
129 
130 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
131 
132 /**
133   * @}
134   */
135 
136 /* Exported constants --------------------------------------------------------*/
137 /** @defgroup COMP_Exported_Constants COMP Exported Constants
138   * @{
139   */
140 
141 /** @defgroup COMP_Error_Code COMP Error Code
142   * @{
143   */
144 #define HAL_COMP_ERROR_NONE             (0x00UL)  /*!< No error */
145 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
146 #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01UL)  /*!< Invalid Callback error */
147 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
148 /**
149   * @}
150   */
151 
152 /** @defgroup COMP_PowerMode COMP power mode
153   * @{
154   */
155 /* Note: For the characteristics of comparator power modes                    */
156 /*       (propagation delay and power consumption),                           */
157 /*       refer to device datasheet.                                           */
158 #define COMP_POWERMODE_HIGHSPEED       (0x00000002UL<<LPCOMP_CR1_MODE_Pos)         /*!< High Speed */
159 #define COMP_POWERMODE_MEDIUMSPEED     (0x00000001UL<<LPCOMP_CR1_MODE_Pos)   /*!< Medium Speed */
160 #define COMP_POWERMODE_ULTRALOWPOWER   (0x00000000UL)     /*!< Ultra-low power mode */
161 /**
162   * @}
163   */
164 
165 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
166   * @{
167   */
168 #define COMP_INPUT_PLUS_IO1            (0x00000000UL)         /*!< Input plus of Comparator 1 connected to LPCOMP1_P OR Comparator 2 connect to LPCOMP2_P*/
169 #define COMP_INPUT_PLUS_IO2            (0x00000001UL<<LPCOMP_CR1_INPSEL_Pos)    /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
170 
171 /**
172   * @}
173   */
174 
175 /** @defgroup COMP_InputMinus COMP input minus (inverting input)
176   * @{
177   */
178 #define COMP_INPUT_MINUS_VREF           (0x00000000UL)                                           /*!< Comparator input minus connected to VREF */
179 #define COMP_INPUT_MINUS_NPIN           (0x00000001UL<<LPCOMP_CR1_INMSEL_Pos)                    /*!< Comparator input minus connected to OUTSID */
180 
181 /**
182   * @}
183   */
184 
185 /** @defgroup COMP_Hysteresis COMP hysteresis
186   * @{
187   */
188 #define COMP_HYSTERESIS_NONE           (0x00000000UL)                       /*!< No hysteresis */
189 #define COMP_HYSTERESIS_LOW            (0x00000001UL<<LPCOMP_CR1_HYST_Pos)  /*!< Hysteresis level low */
190 #define COMP_HYSTERESIS_MEDIUM         (0x00000002UL<<LPCOMP_CR1_HYST_Pos  )  /*!< Hysteresis level medium */
191 #define COMP_HYSTERESIS_HIGH           (0x00000003UL<<LPCOMP_CR1_HYST_Pos)  /*!< Hysteresis level high */
192 /**
193   * @}
194   */
195 
196 /** @defgroup COMP_OutputPolarity COMP output Polarity
197   * @{
198   */
199 #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) */
200 #define COMP_OUTPUTPOL_INVERTED        (LPCOMP_CR1_POL)    /*!< COMP output level is inverted     (comparator output is low  when the input plus is at a higher voltage than the input minus) */
201 /**
202   * @}
203   */
204 
205 
206 /** @defgroup COMP_OutputLevel COMP Output Level
207   * @{
208   */
209 /* Note: Comparator output level values are fixed to "0" and "1",             */
210 /* corresponding COMP register bit is managed by HAL function to match        */
211 /* with these values (independently of bit position in register).             */
212 
213 /* When output polarity is not inverted, comparator output is low when
214    the input plus is at a lower voltage than the input minus */
215 #define COMP_OUTPUT_LEVEL_LOW              (0x00000000UL)
216 /* When output polarity is not inverted, comparator output is high when
217    the input plus is at a higher voltage than the input minus */
218 #define COMP_OUTPUT_LEVEL_HIGH             (0x00000001UL)
219 /**
220   * @}
221   */
222 
223 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
224   * @{
225   */
226 #define COMP_TRIGGERMODE_NONE                 (0x00000000UL)                                            /*!< Comparator output triggering no External Interrupt Line */
227 #define COMP_TRIGGERMODE_IT_RISING            (COMP_EXTI_IT | COMP_EXTI_RISING)                         /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
228 #define COMP_TRIGGERMODE_IT_FALLING           (COMP_EXTI_IT | COMP_EXTI_FALLING)                        /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
229 #define COMP_TRIGGERMODE_IT_RISING_FALLING    (COMP_EXTI_IT | COMP_EXTI_EDGES)                          /*!< Comparator output triggering External Interrupt Line event with interruption, on both rising and falling edges */
230 #define COMP_TRIGGERMODE_EVENT_RISING         (COMP_EXTI_EVENT | COMP_EXTI_RISING)                      /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
231 #define COMP_TRIGGERMODE_EVENT_FALLING        (COMP_EXTI_EVENT | COMP_EXTI_FALLING)                     /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
232 #define COMP_TRIGGERMODE_EVENT_RISING_FALLING (COMP_EXTI_EVENT | COMP_EXTI_EDGES)                       /*!< Comparator output triggering External Interrupt Line event only (without interruption), on both rising and falling edges */
233 /**
234   * @}
235   */
236 
237 /** @defgroup COMP_Internal_VRefMode COMP internal voltage reference
238   * @{
239   */
240 #define COMP_VREFINT_0D6V               (0x00000000UL)                                   /*!< Comparator internal voltage reference to 0.6v */
241 #define COMP_VREFINT_1D2V               (0x00000001UL<<LPCOMP_CR1_VREFINT_Pos)          /*!< Comparator internal voltage reference to 1.2v */
242 #define COMP_VREFINT_1D8V               (0x00000002UL<<LPCOMP_CR1_VREFINT_Pos)          /*!< Comparator internal voltage reference to 1.8v */
243 #define COMP_VREFINT_2D4V               (0x00000003UL<<LPCOMP_CR1_VREFINT_Pos)          /*!< Comparator internal voltage reference to 2.4v */
244 
245 /**
246   * @}
247   */
248 
249 /**
250   * @}
251   */
252 
253 /* Exported macro ------------------------------------------------------------*/
254 /** @defgroup COMP_Exported_Macros COMP Exported Macros
255   * @{
256   */
257 
258 /** @defgroup COMP_Handle_Management  COMP Handle Management
259   * @{
260   */
261 
262 /** @brief  Reset COMP handle state.
263   * @param  \__HANDLE__  COMP handle
264   * @retval None
265   */
266 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
267 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{                                                 \
268                                                      (__HANDLE__)->State = HAL_COMP_STATE_RESET;      \
269                                                      (__HANDLE__)->MspInitCallback = NULL;            \
270                                                      (__HANDLE__)->MspDeInitCallback = NULL;          \
271                                                     } while(0)
272 #else
273 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
274 #endif
275 
276 /**
277   * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
278   * @param \__HANDLE__ COMP handle
279   * @retval None
280   */
281 #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
282 
283 /**
284   * @brief  Enable the specified comparator.
285   * @param  \__HANDLE__  COMP handle
286   * @retval None
287   */
288 #define __HAL_COMP_ENABLE(__HANDLE__)              SET_BIT((__HANDLE__)->Instance->CR1, LPCOMP_CR1_EN)
289 
290 /**
291   * @brief  Disable the specified comparator.
292   * @param  \__HANDLE__  COMP handle
293   * @retval None
294   */
295 #define __HAL_COMP_DISABLE(__HANDLE__)             CLEAR_BIT((__HANDLE__)->Instance->CR1, LPCOMP_CR1_EN)
296 
297 /**
298   * @}
299   */
300 
301 
302 /**
303   * @}
304   */
305 
306 
307 /* Private types -------------------------------------------------------------*/
308 /* Private constants ---------------------------------------------------------*/
309 /** @defgroup COMP_Private_Constants COMP Private Constants
310   * @{
311   */
312 
313 
314 /** @defgroup COMP_ExtiLine COMP EXTI Lines
315   * @{
316   */
317 #define COMP_EXTI_IT                        (LPCOMP_CR1_IE)  /*!< EXTI line event with interruption */
318 #define COMP_EXTI_EVENT                     (0x00000000UL)  /*!< EXTI line event only (without interruption) */
319 #define COMP_EXTI_HIGH                      (0x00000001UL<<LPCOMP_CR1_SENS_Pos)  /*!< EXTI line event on high level */
320 #define COMP_EXTI_LOW                       (0x00000002UL<<LPCOMP_CR1_SENS_Pos)  /*!< EXTI line event on low level */
321 #define COMP_EXTI_RISING                    (0x00000005UL<<LPCOMP_CR1_SENS_Pos)  /*!< EXTI line event on rising edge */
322 #define COMP_EXTI_FALLING                   (0x00000006UL<<LPCOMP_CR1_SENS_Pos)  /*!< EXTI line event on falling edge */
323 #define COMP_EXTI_EDGES                     (0x00000007UL<<LPCOMP_CR1_SENS_Pos)  /*!< EXTI line event on both edge */
324 
325 /**
326   * @}
327   */
328 
329 /**
330   * @}
331   */
332 
333 /* Private macros ------------------------------------------------------------*/
334 
335 /** @defgroup COMP_Private_Constants COMP Private Constants
336   * @{
337   */
338 
339 /**
340   * @brief  Check if power mode.
341   * @param  \__POWERMODE__  COMP handle
342   * @retval true if success
343   */
344 #define IS_COMP_POWERMODE(__POWERMODE__)    (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED)    || \
345                                              ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED)  || \
346                                              ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER)  )
347 
348 /**
349   * @brief  Check if HYSTERESIS.
350   * @param  \__HYSTERESIS__  COMP handle
351   * @retval true if success
352   */
353 #define IS_COMP_HYSTERESIS(__HYSTERESIS__)  (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE)   || \
354                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW)    || \
355                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
356                                              ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
357 
358 /**
359   * @brief  Check if output pol.
360   * @param  \__POL__  COMP handle
361   * @retval true if success
362   */
363 #define IS_COMP_OUTPUTPOL(__POL__)          (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
364                                              ((__POL__) == COMP_OUTPUTPOL_INVERTED))
365 
366 /**
367   * @brief  Check if comp triger mode.
368   * @param  \__MODE__  COMP handle
369   * @retval true if success
370   */
371 #define IS_COMP_TRIGGERMODE(__MODE__)       (((__MODE__) == COMP_TRIGGERMODE_NONE)                 || \
372                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING)            || \
373                                              ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING)           || \
374                                              ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING)    || \
375                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING)         || \
376                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING)        || \
377                                              ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
378 
379 /**
380   * @brief  Check if comp output level.
381   * @param  \__OUTPUT_LEVEL__  COMP handle
382   * @retval true if success
383   */
384 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW)     || \
385                                                 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
386 
387 /**
388   * @}
389   */
390 
391 /* Exported functions --------------------------------------------------------*/
392 /** @addtogroup COMP_Exported_Functions
393   * @{
394   */
395 
396 /** @addtogroup COMP_Exported_Functions_Group1
397   * @{
398   */
399 
400 /* Initialization and de-initialization functions  **********************************/
401 /**
402   * @brief  Initialize the COMP according to the specified
403   *         parameters in the COMP_InitTypeDef and initialize the associated handle.
404   * @note   If the selected comparator is locked, initialization can't be performed.
405   *         To unlock the configuration, perform a system reset.
406   * @param  hcomp  COMP handle
407   * @retval HAL status
408   */
409 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
410 
411 /**
412   * @brief  DeInitialize the COMP peripheral.
413   * @note   Deinitialization cannot be performed if the COMP configuration is locked.
414   *         To unlock the configuration, perform a system reset.
415   * @param  hcomp  COMP handle
416   * @retval HAL status
417   */
418 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp);
419 
420 /**
421   * @brief  Initialize the COMP MSP.
422   * @param  hcomp  COMP handle
423   * @retval None
424   */
425 void              HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
426 
427 /**
428   * @brief  select which comparator to work.
429   * @param  hcomp  COMP handle
430   * @param  cfg configure parameters
431   * @retval HAL status
432   */
433 HAL_StatusTypeDef HAL_COMP_Config(COMP_HandleTypeDef *hcomp, COMP_ConfigTypeDef *cfg);
434 
435 /**
436   * @brief  polling compare result.
437   * @param  hcomp  COMP handle
438   * @param  channel channel select, 0, 1 valid
439   * @param  timeout timeout in ms
440   * @retval compare result
441   */
442 int HAL_COMP_PollForComp(COMP_HandleTypeDef *hcomp, uint8_t channel, uint32_t timeout);
443 
444 /**
445   * @brief  DeInitialize the COMP MSP.
446   * @param  hcomp  COMP handle
447   * @retval None
448   */
449 void              HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
450 
451 #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
452 /* Callbacks Register/UnRegister functions  ***********************************/
453 /**
454   * @brief  Register a User COMP Callback
455   *         To be used instead of the weak predefined callback
456   * @param  hcomp Pointer to a COMP_HandleTypeDef structure that contains
457   *                the configuration information for the specified COMP.
458   * @param  CallbackID ID of the callback to be registered
459   *         This parameter can be one of the following values:
460   *          @arg @ref HAL_COMP_TRIGGER_CB_ID Trigger callback ID
461   *          @arg @ref HAL_COMP_MSPINIT_CB_ID MspInit callback ID
462   *          @arg @ref HAL_COMP_MSPDEINIT_CB_ID MspDeInit callback ID
463   * @param  pCallback pointer to the Callback function
464   * @retval HAL status
465   */
466 HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback);
467 /**
468   * @brief  Unregister a COMP Callback
469   *         COMP callback is redirected to the weak predefined callback
470   * @param  hcomp Pointer to a COMP_HandleTypeDef structure that contains
471   *                the configuration information for the specified COMP.
472   * @param  CallbackID ID of the callback to be unregistered
473   *         This parameter can be one of the following values:
474   *          @arg @ref HAL_COMP_TRIGGER_CB_ID Trigger callback ID
475   *          @arg @ref HAL_COMP_MSPINIT_CB_ID MspInit callback ID
476   *          @arg @ref HAL_COMP_MSPDEINIT_CB_ID MspDeInit callback ID
477   * @retval HAL status
478   */
479 HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
480 #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
481 /**
482   * @}
483   */
484 
485 /* IO operation functions  *****************************************************/
486 /** @addtogroup COMP_Exported_Functions_Group2
487   * @{
488   */
489 
490 /**
491   * @brief  Start the comparator.
492   * @param  hcomp  COMP handle
493   * @retval HAL status
494   */
495 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
496 
497 /**
498   * @brief  Stop the comparator.
499   * @param  hcomp  COMP handle
500   * @retval HAL status
501   */
502 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
503 
504 /**
505   * @brief  Comparator IRQ handler.
506   * @param  hcomp  COMP handle
507   * @retval None
508   */
509 void              HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
510 /**
511   * @}
512   */
513 
514 /* Peripheral Control functions  ************************************************/
515 /** @addtogroup COMP_Exported_Functions_Group3
516   * @{
517   */
518 
519 /**
520   * @brief  Return the output level (high or low) of the selected comparator.
521   *         The output level depends on the selected polarity.
522   *         If the polarity is not inverted:
523   *           - Comparator output is low when the input plus is at a lower
524   *             voltage than the input minus
525   *           - Comparator output is high when the input plus is at a higher
526   *             voltage than the input minus
527   *         If the polarity is inverted:
528   *           - Comparator output is high when the input plus is at a lower
529   *             voltage than the input minus
530   *           - Comparator output is low when the input plus is at a higher
531   *             voltage than the input minus
532   * @param  hcomp  COMP handle
533   * @retval Returns the selected comparator output level:
534   *         @arg COMP_OUTPUT_LEVEL_LOW
535   *         @arg COMP_OUTPUT_LEVEL_HIGH
536   *
537   */
538 uint32_t          HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
539 
540 /**
541   * @brief  Comparator trigger callback.
542   * @param  hcomp  COMP handle
543   * @retval None
544   */
545 void              HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
546 /**
547   * @}
548   */
549 
550 /* Peripheral State functions  **************************************************/
551 /** @addtogroup COMP_Exported_Functions_Group4
552   * @{
553   */
554 /**
555   * @brief  Return the COMP handle state.
556   * @param  hcomp  COMP handle
557   * @retval HAL state
558   */
559 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
560 
561 /**
562   * @brief  Return the COMP error code.
563   * @param hcomp COMP handle
564   * @retval COMP error code
565   */
566 uint32_t              HAL_COMP_GetError(COMP_HandleTypeDef *hcomp);
567 /**
568   * @}
569   */
570 
571 /**
572   * @}
573   */
574 
575 /**
576   * @}
577   */
578 
579 /**
580   * @}
581   */
582 
583 
584 #ifdef __cplusplus
585 }
586 #endif
587 
588 #endif /* BF0_HAL_LPCOMP_H */
589 
590 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/