1 /**
2   **********************************************************************************************************************
3   * @file    stm32h5xx_ll_comp.h
4   * @author  MCD Application Team
5   * @brief   Header file of COMP LL 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_LL_COMP_H
21 #define __STM32H5xx_LL_COMP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ----------------------------------------------------------------------------------------------------------*/
28 #include "stm32h5xx.h"
29 
30 /** @addtogroup STM32H5xx_LL_Driver
31   * @{
32   */
33 
34 #if defined (COMP1)
35 
36 /** @defgroup COMP_LL COMP
37   * @{
38   */
39 
40 /* Private types -----------------------------------------------------------------------------------------------------*/
41 /* Private variables -------------------------------------------------------------------------------------------------*/
42 /* Private constants -------------------------------------------------------------------------------------------------*/
43 /** @defgroup COMP_LL_Private_Constants COMP Private Constants
44   * @{
45   */
46 
47 /* COMP registers bits positions */
48 #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30U) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
49 
50 /**
51   * @}
52   */
53 
54 /* Private macros ----------------------------------------------------------------------------------------------------*/
55 /* Exported types ----------------------------------------------------------------------------------------------------*/
56 #if defined(USE_FULL_LL_DRIVER)
57 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
58   * @{
59   */
60 
61 /**
62   * @brief  Structure definition of some features of COMP instance.
63   */
64 typedef struct
65 {
66   uint32_t PowerMode;             /*!< Set comparator operating mode to adjust power and speed.
67                                        This parameter can be a value of @ref COMP_LL_EC_POWERMODE
68                                        This feature can be modified afterwards using unitary
69                                        function @ref LL_COMP_SetPowerMode().                                          */
70 
71   uint32_t InputPlus;             /*!< Set comparator input plus (non-inverting input).
72                                        This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
73                                        This feature can be modified afterwards using unitary
74                                        function @ref LL_COMP_SetInputPlus(). */
75 
76   uint32_t InputMinus;            /*!< Set comparator input minus (inverting input).
77                                        This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
78                                        This feature can be modified afterwards using unitary
79                                        function @ref LL_COMP_SetInputMinus().                                         */
80 
81   uint32_t InputHysteresis;       /*!< Set comparator hysteresis mode of the input minus.
82                                        This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
83                                        This feature can be modified afterwards using unitary
84                                        function @ref LL_COMP_SetInputHysteresis().                                    */
85 
86   uint32_t OutputPolarity;        /*!< Set comparator output polarity.
87                                        This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
88                                        This feature can be modified afterwards using unitary
89                                        function @ref LL_COMP_SetOutputPolarity().                                     */
90 
91   uint32_t OutputBlankingSource;  /*!< Set comparator blanking source.
92                                        This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
93                                        This feature can be modified afterwards using unitary
94                                        function @ref LL_COMP_SetOutputBlankingSource().                               */
95 } LL_COMP_InitTypeDef;
96 
97 /**
98   * @}
99   */
100 #endif /* USE_FULL_LL_DRIVER */
101 
102 /* Exported constants ------------------------------------------------------------------------------------------------*/
103 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
104   * @{
105   */
106 
107 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
108   * @{
109   */
110 #define LL_COMP_POWERMODE_HIGHSPEED     (0x00000000UL)            /*!< COMP power mode to high speed      */
111 #define LL_COMP_POWERMODE_MEDIUMSPEED   (COMP_CFGR1_PWRMODE_0)    /*!< COMP power mode to medium speed    */
112 #define LL_COMP_POWERMODE_ULTRALOWPOWER (COMP_CFGR1_PWRMODE_1 |\
113                                          COMP_CFGR1_PWRMODE_0)    /*!< COMP power mode to ultra-low power */
114 /**
115   * @}
116   */
117 
118 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
119   * @{
120   */
121 #define LL_COMP_INPUT_PLUS_IO1          (0x00000000UL)          /*!< Comparator input plus connected to IO1 (pin PB0) */
122 #define LL_COMP_INPUT_PLUS_IO2          (COMP_CFGR2_INPSEL0)    /*!< Comparator input plus connected to IO2 (pin PA0) */
123 #define LL_COMP_INPUT_PLUS_IO3          (COMP_CFGR1_INPSEL1)    /*!< Comparator input plus connected to IO3 (pin PB2) */
124 #define LL_COMP_INPUT_PLUS_DAC1_CH1     (COMP_CFGR1_INPSEL2)    /*!< Comparator input plus connected to DAC1 channel 1 */
125 /**
126   * @}
127   */
128 
129 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
130   * @{
131   */
132 #define LL_COMP_INPUT_MINUS_1_4VREFINT  (COMP_CFGR1_SCALEN |\
133                                          COMP_CFGR1_BRGEN)      /*!< Comparator input minus connected to 1/4 VrefInt */
134 #define LL_COMP_INPUT_MINUS_1_2VREFINT  (COMP_CFGR1_INMSEL_0 |\
135                                          COMP_CFGR1_SCALEN |\
136                                          COMP_CFGR1_BRGEN)      /*!< Comparator input minus connected to 1/2 VrefInt */
137 #define LL_COMP_INPUT_MINUS_3_4VREFINT  (COMP_CFGR1_INMSEL_1 |\
138                                          COMP_CFGR1_SCALEN |\
139                                          COMP_CFGR1_BRGEN)      /*!< Comparator input minus connected to 3/4 VrefInt */
140 #define LL_COMP_INPUT_MINUS_VREFINT     (COMP_CFGR1_INMSEL_1 |\
141                                          COMP_CFGR1_INMSEL_0 |\
142                                          COMP_CFGR1_SCALEN)     /*!< Comparator input minus connected to VrefInt */
143 #define LL_COMP_INPUT_MINUS_DAC1_CH1    (COMP_CFGR1_INMSEL_2)   /*!< Comparator input minus connected to DAC1
144                                                                      channel 1 (DAC_OUT1) */
145 #define LL_COMP_INPUT_MINUS_IO1         (COMP_CFGR1_INMSEL_2 |\
146                                          COMP_CFGR1_INMSEL_0)   /*!< Comparator input minus connected to pin PC4 */
147 #define LL_COMP_INPUT_MINUS_IO2         (COMP_CFGR1_INMSEL_2 |\
148                                          COMP_CFGR1_INMSEL_1)   /*!< Comparator input minus connected to pin PB1 */
149 #define LL_COMP_INPUT_MINUS_IO3         (COMP_CFGR1_INMSEL_2 |\
150                                          COMP_CFGR1_INMSEL_1 |\
151                                          COMP_CFGR1_INMSEL_0)   /*!< Comparator input minus connected to pin PA5 */
152 #define LL_COMP_INPUT_MINUS_TEMPSENSOR  (COMP_CFGR1_INMSEL_3)   /*!< Comparator input minus connected to internal
153                                         temperature sensor (also accessible through ADC peripheral) */
154 #define LL_COMP_INPUT_MINUS_VBAT        (COMP_CFGR1_INMSEL_3 |\
155                                          COMP_CFGR1_INMSEL_0)   /*!< Comparator input minus connected to Vbat/4:
156                                         Vbat voltage through a divider ladder of factor 1/4 to have input voltage
157                                         always below Vdda. */
158 
159 /**
160   * @}
161   */
162 
163 /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
164   * @{
165   */
166 #define LL_COMP_HYSTERESIS_NONE         (0x00000000UL)                          /*!< No hysteresis */
167 #define LL_COMP_HYSTERESIS_LOW          (COMP_CFGR1_HYST_0)                     /*!< Hysteresis level low */
168 #define LL_COMP_HYSTERESIS_MEDIUM       (COMP_CFGR1_HYST_1)                     /*!< Hysteresis level medium */
169 #define LL_COMP_HYSTERESIS_HIGH         (COMP_CFGR1_HYST_1 | COMP_CFGR1_HYST_0) /*!< Hysteresis level high */
170 /**
171   * @}
172   */
173 
174 /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
175   * @{
176   */
177 #define LL_COMP_OUTPUTPOL_NONINVERTED   (0x00000000UL)          /*!< COMP output polarity is not inverted: comparator
178                                                                      output is high when the plus (non-inverting) input
179                                                                      is at a higher voltage than the
180                                                                      minus (inverting) input                          */
181 #define LL_COMP_OUTPUTPOL_INVERTED      (COMP_CFGR1_POLARITY)   /*!< COMP output polarity is inverted: comparator output
182                                                                      is low when the plus (non-inverting) input is at a
183                                                                      lower voltage than the minus (inverting) input   */
184 /**
185   * @}
186   */
187 
188 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
189   * @{
190   */
191 #define LL_COMP_BLANKINGSRC_NONE         ((uint32_t)0x00000000)    /*!<Comparator output without blanking */
192 #define LL_COMP_BLANKINGSRC_TIM1_OC5     (COMP_CFGR1_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 */
193 #define LL_COMP_BLANKINGSRC_TIM2_OC3     (COMP_CFGR1_BLANKING_1)   /*!< Comparator output blanking source TIM2 OC3 */
194 #define LL_COMP_BLANKINGSRC_TIM3_OC3     (COMP_CFGR1_BLANKING_0 |\
195                                           COMP_CFGR1_BLANKING_1)   /*!< Comparator output blanking source TIM3 OC3 */
196 #define LL_COMP_BLANKINGSRC_TIM3_OC4     (COMP_CFGR1_BLANKING_2)   /*!< Comparator output blanking source TIM3 OC4 */
197 #define LL_COMP_BLANKINGSRC_LPTIM1_OC2   (COMP_CFGR1_BLANKING_2 |\
198                                           COMP_CFGR1_BLANKING_0)   /*!< Comparator output blanking source LPTIM1 OC2 */
199 #define LL_COMP_BLANKINGSRC_LPTIM2_OC2   (COMP_CFGR1_BLANKING_2 |\
200                                           COMP_CFGR1_BLANKING_1)   /*!< Comparator output blanking source LPTIM2 OC2 */
201 /**
202   * @}
203   */
204 
205 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
206   * @{
207   */
208 #define LL_COMP_OUTPUT_LEVEL_LOW           (0x00000000UL)  /*!< Comparator output level low (if polarity not inverted,
209                                             otherwise to be complemented) */
210 #define LL_COMP_OUTPUT_LEVEL_HIGH          (0x00000001UL)  /*!< Comparator output level high (if polarity not inverted,
211                                            otherwise to be complemented) */
212 /**
213   * @}
214   */
215 
216 /** @defgroup COMP_LL_EC_HW_DELAYS  Definitions of COMP hardware constraints delays
217   * @note   Only COMP peripheral HW delays are defined in COMP LL driver driver,
218   *         not timeout values.
219   *         For details on delays values, refer to descriptions in source code
220   *         above each literal definition.
221   * @{
222   */
223 
224 /* Delay for comparator startup time.                                         */
225 /* Note: Delay required to reach propagation delay specification.             */
226 /* Literal set to maximum value (refer to device datasheet,                   */
227 /* parameter "tSTART").                                                       */
228 /* Unit: us                                                                   */
229 #define LL_COMP_DELAY_STARTUP_US          ( 80UL) /*!< Delay for COMP startup time */
230 
231 /* Delay for comparator voltage scaler stabilization time.                    */
232 /* Note: Voltage scaler is used when selecting comparator input               */
233 /*       based on VrefInt: VrefInt or subdivision of VrefInt.                 */
234 /* Literal set to maximum value (refer to device datasheet,                   */
235 /* parameter "tSTART_SCALER").                                                */
236 /* Unit: us                                                                   */
237 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
238 
239 /**
240   * @}
241   */
242 
243 /**
244   * @}
245   */
246 
247 /* Exported macro ----------------------------------------------------------------------------------------------------*/
248 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
249   * @{
250   */
251 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
252   * @{
253   */
254 
255 /**
256   * @brief  Write a value in COMP register
257   * @param  __INSTANCE__ comparator instance
258   * @param  __REG__ Register to be written
259   * @param  __VALUE__ Value to be written in the register
260   * @retval None
261   */
262 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
263 
264 /**
265   * @brief  Read a value in COMP register
266   * @param  __INSTANCE__ comparator instance
267   * @param  __REG__ Register to be read
268   * @retval Register value
269   */
270 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
271 /**
272   * @}
273   */
274 
275 /**
276   * @}
277   */
278 
279 /* Exported functions ------------------------------------------------------------------------------------------------*/
280 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
281   * @{
282   */
283 
284 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
285   * @{
286   */
287 
288 /**
289   * @brief  Set comparator instance operating mode to adjust power and speed.
290   * @rmtoll CFGR1    PWRMODE        LL_COMP_SetPowerMode
291   * @param  COMPx Comparator instance
292   * @param  PowerMode This parameter can be one of the following values:
293   *         @arg @ref LL_COMP_POWERMODE_HIGHSPEED
294   *         @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
295   *         @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
296   * @retval None
297   */
LL_COMP_SetPowerMode(COMP_TypeDef * COMPx,uint32_t PowerMode)298 __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
299 {
300   MODIFY_REG(COMPx->CFGR1, COMP_CFGR1_PWRMODE, PowerMode);
301 }
302 
303 /**
304   * @brief  Get comparator instance operating mode to adjust power and speed.
305   * @rmtoll CFGR1    PWRMODE        LL_COMP_GetPowerMode
306   * @param  COMPx Comparator instance
307   * @retval Returned value can be one of the following values:
308   *         @arg @ref LL_COMP_POWERMODE_HIGHSPEED
309   *         @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
310   *         @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
311   */
LL_COMP_GetPowerMode(const COMP_TypeDef * COMPx)312 __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(const COMP_TypeDef *COMPx)
313 {
314   return (uint32_t)(READ_BIT(COMPx->CFGR1, COMP_CFGR1_PWRMODE));
315 }
316 
317 /**
318   * @}
319   */
320 
321 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
322   * @{
323   */
324 
325 /**
326   * @brief  Set comparator inputs minus (inverting) and plus (non-inverting).
327   * @note   In case of comparator input selected to be connected to IO:
328   *         GPIO pins are specific to each comparator instance.
329   *         Refer to description of parameters or to reference manual.
330   * @note   On this STM32 series, scaler bridge is configurable:
331   *         to optimize power consumption, this function enables the
332   *         voltage scaler bridge only when required
333   *         (when selecting comparator input based on VrefInt: VrefInt or
334   *         subdivision of VrefInt).
335   *         - For scaler bridge power consumption values,
336   *           refer to device datasheet, parameter "IDDA(SCALER)".
337   *         - Voltage scaler requires a delay for voltage stabilization.
338   *           Refer to device datasheet, parameter "tSTART_SCALER".
339   *         - Scaler bridge is common for all comparator instances,
340   *           therefore if at least one of the comparator instance
341   *           is requiring the scaler bridge, it remains enabled.
342   * @rmtoll CFGR1      INMSEL         LL_COMP_ConfigInputs\n
343   *         CFGR1      INPSEL         LL_COMP_ConfigInputs\n
344   *         CFGR1      BRGEN          LL_COMP_ConfigInputs\n
345   *         CFGR1      SCALEN         LL_COMP_ConfigInputs
346   * @param  COMPx Comparator instance
347   * @param  InputMinus This parameter can be one of the following values:
348   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
349   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
350   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
351   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
352   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
353   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
354   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
355   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
356   *         @arg @ref LL_COMP_INPUT_MINUS_IO3
357   *         @arg @ref LL_COMP_INPUT_MINUS_TEMPSENSOR
358   *         @arg @ref LL_COMP_INPUT_MINUS_VBAT
359   * @param  InputPlus This parameter can be one of the following values:
360   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
361   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
362   *         @arg @ref LL_COMP_INPUT_PLUS_IO3
363   *         @arg @ref LL_COMP_INPUT_PLUS_DAC1_CH1
364   * @retval None
365   */
LL_COMP_ConfigInputs(COMP_TypeDef * COMPx,uint32_t InputMinus,uint32_t InputPlus)366 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
367 {
368   MODIFY_REG(COMPx->CFGR2, COMP_CFGR2_INPSEL0, ((InputPlus == LL_COMP_INPUT_PLUS_IO2) ? COMP_CFGR2_INPSEL0 : 0U));
369 
370   MODIFY_REG(COMPx->CFGR1,
371              COMP_CFGR1_INMSEL | COMP_CFGR1_INPSEL1 | COMP_CFGR1_INPSEL2 | COMP_CFGR1_SCALEN | COMP_CFGR1_BRGEN,
372              InputMinus | InputPlus);
373 }
374 
375 /**
376   * @brief  Set comparator input plus (non-inverting).
377   * @note   In case of comparator input selected to be connected to IO:
378   *         GPIO pins are specific to each comparator instance.
379   *         Refer to description of parameters or to reference manual.
380   * @rmtoll CFGR1    INPSEL         LL_COMP_SetInputPlus
381   * @param  COMPx Comparator instance
382   * @param  InputPlus This parameter can be one of the following values:
383   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
384   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
385   *         @arg @ref LL_COMP_INPUT_PLUS_IO3
386   *         @arg @ref LL_COMP_INPUT_PLUS_DAC1_CH1
387   * @retval None
388   */
LL_COMP_SetInputPlus(COMP_TypeDef * COMPx,uint32_t InputPlus)389 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
390 {
391   MODIFY_REG(COMPx->CFGR2, COMP_CFGR2_INPSEL0, ((InputPlus == LL_COMP_INPUT_PLUS_IO2) ? COMP_CFGR2_INPSEL0 : 0U));
392   MODIFY_REG(COMPx->CFGR1, COMP_CFGR1_INPSEL1 | COMP_CFGR1_INPSEL2, InputPlus);
393 }
394 
395 /**
396   * @brief  Get comparator input plus (non-inverting).
397   * @note   In case of comparator input selected to be connected to IO:
398   *         GPIO pins are specific to each comparator instance.
399   *         Refer to description of parameters or to reference manual.
400   * @rmtoll CFGR1    INPSEL         LL_COMP_GetInputPlus
401   * @param  COMPx Comparator instance
402   * @retval Returned value can be one of the following values:
403   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
404   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
405   *         @arg @ref LL_COMP_INPUT_PLUS_IO3
406   *         @arg @ref LL_COMP_INPUT_PLUS_DAC1_CH1
407   */
LL_COMP_GetInputPlus(const COMP_TypeDef * COMPx)408 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(const COMP_TypeDef *COMPx)
409 {
410   uint32_t val;
411   val = (uint32_t)(READ_BIT(COMPx->CFGR1, COMP_CFGR1_INPSEL1 | COMP_CFGR1_INPSEL2));
412   val |= (uint32_t)(READ_BIT(COMPx->CFGR2, COMP_CFGR2_INPSEL0));
413 
414   return val;
415 }
416 
417 /**
418   * @brief  Set comparator input minus (inverting).
419   * @note   In case of comparator input selected to be connected to IO:
420   *         GPIO pins are specific to each comparator instance.
421   *         Refer to description of parameters or to reference manual.
422   * @note   On this STM32 series, scaler bridge is configurable:
423   *         to optimize power consumption, this function enables the
424   *         voltage scaler bridge only when required
425   *         (when selecting comparator input based on VrefInt: VrefInt or
426   *         subdivision of VrefInt).
427   *         - For scaler bridge power consumption values,
428   *           refer to device datasheet, parameter "IDDA(SCALER)".
429   *         - Voltage scaler requires a delay for voltage stabilization.
430   *           Refer to device datasheet, parameter "tSTART_SCALER".
431   *         - Scaler bridge is common for all comparator instances,
432   *           therefore if at least one of the comparator instance
433   *           is requiring the scaler bridge, it remains enabled.
434   * @rmtoll CFGR1     INMSEL         LL_COMP_SetInputMinus\n
435   *         CFGR1     BRGEN          LL_COMP_SetInputMinus\n
436   *         CFGR1     SCALEN         LL_COMP_SetInputMinus
437   * @param  COMPx Comparator instance
438   * @param  InputMinus This parameter can be one of the following values:
439   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
440   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
441   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
442   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
443   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
444   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
445   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
446   *         @arg @ref LL_COMP_INPUT_MINUS_IO3
447   *         @arg @ref LL_COMP_INPUT_MINUS_TEMPSENSOR
448   *         @arg @ref LL_COMP_INPUT_MINUS_VBAT
449   * @retval None
450   */
LL_COMP_SetInputMinus(COMP_TypeDef * COMPx,uint32_t InputMinus)451 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
452 {
453   MODIFY_REG(COMPx->CFGR1, COMP_CFGR1_INMSEL | COMP_CFGR1_SCALEN | COMP_CFGR1_BRGEN, InputMinus);
454 }
455 
456 /**
457   * @brief  Get comparator input minus (inverting).
458   * @note   In case of comparator input selected to be connected to IO:
459   *         GPIO pins are specific to each comparator instance.
460   *         Refer to description of parameters or to reference manual.
461   * @rmtoll CFGR1     INMSEL         LL_COMP_GetInputMinus\n
462   *         CFGR1     BRGEN          LL_COMP_GetInputMinus\n
463   *         CFGR1     SCALEN         LL_COMP_GetInputMinus
464   * @param  COMPx Comparator instance
465   * @retval Returned value can be one of the following values:
466   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
467   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
468   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
469   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
470   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
471   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
472   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
473   *         @arg @ref LL_COMP_INPUT_MINUS_IO3
474   *         @arg @ref LL_COMP_INPUT_MINUS_TEMPSENSOR
475   *         @arg @ref LL_COMP_INPUT_MINUS_VBAT
476   */
LL_COMP_GetInputMinus(const COMP_TypeDef * COMPx)477 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(const COMP_TypeDef *COMPx)
478 {
479   return (uint32_t)(READ_BIT(COMPx->CFGR1, COMP_CFGR1_INMSEL | COMP_CFGR1_SCALEN | COMP_CFGR1_BRGEN));
480 }
481 
482 /**
483   * @brief  Set comparator instance hysteresis mode of the input minus (inverting input).
484   * @rmtoll CFGR1    HYST           LL_COMP_SetInputHysteresis
485   * @param  COMPx Comparator instance
486   * @param  InputHysteresis This parameter can be one of the following values:
487   *         @arg @ref LL_COMP_HYSTERESIS_NONE
488   *         @arg @ref LL_COMP_HYSTERESIS_LOW
489   *         @arg @ref LL_COMP_HYSTERESIS_MEDIUM
490   *         @arg @ref LL_COMP_HYSTERESIS_HIGH
491   * @retval None
492   */
LL_COMP_SetInputHysteresis(COMP_TypeDef * COMPx,uint32_t InputHysteresis)493 __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
494 {
495   MODIFY_REG(COMPx->CFGR1, COMP_CFGR1_HYST, InputHysteresis);
496 }
497 
498 /**
499   * @brief  Get comparator instance hysteresis mode of the minus (inverting) input.
500   * @rmtoll CSR      HYST           LL_COMP_GetInputHysteresis
501   * @param  COMPx Comparator instance
502   * @retval Returned value can be one of the following values:
503   *         @arg @ref LL_COMP_HYSTERESIS_NONE
504   *         @arg @ref LL_COMP_HYSTERESIS_LOW
505   *         @arg @ref LL_COMP_HYSTERESIS_MEDIUM
506   *         @arg @ref LL_COMP_HYSTERESIS_HIGH
507   */
LL_COMP_GetInputHysteresis(const COMP_TypeDef * COMPx)508 __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(const COMP_TypeDef *COMPx)
509 {
510   return (uint32_t)(READ_BIT(COMPx->CFGR1, COMP_CFGR1_HYST));
511 }
512 
513 /**
514   * @}
515   */
516 
517 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
518   * @{
519   */
520 
521 /**
522   * @brief  Set comparator instance output polarity.
523   * @rmtoll CFGR1    POLARITY       LL_COMP_SetOutputPolarity
524   * @param  COMPx Comparator instance
525   * @param  OutputPolarity This parameter can be one of the following values:
526   *         @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
527   *         @arg @ref LL_COMP_OUTPUTPOL_INVERTED
528   * @retval None
529   */
LL_COMP_SetOutputPolarity(COMP_TypeDef * COMPx,uint32_t OutputPolarity)530 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
531 {
532   MODIFY_REG(COMPx->CFGR1, COMP_CFGR1_POLARITY, OutputPolarity);
533 }
534 
535 /**
536   * @brief  Get comparator instance output polarity.
537   * @rmtoll CFGR1    POLARITY       LL_COMP_GetOutputPolarity
538   * @param  COMPx Comparator instance
539   * @retval Returned value can be one of the following values:
540   *         @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
541   *         @arg @ref LL_COMP_OUTPUTPOL_INVERTED
542   */
LL_COMP_GetOutputPolarity(const COMP_TypeDef * COMPx)543 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(const COMP_TypeDef *COMPx)
544 {
545   return (uint32_t)(READ_BIT(COMPx->CFGR1, COMP_CFGR1_POLARITY));
546 }
547 
548 /**
549   * @brief  Set comparator instance blanking source.
550   * @note   Blanking source may be specific to each comparator instance.
551   *         Refer to description of parameters or to reference manual.
552   * @note   Availability of parameters of blanking source from timer
553   *         depends on timers availability on the selected device.
554   * @rmtoll CFGR     BLANKING       LL_COMP_SetOutputBlankingSource
555   * @param  COMPx Comparator instance
556   * @param  BlankingSource This parameter can be one of the following values:
557   *         @arg @ref LL_COMP_BLANKINGSRC_NONE
558   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5
559   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3
560   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3
561   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4
562   *         @arg @ref LL_COMP_BLANKINGSRC_LPTIM1_OC2
563   *         @arg @ref LL_COMP_BLANKINGSRC_LPTIM2_OC2
564   * @retval None
565   */
LL_COMP_SetOutputBlankingSource(COMP_TypeDef * COMPx,uint32_t BlankingSource)566 __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
567 {
568   MODIFY_REG(COMPx->CFGR1, COMP_CFGR1_BLANKING, BlankingSource);
569 }
570 
571 /**
572   * @brief  Get comparator instance blanking source.
573   * @note   Availability of parameters of blanking source from timer
574   *         depends on timers availability on the selected device.
575   * @note   Blanking source may be specific to each comparator instance.
576   *         Refer to description of parameters or to reference manual.
577   * @rmtoll CFGR     BLANKING       LL_COMP_GetOutputBlankingSource
578   * @param  COMPx Comparator instance
579   * @retval Returned value can be one of the following values:
580   *         @arg @ref LL_COMP_BLANKINGSRC_NONE
581   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5
582   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3
583   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3
584   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4
585   *         @arg @ref LL_COMP_BLANKINGSRC_LPTIM1_OC2
586   *         @arg @ref LL_COMP_BLANKINGSRC_LPTIM2_OC2
587   */
LL_COMP_GetOutputBlankingSource(const COMP_TypeDef * COMPx)588 __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(const COMP_TypeDef *COMPx)
589 {
590   return (uint32_t)(READ_BIT(COMPx->CFGR1, COMP_CFGR1_BLANKING));
591 }
592 
593 /**
594   * @}
595   */
596 
597 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
598   * @{
599   */
600 
601 /**
602   * @brief  Enable comparator instance.
603   * @note   After enable from off state, comparator requires a delay
604   *         to reach reach propagation delay specification.
605   *         Refer to device datasheet, parameter "tSTART".
606   * @rmtoll CFGR1    EN             LL_COMP_Enable
607   * @param  COMPx Comparator instance
608   * @retval None
609   */
LL_COMP_Enable(COMP_TypeDef * COMPx)610 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
611 {
612   SET_BIT(COMPx->CFGR1, COMP_CFGR1_EN);
613 }
614 
615 /**
616   * @brief  Disable comparator instance.
617   * @rmtoll CFGR1    EN             LL_COMP_Disable
618   * @param  COMPx Comparator instance
619   * @retval None
620   */
LL_COMP_Disable(COMP_TypeDef * COMPx)621 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
622 {
623   CLEAR_BIT(COMPx->CFGR1, COMP_CFGR1_EN);
624 }
625 
626 /**
627   * @brief  Get comparator enable state
628   *         (0: COMP is disabled, 1: COMP is enabled)
629   * @rmtoll CFGR1    EN             LL_COMP_IsEnabled
630   * @param  COMPx Comparator instance
631   * @retval State of bit (1 or 0).
632   */
LL_COMP_IsEnabled(const COMP_TypeDef * COMPx)633 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(const COMP_TypeDef *COMPx)
634 {
635   return ((READ_BIT(COMPx->CFGR1, COMP_CFGR1_EN) == (COMP_CFGR1_EN)) ? 1UL : 0UL);
636 }
637 
638 /**
639   * @brief  Lock comparator instance.
640   * @note   Once locked, comparator configuration can be accessed in read-only.
641   * @note   The only way to unlock the comparator is a device hardware reset.
642   * @rmtoll CFGR1    LOCK           LL_COMP_Lock
643   * @param  COMPx Comparator instance
644   * @retval None
645   */
LL_COMP_Lock(COMP_TypeDef * COMPx)646 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
647 {
648   SET_BIT(COMPx->CFGR1, COMP_CFGR1_LOCK);
649 }
650 
651 /**
652   * @brief  Get comparator lock state
653   *         (0: COMP is unlocked, 1: COMP is locked).
654   * @note   Once locked, comparator configuration can be accessed in read-only.
655   * @note   The only way to unlock the comparator is a device hardware reset.
656   * @rmtoll CFGR1    LOCK           LL_COMP_IsLocked
657   * @param  COMPx Comparator instance
658   * @retval State of bit (1 or 0).
659   */
LL_COMP_IsLocked(const COMP_TypeDef * COMPx)660 __STATIC_INLINE uint32_t LL_COMP_IsLocked(const COMP_TypeDef *COMPx)
661 {
662   return ((READ_BIT(COMPx->CFGR1, COMP_CFGR1_LOCK) == (COMP_CFGR1_LOCK)) ? 1UL : 0UL);
663 }
664 
665 /**
666   * @brief  Read comparator instance output level.
667   * @note   The comparator output level depends on the selected polarity
668   *         (Refer to function @ref LL_COMP_SetOutputPolarity()).
669   *         If the comparator polarity is not inverted:
670   *          - Comparator output is low when the input plus
671   *            is at a lower voltage than the input minus
672   *          - Comparator output is high when the input plus
673   *            is at a higher voltage than the input minus
674   *         If the comparator polarity is inverted:
675   *          - Comparator output is high when the input plus
676   *            is at a lower voltage than the input minus
677   *          - Comparator output is low when the input plus
678   *            is at a higher voltage than the input minus
679   * @rmtoll CFGR     VALUE          LL_COMP_ReadOutputLevel
680   * @param  COMPx Comparator instance
681   * @retval Returned value can be one of the following values:
682   *         @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
683   *         @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
684   */
LL_COMP_ReadOutputLevel(const COMP_TypeDef * COMPx)685 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(const COMP_TypeDef *COMPx)
686 {
687   return (uint32_t)(READ_BIT(COMPx->SR, COMP_SR_C1VAL));
688 }
689 
690 /**
691   * @}
692   */
693 
694 /** @defgroup COMP_LL_EF_FLAG_Management Comparator flag Management
695   * @{
696   */
697 
698 /**
699   * @brief  Get comparator output trigger flag (latched)
700   * @rmtoll SR       C1IF           LL_COMP_IsActiveFlag_OutputTrig
701   * @param  COMPx Comparator instance
702   * @retval State of bit (1 or 0).
703   */
LL_COMP_IsActiveFlag_OutputTrig(const COMP_TypeDef * COMPx)704 __STATIC_INLINE uint32_t LL_COMP_IsActiveFlag_OutputTrig(const COMP_TypeDef *COMPx)
705 {
706   return ((READ_BIT(COMPx->SR, COMP_SR_C1IF) == (COMP_SR_C1IF)) ? 1UL : 0UL);
707 }
708 
709 /**
710   * @brief  Clear comparator comparator output trigger flag (latched)
711   * @rmtoll ICFR     CC1IF          LL_COMP_ClearFlag_OutputTrig
712   * @param  COMPx Comparator instance
713   * @retval None
714   */
LL_COMP_ClearFlag_OutputTrig(COMP_TypeDef * COMPx)715 __STATIC_INLINE void LL_COMP_ClearFlag_OutputTrig(COMP_TypeDef *COMPx)
716 {
717   SET_BIT(COMPx->ICFR, COMP_ICFR_CC1IF);
718 }
719 
720 /**
721   * @}
722   */
723 
724 /** @defgroup COMP_LL_EF_IT_Management Comparartor IT management
725   * @{
726   */
727 
728 /**
729   * @brief  Enable comparator output trigger interrupt
730   * @rmtoll ICFR     ITEN           LL_COMP_EnableIT_OutputTrig
731   * @param  COMPx Comparator instance
732   * @retval None
733   */
LL_COMP_EnableIT_OutputTrig(COMP_TypeDef * COMPx)734 __STATIC_INLINE void LL_COMP_EnableIT_OutputTrig(COMP_TypeDef *COMPx)
735 {
736   SET_BIT(COMPx->CFGR1, COMP_CFGR1_ITEN);
737 }
738 
739 /**
740   * @brief  Disable comparator output trigger interrupt
741   * @rmtoll ICFR     ITEN           LL_COMP_DisableIT_OutputTrig
742   * @param  COMPx Comparator instance
743   * @retval None
744   */
LL_COMP_DisableIT_OutputTrig(COMP_TypeDef * COMPx)745 __STATIC_INLINE void LL_COMP_DisableIT_OutputTrig(COMP_TypeDef *COMPx)
746 {
747   CLEAR_BIT(COMPx->CFGR1, COMP_CFGR1_ITEN);
748 }
749 
750 /**
751   * @brief  Get comparator output trigger interrupt state
752   * @rmtoll ICFR     ITEN           LL_COMP_IsEnabledIT_OutputTrig
753   * @param  COMPx Comparator instance
754   * @retval State of bit (1 or 0).
755   */
LL_COMP_IsEnabledIT_OutputTrig(const COMP_TypeDef * COMPx)756 __STATIC_INLINE uint32_t LL_COMP_IsEnabledIT_OutputTrig(const COMP_TypeDef *COMPx)
757 {
758   return ((READ_BIT(COMPx->CFGR1, COMP_CFGR1_ITEN) == (COMP_CFGR1_ITEN)) ? 1UL : 0UL);
759 }
760 
761 /**
762   * @}
763   */
764 
765 #if defined(USE_FULL_LL_DRIVER)
766 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
767   * @{
768   */
769 
770 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
771 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, const LL_COMP_InitTypeDef *COMP_InitStruct);
772 void        LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
773 
774 /**
775   * @}
776   */
777 #endif /* USE_FULL_LL_DRIVER */
778 
779 /**
780   * @}
781   */
782 
783 /**
784   * @}
785   */
786 
787 /**
788   * @}
789   */
790 
791 #endif /* COMP1 */
792 
793 /**
794   * @}
795   */
796 
797 #ifdef __cplusplus
798 }
799 #endif
800 
801 #endif /* __STM32H5xx_LL_COMP_H */
802