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