1 /**
2   ******************************************************************************
3   * @file    stm32l5xx_ll_comp.h
4   * @author  MCD Application Team
5   * @brief   Header file of COMP LL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2019 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32L5xx_LL_COMP_H
21 #define STM32L5xx_LL_COMP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l5xx.h"
29 
30 /** @addtogroup STM32L5xx_LL_Driver
31   * @{
32   */
33 
34 #if defined (COMP1) || defined (COMP2)
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 (30UL) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
49 
50 /**
51   * @}
52   */
53 
54 /* Private macros ------------------------------------------------------------*/
55 /** @defgroup COMP_LL_Private_Macros COMP Private Macros
56   * @{
57   */
58 
59 /**
60   * @}
61   */
62 
63 /* Exported types ------------------------------------------------------------*/
64 #if defined(USE_FULL_LL_DRIVER)
65 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
66   * @{
67   */
68 
69 /**
70   * @brief  Structure definition of some features of COMP instance.
71   */
72 typedef struct
73 {
74   uint32_t PowerMode;                   /*!< Set comparator operating mode to adjust power and speed.
75                                              This parameter can be a value of @ref COMP_LL_EC_POWERMODE
76                                              This feature can be modified afterwards using unitary
77                                              function @ref LL_COMP_SetPowerMode(). */
78 
79   uint32_t InputPlus;                   /*!< Set comparator input plus (non-inverting input).
80                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
81                                              This feature can be modified afterwards using unitary function
82                                              @ref LL_COMP_SetInputPlus(). */
83 
84   uint32_t InputMinus;                  /*!< Set comparator input minus (inverting input).
85                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
86                                              This feature can be modified afterwards using unitary function
87                                               @ref LL_COMP_SetInputMinus(). */
88 
89   uint32_t InputHysteresis;             /*!< Set comparator hysteresis mode of the input minus.
90                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
91                                              This feature can be modified afterwards using unitary function
92                                              @ref LL_COMP_SetInputHysteresis(). */
93 
94   uint32_t OutputPolarity;              /*!< Set comparator output polarity.
95                                              This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
96                                              This feature can be modified afterwards using unitary function
97                                              @ref LL_COMP_SetOutputPolarity(). */
98 
99   uint32_t OutputBlankingSource;        /*!< Set comparator blanking source.
100                                              This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
101                                              This feature can be modified afterwards using unitary function
102                                              @ref LL_COMP_SetOutputBlankingSource(). */
103 
104 } LL_COMP_InitTypeDef;
105 
106 /**
107   * @}
108   */
109 #endif /* USE_FULL_LL_DRIVER */
110 
111 /* Exported constants --------------------------------------------------------*/
112 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
113   * @{
114   */
115 
116 
117 /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
118   * @{
119   */
120 #define LL_COMP_WINDOWMODE_DISABLE                 (0x00000000UL)          /*!< Window mode disable: Comparators 1 and 2 are independent */
121 #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE)      /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP1 input plus (COMP2 input plus is no more accessible). */
122 /**
123   * @}
124   */
125 
126 
127 
128 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
129   * @{
130   */
131 #define LL_COMP_POWERMODE_HIGHSPEED     (0x00000000UL)                            /*!< COMP power mode to high speed */
132 #define LL_COMP_POWERMODE_MEDIUMSPEED   (COMP_CSR_PWRMODE_0)                      /*!< COMP power mode to medium speed */
133 #define LL_COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_PWRMODE_1 | COMP_CSR_PWRMODE_0) /*!< COMP power mode to ultra-low power */
134 /**
135   * @}
136   */
137 
138 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
139   * @{
140   */
141 #define LL_COMP_INPUT_PLUS_IO1          (0x00000000UL)                          /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */
142 #define LL_COMP_INPUT_PLUS_IO2          (COMP_CSR_INPSEL_0)                     /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
143 #define LL_COMP_INPUT_PLUS_IO3          (COMP_CSR_INPSEL_1)                     /*!< Comparator input plus connected to IO3 (pin PA2 for COMP1, not available for COMP2) */
144 /**
145   * @}
146   */
147 
148 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
149   * @{
150   */
151 #define LL_COMP_INPUT_MINUS_1_4VREFINT  (                                                            COMP_CSR_SCALEN | COMP_CSR_BRGEN)        /*!< Comparator input minus connected to 1/4 VrefInt  */
152 #define LL_COMP_INPUT_MINUS_1_2VREFINT  (                                        COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN | COMP_CSR_BRGEN)        /*!< Comparator input minus connected to 1/2 VrefInt  */
153 #define LL_COMP_INPUT_MINUS_3_4VREFINT  (                    COMP_CSR_INMSEL_1                     | COMP_CSR_SCALEN | COMP_CSR_BRGEN)        /*!< Comparator input minus connected to 3/4 VrefInt  */
154 #define LL_COMP_INPUT_MINUS_VREFINT     (                    COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN                 )        /*!< Comparator input minus connected to VrefInt */
155 #define LL_COMP_INPUT_MINUS_DAC1_CH1    (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1)  */
156 #define LL_COMP_INPUT_MINUS_DAC1_CH2    (COMP_CSR_INMSEL_2                     | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2)  */
157 #define LL_COMP_INPUT_MINUS_IO1         (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1                    )                                           /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PB3 for COMP2) */
158 #define LL_COMP_INPUT_MINUS_IO2         (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PB7 for COMP2) */
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_CSR_HYST_0) /*!< Hysteresis level low */
168 #define LL_COMP_HYSTERESIS_MEDIUM       (COMP_CSR_HYST_1                  ) /*!< Hysteresis level medium */
169 #define LL_COMP_HYSTERESIS_HIGH         (COMP_CSR_HYST_1 | COMP_CSR_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 output is high when the plus (non-inverting) input is at a higher voltage than the minus (inverting) input */
178 #define LL_COMP_OUTPUTPOL_INVERTED      (COMP_CSR_POLARITY)     /*!< COMP output polarity is inverted: comparator output is low when the plus (non-inverting) input is at a lower voltage than the minus (inverting) input */
179 /**
180   * @}
181   */
182 
183 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
184   * @{
185   */
186 #define LL_COMP_BLANKINGSRC_NONE            (0x00000000UL)          /*!<Comparator output without blanking */
187 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1  (COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */
188 #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1  (COMP_CSR_BLANKING_1)   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */
189 #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1  (COMP_CSR_BLANKING_2)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */
190 #define LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2  (COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */
191 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2  (COMP_CSR_BLANKING_1)   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2) */
192 #define LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2)   /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP2) */
193 /**
194   * @}
195   */
196 
197 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
198   * @{
199   */
200 #define LL_COMP_OUTPUT_LEVEL_LOW        (0x00000000UL)          /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
201 #define LL_COMP_OUTPUT_LEVEL_HIGH       (0x00000001UL)          /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
202 /**
203   * @}
204   */
205 
206 /** @defgroup COMP_LL_EC_HW_DELAYS  Definitions of COMP hardware constraints delays
207   * @note   Only COMP peripheral HW delays are defined in COMP LL driver driver,
208   *         not timeout values.
209   *         For details on delays values, refer to descriptions in source code
210   *         above each literal definition.
211   * @{
212   */
213 
214 /* Delay for comparator startup time.                                         */
215 /* Note: Delay required to reach propagation delay specification.             */
216 /* Literal set to maximum value (refer to device datasheet,                   */
217 /* parameter "tSTART").                                                       */
218 /* Unit: us                                                                   */
219 #define LL_COMP_DELAY_STARTUP_US          ( 80UL) /*!< Delay for COMP startup time */
220 
221 /* Delay for comparator voltage scaler stabilization time.                    */
222 /* Note: Voltage scaler is used when selecting comparator input               */
223 /*       based on VrefInt: VrefInt or subdivision of VrefInt.                 */
224 /* Literal set to maximum value (refer to device datasheet,                   */
225 /* parameter "tSTART_SCALER").                                                */
226 /* Unit: us                                                                   */
227 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
228 
229 /**
230   * @}
231   */
232 
233 /**
234   * @}
235   */
236 
237 /* Exported macro ------------------------------------------------------------*/
238 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
239   * @{
240   */
241 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
242   * @{
243   */
244 
245 /**
246   * @brief  Write a value in COMP register
247   * @param  __INSTANCE__ comparator instance
248   * @param  __REG__ Register to be written
249   * @param  __VALUE__ Value to be written in the register
250   * @retval None
251   */
252 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
253 
254 /**
255   * @brief  Read a value in COMP register
256   * @param  __INSTANCE__ comparator instance
257   * @param  __REG__ Register to be read
258   * @retval Register value
259   */
260 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
261 /**
262   * @}
263   */
264 
265 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
266   * @{
267   */
268 
269 /**
270   * @brief  Helper macro to select the COMP common instance
271   *         to which is belonging the selected COMP instance.
272   * @note   COMP common register instance can be used to
273   *         set parameters common to several COMP instances.
274   *         Refer to functions having argument "COMPxy_COMMON" as parameter.
275   * @param  __COMPx__ COMP instance
276   * @retval COMP common instance or value "0" if there is no COMP common instance.
277   */
278 #define __LL_COMP_COMMON_INSTANCE(__COMPx__)          (COMP12_COMMON)
279 
280 /**
281   * @}
282   */
283 
284 /**
285   * @}
286   */
287 
288 /* Exported functions --------------------------------------------------------*/
289 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
290   * @{
291   */
292 
293 /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration
294   *           of COMP hierarchical scope: common to several COMP instances
295   * @{
296   */
297 
298 
299 /**
300   * @brief  Set window mode of a pair of comparators instances
301   *         (2 consecutive COMP instances COMP<x> and COMP<x+1>).
302   * @rmtoll CSR      WINMODE        LL_COMP_SetCommonWindowMode
303   * @param  COMPxy_COMMON Comparator common instance
304   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
305   * @param  WindowMode This parameter can be one of the following values:
306   *         @arg @ref LL_COMP_WINDOWMODE_DISABLE
307   *         @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
308   * @retval None
309   */
LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef * COMPxy_COMMON,uint32_t WindowMode)310 __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
311 {
312   /* Note: On this STM32 series, window mode can be set only                  */
313   /*       from COMP instance: COMP2.                                         */
314   MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_WINMODE, WindowMode);
315 }
316 
317 /**
318   * @brief  Get window mode of a pair of comparators instances
319   *         (2 consecutive COMP instances COMP<x> and COMP<x+1>).
320   * @rmtoll CSR      WINMODE        LL_COMP_GetCommonWindowMode
321   * @param  COMPxy_COMMON Comparator common instance
322   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
323   * @retval Returned value can be one of the following values:
324   *         @arg @ref LL_COMP_WINDOWMODE_DISABLE
325   *         @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
326   */
LL_COMP_GetCommonWindowMode(const COMP_Common_TypeDef * COMPxy_COMMON)327 __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(const COMP_Common_TypeDef *COMPxy_COMMON)
328 {
329   return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_WINMODE));
330 }
331 
332 
333 
334 /**
335   * @}
336   */
337 
338 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
339   * @{
340   */
341 
342 /**
343   * @brief  Set comparator instance operating mode to adjust power and speed.
344   * @rmtoll CSR      PWRMODE        LL_COMP_SetPowerMode
345   * @param  COMPx Comparator instance
346   * @param  PowerMode This parameter can be one of the following values:
347   *         @arg @ref LL_COMP_POWERMODE_HIGHSPEED
348   *         @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
349   *         @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
350   * @retval None
351   */
LL_COMP_SetPowerMode(COMP_TypeDef * COMPx,uint32_t PowerMode)352 __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
353 {
354   MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE, PowerMode);
355 }
356 
357 /**
358   * @brief  Get comparator instance operating mode to adjust power and speed.
359   * @rmtoll CSR      PWRMODE        LL_COMP_GetPowerMode
360   * @param  COMPx Comparator instance
361   * @retval Returned value can be one of the following values:
362   *         @arg @ref LL_COMP_POWERMODE_HIGHSPEED
363   *         @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
364   *         @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
365   */
LL_COMP_GetPowerMode(const COMP_TypeDef * COMPx)366 __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(const COMP_TypeDef *COMPx)
367 {
368   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_PWRMODE));
369 }
370 
371 /**
372   * @}
373   */
374 
375 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
376   * @{
377   */
378 
379 /**
380   * @brief  Set comparator inputs minus (inverting) and plus (non-inverting).
381   * @note   In case of comparator input selected to be connected to IO:
382   *         GPIO pins are specific to each comparator instance.
383   *         Refer to description of parameters or to reference manual.
384   * @note   On this STM32 series, scaler bridge is configurable:
385   *         to optimize power consumption, this function enables the
386   *         voltage scaler bridge only when required
387   *         (when selecting comparator input based on VrefInt: VrefInt or
388   *         subdivision of VrefInt).
389   *         - For scaler bridge power consumption values,
390   *           refer to device datasheet, parameter "IDDA(SCALER)".
391   *         - Voltage scaler requires a delay for voltage stabilization.
392   *           Refer to device datasheet, parameter "tSTART_SCALER".
393   *         - Scaler bridge is common for all comparator instances,
394   *           therefore if at least one of the comparator instance
395   *           is requiring the scaler bridge, it remains enabled.
396   * @rmtoll CSR      INMSEL         LL_COMP_ConfigInputs\n
397   *         CSR      INPSEL         LL_COMP_ConfigInputs\n
398   *         CSR      BRGEN          LL_COMP_ConfigInputs\n
399   *         CSR      SCALEN         LL_COMP_ConfigInputs
400   * @param  COMPx Comparator instance
401   * @param  InputMinus This parameter can be one of the following values:
402   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
403   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
404   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
405   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
406   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
407   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
408   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
409   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
410   * @param  InputPlus This parameter can be one of the following values:
411   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
412   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
413   * @retval None
414   */
LL_COMP_ConfigInputs(COMP_TypeDef * COMPx,uint32_t InputMinus,uint32_t InputPlus)415 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
416 {
417   MODIFY_REG(COMPx->CSR,
418              COMP_CSR_INMSEL | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN,
419              InputMinus | InputPlus);
420 }
421 
422 /**
423   * @brief  Set comparator input plus (non-inverting).
424   * @note   In case of comparator input selected to be connected to IO:
425   *         GPIO pins are specific to each comparator instance.
426   *         Refer to description of parameters or to reference manual.
427   * @rmtoll CSR      INPSEL         LL_COMP_SetInputPlus
428   * @param  COMPx Comparator instance
429   * @param  InputPlus This parameter can be one of the following values:
430   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
431   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
432   * @retval None
433   */
LL_COMP_SetInputPlus(COMP_TypeDef * COMPx,uint32_t InputPlus)434 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
435 {
436   MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
437 }
438 
439 /**
440   * @brief  Get comparator input plus (non-inverting).
441   * @note   In case of comparator input selected to be connected to IO:
442   *         GPIO pins are specific to each comparator instance.
443   *         Refer to description of parameters or to reference manual.
444   * @rmtoll CSR      INPSEL         LL_COMP_GetInputPlus
445   * @param  COMPx Comparator instance
446   * @retval Returned value can be one of the following values:
447   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
448   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
449   */
LL_COMP_GetInputPlus(const COMP_TypeDef * COMPx)450 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(const COMP_TypeDef *COMPx)
451 {
452   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
453 }
454 
455 /**
456   * @brief  Set comparator input minus (inverting).
457   * @note   In case of comparator input selected to be connected to IO:
458   *         GPIO pins are specific to each comparator instance.
459   *         Refer to description of parameters or to reference manual.
460   * @note   On this STM32 series, scaler bridge is configurable:
461   *         to optimize power consumption, this function enables the
462   *         voltage scaler bridge only when required
463   *         (when selecting comparator input based on VrefInt: VrefInt or
464   *         subdivision of VrefInt).
465   *         - For scaler bridge power consumption values,
466   *           refer to device datasheet, parameter "IDDA(SCALER)".
467   *         - Voltage scaler requires a delay for voltage stabilization.
468   *           Refer to device datasheet, parameter "tSTART_SCALER".
469   *         - Scaler bridge is common for all comparator instances,
470   *           therefore if at least one of the comparator instance
471   *           is requiring the scaler bridge, it remains enabled.
472   * @rmtoll CSR      INMSEL         LL_COMP_SetInputMinus\n
473   *         CSR      BRGEN          LL_COMP_SetInputMinus\n
474   *         CSR      SCALEN         LL_COMP_SetInputMinus
475   * @param  COMPx Comparator instance
476   * @param  InputMinus This parameter can be one of the following values:
477   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
478   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
479   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
480   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
481   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
482   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
483   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
484   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
485   * @retval None
486   */
LL_COMP_SetInputMinus(COMP_TypeDef * COMPx,uint32_t InputMinus)487 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
488 {
489   MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, InputMinus);
490 }
491 
492 /**
493   * @brief  Get comparator input minus (inverting).
494   * @note   In case of comparator input selected to be connected to IO:
495   *         GPIO pins are specific to each comparator instance.
496   *         Refer to description of parameters or to reference manual.
497   * @rmtoll CSR      INMSEL         LL_COMP_GetInputMinus\n
498   *         CSR      BRGEN          LL_COMP_GetInputMinus\n
499   *         CSR      SCALEN         LL_COMP_GetInputMinus
500   * @param  COMPx Comparator instance
501   * @retval Returned value can be one of the following values:
502   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
503   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
504   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
505   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
506   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
507   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
508   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
509   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
510   */
LL_COMP_GetInputMinus(const COMP_TypeDef * COMPx)511 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(const COMP_TypeDef *COMPx)
512 {
513   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN));
514 }
515 
516 /**
517   * @brief  Set comparator instance hysteresis mode of the input minus (inverting input).
518   * @rmtoll CSR      HYST           LL_COMP_SetInputHysteresis
519   * @param  COMPx Comparator instance
520   * @param  InputHysteresis This parameter can be one of the following values:
521   *         @arg @ref LL_COMP_HYSTERESIS_NONE
522   *         @arg @ref LL_COMP_HYSTERESIS_LOW
523   *         @arg @ref LL_COMP_HYSTERESIS_MEDIUM
524   *         @arg @ref LL_COMP_HYSTERESIS_HIGH
525   * @retval None
526   */
LL_COMP_SetInputHysteresis(COMP_TypeDef * COMPx,uint32_t InputHysteresis)527 __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
528 {
529   MODIFY_REG(COMPx->CSR, COMP_CSR_HYST, InputHysteresis);
530 }
531 
532 /**
533   * @brief  Get comparator instance hysteresis mode of the minus (inverting) input.
534   * @rmtoll CSR      HYST           LL_COMP_GetInputHysteresis
535   * @param  COMPx Comparator instance
536   * @retval Returned value can be one of the following values:
537   *         @arg @ref LL_COMP_HYSTERESIS_NONE
538   *         @arg @ref LL_COMP_HYSTERESIS_LOW
539   *         @arg @ref LL_COMP_HYSTERESIS_MEDIUM
540   *         @arg @ref LL_COMP_HYSTERESIS_HIGH
541   */
LL_COMP_GetInputHysteresis(const COMP_TypeDef * COMPx)542 __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(const COMP_TypeDef *COMPx)
543 {
544   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_HYST));
545 }
546 
547 /**
548   * @}
549   */
550 
551 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
552   * @{
553   */
554 
555 /**
556   * @brief  Set comparator instance output polarity.
557   * @rmtoll CSR      POLARITY       LL_COMP_SetOutputPolarity
558   * @param  COMPx Comparator instance
559   * @param  OutputPolarity This parameter can be one of the following values:
560   *         @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
561   *         @arg @ref LL_COMP_OUTPUTPOL_INVERTED
562   * @retval None
563   */
LL_COMP_SetOutputPolarity(COMP_TypeDef * COMPx,uint32_t OutputPolarity)564 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
565 {
566   MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
567 }
568 
569 /**
570   * @brief  Get comparator instance output polarity.
571   * @rmtoll CSR      POLARITY       LL_COMP_GetOutputPolarity
572   * @param  COMPx Comparator instance
573   * @retval Returned value can be one of the following values:
574   *         @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
575   *         @arg @ref LL_COMP_OUTPUTPOL_INVERTED
576   */
LL_COMP_GetOutputPolarity(const COMP_TypeDef * COMPx)577 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(const COMP_TypeDef *COMPx)
578 {
579   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
580 }
581 
582 /**
583   * @brief  Set comparator instance blanking source.
584   * @note   Blanking source may be specific to each comparator instance.
585   *         Refer to description of parameters or to reference manual.
586   * @note   Availability of parameters of blanking source from timer
587   *         depends on timers availability on the selected device.
588   * @rmtoll CSR      BLANKING       LL_COMP_SetOutputBlankingSource
589   * @param  COMPx Comparator instance
590   * @param  BlankingSource This parameter can be one of the following values:
591   *         @arg @ref LL_COMP_BLANKINGSRC_NONE
592   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1  (1)(2)
593   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1  (1)(2)
594   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1  (1)(2)
595   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2  (1)(3)
596   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2  (1)(3)
597   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (1)(3)
598   *
599   *         (1) Parameter availability depending on timer availability
600   *             on the selected device.
601   *         (2) On STM32L5, parameter available only on comparator instance: COMP1.
602   *         (3) On STM32L5, parameter available only on comparator instance: COMP2.
603   * @retval None
604   */
LL_COMP_SetOutputBlankingSource(COMP_TypeDef * COMPx,uint32_t BlankingSource)605 __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
606 {
607   MODIFY_REG(COMPx->CSR, COMP_CSR_BLANKING, BlankingSource);
608 }
609 
610 /**
611   * @brief  Get comparator instance blanking source.
612   * @note   Availability of parameters of blanking source from timer
613   *         depends on timers availability on the selected device.
614   * @note   Blanking source may be specific to each comparator instance.
615   *         Refer to description of parameters or to reference manual.
616   * @rmtoll CSR      BLANKING       LL_COMP_GetOutputBlankingSource
617   * @param  COMPx Comparator instance
618   * @retval Returned value can be one of the following values:
619   *         @arg @ref LL_COMP_BLANKINGSRC_NONE
620   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1  (1)(2)
621   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1  (1)(2)
622   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1  (1)(2)
623   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP2  (1)(3)
624   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2  (1)(3)
625   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP2 (1)(3)
626   *
627   *         (1) Parameter availability depending on timer availability
628   *             on the selected device.
629   *         (2) On STM32L5, parameter available only on comparator instance: COMP1.
630   *         (3) On STM32L5, parameter available only on comparator instance: COMP2.
631   */
LL_COMP_GetOutputBlankingSource(const COMP_TypeDef * COMPx)632 __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(const COMP_TypeDef *COMPx)
633 {
634   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_BLANKING));
635 }
636 
637 /**
638   * @}
639   */
640 
641 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
642   * @{
643   */
644 
645 /**
646   * @brief  Enable comparator instance.
647   * @note   After enable from off state, comparator requires a delay
648   *         to reach reach propagation delay specification.
649   *         Refer to device datasheet, parameter "tSTART".
650   * @rmtoll CSR      EN             LL_COMP_Enable
651   * @param  COMPx Comparator instance
652   * @retval None
653   */
LL_COMP_Enable(COMP_TypeDef * COMPx)654 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
655 {
656   SET_BIT(COMPx->CSR, COMP_CSR_EN);
657 }
658 
659 /**
660   * @brief  Disable comparator instance.
661   * @rmtoll CSR      EN             LL_COMP_Disable
662   * @param  COMPx Comparator instance
663   * @retval None
664   */
LL_COMP_Disable(COMP_TypeDef * COMPx)665 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
666 {
667   CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
668 }
669 
670 /**
671   * @brief  Get comparator enable state
672   *         (0: COMP is disabled, 1: COMP is enabled)
673   * @rmtoll CSR      EN             LL_COMP_IsEnabled
674   * @param  COMPx Comparator instance
675   * @retval State of bit (1 or 0).
676   */
LL_COMP_IsEnabled(const COMP_TypeDef * COMPx)677 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(const COMP_TypeDef *COMPx)
678 {
679   return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1UL : 0UL);
680 }
681 
682 /**
683   * @brief  Lock comparator instance.
684   * @note   Once locked, comparator configuration can be accessed in read-only.
685   * @note   The only way to unlock the comparator is a device hardware reset.
686   * @rmtoll CSR      LOCK           LL_COMP_Lock
687   * @param  COMPx Comparator instance
688   * @retval None
689   */
LL_COMP_Lock(COMP_TypeDef * COMPx)690 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
691 {
692   SET_BIT(COMPx->CSR, COMP_CSR_LOCK);
693 }
694 
695 /**
696   * @brief  Get comparator lock state
697   *         (0: COMP is unlocked, 1: COMP is locked).
698   * @note   Once locked, comparator configuration can be accessed in read-only.
699   * @note   The only way to unlock the comparator is a device hardware reset.
700   * @rmtoll CSR      LOCK           LL_COMP_IsLocked
701   * @param  COMPx Comparator instance
702   * @retval State of bit (1 or 0).
703   */
LL_COMP_IsLocked(const COMP_TypeDef * COMPx)704 __STATIC_INLINE uint32_t LL_COMP_IsLocked(const COMP_TypeDef *COMPx)
705 {
706   return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1UL : 0UL);
707 }
708 
709 /**
710   * @brief  Read comparator instance output level.
711   * @note   The comparator output level depends on the selected polarity
712   *         (Refer to function @ref LL_COMP_SetOutputPolarity()).
713   *         If the comparator polarity is not inverted:
714   *          - Comparator output is low when the input plus
715   *            is at a lower voltage than the input minus
716   *          - Comparator output is high when the input plus
717   *            is at a higher voltage than the input minus
718   *         If the comparator polarity is inverted:
719   *          - Comparator output is high when the input plus
720   *            is at a lower voltage than the input minus
721   *          - Comparator output is low when the input plus
722   *            is at a higher voltage than the input minus
723   * @rmtoll CSR      VALUE          LL_COMP_ReadOutputLevel
724   * @param  COMPx Comparator instance
725   * @retval Returned value can be one of the following values:
726   *         @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
727   *         @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
728   */
LL_COMP_ReadOutputLevel(const COMP_TypeDef * COMPx)729 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(const COMP_TypeDef *COMPx)
730 {
731   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_VALUE)
732                     >> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
733 }
734 
735 /**
736   * @}
737   */
738 
739 #if defined(USE_FULL_LL_DRIVER)
740 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
741   * @{
742   */
743 
744 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
745 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, const LL_COMP_InitTypeDef *COMP_InitStruct);
746 void        LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
747 
748 /**
749   * @}
750   */
751 #endif /* USE_FULL_LL_DRIVER */
752 
753 /**
754   * @}
755   */
756 
757 /**
758   * @}
759   */
760 
761 /**
762   * @}
763   */
764 
765 #endif /* COMP1 || COMP2 */
766 
767 /**
768   * @}
769   */
770 
771 #ifdef __cplusplus
772 }
773 #endif
774 
775 #endif /* STM32L5xx_LL_COMP_H */
776