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