1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_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) 2016 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 __STM32L0xx_HAL_COMP_H
38 #define __STM32L0xx_HAL_COMP_H
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43 
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32l0xx_hal_def.h"
46 
47 /** @addtogroup STM32L0xx_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 WindowMode;         /*!< Set window mode of a pair of comparators instances
67                                     (2 consecutive instances odd and even COMP<x> and COMP<x+1>).
68                                     Note: HAL COMP driver allows to set window mode from any COMP instance of the pair of COMP instances composing window mode.
69                                     This parameter can be a value of @ref COMP_WindowMode */
70 
71   uint32_t Mode;               /*!< Set comparator operating mode to adjust power and speed.
72                                     Note: For the characteritics of comparator power modes
73                                           (propagation delay and power consumption), refer to device datasheet.
74                                     This parameter can be a value of @ref COMP_PowerMode */
75 
76   uint32_t NonInvertingInput;  /*!< Set comparator input plus (non-inverting input).
77                                     This parameter can be a value of @ref COMP_InputPlus */
78 
79   uint32_t InvertingInput;     /*!< Set comparator input minus (inverting input).
80                                     This parameter can be a value of @ref COMP_InputMinus */
81 
82   uint32_t OutputPol;          /*!< Set comparator output polarity.
83                                     This parameter can be a value of @ref COMP_OutputPolarity */
84 
85   uint32_t LPTIMConnection;    /*!< Set comparator output connection to LPTIM peripheral.
86                                     This parameter can be a value of @ref COMP_LPTIMConnection */
87 
88   uint32_t TriggerMode;        /*!< Set the comparator output triggering External Interrupt Line (EXTI).
89                                     This parameter can be a value of @ref COMP_EXTI_TriggerMode */
90 
91 }COMP_InitTypeDef;
92 
93 /**
94   * @brief  HAL COMP state machine: HAL COMP states definition
95   */
96 #define COMP_STATE_BITFIELD_LOCK  ((uint32_t)0x10)
97 typedef enum
98 {
99   HAL_COMP_STATE_RESET             = 0x00U,                                             /*!< COMP not yet initialized                             */
100   HAL_COMP_STATE_RESET_LOCKED      = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */
101   HAL_COMP_STATE_READY             = 0x01U,                                             /*!< COMP initialized and ready for use                   */
102   HAL_COMP_STATE_READY_LOCKED      = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked         */
103   HAL_COMP_STATE_BUSY              = 0x02U,                                             /*!< COMP is running                                      */
104   HAL_COMP_STATE_BUSY_LOCKED       = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK)   /*!< COMP is running and configuration is locked          */
105 }HAL_COMP_StateTypeDef;
106 
107 /**
108   * @brief  COMP Handle Structure definition
109   */
110 typedef struct
111 {
112   COMP_TypeDef       *Instance;       /*!< Register base address    */
113   COMP_InitTypeDef   Init;            /*!< COMP required parameters */
114   HAL_LockTypeDef    Lock;            /*!< Locking object           */
115   __IO HAL_COMP_StateTypeDef  State;  /*!< COMP communication state */
116 } COMP_HandleTypeDef;
117 
118 /**
119   * @}
120   */
121 
122 /* Exported constants --------------------------------------------------------*/
123 /** @defgroup COMP_Exported_Constants COMP Exported Constants
124   * @{
125   */
126 
127 /** @defgroup COMP_WindowMode COMP Window Mode
128   * @{
129   */
130 #define COMP_WINDOWMODE_DISABLE                 ((uint32_t)0x00000000U) /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */
131 #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_COMP1WM)     /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP1 input plus (COMP2 input plus is no more accessible). */
132 /**
133   * @}
134   */
135 
136 /** @defgroup COMP_PowerMode COMP power mode
137   * @{
138   */
139 /* Note: For the characteritics of comparator power modes                     */
140 /*       (propagation delay and power consumption),                           */
141 /*       refer to device datasheet.                                           */
142 #define COMP_POWERMODE_MEDIUMSPEED     (COMP_CSR_COMP2SPEED)       /*!< COMP power mode to low power (indicated as "high speed" in reference manual) (only for COMP instance: COMP2) */
143 #define COMP_POWERMODE_ULTRALOWPOWER   ((uint32_t)0x00000000U)     /*!< COMP power mode to ultra low power (indicated as "low speed" in reference manual) (only for COMP instance: COMP2) */
144 /**
145   * @}
146   */
147 
148 /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
149   * @{
150   */
151 #define COMP_INPUT_PLUS_IO1            ((uint32_t)0x00000000U)                            /*!< Comparator input plus connected to IO1 (pin PA1 for COMP1, pin PA3 for COMP2) */
152 #define COMP_INPUT_PLUS_IO2            (COMP_CSR_COMP2INPSEL_0)                           /*!< Comparator input plus connected to IO2 (pin PB4 for COMP2) (only for COMP instance: COMP2) */
153 #define COMP_INPUT_PLUS_IO3            (COMP_CSR_COMP2INPSEL_1)                           /*!< Comparator input plus connected to IO3 (pin PA5 for COMP2) (only for COMP instance: COMP2) */
154 #define COMP_INPUT_PLUS_IO4            (COMP_CSR_COMP2INPSEL_0 | COMP_CSR_COMP2INPSEL_1)  /*!< Comparator input plus connected to IO4 (pin PB6 for COMP2) (only for COMP instance: COMP2) */
155 #define COMP_INPUT_PLUS_IO5            (COMP_CSR_COMP2INPSEL_2)                           /*!< Comparator input plus connected to IO5 (pin PB7 for COMP2) (only for COMP instance: COMP2) */
156 #if defined (STM32L011xx) || defined (STM32L021xx)
157 #define COMP_INPUT_PLUS_IO6            (COMP_CSR_COMP2INPSEL_2 | COMP_CSR_COMP2INPSEL_0)  /*!< Comparator input plus connected to IO6 (pin PA7 for COMP2) (only for COMP instance: COMP2) (Available only on devices STM32L0 category 1) */
158 #endif
159 /**
160   * @}
161   */
162 
163 /** @defgroup COMP_InputMinus COMP input minus (inverting input)
164   * @{
165   */
166 #define COMP_INPUT_MINUS_1_4VREFINT    (COMP_CSR_COMP2INNSEL_2                                                  ) /*!< Comparator input minus connected to 1/4 VREFINT (only for COMP instance: COMP2) */
167 #define COMP_INPUT_MINUS_1_2VREFINT    (COMP_CSR_COMP2INNSEL_2 |                          COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to 1/2 VREFINT (only for COMP instance: COMP2) */
168 #define COMP_INPUT_MINUS_3_4VREFINT    (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_1                         ) /*!< Comparator input minus connected to 3/4 VREFINT (only for COMP instance: COMP2) */
169 #define COMP_INPUT_MINUS_VREFINT       ((uint32_t)0x00000000U)                                                    /*!< Comparator input minus connected to VrefInt */
170 #define COMP_INPUT_MINUS_DAC1_CH1      (                         COMP_CSR_COMP2INNSEL_1                         ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
171 #define COMP_INPUT_MINUS_DAC1_CH2      (                         COMP_CSR_COMP2INNSEL_1 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
172 #define COMP_INPUT_MINUS_IO1           (                                                  COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to IO1 (pin PA0 for COMP1, pin PA2 for COMP2) */
173 #define COMP_INPUT_MINUS_IO2           (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_1 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to IO2 (pin PB3 for COMP2) (only for COMP instance: COMP2) */
174 /**
175   * @}
176   */
177 
178 
179 /** @defgroup COMP_LPTIMConnection COMP Low power timer connection definition
180   * @{
181   */
182 
183 #define COMP_LPTIMCONNECTION_DISABLED               ((uint32_t)0x00000000U)    /*!< COMPx signal is gated */
184 #define COMP_LPTIMCONNECTION_IN1_ENABLED            ((uint32_t)0x00000001U)    /*!< COMPx signal is connected to LPTIM input 1 */
185 #define COMP_LPTIMCONNECTION_IN2_ENABLED            ((uint32_t)0x00000002U)    /*!< COMPx signal is connected to LPTIM input 2 */
186 /**
187   * @}
188   */
189 
190 /** @defgroup COMP_OutputPolarity COMP output Polarity
191   * @{
192   */
193 #define COMP_OUTPUTPOL_NONINVERTED             ((uint32_t)0x00000000U)  /*!< COMP output on GPIO isn't inverted */
194 #define COMP_OUTPUTPOL_INVERTED                COMP_CSR_COMPxPOLARITY       /*!< COMP output on GPIO is inverted */
195 /**
196   * @}
197   */
198 
199 /** @defgroup COMP_OutputLevel COMP Output Level
200   * @{
201   */
202 /* Note: Comparator output level values are fixed to "0" and "1",             */
203 /* corresponding COMP register bit is managed by HAL function to match        */
204 /* with these values (independently of bit position in register).             */
205 
206 /* When output polarity is not inverted, comparator output is low when
207    the input plus is at a lower voltage than the input minus */
208 #define COMP_OUTPUT_LEVEL_LOW              ((uint32_t)0x00000000U)
209 /* When output polarity is not inverted, comparator output is high when
210    the input plus is at a higher voltage than the input minus */
211 #define COMP_OUTPUT_LEVEL_HIGH             ((uint32_t)0x00000001U)
212 /**
213   * @}
214   */
215 
216 /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
217   * @{
218   */
219 #define COMP_TRIGGERMODE_NONE                 ((uint32_t)0x00000000U)                                    /*!< Comparator output triggering no External Interrupt Line */
220 #define COMP_TRIGGERMODE_IT_RISING            (COMP_EXTI_IT | COMP_EXTI_RISING)                         /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
221 #define COMP_TRIGGERMODE_IT_FALLING           (COMP_EXTI_IT | COMP_EXTI_FALLING)                        /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
222 #define COMP_TRIGGERMODE_IT_RISING_FALLING    (COMP_EXTI_IT | COMP_EXTI_RISING | COMP_EXTI_FALLING)     /*!< Comparator output triggering External Interrupt Line event with interruption, on both rising and falling edges */
223 #define COMP_TRIGGERMODE_EVENT_RISING         (COMP_EXTI_EVENT | COMP_EXTI_RISING)                      /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
224 #define COMP_TRIGGERMODE_EVENT_FALLING        (COMP_EXTI_EVENT | COMP_EXTI_FALLING)                     /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
225 #define COMP_TRIGGERMODE_EVENT_RISING_FALLING (COMP_EXTI_EVENT | COMP_EXTI_RISING | COMP_EXTI_FALLING)  /*!< Comparator output triggering External Interrupt Line event only (without interruption), on both rising and falling edges */
226 /**
227   * @}
228   */
229 
230 /**
231   * @}
232   */
233 
234 /* Exported macro ------------------------------------------------------------*/
235 /** @defgroup COMP_Exported_Macros COMP Exported Macros
236   * @{
237   */
238 
239 /** @defgroup COMP_Handle_Management  COMP Handle Management
240   * @{
241   */
242 
243 /** @brief  Reset COMP handle state.
244   * @param  __HANDLE__  COMP handle
245   * @retval None
246   */
247 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
248 
249 /**
250   * @brief  Enable the specified comparator.
251   * @param  __HANDLE__  COMP handle
252   * @retval None
253   */
254 #define __HAL_COMP_ENABLE(__HANDLE__)              SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxEN)
255 
256 /**
257   * @brief  Disable the specified comparator.
258   * @param  __HANDLE__  COMP handle
259   * @retval None
260   */
261 #define __HAL_COMP_DISABLE(__HANDLE__)             CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxEN)
262 
263 /**
264   * @brief  Lock the specified comparator configuration.
265   * @note   Using this macro induce HAL COMP handle state machine being no
266   *         more in line with COMP instance state.
267   *         To keep HAL COMP handle state machine updated, it is recommended
268   *         to use function "HAL_COMP_Lock')".
269   * @param  __HANDLE__  COMP handle
270   * @retval None
271   */
272 #define __HAL_COMP_LOCK(__HANDLE__)                SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxLOCK)
273 
274 /**
275   * @brief  Check whether the specified comparator is locked.
276   * @param  __HANDLE__  COMP handle
277   * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
278   */
279 #define __HAL_COMP_IS_LOCKED(__HANDLE__)           (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxLOCK) == COMP_CSR_COMPxLOCK)
280 
281 /**
282   * @}
283   */
284 
285 /** @defgroup COMP_Exti_Management  COMP external interrupt line management
286   * @{
287   */
288 
289 /**
290   * @brief  Enable the COMP1 EXTI line rising edge trigger.
291   * @retval None
292   */
293 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE()    SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
294 
295 /**
296   * @brief  Disable the COMP1 EXTI line rising edge trigger.
297   * @retval None
298   */
299 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE()   CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
300 
301 /**
302   * @brief  Enable the COMP1 EXTI line falling edge trigger.
303   * @retval None
304   */
305 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE()   SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
306 
307 /**
308   * @brief  Disable the COMP1 EXTI line falling edge trigger.
309   * @retval None
310   */
311 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE()  CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
312 
313 /**
314   * @brief  Enable the COMP1 EXTI line rising & falling edge trigger.
315   * @retval None
316   */
317 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
318                                                                __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \
319                                                                __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \
320                                                              } while(0)
321 
322 /**
323   * @brief  Disable the COMP1 EXTI line rising & falling edge trigger.
324   * @retval None
325   */
326 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
327                                                                __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \
328                                                                __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \
329                                                              } while(0)
330 
331 /**
332   * @brief  Enable the COMP1 EXTI line in interrupt mode.
333   * @retval None
334   */
335 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT()             SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
336 
337 /**
338   * @brief  Disable the COMP1 EXTI line in interrupt mode.
339   * @retval None
340   */
341 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT()            CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
342 
343 /**
344   * @brief  Generate a software interrupt on the COMP1 EXTI line.
345   * @retval None
346   */
347 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT()         SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP1)
348 
349 /**
350   * @brief  Enable the COMP1 EXTI line in event mode.
351   * @retval None
352   */
353 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT()           SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
354 
355 /**
356   * @brief  Disable the COMP1 EXTI line in event mode.
357   * @retval None
358   */
359 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT()          CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
360 
361 /**
362   * @brief  Check whether the COMP1 EXTI line flag is set.
363   * @retval RESET or SET
364   */
365 #define __HAL_COMP_COMP1_EXTI_GET_FLAG()              READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP1)
366 
367 /**
368   * @brief  Clear the COMP1 EXTI flag.
369   * @retval None
370   */
371 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG()            WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP1)
372 
373 /**
374   * @brief  Enable the COMP2 EXTI line rising edge trigger.
375   * @retval None
376   */
377 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()    SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
378 
379 /**
380   * @brief  Disable the COMP2 EXTI line rising edge trigger.
381   * @retval None
382   */
383 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE()   CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
384 
385 /**
386   * @brief  Enable the COMP2 EXTI line falling edge trigger.
387   * @retval None
388   */
389 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE()   SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
390 
391 /**
392   * @brief  Disable the COMP2 EXTI line falling edge trigger.
393   * @retval None
394   */
395 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE()  CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
396 
397 /**
398   * @brief  Enable the COMP2 EXTI line rising & falling edge trigger.
399   * @retval None
400   */
401 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
402                                                                __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \
403                                                                __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \
404                                                              } while(0)
405 
406 /**
407   * @brief  Disable the COMP2 EXTI line rising & falling edge trigger.
408   * @retval None
409   */
410 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE()   do { \
411                                                                __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \
412                                                                __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \
413                                                              } while(0)
414 
415 /**
416   * @brief  Enable the COMP2 EXTI line in interrupt mode.
417   * @retval None
418   */
419 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT()             SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
420 
421 /**
422   * @brief  Disable the COMP2 EXTI line in interrupt mode.
423   * @retval None
424   */
425 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT()            CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
426 
427 /**
428   * @brief  Generate a software interrupt on the COMP2 EXTI line.
429   * @retval None
430   */
431 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT()         SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP2)
432 
433 /**
434   * @brief  Enable the COMP2 EXTI line in event mode.
435   * @retval None
436   */
437 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT()           SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
438 
439 /**
440   * @brief  Disable the COMP2 EXTI line in event mode.
441   * @retval None
442   */
443 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT()          CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
444 
445 /**
446   * @brief  Check whether the COMP2 EXTI line flag is set.
447   * @retval RESET or SET
448   */
449 #define __HAL_COMP_COMP2_EXTI_GET_FLAG()              READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP2)
450 
451 /**
452   * @brief  Clear the COMP2 EXTI flag.
453   * @retval None
454   */
455 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG()            WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP2)
456 
457 /**
458   * @}
459   */
460 
461 /**
462   * @}
463   */
464 
465 
466 /* Private types -------------------------------------------------------------*/
467 /* Private constants ---------------------------------------------------------*/
468 /** @defgroup COMP_Private_Constants COMP Private Constants
469   * @{
470   */
471 /** @defgroup COMP_ExtiLine COMP EXTI Lines
472   * @{
473   */
474 #define COMP_EXTI_LINE_COMP1           (EXTI_IMR_IM21)  /*!< EXTI line 21 connected to COMP1 output */
475 #define COMP_EXTI_LINE_COMP2           (EXTI_IMR_IM22)  /*!< EXTI line 22 connected to COMP2 output */
476 /**
477   * @}
478   */
479 
480 /** @defgroup COMP_ExtiLine COMP EXTI Lines
481   * @{
482   */
483 #define COMP_EXTI_IT                        ((uint32_t) 0x01U)  /*!< EXTI line event with interruption */
484 #define COMP_EXTI_EVENT                     ((uint32_t) 0x02U)  /*!< EXTI line event only (without interruption) */
485 #define COMP_EXTI_RISING                    ((uint32_t) 0x10U)  /*!< EXTI line event on rising edge */
486 #define COMP_EXTI_FALLING                   ((uint32_t) 0x20U)  /*!< EXTI line event on falling edge */
487 /**
488   * @}
489   */
490 
491 /**
492   * @}
493   */
494 
495 /* Private macros ------------------------------------------------------------*/
496 /** @defgroup COMP_Private_Macros COMP Private Macros
497   * @{
498   */
499 
500 /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
501   * @{
502   */
503 /**
504   * @brief  Get the specified EXTI line for a comparator instance.
505   * @param  __INSTANCE__  specifies the COMP instance.
506   * @retval value of @ref COMP_ExtiLine
507   */
508 #define COMP_GET_EXTI_LINE(__INSTANCE__)    (((__INSTANCE__) == COMP1) ?                 \
509                                              COMP_EXTI_LINE_COMP1 : COMP_EXTI_LINE_COMP2)
510 /**
511   * @}
512   */
513 
514 /** @defgroup COMP_IS_COMP_Definitions COMP private macros to check input parameters
515   * @{
516   */
517 #define IS_COMP_WINDOWMODE(__WINDOWMODE__)  (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE)                || \
518                                              ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)  )
519 
520 #define IS_COMP_POWERMODE(__POWERMODE__)    (((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED)  || \
521                                              ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER)  )
522 
523 #define IS_COMP_WINDOWMODE_INSTANCE(INSTANCE) ((INSTANCE) == COMP1)
524 
525 #if defined (STM32L011xx) || defined (STM32L021xx)
526 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__)                  \
527   (((__COMP_INSTANCE__) == COMP1)                                              \
528     ? (                                                                        \
529        (__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1                                 \
530       )                                                                        \
531       :                                                                        \
532       (                                                                        \
533           ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1)                            \
534        || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2)                            \
535        || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3)                            \
536        || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO4)                            \
537        || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO5)                            \
538        || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO6)                            \
539       )                                                                        \
540   )
541 #else
542 #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__)                  \
543   (((__COMP_INSTANCE__) == COMP1)                                              \
544     ? (                                                                        \
545        (__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1                                 \
546       )                                                                        \
547       :                                                                        \
548       (                                                                        \
549           ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1)                            \
550        || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2)                            \
551        || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3)                            \
552        || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO4)                            \
553        || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO5)                            \
554       )                                                                        \
555   )
556 #endif
557 
558 #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__)                \
559   (((__COMP_INSTANCE__) == COMP1)                                              \
560     ? (                                                                        \
561           ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)                      \
562        || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)                     \
563        || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2)                     \
564        || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)                          \
565       )                                                                        \
566       :                                                                        \
567       (                                                                        \
568           ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT)                   \
569        || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT)                   \
570        || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT)                   \
571        || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT)                      \
572        || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1)                     \
573        || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2)                     \
574        || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1)                          \
575        || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2)                          \
576       )                                                                        \
577   )
578 
579 #define IS_COMP1_LPTIMCONNECTION(LPTIMCONNECTION)   (((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_DISABLED) || \
580                                                      ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN1_ENABLED))
581 
582 #define IS_COMP2_LPTIMCONNECTION(LPTIMCONNECTION)   (((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_DISABLED) || \
583                                                      ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN1_ENABLED) || \
584                                                      ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN2_ENABLED))
585 
586 #define IS_COMP2_LPTIMCONNECTION_RESTRICTED(LPTIMCONNECTION)   (((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_DISABLED) || \
587                                                                 ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN1_ENABLED))
588 
589 #define IS_COMP_OUTPUTPOL(POL)  (((POL) == COMP_OUTPUTPOL_NONINVERTED)  || \
590                                  ((POL) == COMP_OUTPUTPOL_INVERTED))
591 
592 #define IS_COMP_TRIGGERMODE(__TRIGGERMODE__) (((__TRIGGERMODE__) == COMP_TRIGGERMODE_NONE)                 || \
593                                               ((__TRIGGERMODE__) == COMP_TRIGGERMODE_IT_RISING)            || \
594                                               ((__TRIGGERMODE__) == COMP_TRIGGERMODE_IT_FALLING)           || \
595                                               ((__TRIGGERMODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING)    || \
596                                               ((__TRIGGERMODE__) == COMP_TRIGGERMODE_EVENT_RISING)         || \
597                                               ((__TRIGGERMODE__) == COMP_TRIGGERMODE_EVENT_FALLING)        || \
598                                               ((__TRIGGERMODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING)   )
599 
600 
601 #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW)     || \
602                                                 ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
603 
604 /**
605   * @}
606   */
607 
608 /**
609   * @}
610   */
611 
612 /* Include COMP HAL Extended module */
613 #include "stm32l0xx_hal_comp_ex.h"
614 
615 /* Exported functions --------------------------------------------------------*/
616 /** @addtogroup COMP_Exported_Functions
617   * @{
618   */
619 
620 /** @addtogroup COMP_Exported_Functions_Group1
621   * @{
622   */
623 
624 /* Initialization and de-initialization functions  **********************************/
625 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
626 HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
627 void              HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
628 void              HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
629 /**
630   * @}
631   */
632 
633 /* IO operation functions  *****************************************************/
634 /** @addtogroup COMP_Exported_Functions_Group2
635   * @{
636   */
637 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
638 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
639 void              HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
640 /**
641   * @}
642   */
643 
644 /* Peripheral Control functions  ************************************************/
645 /** @addtogroup COMP_Exported_Functions_Group3
646   * @{
647   */
648 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
649 uint32_t          HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
650 /* Callback in interrupt mode */
651 void              HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
652 /**
653   * @}
654   */
655 
656 /* Peripheral State functions  **************************************************/
657 /** @addtogroup COMP_Exported_Functions_Group4
658   * @{
659   */
660 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
661 /**
662   * @}
663   */
664 
665 /**
666   * @}
667   */
668 
669 /**
670   * @}
671   */
672 
673 /**
674   * @}
675   */
676 
677 #ifdef __cplusplus
678 }
679 #endif
680 
681 #endif /* __STM32L0xx_HAL_COMP_H */
682 
683 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
684