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