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