1 /**
2   ******************************************************************************
3   * @file    stm32g4xx_ll_comp.c
4   * @author  MCD Application Team
5   * @brief   COMP LL module driver
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 #if defined(USE_FULL_LL_DRIVER)
20 
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32g4xx_ll_comp.h"
23 
24 #ifdef  USE_FULL_ASSERT
25 #include "stm32_assert.h"
26 #else
27 #define assert_param(expr) ((void)0U)
28 #endif /* USE_FULL_ASSERT */
29 
30 /** @addtogroup STM32G4xx_LL_Driver
31   * @{
32   */
33 
34 
35 
36 /** @addtogroup COMP_LL COMP
37   * @{
38   */
39 
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
44 
45 /** @addtogroup COMP_LL_Private_Macros
46   * @{
47   */
48 
49 /* Check of parameters for configuration of COMP hierarchical scope:          */
50 /* COMP instance.                                                             */
51 
52 /* Note: On this STM32 series, comparator input plus parameters are           */
53 /*       the same on all COMP instances.                                      */
54 /*       However, comparator instance kept as macro parameter for             */
55 /*       compatibility with other STM32 series.                               */
56 #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__)               \
57   (((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1)                                \
58    || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2)                             \
59   )
60 #if defined(STM32G414xx) || defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
61 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__)             \
62   (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT)  ||                   \
63     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT)  ||                  \
64     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT)  ||                  \
65     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT)     ||                  \
66     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1)         ||                  \
67     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2)         ||                  \
68     (((__COMP_INSTANCE__) == COMP1)                        &&                  \
69     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1)  ||                   \
70     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1))                       \
71     )                                                      ||                  \
72     (((__COMP_INSTANCE__) == COMP2)                        &&                  \
73     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2)  ||                   \
74     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH2))                       \
75     )                                                      ||                  \
76     (((__COMP_INSTANCE__) == COMP3)                        &&                  \
77     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1)  ||                   \
78     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1))                       \
79     )                                                      ||                  \
80     (((__COMP_INSTANCE__) == COMP4)                        &&                  \
81     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1)  ||                   \
82     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH2))                       \
83     )                                                      ||                  \
84     (((__COMP_INSTANCE__) == COMP5)                        &&                  \
85     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2)  ||                   \
86     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC4_CH1))                       \
87     )                                                      ||                  \
88     (((__COMP_INSTANCE__) == COMP6)                        &&                  \
89     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC2_CH1)  ||                   \
90     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC4_CH2))                       \
91     )                                                      ||                  \
92     (((__COMP_INSTANCE__) == COMP7)                        &&                  \
93     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC2_CH1)  ||                   \
94     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC4_CH1))                       \
95       ))
96 #elif defined(STM32GBK1CB) || defined(STM32G431xx) || defined(STM32G441xx) || defined(STM32G471xx) || defined(STM32G491xx) || defined(STM32G4A1xx)
97 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__)             \
98   (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT)  ||                   \
99    ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT)  ||                   \
100    ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT)  ||                   \
101    ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT)     ||                   \
102    ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1)         ||                   \
103    ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2)         ||                   \
104    (((__COMP_INSTANCE__) == COMP1)                        &&                   \
105     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1)  ||                   \
106     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1))                       \
107    )                                                      ||                   \
108    (((__COMP_INSTANCE__) == COMP2)                        &&                   \
109     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2)  ||                   \
110     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH2))                       \
111    )                                                      ||                   \
112    (((__COMP_INSTANCE__) == COMP3)                        &&                   \
113     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1)  ||                   \
114     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1))                       \
115    )                                                      ||                   \
116    (((__COMP_INSTANCE__) == COMP4)                        &&                   \
117     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1)  ||                   \
118     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH2))                       \
119    ))
120 #elif defined(STM32G411xB) || defined(STM32G411xC)
121 #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__)             \
122   (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT)  ||                   \
123    ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT)  ||                   \
124    ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT)  ||                   \
125    ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT)     ||                   \
126    ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1)         ||                   \
127    ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2)         ||                   \
128    (((__COMP_INSTANCE__) == COMP1)                        &&                   \
129     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1)  ||                   \
130     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1))                       \
131    )                                                      ||                   \
132    (((__COMP_INSTANCE__) == COMP2)                        &&                   \
133     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2)  ||                   \
134     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH2))                       \
135    )                                                      ||                   \
136    (((__COMP_INSTANCE__) == COMP3)                        &&                   \
137     (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1)  ||                   \
138     ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1))                       \
139    ))
140 #endif
141 
142 #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__)                      \
143   (((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE)                         \
144    || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_10MV)                      \
145    || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_20MV)                      \
146    || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_30MV)                      \
147    || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_40MV)                      \
148    || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_50MV)                      \
149    || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_60MV)                      \
150    || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_70MV)                      \
151   )
152 
153 #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__)                               \
154   (((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED)                           \
155    || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED)                           \
156   )
157 
158 #if defined(STM32G414xx) || defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
159 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)      \
160   ((((__INSTANCE__) == COMP1) &&                                                         \
161     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
162      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||            \
163      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||            \
164      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1)  ||            \
165      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1)))              \
166    ||                                                                                    \
167    (((__INSTANCE__) == COMP2) &&                                                         \
168     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
169      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2)  ||            \
170      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2)  ||            \
171      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2)  ||            \
172      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2)))              \
173    ||                                                                                    \
174    (((__INSTANCE__) == COMP3) &&                                                         \
175     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
176      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3)  ||            \
177      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3)  ||            \
178      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3)  ||            \
179      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3)))              \
180    ||                                                                                    \
181    (((__INSTANCE__) == COMP4) &&                                                         \
182     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
183      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4)  ||            \
184      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4)  ||            \
185      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4)  ||            \
186      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4)))             \
187    ||                                                                                    \
188    (((__INSTANCE__) == COMP5) &&                                                         \
189     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
190      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP5)  ||            \
191      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP5)  ||            \
192      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP5)  ||            \
193      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP5)))              \
194    ||                                                                                    \
195    (((__INSTANCE__) == COMP6) &&                                                         \
196     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
197      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP6)  ||            \
198      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6)  ||            \
199      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP6)  ||            \
200      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6)))             \
201    ||                                                                                    \
202    (((__INSTANCE__) == COMP7) &&                                                         \
203     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
204      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP7)  ||            \
205      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP7)  ||            \
206      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP7)  ||            \
207      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP7)))             \
208    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM20_OC5)                    \
209    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1)                    \
210    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM4_OC3)                     \
211   )
212 #elif defined(STM32GBK1CB) || defined(STM32G431xx) || defined(STM32G441xx) || defined(STM32G471xx)
213 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)      \
214   ((((__INSTANCE__) == COMP1) &&                                                         \
215     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
216      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||            \
217      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||            \
218      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1)  ||            \
219      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1)))              \
220    ||                                                                                    \
221    (((__INSTANCE__) == COMP2) &&                                                         \
222     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
223      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2)  ||            \
224      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2)  ||            \
225      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2)  ||            \
226      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2)))              \
227    ||                                                                                    \
228    (((__INSTANCE__) == COMP3) &&                                                         \
229     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
230      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3)  ||            \
231      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3)  ||            \
232      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3)  ||            \
233      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3)))              \
234    ||                                                                                    \
235    (((__INSTANCE__) == COMP4) &&                                                         \
236     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
237      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4)  ||            \
238      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4)  ||            \
239      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4)  ||            \
240      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4)))             \
241    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1)                    \
242    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM4_OC3)                     \
243   )
244 #elif defined(STM32G491xx) || defined(STM32G4A1xx)
245 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)      \
246   ((((__INSTANCE__) == COMP1) &&                                                         \
247     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
248      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||            \
249      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||            \
250      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1)  ||            \
251      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1)))              \
252    ||                                                                                    \
253    (((__INSTANCE__) == COMP2) &&                                                         \
254     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
255      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2)  ||            \
256      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2)  ||            \
257      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2)  ||            \
258      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2)))              \
259    ||                                                                                    \
260    (((__INSTANCE__) == COMP3) &&                                                         \
261     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
262      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3)  ||            \
263      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3)  ||            \
264      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3)  ||            \
265      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3)))              \
266    ||                                                                                    \
267    (((__INSTANCE__) == COMP4) &&                                                         \
268     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
269      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4)  ||            \
270      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4)  ||            \
271      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4)  ||            \
272      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4)))             \
273    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM20_OC5)                    \
274    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1)                    \
275    || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM4_OC3)                     \
276   )
277 #elif defined(STM32G411xB) || defined(STM32G411xC)
278 #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__)      \
279   ((((__INSTANCE__) == COMP1) &&                                                         \
280     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
281      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1)  ||            \
282      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1)  ||            \
283      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1)  ||            \
284      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1)))              \
285    ||                                                                                    \
286    (((__INSTANCE__) == COMP2) &&                                                         \
287     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
288      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2)  ||            \
289      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2)  ||            \
290      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2)  ||            \
291      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2)))              \
292    ||                                                                                    \
293    (((__INSTANCE__) == COMP3) &&                                                         \
294     (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)            ||            \
295      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3)  ||            \
296      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3)  ||            \
297      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3)  ||            \
298      ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3)))              \
299   )
300 #endif
301 /**
302   * @}
303   */
304 
305 
306 /* Private function prototypes -----------------------------------------------*/
307 
308 /* Exported functions --------------------------------------------------------*/
309 /** @addtogroup COMP_LL_Exported_Functions
310   * @{
311   */
312 
313 /** @addtogroup COMP_LL_EF_Init
314   * @{
315   */
316 
317 /**
318   * @brief  De-initialize registers of the selected COMP instance
319   *         to their default reset values.
320   * @note   If comparator is locked, de-initialization by software is
321   *         not possible.
322   *         The only way to unlock the comparator is a device hardware reset.
323   * @param  COMPx COMP instance
324   * @retval An ErrorStatus enumeration value:
325   *          - SUCCESS: COMP registers are de-initialized
326   *          - ERROR: COMP registers are not de-initialized
327   */
LL_COMP_DeInit(COMP_TypeDef * COMPx)328 ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
329 {
330   ErrorStatus status = SUCCESS;
331 
332   /* Check the parameters */
333   assert_param(IS_COMP_ALL_INSTANCE(COMPx));
334 
335   /* Note: Hardware constraint (refer to description of this function):       */
336   /*       COMP instance must not be locked.                                  */
337   if (LL_COMP_IsLocked(COMPx) == 0UL)
338   {
339     LL_COMP_WriteReg(COMPx, CSR, 0x00000000UL);
340 
341   }
342   else
343   {
344     /* Comparator instance is locked: de-initialization by software is         */
345     /* not possible.                                                           */
346     /* The only way to unlock the comparator is a device hardware reset.       */
347     status = ERROR;
348   }
349 
350   return status;
351 }
352 
353 /**
354   * @brief  Initialize some features of COMP instance.
355   * @note   This function configures features of the selected COMP instance.
356   *         Some features are also available at scope COMP common instance
357   *         (common to several COMP instances).
358   *         Refer to functions having argument "COMPxy_COMMON" as parameter.
359   * @param  COMPx COMP instance
360   * @param  COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
361   * @retval An ErrorStatus enumeration value:
362   *          - SUCCESS: COMP registers are initialized
363   *          - ERROR: COMP registers are not initialized
364   */
LL_COMP_Init(COMP_TypeDef * COMPx,const LL_COMP_InitTypeDef * COMP_InitStruct)365 ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, const LL_COMP_InitTypeDef *COMP_InitStruct)
366 {
367   ErrorStatus status = SUCCESS;
368 
369   /* Check the parameters */
370   assert_param(IS_COMP_ALL_INSTANCE(COMPx));
371   assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
372   assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
373   assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis));
374   assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity));
375   assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMPx, COMP_InitStruct->OutputBlankingSource));
376 
377   /* Note: Hardware constraint (refer to description of this function)        */
378   /*       COMP instance must not be locked.                                  */
379   if (LL_COMP_IsLocked(COMPx) == 0UL)
380   {
381     /* Configuration of comparator instance :                                 */
382     /*  - InputPlus                                                           */
383     /*  - InputMinus                                                          */
384     /*  - InputHysteresis                                                     */
385     /*  - OutputPolarity                                                      */
386     /*  - OutputBlankingSource                                                */
387     MODIFY_REG(COMPx->CSR,
388                COMP_CSR_INPSEL
389                | COMP_CSR_SCALEN
390                | COMP_CSR_BRGEN
391                | COMP_CSR_INMSEL
392                | COMP_CSR_HYST
393                | COMP_CSR_POLARITY
394                | COMP_CSR_BLANKING
395                ,
396                COMP_InitStruct->InputPlus
397                | COMP_InitStruct->InputMinus
398                | COMP_InitStruct->InputHysteresis
399                | COMP_InitStruct->OutputPolarity
400                | COMP_InitStruct->OutputBlankingSource
401               );
402 
403   }
404   else
405   {
406     /* Initialization error: COMP instance is locked.                         */
407     status = ERROR;
408   }
409 
410   return status;
411 }
412 
413 /**
414   * @brief Set each @ref LL_COMP_InitTypeDef field to default value.
415   * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
416   *                        whose fields will be set to default values.
417   * @retval None
418   */
LL_COMP_StructInit(LL_COMP_InitTypeDef * COMP_InitStruct)419 void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
420 {
421   /* Set COMP_InitStruct fields to default values */
422   COMP_InitStruct->InputPlus            = LL_COMP_INPUT_PLUS_IO1;
423   COMP_InitStruct->InputMinus           = LL_COMP_INPUT_MINUS_VREFINT;
424   COMP_InitStruct->InputHysteresis      = LL_COMP_HYSTERESIS_NONE;
425   COMP_InitStruct->OutputPolarity       = LL_COMP_OUTPUTPOL_NONINVERTED;
426   COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
427 }
428 
429 /**
430   * @}
431   */
432 
433 /**
434   * @}
435   */
436 
437 /**
438   * @}
439   */
440 
441 
442 
443 /**
444   * @}
445   */
446 
447 #endif /* USE_FULL_LL_DRIVER */
448