source: trunk/firmware/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_ll_comp.h

Last change on this file was 6, checked in by f.jahn, 8 months ago
File size: 38.6 KB
Line 
1/**
2 ******************************************************************************
3 * @file stm32g0xx_ll_comp.h
4 * @author MCD Application Team
5 * @brief Header file of COMP LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
10 * All rights reserved.</center></h2>
11 *
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
16 *
17 ******************************************************************************
18 */
19
20/* Define to prevent recursive inclusion -------------------------------------*/
21#ifndef STM32G0xx_LL_COMP_H
22#define STM32G0xx_LL_COMP_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/* Includes ------------------------------------------------------------------*/
29#include "stm32g0xx.h"
30
31/** @addtogroup STM32G0xx_LL_Driver
32 * @{
33 */
34
35#if defined (COMP1) || defined (COMP2)
36
37/** @defgroup COMP_LL COMP
38 * @{
39 */
40
41/* Private types -------------------------------------------------------------*/
42/* Private variables ---------------------------------------------------------*/
43/* Private constants ---------------------------------------------------------*/
44/** @defgroup COMP_LL_Private_Constants COMP Private Constants
45 * @{
46 */
47
48/* Internal mask for pair of comparators instances window mode: */
49/* To select into literals LL_COMP_WINDOWMODE_COMPx_INPUT_PLUS_COMMON */
50/* the relevant bits for: */
51/* (concatenation of multiple bits used in different registers) */
52/* - Comparator instance selected as master for window mode : register offset */
53/* - Window mode enable or disable: bit value */
54#define LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK (0x00000000UL) /* Register of COMP instance odd (COMP1_CSR, ...) defined as reference register */
55#define LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK (0x00000001UL) /* Register of COMP instance even (COMP2_CSR, ...) offset vs register of COMP instance odd */
56#define LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK (LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK)
57#define LL_COMP_WINDOWMODE_COMPX_SETTING_MASK (COMP_CSR_WINMODE)
58#define LL_COMP_WINDOWOUTPUT_COMPX_SETTING_MASK (COMP_CSR_WINOUT)
59#define LL_COMP_WINDOWOUTPUT_BOTH_SETTING_MASK (COMP_CSR_WINOUT << 1UL)
60#define LL_COMP_WINDOWOUTPUT_BOTH_POS_VS_WINDOW (1UL)
61
62/* COMP registers bits positions */
63#define LL_COMP_WINDOWMODE_BITOFFSET_POS (11UL) /* Value equivalent to POSITION_VAL(COMP_CSR_WINMODE) */
64#define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30UL) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
65
66/**
67 * @}
68 */
69
70/* Private macros ------------------------------------------------------------*/
71/** @defgroup COMP_LL_Private_Macros COMP Private Macros
72 * @{
73 */
74
75/**
76 * @brief Driver macro reserved for internal use: set a pointer to
77 * a register from a register basis from which an offset
78 * is applied.
79 * @param __REG__ Register basis from which the offset is applied.
80 * @param __REG_OFFFSET__ Offset to be applied (unit: number of registers).
81 * @retval Pointer to register address
82 */
83#define __COMP_PTR_REG_OFFSET(__REG__, __REG_OFFFSET__) \
84 ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFFSET__) << 2UL))))
85
86/**
87 * @}
88 */
89
90/* Exported types ------------------------------------------------------------*/
91#if defined(USE_FULL_LL_DRIVER)
92/** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
93 * @{
94 */
95
96/**
97 * @brief Structure definition of some features of COMP instance.
98 */
99typedef struct
100{
101 uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed.
102 This parameter can be a value of @ref COMP_LL_EC_POWERMODE
103
104 This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
105
106 uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
107 This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
108
109 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
110
111 uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
112 This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
113
114 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
115
116 uint32_t InputHysteresis; /*!< Set comparator hysteresis mode of the input minus.
117 This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
118
119 This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputHysteresis(). */
120
121 uint32_t OutputPolarity; /*!< Set comparator output polarity.
122 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
123
124 This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
125
126 uint32_t OutputBlankingSource; /*!< Set comparator blanking source.
127 This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
128
129 This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputBlankingSource(). */
130
131} LL_COMP_InitTypeDef;
132
133/**
134 * @}
135 */
136#endif /* USE_FULL_LL_DRIVER */
137
138/* Exported constants --------------------------------------------------------*/
139/** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
140 * @{
141 */
142
143/** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
144 * @{
145 */
146#define LL_COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators 1 and 2 are independent */
147#define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK) /*!< 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). */
148#define LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (COMP_CSR_WINMODE | LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK) /*!< 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). */
149/**
150 * @}
151 */
152
153/** @defgroup COMP_LL_EC_COMMON_WINDOWOUTPUT Comparator common modes - Window output
154 * @{
155 */
156#define LL_COMP_WINDOWOUTPUT_EACH_COMP (0x00000000UL) /*!< Window output default mode: Comparators output are indicating each their own state. To know window mode state: each comparator output must be read, if "((COMPx exclusive or COMPy) == 1)" then monitored signal is within comparators window. The same way, if both comparators output are high, then monitored signal is below window. */
157#define LL_COMP_WINDOWOUTPUT_COMP1 (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK) /*!< Window output synthetized on COMP1 output: COMP1 output is no more indicating its own state, but global window mode state (logical high means monitored signal is within comparators window). */
158#define LL_COMP_WINDOWOUTPUT_COMP2 (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK) /*!< Window output synthetized on COMP2 output: COMP2 output is no more indicating its own state, but global window mode state (logical high means monitored signal is within comparators window). */
159#define LL_COMP_WINDOWOUTPUT_BOTH (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK | LL_COMP_WINDOWOUTPUT_BOTH_SETTING_MASK) /*!< Window output synthetized on both COMP1 and COMP2 output: COMP1 and COMP2 outputs are no more indicating their own state, but global window mode state (logical high means monitored signal is within comparators window). This is a specific configuraton (technically possible but not relevant from application point of view: 2 comparators output used for the same signal level), standard configuraton for window mode is one of the 3 settings above. */
160/**
161 * @}
162 */
163
164/** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
165 * @{
166 */
167#define LL_COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< COMP power mode to high speed */
168#define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< COMP power mode to medium speed */
169/**
170 * @}
171 */
172
173/** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
174 * @{
175 */
176#define LL_COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */
177#define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
178#define LL_COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */
179/**
180 * @}
181 */
182
183/** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
184 * @{
185 */
186#define LL_COMP_INPUT_MINUS_1_4VREFINT (0x00000000UL) /*!< Comparator input minus connected to 1/4 VrefInt */
187#define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt */
188#define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to 3/4 VrefInt */
189#define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to VrefInt */
190#define LL_COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
191#define LL_COMP_INPUT_MINUS_DAC1_CH2 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
192#define LL_COMP_INPUT_MINUS_IO1 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PA9 for COMP1, pin PB3 for COMP2) */
193#define LL_COMP_INPUT_MINUS_IO2 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PB7 for COMP2) */
194#define LL_COMP_INPUT_MINUS_IO3 (COMP_CSR_INMSEL_3 ) /*!< Comparator input minus connected to IO3 (pin PA0 for COMP1, pin PA2 for COMP2) */
195/**
196 * @}
197 */
198
199/** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
200 * @{
201 */
202#define LL_COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */
203#define LL_COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0) /*!< Hysteresis level low */
204#define LL_COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 ) /*!< Hysteresis level medium */
205#define LL_COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level high */
206/**
207 * @}
208 */
209
210/** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
211 * @{
212 */
213#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 */
214#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 */
215/**
216 * @}
217 */
218
219/** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
220 * @{
221 */
222#define LL_COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */
223/* Note: Output blanking source common to all COMP instances */
224#define LL_COMP_BLANKINGSRC_TIM1_OC4 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC4 (common to all COMP instances: COMP1, COMP2) */
225#define LL_COMP_BLANKINGSRC_TIM1_OC5 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM1 OC5 (common to all COMP instances: COMP1, COMP2) */
226#define LL_COMP_BLANKINGSRC_TIM2_OC3 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM2 OC3 (common to all COMP instances: COMP1, COMP2) */
227#define LL_COMP_BLANKINGSRC_TIM3_OC3 (COMP_CSR_BLANKING_3) /*!< Comparator output blanking source TIM3 OC3 (common to all COMP instances: COMP1, COMP2) */
228#define LL_COMP_BLANKINGSRC_TIM15_OC2 (COMP_CSR_BLANKING_4) /*!< Comparator output blanking source TIM15 OC2 (common to all COMP instances: COMP1, COMP2) */
229/**
230 * @}
231 */
232
233/** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
234 * @{
235 */
236#define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000UL) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
237#define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
238/**
239 * @}
240 */
241
242/** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
243 * @note Only COMP peripheral HW delays are defined in COMP LL driver driver,
244 * not timeout values.
245 * For details on delays values, refer to descriptions in source code
246 * above each literal definition.
247 * @{
248 */
249
250/* Delay for comparator startup time. */
251/* Note: Delay required to reach propagation delay specification. */
252/* Literal set to maximum value (refer to device datasheet, */
253/* parameter "tSTART"). */
254/* Unit: us */
255#define LL_COMP_DELAY_STARTUP_US ( 80UL) /*!< Delay for COMP startup time */
256
257/* Delay for comparator voltage scaler stabilization time. */
258/* Note: Voltage scaler is used when selecting comparator input */
259/* based on VrefInt: VrefInt or subdivision of VrefInt. */
260/* Literal set to maximum value (refer to device datasheet, */
261/* parameter "tSTART_SCALER"). */
262/* Unit: us */
263#define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
264
265/**
266 * @}
267 */
268
269/**
270 * @}
271 */
272
273/* Exported macro ------------------------------------------------------------*/
274/** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
275 * @{
276 */
277/** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
278 * @{
279 */
280
281/**
282 * @brief Write a value in COMP register
283 * @param __INSTANCE__ comparator instance
284 * @param __REG__ Register to be written
285 * @param __VALUE__ Value to be written in the register
286 * @retval None
287 */
288#define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
289
290/**
291 * @brief Read a value in COMP register
292 * @param __INSTANCE__ comparator instance
293 * @param __REG__ Register to be read
294 * @retval Register value
295 */
296#define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
297/**
298 * @}
299 */
300
301/** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
302 * @{
303 */
304
305/**
306 * @brief Helper macro to select the COMP common instance
307 * to which is belonging the selected COMP instance.
308 * @note COMP common register instance can be used to
309 * set parameters common to several COMP instances.
310 * Refer to functions having argument "COMPxy_COMMON" as parameter.
311 * @param __COMPx__ COMP instance
312 * @retval COMP common instance or value "0" if there is no COMP common instance.
313 */
314#define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
315 (COMP12_COMMON)
316
317/**
318 * @}
319 */
320
321/**
322 * @}
323 */
324
325/* Exported functions --------------------------------------------------------*/
326/** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
327 * @{
328 */
329
330/** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
331 * @{
332 */
333
334/**
335 * @brief Set window mode of a pair of comparators instances
336 * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
337 * @rmtoll CSR WINMODE LL_COMP_SetCommonWindowMode
338 * @param COMPxy_COMMON Comparator common instance
339 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
340 * @param WindowMode This parameter can be one of the following values:
341 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
342 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
343 * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
344 * @retval None
345 */
346__STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
347{
348 /* Note: On this STM32 serie, window mode can be set from one of the pair */
349 /* of COMP instances: COMP1 or COMP2. */
350 register __IO uint32_t *preg = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (WindowMode & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK));
351
352 /* Clear the potential previous setting of window mode */
353 register __IO uint32_t *preg_clear = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (~(WindowMode & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK) & 0x1UL));
354 CLEAR_BIT(*preg_clear,
355 COMP_CSR_WINMODE
356 );
357
358 /* Set window mode */
359 MODIFY_REG(*preg,
360 COMP_CSR_WINMODE,
361 (WindowMode & LL_COMP_WINDOWMODE_COMPX_SETTING_MASK)
362 );
363}
364
365/**
366 * @brief Get window mode of a pair of comparators instances
367 * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
368 * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowMode
369 * @param COMPxy_COMMON Comparator common instance
370 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
371 * @retval Returned value can be one of the following values:
372 * @arg @ref LL_COMP_WINDOWMODE_DISABLE
373 * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
374 * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
375 */
376__STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
377{
378 /* Note: On this STM32 serie, window mode can be set from one of the pair */
379 /* of COMP instances: COMP1 or COMP2. */
380 register const uint32_t window_mode_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINMODE);
381 register const uint32_t window_mode_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINMODE);
382
383 return (uint32_t)(window_mode_comp_odd
384 | window_mode_comp_even
385 | ((window_mode_comp_even >> LL_COMP_WINDOWMODE_BITOFFSET_POS) * LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK));
386}
387
388/**
389 * @brief Set window output of a pair of comparators instances
390 * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
391 * @rmtoll CSR WINOUT LL_COMP_SetCommonWindowOutput
392 * @param COMPxy_COMMON Comparator common instance
393 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
394 * @param WindowOutput This parameter can be one of the following values:
395 * @arg @ref LL_COMP_WINDOWOUTPUT_EACH_COMP
396 * @arg @ref LL_COMP_WINDOWOUTPUT_COMP1
397 * @arg @ref LL_COMP_WINDOWOUTPUT_COMP2
398 * @arg @ref LL_COMP_WINDOWOUTPUT_BOTH
399 * @retval None
400 */
401__STATIC_INLINE void LL_COMP_SetCommonWindowOutput(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowOutput)
402{
403 register __IO uint32_t *preg = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (WindowOutput & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK));
404
405 /* Clear the potential previous setting of window output on the relevant comparator instance */
406 /* (clear bit of window output unless specific case of setting of comparator both output selected) */
407 register __IO uint32_t *preg_clear = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (~(WindowOutput & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK) & 0x1UL));
408 MODIFY_REG(*preg_clear,
409 COMP_CSR_WINOUT,
410 ((WindowOutput & LL_COMP_WINDOWOUTPUT_BOTH_SETTING_MASK) >> LL_COMP_WINDOWOUTPUT_BOTH_POS_VS_WINDOW)
411 );
412
413 /* Set window output */
414 MODIFY_REG(*preg,
415 COMP_CSR_WINOUT,
416 (WindowOutput & LL_COMP_WINDOWOUTPUT_COMPX_SETTING_MASK)
417 );
418}
419
420/**
421 * @brief Get window output of a pair of comparators instances
422 * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
423 * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowOutput
424 * @param COMPxy_COMMON Comparator common instance
425 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
426 * @retval Returned value can be one of the following values:
427 * @arg @ref LL_COMP_WINDOWOUTPUT_EACH_COMP
428 * @arg @ref LL_COMP_WINDOWOUTPUT_COMP1
429 * @arg @ref LL_COMP_WINDOWOUTPUT_COMP2
430 * @arg @ref LL_COMP_WINDOWOUTPUT_BOTH
431 */
432__STATIC_INLINE uint32_t LL_COMP_GetCommonWindowOutput(COMP_Common_TypeDef *COMPxy_COMMON)
433{
434 register const uint32_t window_output_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINOUT);
435 register const uint32_t window_output_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINOUT);
436
437 /* Construct value corresponding to LL_COMP_WINDOWOUTPUT_xxx */
438 return (uint32_t)(window_output_comp_odd
439 | window_output_comp_even
440 | ((window_output_comp_even >> COMP_CSR_WINOUT_Pos) * LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK)
441 | (window_output_comp_odd + window_output_comp_even));
442}
443
444/**
445 * @}
446 */
447
448/** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
449 * @{
450 */
451
452/**
453 * @brief Set comparator instance operating mode to adjust power and speed.
454 * @rmtoll CSR PWRMODE LL_COMP_SetPowerMode
455 * @param COMPx Comparator instance
456 * @param PowerMode This parameter can be one of the following values:
457 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
458 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
459 * @retval None
460 */
461__STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
462{
463 MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE, PowerMode);
464}
465
466/**
467 * @brief Get comparator instance operating mode to adjust power and speed.
468 * @rmtoll CSR PWRMODE LL_COMP_GetPowerMode
469 * @param COMPx Comparator instance
470 * @retval Returned value can be one of the following values:
471 * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
472 * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
473 */
474__STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
475{
476 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_PWRMODE));
477}
478
479/**
480 * @}
481 */
482
483/** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
484 * @{
485 */
486
487/**
488 * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
489 * @note In case of comparator input selected to be connected to IO:
490 * GPIO pins are specific to each comparator instance.
491 * Refer to description of parameters or to reference manual.
492 * @note On this STM32 serie, a voltage scaler is used
493 * when COMP input is based on VrefInt (VrefInt or subdivision
494 * of VrefInt):
495 * Voltage scaler requires a delay for voltage stabilization.
496 * Refer to device datasheet, parameter "tSTART_SCALER".
497 * @rmtoll CSR INMSEL LL_COMP_ConfigInputs\n
498 * CSR INPSEL LL_COMP_ConfigInputs\n
499 * @param COMPx Comparator instance
500 * @param InputMinus This parameter can be one of the following values:
501 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
502 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
503 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
504 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
505 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
506 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
507 * @arg @ref LL_COMP_INPUT_MINUS_IO1
508 * @arg @ref LL_COMP_INPUT_MINUS_IO2
509 * @arg @ref LL_COMP_INPUT_MINUS_IO3
510 * @param InputPlus This parameter can be one of the following values:
511 * @arg @ref LL_COMP_INPUT_PLUS_IO1
512 * @arg @ref LL_COMP_INPUT_PLUS_IO2
513 * @arg @ref LL_COMP_INPUT_PLUS_IO3
514 * @retval None
515 */
516__STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
517{
518 MODIFY_REG(COMPx->CSR,
519 COMP_CSR_INMSEL | COMP_CSR_INPSEL,
520 InputMinus | InputPlus);
521}
522
523/**
524 * @brief Set comparator input plus (non-inverting).
525 * @note In case of comparator input selected to be connected to IO:
526 * GPIO pins are specific to each comparator instance.
527 * Refer to description of parameters or to reference manual.
528 * @rmtoll CSR INPSEL LL_COMP_SetInputPlus
529 * @param COMPx Comparator instance
530 * @param InputPlus This parameter can be one of the following values:
531 * @arg @ref LL_COMP_INPUT_PLUS_IO1
532 * @arg @ref LL_COMP_INPUT_PLUS_IO2
533 * @arg @ref LL_COMP_INPUT_PLUS_IO3
534 * @retval None
535 */
536__STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
537{
538 MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
539}
540
541/**
542 * @brief Get comparator input plus (non-inverting).
543 * @note In case of comparator input selected to be connected to IO:
544 * GPIO pins are specific to each comparator instance.
545 * Refer to description of parameters or to reference manual.
546 * @rmtoll CSR INPSEL LL_COMP_GetInputPlus
547 * @param COMPx Comparator instance
548 * @retval Returned value can be one of the following values:
549 * @arg @ref LL_COMP_INPUT_PLUS_IO1
550 * @arg @ref LL_COMP_INPUT_PLUS_IO2
551 * @arg @ref LL_COMP_INPUT_PLUS_IO3
552 */
553__STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
554{
555 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
556}
557
558/**
559 * @brief Set comparator input minus (inverting).
560 * @note In case of comparator input selected to be connected to IO:
561 * GPIO pins are specific to each comparator instance.
562 * Refer to description of parameters or to reference manual.
563 * @note On this STM32 serie, a voltage scaler is used
564 * when COMP input is based on VrefInt (VrefInt or subdivision
565 * of VrefInt):
566 * Voltage scaler requires a delay for voltage stabilization.
567 * Refer to device datasheet, parameter "tSTART_SCALER".
568 * @rmtoll CSR INMSEL LL_COMP_SetInputMinus
569 * @param COMPx Comparator instance
570 * @param InputMinus This parameter can be one of the following values:
571 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
572 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
573 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
574 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
575 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
576 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
577 * @arg @ref LL_COMP_INPUT_MINUS_IO1
578 * @arg @ref LL_COMP_INPUT_MINUS_IO2
579 * @arg @ref LL_COMP_INPUT_MINUS_IO3
580 * @retval None
581 */
582__STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
583{
584 MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL, InputMinus);
585}
586
587/**
588 * @brief Get comparator input minus (inverting).
589 * @note In case of comparator input selected to be connected to IO:
590 * GPIO pins are specific to each comparator instance.
591 * Refer to description of parameters or to reference manual.
592 * @rmtoll CSR INMSEL LL_COMP_GetInputMinus
593 * @param COMPx Comparator instance
594 * @retval Returned value can be one of the following values:
595 * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
596 * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
597 * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
598 * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
599 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
600 * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
601 * @arg @ref LL_COMP_INPUT_MINUS_IO1
602 * @arg @ref LL_COMP_INPUT_MINUS_IO2
603 * @arg @ref LL_COMP_INPUT_MINUS_IO3
604 */
605__STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
606{
607 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL));
608}
609
610/**
611 * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
612 * @rmtoll CSR HYST LL_COMP_SetInputHysteresis
613 * @param COMPx Comparator instance
614 * @param InputHysteresis This parameter can be one of the following values:
615 * @arg @ref LL_COMP_HYSTERESIS_NONE
616 * @arg @ref LL_COMP_HYSTERESIS_LOW
617 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
618 * @arg @ref LL_COMP_HYSTERESIS_HIGH
619 * @retval None
620 */
621__STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
622{
623 MODIFY_REG(COMPx->CSR, COMP_CSR_HYST, InputHysteresis);
624}
625
626/**
627 * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
628 * @rmtoll CSR HYST LL_COMP_GetInputHysteresis
629 * @param COMPx Comparator instance
630 * @retval Returned value can be one of the following values:
631 * @arg @ref LL_COMP_HYSTERESIS_NONE
632 * @arg @ref LL_COMP_HYSTERESIS_LOW
633 * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
634 * @arg @ref LL_COMP_HYSTERESIS_HIGH
635 */
636__STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx)
637{
638 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_HYST));
639}
640
641/**
642 * @}
643 */
644
645/** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
646 * @{
647 */
648
649/**
650 * @brief Set comparator instance output polarity.
651 * @rmtoll CSR POLARITY LL_COMP_SetOutputPolarity
652 * @param COMPx Comparator instance
653 * @param OutputPolarity This parameter can be one of the following values:
654 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
655 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
656 * @retval None
657 */
658__STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
659{
660 MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
661}
662
663/**
664 * @brief Get comparator instance output polarity.
665 * @rmtoll CSR POLARITY LL_COMP_GetOutputPolarity
666 * @param COMPx Comparator instance
667 * @retval Returned value can be one of the following values:
668 * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
669 * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
670 */
671__STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
672{
673 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
674}
675
676/**
677 * @brief Set comparator instance blanking source.
678 * @note Blanking source may be specific to each comparator instance.
679 * Refer to description of parameters or to reference manual.
680 * @note Availability of parameters of blanking source from timer
681 * depends on timers availability on the selected device.
682 * @rmtoll CSR BLANKING LL_COMP_SetOutputBlankingSource
683 * @param COMPx Comparator instance
684 * @param BlankingSource This parameter can be one of the following values:
685 * @arg @ref LL_COMP_BLANKINGSRC_NONE
686 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC4 (1)
687 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5 (1)
688 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3 (1)
689 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3 (1)
690 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2 (1)
691 *
692 * (1) Parameter availability depending on timer availability
693 * on the selected device.
694 * @retval None
695 */
696__STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
697{
698 MODIFY_REG(COMPx->CSR, COMP_CSR_BLANKING, BlankingSource);
699}
700
701/**
702 * @brief Get comparator instance blanking source.
703 * @note Availability of parameters of blanking source from timer
704 * depends on timers availability on the selected device.
705 * @note Blanking source may be specific to each comparator instance.
706 * Refer to description of parameters or to reference manual.
707 * @rmtoll CSR BLANKING LL_COMP_GetOutputBlankingSource
708 * @param COMPx Comparator instance
709 * @retval Returned value can be one of the following values:
710 * @arg @ref LL_COMP_BLANKINGSRC_NONE
711 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC4 (1)
712 * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5 (1)
713 * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3 (1)
714 * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3 (1)
715 * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2 (1)
716 *
717 * (1) Parameter availability depending on timer availability
718 * on the selected device.
719 */
720__STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(COMP_TypeDef *COMPx)
721{
722 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_BLANKING));
723}
724
725/**
726 * @}
727 */
728
729/** @defgroup COMP_LL_EF_Operation Operation on comparator instance
730 * @{
731 */
732
733/**
734 * @brief Enable comparator instance.
735 * @note After enable from off state, comparator requires a delay
736 * to reach reach propagation delay specification.
737 * Refer to device datasheet, parameter "tSTART".
738 * @rmtoll CSR EN LL_COMP_Enable
739 * @param COMPx Comparator instance
740 * @retval None
741 */
742__STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
743{
744 SET_BIT(COMPx->CSR, COMP_CSR_EN);
745}
746
747/**
748 * @brief Disable comparator instance.
749 * @rmtoll CSR EN LL_COMP_Disable
750 * @param COMPx Comparator instance
751 * @retval None
752 */
753__STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
754{
755 CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
756}
757
758/**
759 * @brief Get comparator enable state
760 * (0: COMP is disabled, 1: COMP is enabled)
761 * @rmtoll CSR EN LL_COMP_IsEnabled
762 * @param COMPx Comparator instance
763 * @retval State of bit (1 or 0).
764 */
765__STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
766{
767 return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1UL : 0UL);
768}
769
770/**
771 * @brief Lock comparator instance.
772 * @note Once locked, comparator configuration can be accessed in read-only.
773 * @note The only way to unlock the comparator is a device hardware reset.
774 * @rmtoll CSR LOCK LL_COMP_Lock
775 * @param COMPx Comparator instance
776 * @retval None
777 */
778__STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
779{
780 SET_BIT(COMPx->CSR, COMP_CSR_LOCK);
781}
782
783/**
784 * @brief Get comparator lock state
785 * (0: COMP is unlocked, 1: COMP is locked).
786 * @note Once locked, comparator configuration can be accessed in read-only.
787 * @note The only way to unlock the comparator is a device hardware reset.
788 * @rmtoll CSR LOCK LL_COMP_IsLocked
789 * @param COMPx Comparator instance
790 * @retval State of bit (1 or 0).
791 */
792__STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
793{
794 return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1UL : 0UL);
795}
796
797/**
798 * @brief Read comparator instance output level.
799 * @note The comparator output level depends on the selected polarity
800 * (Refer to function @ref LL_COMP_SetOutputPolarity()).
801 * If the comparator polarity is not inverted:
802 * - Comparator output is low when the input plus
803 * is at a lower voltage than the input minus
804 * - Comparator output is high when the input plus
805 * is at a higher voltage than the input minus
806 * If the comparator polarity is inverted:
807 * - Comparator output is high when the input plus
808 * is at a lower voltage than the input minus
809 * - Comparator output is low when the input plus
810 * is at a higher voltage than the input minus
811 * @rmtoll CSR VALUE LL_COMP_ReadOutputLevel
812 * @param COMPx Comparator instance
813 * @retval Returned value can be one of the following values:
814 * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
815 * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
816 */
817__STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
818{
819 return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_VALUE)
820 >> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
821}
822
823/**
824 * @}
825 */
826
827#if defined(USE_FULL_LL_DRIVER)
828/** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
829 * @{
830 */
831
832ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
833ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
834void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
835
836/**
837 * @}
838 */
839#endif /* USE_FULL_LL_DRIVER */
840
841/**
842 * @}
843 */
844
845/**
846 * @}
847 */
848
849/**
850 * @}
851 */
852
853#endif /* COMP1 || COMP2 */
854
855/**
856 * @}
857 */
858
859#ifdef __cplusplus
860}
861#endif
862
863#endif /* STM32G0xx_LL_COMP_H */
864
865/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.