1 /**
2   ******************************************************************************
3   * @file    stm32g4xx_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 STM32G4xx_LL_COMP_H
21 #define STM32G4xx_LL_COMP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g4xx.h"
29 
30 /** @addtogroup STM32G4xx_LL_Driver
31   * @{
32   */
33 
34 
35 
36 /** @defgroup COMP_LL COMP
37   * @{
38   */
39 
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 
44 /* Private macros ------------------------------------------------------------*/
45 /** @defgroup COMP_LL_Private_Macros COMP Private Macros
46   * @{
47   */
48 
49 /**
50   * @}
51   */
52 
53 /* Exported types ------------------------------------------------------------*/
54 #if defined(USE_FULL_LL_DRIVER)
55 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
56   * @{
57   */
58 
59 /**
60   * @brief  Structure definition of some features of COMP instance.
61   */
62 typedef struct
63 {
64   uint32_t InputPlus;                   /*!< Set comparator input plus (non-inverting input).
65                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
66 
67                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
68 
69   uint32_t InputMinus;                  /*!< Set comparator input minus (inverting input).
70                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
71 
72                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
73 
74   uint32_t InputHysteresis;             /*!< Set comparator hysteresis mode of the input minus.
75                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
76 
77                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputHysteresis(). */
78 
79   uint32_t OutputPolarity;              /*!< Set comparator output polarity.
80                                              This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
81 
82                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
83 
84   uint32_t OutputBlankingSource;        /*!< Set comparator blanking source.
85                                              This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
86 
87                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputBlankingSource(). */
88 
89 } LL_COMP_InitTypeDef;
90 
91 /**
92   * @}
93   */
94 #endif /* USE_FULL_LL_DRIVER */
95 
96 /* Exported constants --------------------------------------------------------*/
97 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
98   * @{
99   */
100 
101 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
102   * @{
103   */
104 #define LL_COMP_INPUT_PLUS_IO1          (0x00000000UL)                          /*!< Comparator input plus connected to IO1 (pin PA1 for COMP1, pin PA7 for COMP2, pin PA0 for COMP3, pin PB0 for COMP4, pin PB13 for COMP5, pin PB11 for COMP6, pin PB14 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
105 #define LL_COMP_INPUT_PLUS_IO2          (COMP_CSR_INPSEL)                       /*!< Comparator input plus connected to IO2 (pin PB1 for COMP1, pin PA3 for COMP2, pin PC1 for COMP3, pin PE7 for COMP4, pin PD12 for COMP5, pin PD11 for COMP6, pin PD14 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
106 /**
107   * @}
108   */
109 
110 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
111   * @{
112   */
113 #define LL_COMP_INPUT_MINUS_1_4VREFINT  (                                                            COMP_CSR_SCALEN | COMP_CSR_BRGEN)        /*!< Comparator input minus connected to 1/4 VrefInt  */
114 #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  */
115 #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  */
116 #define LL_COMP_INPUT_MINUS_VREFINT     (                    COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN                 )        /*!< Comparator input minus connected to VrefInt */
117 #define LL_COMP_INPUT_MINUS_DAC1_CH1    (COMP_CSR_INMSEL_2                     | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to DAC1 Channel 1 for COMP1/3/4. Note: For COMPx & DACx instances availability, please refer to datasheet */
118 #define LL_COMP_INPUT_MINUS_DAC1_CH2    (COMP_CSR_INMSEL_2                     | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to DAC1 Channel 2 for COMP2/5. Note: For COMPx & DACx instances availability, please refer to datasheet */
119 #define LL_COMP_INPUT_MINUS_DAC2_CH1    (COMP_CSR_INMSEL_2                     | COMP_CSR_INMSEL_0)                                           /*!< Comparator input minus connected to DAC2 Channel 1 for COMP6/7. Note: For COMPx & DACx instances availability, please refer to datasheet */
120 #define LL_COMP_INPUT_MINUS_DAC3_CH1    (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC3 Channel 1 for COMP1/3. Note: For COMPx & DACx instances availability, please refer to datasheet */
121 #define LL_COMP_INPUT_MINUS_DAC3_CH2    (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC3 Channel 2 for COMP2/4. Note: For COMPx & DACx instances availability, please refer to datasheet */
122 #define LL_COMP_INPUT_MINUS_DAC4_CH1    (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC4 Channel 1 for COMP5/7. Note: For COMPx & DACx instances availability, please refer to datasheet */
123 #define LL_COMP_INPUT_MINUS_DAC4_CH2    (COMP_CSR_INMSEL_2                                        )                                           /*!< Comparator input minus connected to DAC4 Channel 2 for COMP6. Note: For COMPx & DACx instances availability, please refer to datasheet */
124 #define LL_COMP_INPUT_MINUS_IO1         (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1                    )                                           /*!< Comparator input minus connected to IO1 (pin PA4 for COMP1, pin PA5 for COMP2, pin PF1 for COMP3, pin PE8 for COMP4, pin PB10 for COMP5, pin PD10 for COMP6, pin PD15 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
125 #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 PA0 for COMP1, pin PA2 for COMP2, pin PC0 for COMP3, pin PB2 for COMP4, pin PD13 for COMP5, pin PB15 for COMP6, pin PB12 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
126 
127 /**
128   * @}
129   */
130 
131 /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
132   * @{
133   */
134 #define LL_COMP_HYSTERESIS_NONE         (0x00000000UL)                                       /*!< No hysteresis */
135 #define LL_COMP_HYSTERESIS_10MV         (                                    COMP_CSR_HYST_0) /*!< Hysteresis level 10mV */
136 #define LL_COMP_HYSTERESIS_20MV         (                  COMP_CSR_HYST_1                  ) /*!< Hysteresis level 20mV */
137 #define LL_COMP_HYSTERESIS_30MV         (                  COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level 30mV */
138 #define LL_COMP_HYSTERESIS_40MV         (COMP_CSR_HYST_2                                    ) /*!< Hysteresis level 40mV */
139 #define LL_COMP_HYSTERESIS_50MV         (COMP_CSR_HYST_2                   | COMP_CSR_HYST_0) /*!< Hysteresis level 50mV */
140 #define LL_COMP_HYSTERESIS_60MV         (COMP_CSR_HYST_2 | COMP_CSR_HYST_1                  ) /*!< Hysteresis level 60mV */
141 #define LL_COMP_HYSTERESIS_70MV         (COMP_CSR_HYST_2 | COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level 70mV */
142 #define LL_COMP_HYSTERESIS_LOW          LL_COMP_HYSTERESIS_10MV /*!< Hysteresis level low */
143 #define LL_COMP_HYSTERESIS_MEDIUM       LL_COMP_HYSTERESIS_40MV /*!< Hysteresis level medium */
144 #define LL_COMP_HYSTERESIS_HIGH         LL_COMP_HYSTERESIS_70MV /*!< Hysteresis level high */
145 /**
146   * @}
147   */
148 
149 /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
150   * @{
151   */
152 #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 */
153 #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 */
154 /**
155   * @}
156   */
157 
158 /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
159   * @{
160   */
161 #define LL_COMP_BLANKINGSRC_NONE            (0x00000000UL)          /*!<Comparator output without blanking */
162 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1). Note: For COMPx instance availability, please refer to datasheet */
163 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP2). Note: For COMPx instance availability, please refer to datasheet */
164 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP3). Note: For COMPx instance availability, please refer to datasheet */
165 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP4). Note: For COMPx instance availability, please refer to datasheet */
166 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP5  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP5). Note: For COMPx instance availability, please refer to datasheet */
167 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP6  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP6). Note: For COMPx instance availability, please refer to datasheet */
168 #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP7  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP7). Note: For COMPx instance availability, please refer to datasheet */
169 #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1). Note: For COMPx instance availability, please refer to datasheet */
170 #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP2). Note: For COMPx instance availability, please refer to datasheet */
171 #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP5  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP5). Note: For COMPx instance availability, please refer to datasheet */
172 #define LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3  (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM2 OC4 (specific to COMP instance: COMP3). Note: For COMPx instance availability, please refer to datasheet */
173 #define LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM2 OC4 (specific to COMP instance: COMP6). Note: For COMPx instance availability, please refer to datasheet */
174 #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1  (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1). Note: For COMPx instance availability, please refer to datasheet */
175 #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2  (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP2). Note: For COMPx instance availability, please refer to datasheet */
176 #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP3). Note: For COMPx instance availability, please refer to datasheet */
177 #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP5  (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP5). Note: For COMPx instance availability, please refer to datasheet */
178 #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP7  (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP7). Note: For COMPx instance availability, please refer to datasheet */
179 #define LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP4). Note: For COMPx instance availability, please refer to datasheet */
180 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP1). Note: For COMPx instance availability, please refer to datasheet */
181 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2). Note: For COMPx instance availability, please refer to datasheet */
182 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3  (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP3). Note: For COMPx instance availability, please refer to datasheet */
183 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP4). Note: For COMPx instance availability, please refer to datasheet */
184 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP5  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP5). Note: For COMPx instance availability, please refer to datasheet */
185 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP6  (                                            COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP6). Note: For COMPx instance availability, please refer to datasheet */
186 #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP7  (                      COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP7). Note: For COMPx instance availability, please refer to datasheet */
187 #define LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4 (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP4). Note: For COMPx instance availability, please refer to datasheet */
188 #define LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6 (                      COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM15 OC2 (specific to COMP instance: COMP6). Note: For COMPx instance availability, please refer to datasheet */
189 #define LL_COMP_BLANKINGSRC_TIM15_OC2_COMP7 (COMP_CSR_BLANKING_2                                            )   /*!< Comparator output blanking source TIM15 OC3 (specific to COMP instance: COMP7). Note: For COMPx instance availability, please refer to datasheet */
190 #define LL_COMP_BLANKINGSRC_TIM20_OC5       (COMP_CSR_BLANKING_2 |                       COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM20 OC5 (Common to all COMP instances). Note: For TIM20 instance availability, please refer to datasheet */
191 #define LL_COMP_BLANKINGSRC_TIM15_OC1       (COMP_CSR_BLANKING_2 | COMP_CSR_BLANKING_1                      )   /*!< Comparator output blanking source TIM15 OC1 (Common to all COMP instances). */
192 #define LL_COMP_BLANKINGSRC_TIM4_OC3        (COMP_CSR_BLANKING_2 | COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0)   /*!< Comparator output blanking source TIM4 OC3 (Common to all COMP instances). */
193 
194 /**
195   * @}
196   */
197 
198 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
199   * @{
200   */
201 #define LL_COMP_OUTPUT_LEVEL_LOW        (0x00000000UL)          /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
202 #define LL_COMP_OUTPUT_LEVEL_HIGH       (0x00000001UL)          /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
203 /**
204   * @}
205   */
206 
207 /** @defgroup COMP_LL_EC_HW_DELAYS  Definitions of COMP hardware constraints delays
208   * @note   Only COMP peripheral HW delays are defined in COMP LL driver driver,
209   *         not timeout values.
210   *         For details on delays values, refer to descriptions in source code
211   *         above each literal definition.
212   * @{
213   */
214 
215 /* Delay for comparator startup time.                                         */
216 /* Note: Delay required to reach propagation delay specification.             */
217 /* Literal set to maximum value (refer to device datasheet,                   */
218 /* parameter "tSTART").                                                       */
219 /* Unit: us                                                                   */
220 #define LL_COMP_DELAY_STARTUP_US          (  5UL) /*!< Delay for COMP startup time */
221 
222 /* Delay for comparator voltage scaler stabilization time.                    */
223 /* Note: Voltage scaler is used when selecting comparator input               */
224 /*       based on VrefInt: VrefInt or subdivision of VrefInt.                 */
225 /* Literal set to maximum value (refer to device datasheet,                   */
226 /* parameter "tSTART_SCALER").                                                */
227 /* Unit: us                                                                   */
228 #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
229 
230 /**
231   * @}
232   */
233 
234 /**
235   * @}
236   */
237 
238 /* Exported macro ------------------------------------------------------------*/
239 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
240   * @{
241   */
242 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
243   * @{
244   */
245 
246 /**
247   * @brief  Write a value in COMP register
248   * @param  __INSTANCE__ comparator instance
249   * @param  __REG__ Register to be written
250   * @param  __VALUE__ Value to be written in the register
251   * @retval None
252   */
253 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
254 
255 /**
256   * @brief  Read a value in COMP register
257   * @param  __INSTANCE__ comparator instance
258   * @param  __REG__ Register to be read
259   * @retval Register value
260   */
261 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
262 /**
263   * @}
264   */
265 
266 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
267   * @{
268   */
269 
270 /**
271   * @}
272   */
273 
274 /**
275   * @}
276   */
277 
278 /* Exported functions --------------------------------------------------------*/
279 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
280   * @{
281   */
282 
283 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
284   * @{
285   */
286 
287 /**
288   * @brief  Set comparator inputs minus (inverting) and plus (non-inverting).
289   * @note   In case of comparator input selected to be connected to IO:
290   *         GPIO pins are specific to each comparator instance.
291   *         Refer to description of parameters or to reference manual.
292   * @note   On this STM32 series, scaler bridge is configurable:
293   *         to optimize power consumption, this function enables the
294   *         voltage scaler bridge only when required
295   *         (when selecting comparator input based on VrefInt: VrefInt or
296   *         subdivision of VrefInt).
297   *         - For scaler bridge power consumption values,
298   *           refer to device datasheet, parameter "IDDA(SCALER)".
299   *         - Voltage scaler requires a delay for voltage stabilization.
300   *           Refer to device datasheet, parameter "tSTART_SCALER".
301   *         - Scaler bridge is common for all comparator instances,
302   *           therefore if at least one of the comparator instance
303   *           is requiring the scaler bridge, it remains enabled.
304   * @rmtoll CSR      INMSEL         LL_COMP_ConfigInputs\n
305   *         CSR      INPSEL         LL_COMP_ConfigInputs\n
306   *         CSR      BRGEN          LL_COMP_ConfigInputs\n
307   *         CSR      SCALEN         LL_COMP_ConfigInputs
308   * @param  COMPx Comparator instance
309   * @param  InputMinus This parameter can be one of the following values:
310   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
311   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
312   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
313   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
314   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1   (1,3,4)
315   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2   (2,5)
316   *         @arg @ref LL_COMP_INPUT_MINUS_DAC2_CH1   (6,7)
317   *         @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH1   (1,3)
318   *         @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH2   (2,4)
319   *         @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH1   (5,7)
320   *         @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH2   (6)
321   *         (a,b...) Only available for COMPa, COMPb...
322   *                  For COMPx & DACx instances availability, please refer to datasheet
323   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
324   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
325   * @param  InputPlus This parameter can be one of the following values:
326   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
327   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
328   * @retval None
329   */
LL_COMP_ConfigInputs(COMP_TypeDef * COMPx,uint32_t InputMinus,uint32_t InputPlus)330 __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
331 {
332   MODIFY_REG(COMPx->CSR,
333              COMP_CSR_INMSEL | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN,
334              InputMinus | InputPlus);
335 }
336 
337 /**
338   * @brief  Set comparator input plus (non-inverting).
339   * @note   In case of comparator input selected to be connected to IO:
340   *         GPIO pins are specific to each comparator instance.
341   *         Refer to description of parameters or to reference manual.
342   * @rmtoll CSR      INPSEL         LL_COMP_SetInputPlus
343   * @param  COMPx Comparator instance
344   * @param  InputPlus This parameter can be one of the following values:
345   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
346   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
347   * @retval None
348   */
LL_COMP_SetInputPlus(COMP_TypeDef * COMPx,uint32_t InputPlus)349 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
350 {
351   MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
352 }
353 
354 /**
355   * @brief  Get comparator input plus (non-inverting).
356   * @note   In case of comparator input selected to be connected to IO:
357   *         GPIO pins are specific to each comparator instance.
358   *         Refer to description of parameters or to reference manual.
359   * @rmtoll CSR      INPSEL         LL_COMP_GetInputPlus
360   * @param  COMPx Comparator instance
361   * @retval Returned value can be one of the following values:
362   *         @arg @ref LL_COMP_INPUT_PLUS_IO1
363   *         @arg @ref LL_COMP_INPUT_PLUS_IO2
364   */
LL_COMP_GetInputPlus(COMP_TypeDef * COMPx)365 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
366 {
367   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
368 }
369 
370 /**
371   * @brief  Set comparator input minus (inverting).
372   * @note   In case of comparator input selected to be connected to IO:
373   *         GPIO pins are specific to each comparator instance.
374   *         Refer to description of parameters or to reference manual.
375   * @note   On this STM32 series, scaler bridge is configurable:
376   *         to optimize power consumption, this function enables the
377   *         voltage scaler bridge only when required
378   *         (when selecting comparator input based on VrefInt: VrefInt or
379   *         subdivision of VrefInt).
380   *         - For scaler bridge power consumption values,
381   *           refer to device datasheet, parameter "IDDA(SCALER)".
382   *         - Voltage scaler requires a delay for voltage stabilization.
383   *           Refer to device datasheet, parameter "tSTART_SCALER".
384   *         - Scaler bridge is common for all comparator instances,
385   *           therefore if at least one of the comparator instance
386   *           is requiring the scaler bridge, it remains enabled.
387   * @rmtoll CSR      INMSEL         LL_COMP_SetInputMinus\n
388   *         CSR      BRGEN          LL_COMP_SetInputMinus\n
389   *         CSR      SCALEN         LL_COMP_SetInputMinus
390   * @param  COMPx Comparator instance
391   * @param  InputMinus This parameter can be one of the following values:
392   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
393   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
394   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
395   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
396   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1   (1,3,4)
397   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2   (2,5)
398   *         @arg @ref LL_COMP_INPUT_MINUS_DAC2_CH1   (6,7)
399   *         @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH1   (1,3)
400   *         @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH2   (2,4)
401   *         @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH1   (5,7)
402   *         @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH2   (6)
403   *         (a,b...) Only available for COMPa, COMPb...
404   *                  For COMPx & DACx instances availability, please refer to datasheet
405   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
406   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
407   * @retval None
408   */
LL_COMP_SetInputMinus(COMP_TypeDef * COMPx,uint32_t InputMinus)409 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
410 {
411   MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, InputMinus);
412 }
413 
414 /**
415   * @brief  Get comparator input minus (inverting).
416   * @note   In case of comparator input selected to be connected to IO:
417   *         GPIO pins are specific to each comparator instance.
418   *         Refer to description of parameters or to reference manual.
419   * @rmtoll CSR      INMSEL         LL_COMP_GetInputMinus\n
420   *         CSR      BRGEN          LL_COMP_GetInputMinus\n
421   *         CSR      SCALEN         LL_COMP_GetInputMinus
422   * @param  COMPx Comparator instance
423   * @retval Returned value can be one of the following values:
424   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
425   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
426   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
427   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
428   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1   (1,3,4)
429   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2   (2,5)
430   *         @arg @ref LL_COMP_INPUT_MINUS_DAC2_CH1   (6,7)
431   *         @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH1   (1,3)
432   *         @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH2   (2,4)
433   *         @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH1   (5,7)
434   *         @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH2   (6)
435   *         (a,b...) Only available for COMPa, COMPb...
436   *                  For COMPx & DACx instances availability, please refer to datasheet
437   *         @arg @ref LL_COMP_INPUT_MINUS_IO1
438   *         @arg @ref LL_COMP_INPUT_MINUS_IO2
439   */
LL_COMP_GetInputMinus(COMP_TypeDef * COMPx)440 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
441 {
442   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN));
443 }
444 
445 /**
446   * @brief  Set comparator instance hysteresis mode of the input minus (inverting input).
447   * @rmtoll CSR      HYST           LL_COMP_SetInputHysteresis
448   * @param  COMPx Comparator instance
449   * @param  InputHysteresis This parameter can be one of the following values:
450   *         @arg @ref LL_COMP_HYSTERESIS_NONE
451   *         @arg @ref LL_COMP_HYSTERESIS_10MV
452   *         @arg @ref LL_COMP_HYSTERESIS_20MV
453   *         @arg @ref LL_COMP_HYSTERESIS_30MV
454   *         @arg @ref LL_COMP_HYSTERESIS_40MV
455   *         @arg @ref LL_COMP_HYSTERESIS_50MV
456   *         @arg @ref LL_COMP_HYSTERESIS_60MV
457   *         @arg @ref LL_COMP_HYSTERESIS_70MV
458   *         @arg @ref LL_COMP_HYSTERESIS_LOW
459   *         @arg @ref LL_COMP_HYSTERESIS_MEDIUM
460   *         @arg @ref LL_COMP_HYSTERESIS_HIGH
461   * @retval None
462   */
LL_COMP_SetInputHysteresis(COMP_TypeDef * COMPx,uint32_t InputHysteresis)463 __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
464 {
465   MODIFY_REG(COMPx->CSR, COMP_CSR_HYST, InputHysteresis);
466 }
467 
468 /**
469   * @brief  Get comparator instance hysteresis mode of the minus (inverting) input.
470   * @rmtoll CSR      HYST           LL_COMP_GetInputHysteresis
471   * @param  COMPx Comparator instance
472   * @retval Returned value can be one of the following values:
473   *         @arg @ref LL_COMP_HYSTERESIS_NONE
474   *         @arg @ref LL_COMP_HYSTERESIS_10MV
475   *         @arg @ref LL_COMP_HYSTERESIS_20MV
476   *         @arg @ref LL_COMP_HYSTERESIS_30MV
477   *         @arg @ref LL_COMP_HYSTERESIS_40MV
478   *         @arg @ref LL_COMP_HYSTERESIS_50MV
479   *         @arg @ref LL_COMP_HYSTERESIS_60MV
480   *         @arg @ref LL_COMP_HYSTERESIS_70MV
481   */
LL_COMP_GetInputHysteresis(COMP_TypeDef * COMPx)482 __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx)
483 {
484   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_HYST));
485 }
486 
487 /**
488   * @}
489   */
490 
491 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
492   * @{
493   */
494 
495 /**
496   * @brief  Set comparator instance output polarity.
497   * @rmtoll CSR      POLARITY       LL_COMP_SetOutputPolarity
498   * @param  COMPx Comparator instance
499   * @param  OutputPolarity This parameter can be one of the following values:
500   *         @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
501   *         @arg @ref LL_COMP_OUTPUTPOL_INVERTED
502   * @retval None
503   */
LL_COMP_SetOutputPolarity(COMP_TypeDef * COMPx,uint32_t OutputPolarity)504 __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
505 {
506   MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
507 }
508 
509 /**
510   * @brief  Get comparator instance output polarity.
511   * @rmtoll CSR      POLARITY       LL_COMP_GetOutputPolarity
512   * @param  COMPx Comparator instance
513   * @retval Returned value can be one of the following values:
514   *         @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
515   *         @arg @ref LL_COMP_OUTPUTPOL_INVERTED
516   */
LL_COMP_GetOutputPolarity(COMP_TypeDef * COMPx)517 __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
518 {
519   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
520 }
521 
522 /**
523   * @brief  Set comparator instance blanking source.
524   * @note   Blanking source may be specific to each comparator instance.
525   *         Refer to description of parameters or to reference manual.
526   * @note   Availability of parameters of blanking source from timer
527   *         depends on timers availability on the selected device.
528   * @rmtoll CSR      BLANKING       LL_COMP_SetOutputBlankingSource
529   * @param  COMPx Comparator instance
530   * @param  BlankingSource This parameter can be one of the following values:
531   *         @arg @ref LL_COMP_BLANKINGSRC_NONE
532   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1
533   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2
534   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3
535   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4
536   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP5
537   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP6
538   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP7
539   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1
540   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2
541   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP5
542   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3
543   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6
544   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1
545   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2
546   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3
547   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP5
548   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP7
549   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4
550   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1
551   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2
552   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3
553   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4
554   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP5
555   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP6
556   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP7
557   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4
558   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6
559   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2_COMP7
560   *         @arg @ref LL_COMP_BLANKINGSRC_TIM20_OC5
561   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1
562   *         @arg @ref LL_COMP_BLANKINGSRC_TIM4_OC3
563   *
564   *         On STM32G4 series, blanking sources are linked to COMP instance (except
565   *         those without COMPx suffix that are common to all instances)
566   *         Note: For COMPx & TIMx instances availability, please refer to datasheet
567   * @retval None
568   */
LL_COMP_SetOutputBlankingSource(COMP_TypeDef * COMPx,uint32_t BlankingSource)569 __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
570 {
571   MODIFY_REG(COMPx->CSR, COMP_CSR_BLANKING, BlankingSource);
572 }
573 
574 /**
575   * @brief  Get comparator instance blanking source.
576   * @note   Availability of parameters of blanking source from timer
577   *         depends on timers availability on the selected device.
578   * @note   Blanking source may be specific to each comparator instance.
579   *         Refer to description of parameters or to reference manual.
580   * @rmtoll CSR      BLANKING       LL_COMP_GetOutputBlankingSource
581   * @param  COMPx Comparator instance
582   * @retval Returned value can be one of the following values:
583   *         @arg @ref LL_COMP_BLANKINGSRC_NONE
584   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1
585   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2
586   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3
587   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4
588   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP5
589   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP6
590   *         @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP7
591   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1
592   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2
593   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP5
594   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3
595   *         @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6
596   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1
597   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2
598   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3
599   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP5
600   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP7
601   *         @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4
602   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1
603   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2
604   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3
605   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4
606   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP5
607   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP6
608   *         @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP7
609   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4
610   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6
611   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2_COMP7
612   *         @arg @ref LL_COMP_BLANKINGSRC_TIM20_OC5
613   *         @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1
614   *         @arg @ref LL_COMP_BLANKINGSRC_TIM4_OC3
615   *
616   *         On STM32G4 series, blanking sources are linked to COMP instance (except
617   *         those without COMPx suffix that are common to all instances)
618   *         Note: For COMPx & TIMx instances availability, please refer to datasheet
619   */
LL_COMP_GetOutputBlankingSource(COMP_TypeDef * COMPx)620 __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(COMP_TypeDef *COMPx)
621 {
622   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_BLANKING));
623 }
624 
625 /**
626   * @}
627   */
628 
629 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
630   * @{
631   */
632 
633 /**
634   * @brief  Enable comparator instance.
635   * @note   After enable from off state, comparator requires a delay
636   *         to reach reach propagation delay specification.
637   *         Refer to device datasheet, parameter "tSTART".
638   * @rmtoll CSR      EN             LL_COMP_Enable
639   * @param  COMPx Comparator instance
640   * @retval None
641   */
LL_COMP_Enable(COMP_TypeDef * COMPx)642 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
643 {
644   SET_BIT(COMPx->CSR, COMP_CSR_EN);
645 }
646 
647 /**
648   * @brief  Disable comparator instance.
649   * @rmtoll CSR      EN             LL_COMP_Disable
650   * @param  COMPx Comparator instance
651   * @retval None
652   */
LL_COMP_Disable(COMP_TypeDef * COMPx)653 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
654 {
655   CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
656 }
657 
658 /**
659   * @brief  Get comparator enable state
660   *         (0: COMP is disabled, 1: COMP is enabled)
661   * @rmtoll CSR      EN             LL_COMP_IsEnabled
662   * @param  COMPx Comparator instance
663   * @retval State of bit (1 or 0).
664   */
LL_COMP_IsEnabled(COMP_TypeDef * COMPx)665 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
666 {
667   return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1UL : 0UL);
668 }
669 
670 /**
671   * @brief  Lock comparator instance.
672   * @note   Once locked, comparator configuration can be accessed in read-only.
673   * @note   The only way to unlock the comparator is a device hardware reset.
674   * @rmtoll CSR      LOCK           LL_COMP_Lock
675   * @param  COMPx Comparator instance
676   * @retval None
677   */
LL_COMP_Lock(COMP_TypeDef * COMPx)678 __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
679 {
680   SET_BIT(COMPx->CSR, COMP_CSR_LOCK);
681 }
682 
683 /**
684   * @brief  Get comparator lock state
685   *         (0: COMP is unlocked, 1: COMP is locked).
686   * @note   Once locked, comparator configuration can be accessed in read-only.
687   * @note   The only way to unlock the comparator is a device hardware reset.
688   * @rmtoll CSR      LOCK           LL_COMP_IsLocked
689   * @param  COMPx Comparator instance
690   * @retval State of bit (1 or 0).
691   */
LL_COMP_IsLocked(COMP_TypeDef * COMPx)692 __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
693 {
694   return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1UL : 0UL);
695 }
696 
697 /**
698   * @brief  Read comparator instance output level.
699   * @note   On this STM32 series, comparator 'value' is taken before
700   *         polarity and blanking are applied, thus:
701   *          - Comparator output is low when the input plus
702   *            is at a lower voltage than the input minus
703   *          - Comparator output is high when the input plus
704   *            is at a higher voltage than the input minus
705   * @rmtoll CSR      VALUE          LL_COMP_ReadOutputLevel
706   * @param  COMPx Comparator instance
707   * @retval Returned value can be one of the following values:
708   *         @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
709   *         @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
710   */
LL_COMP_ReadOutputLevel(COMP_TypeDef * COMPx)711 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
712 {
713   return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_VALUE)
714                     >> COMP_CSR_VALUE_Pos);
715 }
716 
717 /**
718   * @}
719   */
720 
721 #if defined(USE_FULL_LL_DRIVER)
722 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
723   * @{
724   */
725 
726 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
727 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
728 void        LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
729 
730 /**
731   * @}
732   */
733 #endif /* USE_FULL_LL_DRIVER */
734 
735 /**
736   * @}
737   */
738 
739 /**
740   * @}
741   */
742 
743 /**
744   * @}
745   */
746 
747 
748 
749 /**
750   * @}
751   */
752 
753 #ifdef __cplusplus
754 }
755 #endif
756 
757 #endif /* STM32G4xx_LL_COMP_H */
758