1 /**
2   ******************************************************************************
3   * @file    stm32l1xx_ll_comp.h
4   * @author  MCD Application Team
5   * @brief   Header file of COMP LL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2017 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 __STM32L1xx_LL_COMP_H
21 #define __STM32L1xx_LL_COMP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l1xx.h"
29 
30 /** @addtogroup STM32L1xx_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_COMP1_BITOFFSET_POS ( 7U) /* Value equivalent to POSITION_VAL(COMP_CSR_CMP1OUT) */
49 #define LL_COMP_OUTPUT_LEVEL_COMP2_BITOFFSET_POS (13U) /* Value equivalent to POSITION_VAL(COMP_CSR_CMP2OUT) */
50 #define LL_COMP_ENABLE_COMP1_BITOFFSET_POS       ( 4U) /* Value equivalent to POSITION_VAL(COMP_CSR_CMP1EN) */
51 
52 /**
53   * @}
54   */
55 
56 /* Private macros ------------------------------------------------------------*/
57 /** @defgroup COMP_LL_Private_Macros COMP Private Macros
58   * @{
59   */
60 
61 /**
62   * @brief  Driver macro reserved for internal use: if COMP instance selected
63   *         is odd (COMP1, COMP3, ...), return value '1', else return '0'.
64   * @param  __COMP_INSTANCE__ COMP instance
65   * @retval If COMP instance is odd, value '1'. Else, value '0'.
66 */
67 #define __COMP_IS_INSTANCE_ODD(__COMP_INSTANCE__)                              \
68   ((~((uint32_t)(__COMP_INSTANCE__) - COMP_BASE)) & 0x00000001)
69 
70 /**
71   * @brief  Driver macro reserved for internal use: if COMP instance selected
72   *         is even (COMP2, COMP4, ...), return value '1', else return '0'.
73   * @param  __COMP_INSTANCE__ COMP instance
74   * @retval If COMP instance is even, value '1'. Else, value '0'.
75 */
76 #define __COMP_IS_INSTANCE_EVEN(__COMP_INSTANCE__)                             \
77   ((uint32_t)(__COMP_INSTANCE__) - COMP_BASE)
78 
79 /**
80   * @}
81   */
82 
83 /* Exported types ------------------------------------------------------------*/
84 #if defined(USE_FULL_LL_DRIVER)
85 /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
86   * @{
87   */
88 
89 /**
90   * @brief  Structure definition of some features of COMP instance.
91   */
92 typedef struct
93 {
94   uint32_t PowerMode;                   /*!< Set comparator operating mode to adjust power and speed.
95                                              This parameter can be a value of @ref COMP_LL_EC_POWERMODE
96 
97                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
98 
99   uint32_t InputPlus;                   /*!< Set comparator input plus (non-inverting input).
100                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
101 
102                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
103 
104   uint32_t InputMinus;                  /*!< Set comparator input minus (inverting input).
105                                              This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
106 
107                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
108 
109   uint32_t OutputSelection;             /*!< Set comparator output selection.
110                                              This parameter can be a value of @ref COMP_LL_EC_OUTPUT_SELECTION
111 
112                                              This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputSelection(). */
113 
114 } LL_COMP_InitTypeDef;
115 
116 /**
117   * @}
118   */
119 #endif /* USE_FULL_LL_DRIVER */
120 
121 /* Exported constants --------------------------------------------------------*/
122 /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
123   * @{
124   */
125 
126 /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
127   * @{
128   */
129 #define LL_COMP_WINDOWMODE_DISABLE                 (0x00000000U)           /*!< Window mode disable: Comparators 1 and 2 are independent */
130 #define LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (COMP_CSR_WNDWE)        /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP2 input plus (COMP1 input plus is no more accessible, either from GPIO and from ADC channel VCOMP). */
131 /**
132   * @}
133   */
134 
135 /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
136   * @{
137   */
138 #define LL_COMP_POWERMODE_ULTRALOWPOWER   (0x00000000U)               /*!< COMP power mode to low speed (specific to COMP instance: COMP2) */
139 #define LL_COMP_POWERMODE_MEDIUMSPEED     (COMP_CSR_SPEED)            /*!< COMP power mode to fast speed (specific to COMP instance: COMP2) */
140 /**
141   * @}
142   */
143 
144 /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
145   * @{
146   */
147 #define LL_COMP_INPUT_PLUS_NONE         (0x00000000U)           /*!< Comparator input plus connected not connected */
148 #define LL_COMP_INPUT_PLUS_IO1          (RI_ASCR2_GR6_1)        /*!< Comparator input plus connected to IO1 (pin PB4 for COMP2) (specific to COMP instance: COMP2) */
149 #define LL_COMP_INPUT_PLUS_IO2          (RI_ASCR2_GR6_2)        /*!< Comparator input plus connected to IO1 (pin PB5 for COMP2) (specific to COMP instance: COMP2) */
150 #if defined(RI_ASCR1_CH_31)
151 #define LL_COMP_INPUT_PLUS_IO3          (RI_ASCR2_GR6_3)        /*!< Comparator input plus connected to IO1 (pin PB6 for COMP2) (specific to COMP instance: COMP2) */
152 #define LL_COMP_INPUT_PLUS_IO4          (RI_ASCR2_GR6_4)        /*!< Comparator input plus connected to IO1 (pin PB7 for COMP2) (specific to COMP instance: COMP2) */
153 #endif
154 #define LL_COMP_INPUT_PLUS_IO5          (RI_ASCR1_CH_0)         /*!< Comparator input plus connected to IO5 (pin PA0 for COMP1) (specific to COMP instance: COMP1) */
155 #define LL_COMP_INPUT_PLUS_IO6          (RI_ASCR1_CH_1)         /*!< Comparator input plus connected to IO6 (pin PA1 for COMP1) (specific to COMP instance: COMP1) */
156 #define LL_COMP_INPUT_PLUS_IO7          (RI_ASCR1_CH_2)         /*!< Comparator input plus connected to IO7 (pin PA2 for COMP1) (specific to COMP instance: COMP1) */
157 #define LL_COMP_INPUT_PLUS_IO8          (RI_ASCR1_CH_3)         /*!< Comparator input plus connected to IO8 (pin PA3 for COMP1) (specific to COMP instance: COMP1) */
158 #define LL_COMP_INPUT_PLUS_IO9          (RI_ASCR1_CH_4)         /*!< Comparator input plus connected to IO9 (pin PA4 for COMP1) (specific to COMP instance: COMP1) */
159 #define LL_COMP_INPUT_PLUS_IO10         (RI_ASCR1_CH_5)         /*!< Comparator input plus connected to IO10 (pin PA5 for COMP1) (specific to COMP instance: COMP1) */
160 #define LL_COMP_INPUT_PLUS_IO11         (RI_ASCR1_CH_6)         /*!< Comparator input plus connected to IO11 (pin PA6 for COMP1) (specific to COMP instance: COMP1) */
161 #define LL_COMP_INPUT_PLUS_IO12         (RI_ASCR1_CH_7)         /*!< Comparator input plus connected to IO12 (pin PA7 for COMP1) (specific to COMP instance: COMP1) */
162 #define LL_COMP_INPUT_PLUS_IO13         (RI_ASCR1_CH_8)         /*!< Comparator input plus connected to IO13 (pin PB0 for COMP1) (specific to COMP instance: COMP1) */
163 #define LL_COMP_INPUT_PLUS_IO14         (RI_ASCR1_CH_9)         /*!< Comparator input plus connected to IO14 (pin PB1 for COMP1) (specific to COMP instance: COMP1) */
164 #define LL_COMP_INPUT_PLUS_IO15         (RI_ASCR1_CH_10)        /*!< Comparator input plus connected to IO15 (pin PC0 for COMP1) (specific to COMP instance: COMP1) */
165 #define LL_COMP_INPUT_PLUS_IO16         (RI_ASCR1_CH_11)        /*!< Comparator input plus connected to IO16 (pin PC1 for COMP1) (specific to COMP instance: COMP1) */
166 #define LL_COMP_INPUT_PLUS_IO17         (RI_ASCR1_CH_12)        /*!< Comparator input plus connected to IO17 (pin PC2 for COMP1) (specific to COMP instance: COMP1) */
167 #define LL_COMP_INPUT_PLUS_IO18         (RI_ASCR1_CH_13)        /*!< Comparator input plus connected to IO18 (pin PC3 for COMP1) (specific to COMP instance: COMP1) */
168 #define LL_COMP_INPUT_PLUS_IO19         (RI_ASCR1_CH_14)        /*!< Comparator input plus connected to IO19 (pin PC4 for COMP1) (specific to COMP instance: COMP1) */
169 #define LL_COMP_INPUT_PLUS_IO20         (RI_ASCR1_CH_15)        /*!< Comparator input plus connected to IO20 (pin PC5 for COMP1) (specific to COMP instance: COMP1) */
170 #define LL_COMP_INPUT_PLUS_IO21         (RI_ASCR1_CH_18)        /*!< Comparator input plus connected to IO21 (pin PB12 for COMP1) (specific to COMP instance: COMP1) */
171 #define LL_COMP_INPUT_PLUS_IO22         (RI_ASCR1_CH_19)        /*!< Comparator input plus connected to IO22 (pin PB13 for COMP1) (specific to COMP instance: COMP1) */
172 #define LL_COMP_INPUT_PLUS_IO23         (RI_ASCR1_CH_20)        /*!< Comparator input plus connected to IO23 (pin PB14 for COMP1) (specific to COMP instance: COMP1) */
173 #define LL_COMP_INPUT_PLUS_IO24         (RI_ASCR1_CH_21)        /*!< Comparator input plus connected to IO24 (pin PB15 for COMP1) (specific to COMP instance: COMP1) */
174 #define LL_COMP_INPUT_PLUS_IO25         (RI_ASCR1_CH_22)        /*!< Comparator input plus connected to IO25 (pin PE7 for COMP1) (specific to COMP instance: COMP1) */
175 #define LL_COMP_INPUT_PLUS_IO26         (RI_ASCR1_CH_23)        /*!< Comparator input plus connected to IO26 (pin PE8 for COMP1) (specific to COMP instance: COMP1) */
176 #define LL_COMP_INPUT_PLUS_IO27         (RI_ASCR1_CH_24)        /*!< Comparator input plus connected to IO27 (pin PE9 for COMP1) (specific to COMP instance: COMP1) */
177 #define LL_COMP_INPUT_PLUS_IO28         (RI_ASCR1_CH_25)        /*!< Comparator input plus connected to IO28 (pin PE10 for COMP1) (specific to COMP instance: COMP1) */
178 #if defined(RI_ASCR1_CH_31)
179 #define LL_COMP_INPUT_PLUS_IO29         (RI_ASCR1_CH_27)        /*!< Comparator input plus connected to IO29 (pin PF6 for COMP1) (specific to COMP instance: COMP1) */
180 #define LL_COMP_INPUT_PLUS_IO30         (RI_ASCR1_CH_28)        /*!< Comparator input plus connected to IO30 (pin PF7 for COMP1) (specific to COMP instance: COMP1) */
181 #define LL_COMP_INPUT_PLUS_IO31         (RI_ASCR1_CH_29)        /*!< Comparator input plus connected to IO31 (pin PF8 for COMP1) (specific to COMP instance: COMP1) */
182 #define LL_COMP_INPUT_PLUS_IO32         (RI_ASCR1_CH_30)        /*!< Comparator input plus connected to IO32 (pin PF9 for COMP1) (specific to COMP instance: COMP1) */
183 #define LL_COMP_INPUT_PLUS_IO33         (RI_ASCR1_CH_31)        /*!< Comparator input plus connected to IO33 (pin PF10 for COMP1) (specific to COMP instance: COMP1) */
184 #endif
185 #if defined(OPAMP1)
186 #define LL_COMP_INPUT_PLUS_OPAMP1       (RI_ASCR1_CH_3)         /*!< Comparator input plus connected to OPAMP1 output (specific to COMP instance: COMP1) */
187 #define LL_COMP_INPUT_PLUS_OPAMP2       (RI_ASCR1_CH_8)         /*!< Comparator input plus connected to OPAMP2 output (specific to COMP instance: COMP1) */
188 #endif
189 #if defined(OPAMP3)
190 #define LL_COMP_INPUT_PLUS_OPAMP3       (RI_ASCR1_CH_13)        /*!< Comparator input plus connected to OPAMP3 output (specific to COMP instance: COMP1) */
191 #endif
192 /**
193   * @}
194   */
195 
196 /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
197   * @{
198   */
199 #define LL_COMP_INPUT_MINUS_1_4VREFINT  (COMP_CSR_INSEL_2                    | COMP_CSR_INSEL_0) /*!< Comparator input minus connected to 1/4 VrefInt (specific to COMP instance: COMP2) */
200 #define LL_COMP_INPUT_MINUS_1_2VREFINT  (COMP_CSR_INSEL_2                                      ) /*!< Comparator input minus connected to 1/2 VrefInt (specific to COMP instance: COMP2) */
201 #define LL_COMP_INPUT_MINUS_3_4VREFINT  (                   COMP_CSR_INSEL_1 | COMP_CSR_INSEL_0) /*!< Comparator input minus connected to 3/4 VrefInt (specific to COMP instance: COMP2) */
202 #define LL_COMP_INPUT_MINUS_VREFINT     (                   COMP_CSR_INSEL_1                   ) /*!< Comparator input minus connected to VrefInt */
203 #define LL_COMP_INPUT_MINUS_DAC1_CH1    (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_1                   ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) (specific to COMP instance: COMP2) */
204 #define LL_COMP_INPUT_MINUS_DAC1_CH2    (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_1 | COMP_CSR_INSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) (specific to COMP instance: COMP2) */
205 #define LL_COMP_INPUT_MINUS_IO1         (                                      COMP_CSR_INSEL_0) /*!< Comparator input minus connected to IO1 (pin PB3 for COMP2) (specific to COMP instance: COMP2) */
206 /**
207   * @}
208   */
209 
210 /** @defgroup COMP_LL_EC_INPUT_PULLING_RESISTOR Comparator input - Pulling resistor
211   * @{
212   */
213 #define LL_COMP_INPUT_MINUS_PULL_NO        (0x00000000U)           /*!< Comparator input minus not connected to any pulling resistor */
214 #define LL_COMP_INPUT_MINUS_PULL_UP_10K    (COMP_CSR_10KPU)        /*!< Comparator input minus connected to pull-up resistor of 10kOhm (specific to COMP instance: COMP1) */
215 #define LL_COMP_INPUT_MINUS_PULL_UP_400K   (COMP_CSR_400KPU)       /*!< Comparator input minus connected to pull-up resistor of 400kOhm (specific to COMP instance: COMP1) */
216 #define LL_COMP_INPUT_MINUS_PULL_DOWN_10K  (COMP_CSR_10KPD)        /*!< Comparator input minus connected to pull-down resistor of 10kOhm (specific to COMP instance: COMP1) */
217 #define LL_COMP_INPUT_MINUS_PULL_DOWN_400K (COMP_CSR_400KPD)       /*!< Comparator input minus connected to pull-down resistor of 400kOhm (specific to COMP instance: COMP1) */
218 
219 /**
220   * @}
221   */
222 
223 /** @defgroup COMP_LL_EC_OUTPUT_SELECTION Comparator output - Output selection
224   * @{
225   */
226 #define LL_COMP_OUTPUT_NONE             (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_1 | COMP_CSR_OUTSEL_0) /*!< COMP output is not connected to other peripherals (except GPIO and EXTI that are always connected to COMP output) (specific to COMP instance: COMP2) */
227 #define LL_COMP_OUTPUT_TIM2_IC4         (0x00000000)                                                /*!< COMP output connected to TIM2 input capture 4  (specific to COMP instance: COMP2) */
228 #define LL_COMP_OUTPUT_TIM2_OCREFCLR    (                                        COMP_CSR_OUTSEL_0) /*!< COMP output connected to TIM2 OCREF clear      (specific to COMP instance: COMP2) */
229 #define LL_COMP_OUTPUT_TIM3_IC4         (                    COMP_CSR_OUTSEL_1                    ) /*!< COMP output connected to TIM3 input capture 4  (specific to COMP instance: COMP2) */
230 #define LL_COMP_OUTPUT_TIM3_OCREFCLR    (                    COMP_CSR_OUTSEL_1 | COMP_CSR_OUTSEL_0) /*!< COMP output connected to TIM3 OCREF clear      (specific to COMP instance: COMP2) */
231 #define LL_COMP_OUTPUT_TIM4_IC4         (COMP_CSR_OUTSEL_2                                        ) /*!< COMP output connected to TIM4 input capture 4  (specific to COMP instance: COMP2) */
232 #define LL_COMP_OUTPUT_TIM4_OCREFCLR    (COMP_CSR_OUTSEL_2                     | COMP_CSR_OUTSEL_0) /*!< COMP output connected to TIM4 OCREF clear      (specific to COMP instance: COMP2) */
233 #define LL_COMP_OUTPUT_TIM10_IC1        (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_1                    ) /*!< COMP output connected to TIM10 input capture 1 (specific to COMP instance: COMP2) */
234 /**
235   * @}
236   */
237 
238 /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
239   * @{
240   */
241 #define LL_COMP_OUTPUT_LEVEL_LOW        (0x00000000U) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
242 #define LL_COMP_OUTPUT_LEVEL_HIGH       (0x00000001U) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
243 /**
244   * @}
245   */
246 
247 /** @defgroup COMP_LL_EC_HW_DELAYS  Definitions of COMP hardware constraints delays
248   * @note   Only COMP IP HW delays are defined in COMP LL driver driver,
249   *         not timeout values.
250   *         For details on delays values, refer to descriptions in source code
251   *         above each literal definition.
252   * @{
253   */
254 
255 /* Delay for comparator startup time.                                         */
256 /* Note: Delay required to reach propagation delay specification.             */
257 /* Literal set to maximum value (refer to device datasheet,                   */
258 /* parameter "tSTART").                                                       */
259 /* Unit: us                                                                   */
260 #define LL_COMP_DELAY_STARTUP_US          (25U)  /*!< Delay for COMP startup time */
261 
262 
263 /**
264   * @}
265   */
266 
267 /**
268   * @}
269   */
270 
271 /* Exported macro ------------------------------------------------------------*/
272 /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
273   * @{
274   */
275 /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
276   * @{
277   */
278 
279 /**
280   * @brief  Write a value in COMP register
281   * @param  __INSTANCE__ comparator instance
282   * @param  __REG__ Register to be written
283   * @param  __VALUE__ Value to be written in the register
284   * @retval None
285   */
286 #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
287 
288 /**
289   * @brief  Read a value in COMP register
290   * @param  __INSTANCE__ comparator instance
291   * @param  __REG__ Register to be read
292   * @retval Register value
293   */
294 #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
295 /**
296   * @}
297   */
298 
299 /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
300   * @{
301   */
302 
303 /**
304   * @brief  Helper macro to select the COMP common instance
305   *         to which is belonging the selected COMP instance.
306   * @note   COMP common register instance can be used to
307   *         set parameters common to several COMP instances.
308   *         Refer to functions having argument "COMPxy_COMMON" as parameter.
309   * @param  __COMPx__ COMP instance
310   * @retval COMP common instance or value "0" if there is no COMP common instance.
311   */
312 #define __LL_COMP_COMMON_INSTANCE(__COMPx__)                                   \
313   (COMP12_COMMON)
314 
315 /**
316   * @}
317   */
318 
319 /**
320   * @}
321   */
322 
323 /* Exported functions --------------------------------------------------------*/
324 /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
325   * @{
326   */
327 
328 /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
329   * @{
330   */
331 
332 /**
333   * @brief  Set window mode of a pair of comparators instances
334   *         (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
335   * @rmtoll CSR      WNDWE          LL_COMP_SetCommonWindowMode
336   * @param  COMPxy_COMMON Comparator common instance
337   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
338   * @param  WindowMode This parameter can be one of the following values:
339   *         @arg @ref LL_COMP_WINDOWMODE_DISABLE
340   *         @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
341   * @retval None
342   */
LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef * COMPxy_COMMON,uint32_t WindowMode)343 __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
344 {
345   MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_WNDWE, WindowMode);
346 }
347 
348 /**
349   * @brief  Get window mode of a pair of comparators instances
350   *         (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
351   * @rmtoll CSR      WNDWE          LL_COMP_GetCommonWindowMode
352   * @param  COMPxy_COMMON Comparator common instance
353   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
354   * @retval Returned value can be one of the following values:
355   *         @arg @ref LL_COMP_WINDOWMODE_DISABLE
356   *         @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
357   */
LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef * COMPxy_COMMON)358 __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
359 {
360   return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_WNDWE));
361 }
362 
363 /**
364   * @}
365   */
366 
367 /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
368   * @{
369   */
370 
371 /**
372   * @brief  Set comparator instance operating mode to adjust power and speed.
373   * @rmtoll COMP2_CSR   SPEED           LL_COMP_SetPowerMode
374   * @param  COMPx Comparator instance
375   * @param  PowerMode This parameter can be one of the following values:
376   *         @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED   (1)
377   *         @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER (1)
378   *
379   *         (1) Available only on COMP instance: COMP2.
380   * @retval None
381   */
LL_COMP_SetPowerMode(COMP_TypeDef * COMPx,uint32_t PowerMode)382 __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
383 {
384   MODIFY_REG(COMP->CSR, COMP_CSR_SPEED, PowerMode);
385 }
386 
387 /**
388   * @brief  Get comparator instance operating mode to adjust power and speed.
389   * @rmtoll COMP2_CSR   SPEED           LL_COMP_GetPowerMode
390   * @param  COMPx Comparator instance
391   * @retval Returned value can be one of the following values:
392   *         @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED   (1)
393   *         @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER (1)
394   *
395   *         (1) Available only on COMP instance: COMP2.
396   */
LL_COMP_GetPowerMode(COMP_TypeDef * COMPx)397 __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
398 {
399   return (uint32_t)(READ_BIT(COMP->CSR, COMP_CSR_SPEED));
400 }
401 
402 /**
403   * @}
404   */
405 
406 /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
407   * @{
408   */
409 
410 /**
411   * @brief  Set comparator input plus (non-inverting).
412   * @note   In case of comparator input selected to be connected to IO:
413   *         GPIO pins are specific to each comparator instance.
414   *         Refer to description of parameters or to reference manual.
415   * @rmtoll RI       RI_ASCR1_CH    LL_COMP_SetInputPlus\n
416   *         RI       RI_ASCR2_GR6   LL_COMP_SetInputPlus
417   * @param  COMPx Comparator instance
418   * @param  InputPlus This parameter can be one of the following values:
419   *         @arg @ref LL_COMP_INPUT_PLUS_NONE
420   *         @arg @ref LL_COMP_INPUT_PLUS_IO1 (2)
421   *         @arg @ref LL_COMP_INPUT_PLUS_IO2 (2)
422   *         @arg @ref LL_COMP_INPUT_PLUS_IO3 (2)(5)
423   *         @arg @ref LL_COMP_INPUT_PLUS_IO4 (2)(5)
424   *         @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
425   *         @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)
426   *         @arg @ref LL_COMP_INPUT_PLUS_IO7 (1)
427   *         @arg @ref LL_COMP_INPUT_PLUS_IO8 (1)
428   *         @arg @ref LL_COMP_INPUT_PLUS_IO9 (1)
429   *         @arg @ref LL_COMP_INPUT_PLUS_IO10 (1)
430   *         @arg @ref LL_COMP_INPUT_PLUS_IO11 (1)
431   *         @arg @ref LL_COMP_INPUT_PLUS_IO12 (1)
432   *         @arg @ref LL_COMP_INPUT_PLUS_IO13 (1)
433   *         @arg @ref LL_COMP_INPUT_PLUS_IO14 (1)
434   *         @arg @ref LL_COMP_INPUT_PLUS_IO15 (1)
435   *         @arg @ref LL_COMP_INPUT_PLUS_IO16 (1)
436   *         @arg @ref LL_COMP_INPUT_PLUS_IO17 (1)
437   *         @arg @ref LL_COMP_INPUT_PLUS_IO18 (1)
438   *         @arg @ref LL_COMP_INPUT_PLUS_IO19 (1)
439   *         @arg @ref LL_COMP_INPUT_PLUS_IO20 (1)
440   *         @arg @ref LL_COMP_INPUT_PLUS_IO21 (1)
441   *         @arg @ref LL_COMP_INPUT_PLUS_IO22 (1)
442   *         @arg @ref LL_COMP_INPUT_PLUS_IO23 (1)
443   *         @arg @ref LL_COMP_INPUT_PLUS_IO24 (1)
444   *         @arg @ref LL_COMP_INPUT_PLUS_IO25 (1)
445   *         @arg @ref LL_COMP_INPUT_PLUS_IO26 (1)
446   *         @arg @ref LL_COMP_INPUT_PLUS_IO27 (1)
447   *         @arg @ref LL_COMP_INPUT_PLUS_IO28 (1)
448   *         @arg @ref LL_COMP_INPUT_PLUS_IO29 (1)(4)
449   *         @arg @ref LL_COMP_INPUT_PLUS_IO30 (1)(4)
450   *         @arg @ref LL_COMP_INPUT_PLUS_IO31 (1)(4)
451   *         @arg @ref LL_COMP_INPUT_PLUS_IO32 (1)(4)
452   *         @arg @ref LL_COMP_INPUT_PLUS_IO33 (1)(4)
453   *         @arg @ref LL_COMP_INPUT_PLUS_OPAMP1 (1)(3)
454   *         @arg @ref LL_COMP_INPUT_PLUS_OPAMP2 (1)(3)
455   *         @arg @ref LL_COMP_INPUT_PLUS_OPAMP3 (1)(4)
456   *
457   *         (1) Available only on COMP instance: COMP1. \n
458   *         (2) Available only on COMP instance: COMP2. \n
459   *         (3) Available on devices: STM32L100xB, STM32L151xB, STM32L152xB, STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
460   *         (4) Available on devices: STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
461   *         (5) Available on devices: STM32L100xC, STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX, STM32L152xE, STM32L152xDX, STM32L162xE, STM32L162xDX
462   * @retval None
463   */
LL_COMP_SetInputPlus(COMP_TypeDef * COMPx,uint32_t InputPlus)464 __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
465 {
466   /* Set switch in routing interface (RI) register ASCR1 or ASCR2 */
467   /* Note: If COMP instance COMP1 is selected, this function performs         */
468   /*       necessary actions on routing interface:                            */
469   /*        - close switch netween comparator 1 and switch matrix             */
470   /*          (RI_ASCR1_VCOMP)                                                */
471   /*        - enable IO switch control mode (RI_ASCR1_SCM)                    */
472   /*          If ADC needs to be used afterwards, disable IO switch control   */
473   /*          mode using function @ref LL_RI_DisableSwitchControlMode().      */
474   uint32_t *preg = ((uint32_t *)((uint32_t) ((uint32_t)(&(RI->ASCR1)) + ((__COMP_IS_INSTANCE_EVEN(COMPx)) << 2U))));
475 
476   MODIFY_REG(*preg,
477              (RI_ASCR1_CH * __COMP_IS_INSTANCE_ODD(COMPx)) | (RI_ASCR2_GR6 * __COMP_IS_INSTANCE_EVEN(COMPx)),
478              InputPlus | ((RI_ASCR1_VCOMP | RI_ASCR1_SCM) * __COMP_IS_INSTANCE_ODD(COMPx)));
479 }
480 
481 /**
482   * @brief  Get comparator input plus (non-inverting).
483   * @note   In case of comparator input selected to be connected to IO:
484   *         GPIO pins are specific to each comparator instance.
485   *         Refer to description of parameters or to reference manual.
486   * @rmtoll RI       RI_ASCR1_CH    LL_COMP_GetInputPlus\n
487   *         RI       RI_ASCR2_GR6   LL_COMP_GetInputPlus
488   * @param  COMPx Comparator instance
489   * @retval Returned value can be one of the following values:
490   *         @arg @ref LL_COMP_INPUT_PLUS_NONE
491   *         @arg @ref LL_COMP_INPUT_PLUS_IO1 (2)
492   *         @arg @ref LL_COMP_INPUT_PLUS_IO2 (2)
493   *         @arg @ref LL_COMP_INPUT_PLUS_IO3 (2)(5)
494   *         @arg @ref LL_COMP_INPUT_PLUS_IO4 (2)(5)
495   *         @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
496   *         @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)
497   *         @arg @ref LL_COMP_INPUT_PLUS_IO7 (1)
498   *         @arg @ref LL_COMP_INPUT_PLUS_IO8 (1)
499   *         @arg @ref LL_COMP_INPUT_PLUS_IO9 (1)
500   *         @arg @ref LL_COMP_INPUT_PLUS_IO10 (1)
501   *         @arg @ref LL_COMP_INPUT_PLUS_IO11 (1)
502   *         @arg @ref LL_COMP_INPUT_PLUS_IO12 (1)
503   *         @arg @ref LL_COMP_INPUT_PLUS_IO13 (1)
504   *         @arg @ref LL_COMP_INPUT_PLUS_IO14 (1)
505   *         @arg @ref LL_COMP_INPUT_PLUS_IO15 (1)
506   *         @arg @ref LL_COMP_INPUT_PLUS_IO16 (1)
507   *         @arg @ref LL_COMP_INPUT_PLUS_IO17 (1)
508   *         @arg @ref LL_COMP_INPUT_PLUS_IO18 (1)
509   *         @arg @ref LL_COMP_INPUT_PLUS_IO19 (1)
510   *         @arg @ref LL_COMP_INPUT_PLUS_IO20 (1)
511   *         @arg @ref LL_COMP_INPUT_PLUS_IO21 (1)
512   *         @arg @ref LL_COMP_INPUT_PLUS_IO22 (1)
513   *         @arg @ref LL_COMP_INPUT_PLUS_IO23 (1)
514   *         @arg @ref LL_COMP_INPUT_PLUS_IO24 (1)
515   *         @arg @ref LL_COMP_INPUT_PLUS_IO25 (1)
516   *         @arg @ref LL_COMP_INPUT_PLUS_IO26 (1)
517   *         @arg @ref LL_COMP_INPUT_PLUS_IO27 (1)
518   *         @arg @ref LL_COMP_INPUT_PLUS_IO28 (1)
519   *         @arg @ref LL_COMP_INPUT_PLUS_IO29 (1)(4)
520   *         @arg @ref LL_COMP_INPUT_PLUS_IO30 (1)(4)
521   *         @arg @ref LL_COMP_INPUT_PLUS_IO31 (1)(4)
522   *         @arg @ref LL_COMP_INPUT_PLUS_IO32 (1)(4)
523   *         @arg @ref LL_COMP_INPUT_PLUS_IO33 (1)(4)
524   *         @arg @ref LL_COMP_INPUT_PLUS_OPAMP1 (1)(3)
525   *         @arg @ref LL_COMP_INPUT_PLUS_OPAMP2 (1)(3)
526   *         @arg @ref LL_COMP_INPUT_PLUS_OPAMP3 (1)(4)
527   *
528   *         (1) Available only on COMP instance: COMP1. \n
529   *         (2) Available only on COMP instance: COMP2. \n
530   *         (3) Available on devices: STM32L100xB, STM32L151xB, STM32L152xB, STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
531   *         (4) Available on devices: STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
532   *         (5) Available on devices: STM32L100xC, STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX, STM32L152xE, STM32L152xDX, STM32L162xE, STM32L162xDX
533   */
LL_COMP_GetInputPlus(COMP_TypeDef * COMPx)534 __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
535 {
536   /* Get switch state in routing interface (RI) register ASCR1 or ASCR2 */
537   uint32_t *preg = ((uint32_t *)((uint32_t) ((uint32_t)(&(RI->ASCR1)) + ((__COMP_IS_INSTANCE_EVEN(COMPx)) << 2U))));
538 
539   return (uint32_t)(READ_BIT(*preg,
540                              (RI_ASCR1_CH * __COMP_IS_INSTANCE_ODD(COMPx)) | (RI_ASCR2_GR6 * __COMP_IS_INSTANCE_EVEN(COMPx))));
541 }
542 
543 /**
544   * @brief  Set comparator input minus (inverting).
545   * @note   In case of comparator input selected to be connected to IO:
546   *         GPIO pins are specific to each comparator instance.
547   *         Refer to description of parameters or to reference manual.
548   * @rmtoll CSR      COMP_CSR_INSEL LL_COMP_SetInputMinus
549   * @param  COMPx Comparator instance
550   * @param  InputMinus This parameter can be one of the following values:
551   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT (1)
552   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT (1)
553   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT (1)
554   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
555   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1   (1)
556   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2   (1)
557   *         @arg @ref LL_COMP_INPUT_MINUS_IO1        (1)
558   *
559   *         (1) Available only on COMP instance: COMP2.
560   * @retval None
561   */
LL_COMP_SetInputMinus(COMP_TypeDef * COMPx,uint32_t InputMinus)562 __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
563 {
564   /* On this STM32 series, only COMP instance COMP1 input minus is fixed to   */
565   /* VrefInt. Check of comparator instance is implemented to modify register  */
566   /* only if COMP2 is selected.                                               */
567   MODIFY_REG(COMP->CSR,
568              COMP_CSR_INSEL * __COMP_IS_INSTANCE_EVEN(COMPx),
569              InputMinus     * __COMP_IS_INSTANCE_EVEN(COMPx));
570 }
571 
572 /**
573   * @brief  Get comparator input minus (inverting).
574   * @note   In case of comparator input selected to be connected to IO:
575   *         GPIO pins are specific to each comparator instance.
576   *         Refer to description of parameters or to reference manual.
577   * @rmtoll CSR      COMP_CSR_INSEL LL_COMP_SetInputMinus
578   * @param  COMPx Comparator instance
579   * @retval Returned value can be one of the following values:
580   *         @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT (1)
581   *         @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT (1)
582   *         @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT (1)
583   *         @arg @ref LL_COMP_INPUT_MINUS_VREFINT
584   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1   (1)
585   *         @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2   (1)
586   *         @arg @ref LL_COMP_INPUT_MINUS_IO1        (1)
587   *
588   *         (1) Available only on COMP instance: COMP2.
589   */
LL_COMP_GetInputMinus(COMP_TypeDef * COMPx)590 __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
591 {
592   /* On this STM32 series, only COMP instance COMP1 input minus is fixed to   */
593   /* VrefInt. Check of comparator instance is implemented to return           */
594   /* the comparator input plus depending on COMP instance selected.           */
595   return (uint32_t)((READ_BIT(COMP->CSR, COMP_CSR_INSEL) * __COMP_IS_INSTANCE_EVEN(COMPx))
596                      | (LL_COMP_INPUT_MINUS_VREFINT * __COMP_IS_INSTANCE_ODD(COMPx)));
597 }
598 
599 /**
600   * @brief  Set comparator input pulling resistor.
601   * @rmtoll CSR      10KPU          LL_COMP_SetInputPullingResistor\n
602   *         CSR      400KPU         LL_COMP_SetInputPullingResistor\n
603   *         CSR      10KPD          LL_COMP_SetInputPullingResistor\n
604   *         CSR      400KPD         LL_COMP_SetInputPullingResistor
605   * @param  COMPx Comparator instance
606   * @param  InputPullingResistor This parameter can be one of the following values:
607   *         @arg @ref LL_COMP_INPUT_MINUS_PULL_NO
608   *         @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_10K    (1)
609   *         @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_400K   (1)
610   *         @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_10K  (1)
611   *         @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_400K (1)
612   *
613   *         (1) Available only on COMP instance: COMP1.
614   * @retval None
615   */
LL_COMP_SetInputPullingResistor(COMP_TypeDef * COMPx,uint32_t InputPullingResistor)616 __STATIC_INLINE void LL_COMP_SetInputPullingResistor(COMP_TypeDef *COMPx, uint32_t InputPullingResistor)
617 {
618   /* On this STM32 series, only COMP instance COMP1 has input pulling         */
619   /* resistor. Check of comparator instance is implemented to modify register */
620   /* only if COMP1 is selected.                                               */
621   MODIFY_REG(COMP->CSR,
622              (COMP_CSR_10KPU | COMP_CSR_400KPU | COMP_CSR_10KPD | COMP_CSR_400KPD) * __COMP_IS_INSTANCE_ODD(COMPx),
623              InputPullingResistor * __COMP_IS_INSTANCE_ODD(COMPx));
624 }
625 
626 /**
627   * @brief  Get comparator input pulling resistor.
628   * @rmtoll CSR      10KPU          LL_COMP_SetInputPullingResistor\n
629   *         CSR      400KPU         LL_COMP_SetInputPullingResistor\n
630   *         CSR      10KPD          LL_COMP_SetInputPullingResistor\n
631   *         CSR      400KPD         LL_COMP_SetInputPullingResistor
632   * @param  COMPx Comparator instance
633   * @retval Returned value can be one of the following values:
634   *         @arg @ref LL_COMP_INPUT_MINUS_PULL_NO
635   *         @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_10K    (1)
636   *         @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_400K   (1)
637   *         @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_10K  (1)
638   *         @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_400K (1)
639   *
640   *         (1) Available only on COMP instance: COMP1.
641   */
LL_COMP_GetInputPullingResistor(COMP_TypeDef * COMPx)642 __STATIC_INLINE uint32_t LL_COMP_GetInputPullingResistor(COMP_TypeDef *COMPx)
643 {
644   /* On this STM32 series, only COMP instance COMP1 has input pulling         */
645   /* resistor. Check of comparator instance is implemented to return          */
646   /* the comparator input pulling resistor depending on COMP instance         */
647   /* selected.                                                                */
648   /* On this STM32 series, only COMP instance COMP1 input minus is fixed to   */
649   /* VrefInt. Check of comparator instance is implemented to return           */
650   /* the comparator input plus depending on COMP instance selected.           */
651   return (uint32_t)((READ_BIT(COMP->CSR, (COMP_CSR_10KPU | COMP_CSR_400KPU | COMP_CSR_10KPD | COMP_CSR_400KPD)) * __COMP_IS_INSTANCE_ODD(COMPx))
652                      | (LL_COMP_INPUT_MINUS_PULL_NO * __COMP_IS_INSTANCE_EVEN(COMPx)));
653 }
654 
655 /**
656   * @}
657   */
658 
659 /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
660   * @{
661   */
662 
663 /**
664   * @brief  Set comparator output selection.
665   * @note   Availability of parameters of output selection to timer
666   *         depends on timers availability on the selected device.
667   * @rmtoll CSR      OUTSEL         LL_COMP_SetOutputSelection
668   * @param  COMPx Comparator instance
669   * @param  OutputSelection This parameter can be one of the following values:
670   *         @arg @ref LL_COMP_OUTPUT_NONE
671   *         @arg @ref LL_COMP_OUTPUT_TIM2_IC4      (1)(2)
672   *         @arg @ref LL_COMP_OUTPUT_TIM2_OCREFCLR (1)(2)
673   *         @arg @ref LL_COMP_OUTPUT_TIM3_IC4      (1)(2)
674   *         @arg @ref LL_COMP_OUTPUT_TIM3_OCREFCLR (1)(2)
675   *         @arg @ref LL_COMP_OUTPUT_TIM4_IC4      (1)(2)
676   *         @arg @ref LL_COMP_OUTPUT_TIM4_OCREFCLR (1)(2)
677   *         @arg @ref LL_COMP_OUTPUT_TIM10_IC1     (1)(2)
678   *
679   *         (1) Parameter availability depending on timer availability
680   *             on the selected device.
681   *         (2) Available only on COMP instance: COMP2.
682   * @retval None
683   */
LL_COMP_SetOutputSelection(COMP_TypeDef * COMPx,uint32_t OutputSelection)684 __STATIC_INLINE void LL_COMP_SetOutputSelection(COMP_TypeDef *COMPx, uint32_t OutputSelection)
685 {
686   /* On this STM32 series, only COMP instance COMP2 has feature output        */
687   /* selection. Check of comparator instance is implemented to modify register*/
688   /* only if COMP2 is selected.                                               */
689   MODIFY_REG(COMP->CSR,
690              COMP_CSR_OUTSEL * __COMP_IS_INSTANCE_EVEN(COMPx),
691              OutputSelection * __COMP_IS_INSTANCE_EVEN(COMPx));
692 }
693 
694 /**
695   * @brief  Get comparator output selection.
696   * @note   Availability of parameters of output selection to timer
697   *         depends on timers availability on the selected device.
698   * @rmtoll CSR      OUTSEL         LL_COMP_GetOutputSelection
699   * @param  COMPx Comparator instance
700   * @retval Returned value can be one of the following values:
701   *         @arg @ref LL_COMP_OUTPUT_NONE
702   *         @arg @ref LL_COMP_OUTPUT_TIM2_IC4      (1)(2)
703   *         @arg @ref LL_COMP_OUTPUT_TIM2_OCREFCLR (1)(2)
704   *         @arg @ref LL_COMP_OUTPUT_TIM3_IC4      (1)(2)
705   *         @arg @ref LL_COMP_OUTPUT_TIM3_OCREFCLR (1)(2)
706   *         @arg @ref LL_COMP_OUTPUT_TIM4_IC4      (1)(2)
707   *         @arg @ref LL_COMP_OUTPUT_TIM4_OCREFCLR (1)(2)
708   *         @arg @ref LL_COMP_OUTPUT_TIM10_IC1     (1)(2)
709   *
710   *         (1) Parameter availability depending on timer availability
711   *             on the selected device.
712   *         (2) Available only on COMP instance: COMP2.
713   */
LL_COMP_GetOutputSelection(COMP_TypeDef * COMPx)714 __STATIC_INLINE uint32_t LL_COMP_GetOutputSelection(COMP_TypeDef *COMPx)
715 {
716   /* On this STM32 series, only COMP instance COMP2 has feature output        */
717   /* selection. Check of comparator instance is implemented to return         */
718   /* the comparator output depending on COMP instance selected.               */
719   return (uint32_t)((READ_BIT(COMP->CSR, COMP_CSR_OUTSEL) * __COMP_IS_INSTANCE_EVEN(COMPx))
720                      | (LL_COMP_OUTPUT_NONE * __COMP_IS_INSTANCE_ODD(COMPx)));
721 }
722 
723 /**
724   * @}
725   */
726 
727 /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
728   * @{
729   */
730 
731 /**
732   * @brief  Enable comparator instance.
733   * @note   After enable from off state, comparator requires a delay
734   *         to reach reach propagation delay specification.
735   *         Refer to device datasheet, parameter "tSTART".
736   * @rmtoll CSR      COMP1EN        LL_COMP_Enable\n
737   *         CSR      COMP_CSR_INSEL LL_COMP_Enable
738   * @param  COMPx Comparator instance (1)
739   *
740   *         (1) On this STM32 series, the only COMP instance that can be enabled
741   *             using this function is COMP1.
742   *             COMP2 is enabled by setting input minus.
743   *             Refer to function @ref LL_COMP_SetInputMinus().
744   * @retval None
745   */
LL_COMP_Enable(COMP_TypeDef * COMPx)746 __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
747 {
748   /* On this STM32 series, only COMP instance COMP1 has a dedicated bit       */
749   /* for comparator enable. Check of comparator instance is implemented       */
750   /* to modify register only if COMP1 is selected.                            */
751   SET_BIT(COMP->CSR, __COMP_IS_INSTANCE_ODD(COMPx) << LL_COMP_ENABLE_COMP1_BITOFFSET_POS);
752 }
753 
754 /**
755   * @brief  Disable comparator instance.
756   * @note   On this STM32 series, COMP2 is disabled by clearing input minus
757   *         selection. If COMP2 must be enabled afterwards, input minus must
758   *         be set. Refer to function @ref LL_COMP_SetInputMinus().
759   * @rmtoll CSR      COMP1EN        LL_COMP_Disable\n
760   *         CSR      COMP_CSR_INSEL LL_COMP_Disable
761   * @param  COMPx Comparator instance
762   * @retval None
763   */
LL_COMP_Disable(COMP_TypeDef * COMPx)764 __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
765 {
766   /* Note: On this STM32 series, COMP2 is enabled by setting input minus.     */
767   /*       Refer to function @ref LL_COMP_SetInputMinus().                    */
768   /*       To disable COMP2, bitfield of input minus selection is reset.      */
769   CLEAR_BIT(COMP->CSR, (COMP_CSR_CMP1EN * __COMP_IS_INSTANCE_ODD(COMPx)) | (COMP_CSR_INSEL * __COMP_IS_INSTANCE_EVEN(COMPx)));
770 }
771 
772 /**
773   * @brief  Get comparator enable state
774   *         (0: COMP is disabled, 1: COMP is enabled)
775   * @rmtoll CSR      COMP1EN        LL_COMP_IsEnabled\n
776   *         CSR      COMP_CSR_INSEL LL_COMP_IsEnabled
777   * @param  COMPx Comparator instance
778   * @retval State of bit (1 or 0).
779   */
LL_COMP_IsEnabled(COMP_TypeDef * COMPx)780 __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
781 {
782   return (READ_BIT(COMP->CSR, (COMP_CSR_CMP1EN * __COMP_IS_INSTANCE_ODD(COMPx)) | (COMP_CSR_INSEL * __COMP_IS_INSTANCE_EVEN(COMPx))) != (0U));
783 }
784 
785 /**
786   * @brief  Read comparator instance output level.
787   * @note   On this STM32 series, comparator polarity is not settable
788   *         and not inverted:
789   *          - Comparator output is low when the input plus
790   *            is at a lower voltage than the input minus
791   *          - Comparator output is high when the input plus
792   *            is at a higher voltage than the input minus
793   * @rmtoll CSR      CMP1OUT        LL_COMP_ReadOutputLevel\n
794   *         CSR      CMP2OUT        LL_COMP_ReadOutputLevel
795   * @param  COMPx Comparator instance
796   * @retval Returned value can be one of the following values:
797   *         @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
798   *         @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
799   */
LL_COMP_ReadOutputLevel(COMP_TypeDef * COMPx)800 __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
801 {
802   return (uint32_t)(READ_BIT(COMP->CSR,
803                              ((__COMP_IS_INSTANCE_ODD(COMPx) << LL_COMP_OUTPUT_LEVEL_COMP1_BITOFFSET_POS) | (__COMP_IS_INSTANCE_EVEN(COMPx) << LL_COMP_OUTPUT_LEVEL_COMP2_BITOFFSET_POS)))
804                     >> (LL_COMP_OUTPUT_LEVEL_COMP1_BITOFFSET_POS + ((LL_COMP_OUTPUT_LEVEL_COMP2_BITOFFSET_POS - LL_COMP_OUTPUT_LEVEL_COMP1_BITOFFSET_POS) * __COMP_IS_INSTANCE_EVEN(COMPx)))
805                    );
806 }
807 
808 /**
809   * @}
810   */
811 
812 #if defined(USE_FULL_LL_DRIVER)
813 /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
814   * @{
815   */
816 
817 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
818 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
819 void        LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
820 
821 /**
822   * @}
823   */
824 #endif /* USE_FULL_LL_DRIVER */
825 
826 /**
827   * @}
828   */
829 
830 /**
831   * @}
832   */
833 
834 #endif /* COMP1 || COMP2 */
835 
836 /**
837   * @}
838   */
839 
840 #ifdef __cplusplus
841 }
842 #endif
843 
844 #endif /* __STM32L1xx_LL_COMP_H */
845 
846