1 /**
2   ******************************************************************************
3   * @file    stm32l1xx_hal_comp.h
4   * @author  MCD Application Team
5   * @brief   Header file of COMP HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10   *
11   * Redistribution and use in source and binary forms, with or without modification,
12   * are permitted provided that the following conditions are met:
13   *   1. Redistributions of source code must retain the above copyright notice,
14   *      this list of conditions and the following disclaimer.
15   *   2. Redistributions in binary form must reproduce the above copyright notice,
16   *      this list of conditions and the following disclaimer in the documentation
17   *      and/or other materials provided with the distribution.
18   *   3. Neither the name of STMicroelectronics nor the names of its contributors
19   *      may be used to endorse or promote products derived from this software
20   *      without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   *
33   ******************************************************************************
34   */
35 
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32L1xx_HAL_COMP_H
38 #define __STM32L1xx_HAL_COMP_H
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43 
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32l1xx_hal_def.h"
46 
47 /** @addtogroup STM32L1xx_HAL_Driver
48   * @{
49   */
50 
51 /** @addtogroup COMP
52   * @{
53   */
54 
55 /* Exported types ------------------------------------------------------------*/
56 /** @defgroup COMP_Exported_Types COMP Exported Types
57   * @{
58   */
59 
60 /**
61   * @brief  COMP Init structure definition
62   */
63 typedef struct
64 {
65 
66   uint32_t InvertingInput;        /*!< Selects the inverting input of the comparator.
67                                        This parameter can be a value of @ref COMP_InvertingInput
68                                        Note: Inverting input can be changed on the fly, while comparator is running.
69                                        Note: This feature is available on COMP2 only. If COMP1 is selected, this parameter is discarded (On COMP1, inverting input is fixed to Vrefint). */
70 
71   uint32_t NonInvertingInput;     /*!< Selects the non inverting input of the comparator.
72                                        This parameter can be a value of @ref COMPEx_NonInvertingInput */
73 
74   uint32_t Output;                /*!< Selects the output redirection of the comparator.
75                                        This parameter can be a value of @ref COMP_Output
76                                        Note: This feature is available on COMP2 only. If COMP1 is selected, this parameter is discarded. */
77 
78   uint32_t Mode;                  /*!< Selects the operating consumption mode of the comparator
79                                        to adjust the speed/consumption.
80                                        This parameter can be a value of @ref COMP_Mode
81                                        Note: This feature is available on COMP2 only. If COMP1 is selected, this parameter is discarded. */
82 
83   uint32_t WindowMode;            /*!< Selects the window mode of the 2 comparators.
84                                        If enabled, non-inverting inputs of the 2 comparators are connected together and are using inputs of COMP2 only (COMP1 non-inverting input is no more accessible, even from ADC channel VCOMP).
85                                        This parameter can be a value of @ref COMP_WindowMode
86                                        Note: This feature must be enabled from COMP2 instance. If COMP1 is selected, this parameter is discarded. */
87 
88   uint32_t TriggerMode;           /*!< Selects the trigger mode of the comparator when using interruption on EXTI line (interrupt mode).
89                                        This parameter can be a value of @ref COMP_TriggerMode
90                                        Note: This feature is used with function "HAL_COMP_Start_IT()". In all other functions, this parameter is discarded. */
91 
92   uint32_t NonInvertingInputPull; /*!< Selects the internal pulling resistor connected on non inverting input.
93                                        This parameter can be a value of @ref COMP_NonInvertingInputPull
94                                        Note: To avoid extra power consumption, only one resistor should be enabled at a time.
95                                        Note: This feature is available on COMP1 only. If COMP2 is selected, this parameter is discarded. */
96 
97 }COMP_InitTypeDef;
98 
99 /**
100   * @brief  HAL State structures definition
101   */
102 typedef enum
103 {
104   HAL_COMP_STATE_RESET             = 0x00,    /*!< COMP not yet initialized or disabled             */
105   HAL_COMP_STATE_READY             = 0x01,    /*!< COMP initialized and ready for use               */
106   HAL_COMP_STATE_READY_LOCKED      = 0x11,    /*!< COMP initialized but the configuration is locked */
107   HAL_COMP_STATE_BUSY              = 0x02,    /*!< COMP is running                                  */
108   HAL_COMP_STATE_BUSY_LOCKED       = 0x12     /*!< COMP is running and the configuration is locked  */
109 }HAL_COMP_StateTypeDef;
110 
111 /**
112   * @brief  COMP Handle Structure definition
113   */
114 typedef struct
115 {
116   COMP_TypeDef       *Instance;       /*!< Register base address    */
117   COMP_InitTypeDef   Init;            /*!< COMP required parameters */
118   HAL_LockTypeDef    Lock;            /*!< Locking object           */
119   __IO HAL_COMP_StateTypeDef  State;  /*!< COMP communication state */
120 } COMP_HandleTypeDef;
121 
122 /**
123   * @}
124   */
125 
126 /* Exported constants --------------------------------------------------------*/
127 /** @defgroup COMP_Exported_Constants COMP Exported Constants
128   * @{
129   */
130 
131 /** @defgroup COMP_Output COMP Output
132   * @{
133   */
134 #define COMP_OUTPUT_TIM2IC4                     (0x00000000U)                                               /*!< COMP2 output connected to TIM2 Input Capture 4 */
135 #define COMP_OUTPUT_TIM2OCREFCLR                (                                        COMP_CSR_OUTSEL_0) /*!< COMP2 output connected to TIM2 OCREF Clear */
136 #define COMP_OUTPUT_TIM3IC4                     (                    COMP_CSR_OUTSEL_1                    ) /*!< COMP2 output connected to TIM3 Input Capture 4 */
137 #define COMP_OUTPUT_TIM3OCREFCLR                (                    COMP_CSR_OUTSEL_1 | COMP_CSR_OUTSEL_0) /*!< COMP2 output connected to TIM3 OCREF Clear */
138 #define COMP_OUTPUT_TIM4IC4                     (COMP_CSR_OUTSEL_2                                        ) /*!< COMP2 output connected to TIM4 Input Capture 4 */
139 #define COMP_OUTPUT_TIM4OCREFCLR                (COMP_CSR_OUTSEL_2                     | COMP_CSR_OUTSEL_0) /*!< COMP2 output connected to TIM4 OCREF Clear */
140 #define COMP_OUTPUT_TIM10IC1                    (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_1                    ) /*!< COMP2 output connected to TIM10 Input Capture 1 */
141 #define COMP_OUTPUT_NONE                        (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_1 | COMP_CSR_OUTSEL_0) /*!< COMP2 output is not connected to other peripherals */
142 
143 #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_OUTPUT_TIM2IC4)      || \
144                                 ((OUTPUT) == COMP_OUTPUT_TIM2OCREFCLR) || \
145                                 ((OUTPUT) == COMP_OUTPUT_TIM3IC4)      || \
146                                 ((OUTPUT) == COMP_OUTPUT_TIM3OCREFCLR) || \
147                                 ((OUTPUT) == COMP_OUTPUT_TIM4IC4)      || \
148                                 ((OUTPUT) == COMP_OUTPUT_TIM4OCREFCLR) || \
149                                 ((OUTPUT) == COMP_OUTPUT_TIM10IC1)     || \
150                                 ((OUTPUT) == COMP_OUTPUT_NONE)           )
151 /**
152   * @}
153   */
154 
155 /** @defgroup COMP_InvertingInput COMP InvertingInput
156   * @{
157   */
158 /* Inverting Input specific to COMP2 */
159 #define COMP_INVERTINGINPUT_IO                  (                                      COMP_CSR_INSEL_0) /*!< External I/O (COMP2_INM connected to pin PB3) connected to comparator 2 inverting input */
160 #define COMP_INVERTINGINPUT_VREFINT             (                   COMP_CSR_INSEL_1                   ) /*!< VREFINT connected to comparator 2 inverting input */
161 #define COMP_INVERTINGINPUT_3_4VREFINT          (                   COMP_CSR_INSEL_1 | COMP_CSR_INSEL_0) /*!< 3/4 VREFINT connected to comparator 2 inverting input */
162 #define COMP_INVERTINGINPUT_1_2VREFINT          (COMP_CSR_INSEL_2                                      ) /*!< 1/2 VREFINT connected to comparator 2 inverting input */
163 #define COMP_INVERTINGINPUT_1_4VREFINT          (COMP_CSR_INSEL_2                    | COMP_CSR_INSEL_0) /*!< 1/4 VREFINT connected to comparator 2 inverting input */
164 #define COMP_INVERTINGINPUT_DAC1                (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_1                   ) /*!< DAC_OUT1 (PA4) connected to comparator 2 inverting input */
165 #define COMP_INVERTINGINPUT_DAC2                (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_1 | COMP_CSR_INSEL_0) /*!< DAC2_OUT (PA5) connected to comparator 2 inverting input */
166 
167 #define IS_COMP_INVERTINGINPUT(INPUT) (((INPUT) == COMP_INVERTINGINPUT_IO)         || \
168                                        ((INPUT) == COMP_INVERTINGINPUT_VREFINT)    || \
169                                        ((INPUT) == COMP_INVERTINGINPUT_3_4VREFINT) || \
170                                        ((INPUT) == COMP_INVERTINGINPUT_1_2VREFINT) || \
171                                        ((INPUT) == COMP_INVERTINGINPUT_1_4VREFINT) || \
172                                        ((INPUT) == COMP_INVERTINGINPUT_DAC1)       || \
173                                        ((INPUT) == COMP_INVERTINGINPUT_DAC2)         )
174 /**
175   * @}
176   */
177 
178 /** @defgroup COMP_Mode COMP Mode
179   * @{
180   */
181 /* Please refer to the electrical characteristics in the device datasheet for
182    the power consumption values */
183 #define COMP_MODE_LOWSPEED          (0x00000000U)           /*!< Low Speed */
184 #define COMP_MODE_HIGHSPEED         COMP_CSR_SPEED          /*!< High Speed */
185 
186 #define IS_COMP_MODE(SPEED)    (((SPEED) == COMP_MODE_LOWSPEED) || \
187                                 ((SPEED) == COMP_MODE_HIGHSPEED))
188 /**
189   * @}
190   */
191 
192 /** @defgroup COMP_WindowMode COMP WindowMode
193   * @{
194   */
195 #define COMP_WINDOWMODE_DISABLE               (0x00000000U)  /*!< Window mode disabled: COMP1 non-inverting input is independant */
196 #define COMP_WINDOWMODE_ENABLE                COMP_CSR_WNDWE          /*!< Window mode enabled: COMP1 non-inverting input is no more accessible, even from ADC channel VCOMP) (connected to COMP2 non-inverting input) */
197 
198 #define IS_COMP_WINDOWMODE(WINDOWMODE) (((WINDOWMODE) == COMP_WINDOWMODE_DISABLE) || \
199                                         ((WINDOWMODE) == COMP_WINDOWMODE_ENABLE))
200 /**
201   * @}
202   */
203 
204 /** @defgroup COMP_OutputLevel COMP OutputLevel
205   * @{
206   */
207 /* Comparator output is low when the non-inverting input is at a lower        */
208 /* voltage than the inverting input.                                          */
209 #define COMP_OUTPUTLEVEL_LOW                   (0x00000000U)
210 
211 /* Comparator output is high when the non-inverting input is at a higher      */
212 /* voltage than the inverting input.                                          */
213 #define COMP_OUTPUTLEVEL_HIGH                  (0x00000001U)
214 /**
215   * @}
216   */
217 
218 /** @defgroup COMP_TriggerMode COMP TriggerMode
219   * @{
220   */
221 #define COMP_TRIGGERMODE_NONE                  (0x00000000U)   /*!< No External Interrupt trigger detection */
222 #define COMP_TRIGGERMODE_IT_RISING             (0x00000001U)   /*!< External Interrupt Mode with Rising edge trigger detection */
223 #define COMP_TRIGGERMODE_IT_FALLING            (0x00000002U)   /*!< External Interrupt Mode with Falling edge trigger detection */
224 #define COMP_TRIGGERMODE_IT_RISING_FALLING     (0x00000003U)   /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
225 
226 #define IS_COMP_TRIGGERMODE(MODE)  (((MODE) == COMP_TRIGGERMODE_NONE)             || \
227                                     ((MODE) == COMP_TRIGGERMODE_IT_RISING)        || \
228                                     ((MODE) == COMP_TRIGGERMODE_IT_FALLING)       || \
229                                     ((MODE) == COMP_TRIGGERMODE_IT_RISING_FALLING)  )
230 /**
231   * @}
232   */
233 
234 /** @defgroup COMP_ExtiLineEvent COMP ExtiLineEvent
235   * @{
236   */
237 #define COMP_EXTI_LINE_COMP1             EXTI_RTSR_TR21  /*!< External interrupt line 21 Connected to COMP1 */
238 #define COMP_EXTI_LINE_COMP2             EXTI_RTSR_TR22  /*!< External interrupt line 22 Connected to COMP2 */
239 
240 /**
241   * @}
242   */
243 
244 /** @defgroup COMP_NonInvertingInputPull COMP NonInvertingInputPull
245   * @{
246   */
247 #define COMP_NONINVERTINGINPUT_NOPULL           (0x00000000U)           /*!< No internal pull-up or pull-down resistor connected to comparator non inverting input */
248 #define COMP_NONINVERTINGINPUT_10KPU            COMP_CSR_10KPU          /*!< Internal 10kOhm pull-up resistor connected to comparator non inverting input */
249 #define COMP_NONINVERTINGINPUT_10KPD            COMP_CSR_10KPD          /*!< Internal 10kOhm pull-down resistor connected to comparator non inverting input */
250 #define COMP_NONINVERTINGINPUT_400KPU           COMP_CSR_400KPU         /*!< Internal 400kOhm pull-up resistor connected to comparator non inverting input */
251 #define COMP_NONINVERTINGINPUT_400KPD           COMP_CSR_400KPD         /*!< Internal 400kOhm pull-down resistor connected to comparator non inverting input */
252 
253 #define IS_COMP_NONINVERTINGINPUTPULL(INPUT) (((INPUT) == COMP_NONINVERTINGINPUT_NOPULL) || \
254                                               ((INPUT) == COMP_NONINVERTINGINPUT_10KPU)  || \
255                                               ((INPUT) == COMP_NONINVERTINGINPUT_10KPD)  || \
256                                               ((INPUT) == COMP_NONINVERTINGINPUT_400KPU) || \
257                                               ((INPUT) == COMP_NONINVERTINGINPUT_400KPD)   )
258 /**
259   * @}
260   */
261 
262 /**
263   * @}
264   */
265 
266 
267 /* Exported macro ------------------------------------------------------------*/
268 
269 /** @defgroup COMP_Exported_Macro COMP Exported Macro
270   * @{
271   */
272 
273 /** @brief Reset COMP handle state
274   * @param  __HANDLE__: COMP handle.
275   * @retval None
276   */
277 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
278 
279 /**
280   * @brief Enables the specified comparator
281   * @param  __HANDLE__: COMP handle.
282   * @retval None.
283   */
284 #define __HAL_COMP_ENABLE(__HANDLE__)                                          \
285   ( ( ((__HANDLE__)->Instance == COMP1)                                        \
286     )?                                                                         \
287      SET_BIT(COMP->CSR, COMP_CSR_CMP1EN)                                       \
288      :                                                                         \
289      MODIFY_REG(COMP->CSR, COMP_CSR_INSEL, (__HANDLE__)->Init.InvertingInput ) \
290   )
291 
292 /**
293   * @brief Disables the specified comparator
294   * @param  __HANDLE__: COMP handle.
295   * @retval None.
296   */
297 #define __HAL_COMP_DISABLE(__HANDLE__)                                         \
298   ( ( ((__HANDLE__)->Instance == COMP1)                                        \
299     )?                                                                         \
300      CLEAR_BIT(COMP->CSR, COMP_CSR_CMP1EN)                                     \
301      :                                                                         \
302      CLEAR_BIT(COMP->CSR, COMP_CSR_INSEL)                                      \
303   )
304 
305 /** @brief  Checks whether the specified COMP flag is set or not.
306   * @param  __HANDLE__: specifies the COMP Handle.
307   * @param  __FLAG__: specifies the flag to check.
308   *        This parameter can be one of the following values:
309   *            @arg COMP_FLAG_LOCK:  lock flag
310   * @retval The new state of __FLAG__ (TRUE or FALSE).
311   */
312 #define __HAL_COMP_GET_FLAG(__HANDLE__, __FLAG__) (READ_BIT((__HANDLE__)->Instance->CSR, (__FLAG__)) == (__FLAG__))
313 
314 /**
315   * @brief  Enable the COMP1 EXTI line rising edge trigger.
316   * @retval None
317   */
318 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE()    SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
319 
320 /**
321   * @brief  Disable the COMP1 EXTI line rising edge trigger.
322   * @retval None
323   */
324 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE()   CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
325 
326 /**
327   * @brief  Enable the COMP1 EXTI line falling edge trigger.
328   * @retval None
329   */
330 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE()   SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
331 
332 /**
333   * @brief  Disable the COMP1 EXTI line falling edge trigger.
334   * @retval None
335   */
336 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE()  CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
337 
338 /**
339   * @brief  Enable the COMP1 EXTI line rising & falling edge trigger.
340   * @retval None
341   */
342 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
343                                                                __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \
344                                                                __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \
345                                                              } while(0)
346 
347 /**
348   * @brief  Disable the COMP1 EXTI line rising & falling edge trigger.
349   * @retval None
350   */
351 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
352                                                                __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \
353                                                                __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \
354                                                              } while(0)
355 
356 /**
357   * @brief  Enable the COMP1 EXTI line in interrupt mode.
358   * @retval None
359   */
360 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT()             SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
361 
362 /**
363   * @brief  Disable the COMP1 EXTI line in interrupt mode.
364   * @retval None
365   */
366 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT()            CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
367 
368 /**
369   * @brief  Enable the COMP1 EXTI Line in event mode.
370   * @retval None
371   */
372 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT()           SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
373 
374 /**
375   * @brief  Disable the COMP1 EXTI Line in event mode.
376   * @retval None
377   */
378 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT()          CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
379 
380 /**
381   * @brief  Check whether the COMP1 EXTI line flag is set or not.
382   * @retval RESET or SET
383   */
384 #define __HAL_COMP_COMP1_EXTI_GET_FLAG()              READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP1)
385 
386 /**
387   * @brief  Clear the the COMP1 EXTI flag.
388   * @retval None
389   */
390 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG()            WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP1)
391 
392 /**
393   * @brief  Generates a Software interrupt on COMP1 EXTI Line.
394   * @retval None
395   */
396 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT()              SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP1)
397 
398 /**
399   * @brief  Enable the COMP2 EXTI line rising edge trigger.
400   * @retval None
401   */
402 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()    SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
403 
404 /**
405   * @brief  Disable the COMP2 EXTI line rising edge trigger.
406   * @retval None
407   */
408 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE()   CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
409 
410 /**
411   * @brief  Enable the COMP2 EXTI line falling edge trigger.
412   * @retval None
413   */
414 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE()   SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
415 
416 /**
417   * @brief  Disable the COMP2 EXTI line falling edge trigger.
418   * @retval None
419   */
420 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE()  CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
421 
422 /**
423   * @brief  Enable the COMP2 EXTI line rising & falling edge trigger.
424   * @retval None
425   */
426 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
427                                                                __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \
428                                                                __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \
429                                                              } while(0)
430 
431 /**
432   * @brief  Disable the COMP2 EXTI line rising & falling edge trigger.
433   * @retval None
434   */
435 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE()   do { \
436                                                                __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \
437                                                                __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \
438                                                              } while(0)
439 
440 /**
441   * @brief  Enable the COMP2 EXTI line.
442   * @retval None
443   */
444 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT()             SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
445 
446 /**
447   * @brief  Disable the COMP2 EXTI line.
448   * @retval None
449   */
450 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT()            CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
451 
452 /**
453   * @brief  Enable the COMP2 EXTI Line in event mode.
454   * @retval None
455   */
456 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT()           SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
457 
458 /**
459   * @brief  Disable the COMP2 EXTI Line in event mode.
460   * @retval None
461   */
462 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT()          CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
463 
464 /**
465   * @brief  Check whether the COMP2 EXTI line flag is set or not.
466   * @retval RESET or SET
467   */
468 #define __HAL_COMP_COMP2_EXTI_GET_FLAG()              READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP2)
469 
470 /**
471   * @brief  Clear the the COMP2 EXTI flag.
472   * @retval None
473   */
474 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG()            WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP2)
475 
476 /**
477   * @brief  Generates a Software interrupt on COMP1 EXTI Line.
478   * @retval None
479   */
480 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT()              SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP2)
481 
482 /**
483   * @}
484   */
485 
486 /* Private macro -------------------------------------------------------------*/
487 
488 /** @defgroup COMP_Private_Macro COMP Private Macro
489   * @{
490   */
491 
492 /**
493   * @brief  Get the specified EXTI line for a comparator instance
494   * @param  __INSTANCE__: specifies the COMP instance.
495   * @retval value of @ref COMP_ExtiLineEvent
496   */
497 #define COMP_GET_EXTI_LINE(__INSTANCE__)                                       \
498   ( ( ((__INSTANCE__) == COMP1)                                                \
499     )?                                                                         \
500      (COMP_EXTI_LINE_COMP1)                                                    \
501      :                                                                         \
502      (COMP_EXTI_LINE_COMP2)                                                    \
503   )
504 
505 /**
506   * @brief Select the COMP register CSR bit CMPxOUT corresponding to the
507   * selected COMP instance.
508   * @param __HANDLE__: COMP handle
509   * @retval Comparator register CSR bit COMP_CSR_CMP1OUT or COMP_CSR_CMP2OUT
510   */
511 #define __COMP_CSR_CMPXOUT(__HANDLE__)                                         \
512   ( ( ((__HANDLE__)->Instance == COMP1)                                        \
513     )?                                                                         \
514      (COMP_CSR_CMP1OUT)                                                        \
515      :                                                                         \
516      (COMP_CSR_CMP2OUT)                                                        \
517   )
518 
519 /**
520   * @brief Verification of COMP state: enabled or disabled
521   * @param __HANDLE__: COMP handle
522   * @retval SET (COMP enabled) or RESET (COMP disabled)
523   */
524 #define __COMP_IS_ENABLED(__HANDLE__)                                          \
525   ( ( ((__HANDLE__)->Instance == COMP1)                                        \
526     )?                                                                         \
527      (((READ_BIT(COMP->CSR , COMP_CSR_CMP1EN) == COMP_CSR_CMP1EN)              \
528       ) ? SET : RESET)                                                         \
529      :                                                                         \
530      (((READ_BIT(COMP->CSR , COMP_CSR_INSEL) != RESET)                         \
531       ) ? SET : RESET)                                                         \
532   )
533 
534 /**
535   * @}
536   */
537 
538 
539 /* Include COMP HAL Extension module */
540 #include "stm32l1xx_hal_comp_ex.h"
541 
542 /* Exported functions --------------------------------------------------------*/
543 /** @addtogroup COMP_Exported_Functions
544   * @{
545   */
546 
547 /* Initialization and de-initialization functions  ******************************/
548 /** @addtogroup COMP_Exported_Functions_Group1
549   * @{
550   */
551 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
552 HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
553 void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
554 void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
555 /**
556   * @}
557   */
558 
559 /* I/O operation functions  *****************************************************/
560 /** @addtogroup COMP_Exported_Functions_Group2
561   * @{
562   */
563 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
564 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
565 HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp);
566 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp);
567 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
568 /**
569   * @}
570   */
571 
572 /* Peripheral Control functions  ************************************************/
573 /** @addtogroup COMP_Exported_Functions_Group3
574   * @{
575   */
576 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
577 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
578 
579 /* Callback in Interrupt mode */
580 void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
581 /**
582   * @}
583   */
584 
585 /* Peripheral State functions  **************************************************/
586 /** @addtogroup COMP_Exported_Functions_Group4
587   * @{
588   */
589 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
590 /**
591   * @}
592   */
593 
594 /**
595   * @}
596   */
597 
598 /**
599   * @}
600   */
601 
602 /**
603   * @}
604   */
605 
606 #ifdef __cplusplus
607 }
608 #endif
609 
610 #endif /* __STM32L1xx_HAL_COMP_H */
611 
612 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
613