Subversion Repositories DashDisplay

Rev

Rev 56 | Details | Compare with Previous | Last modification | View Log | RSS feed

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