QuakeGod
2024-07-27 842bb64195f958b050867c50db66fc0aa413dafb
提交 | 用户 | age
483170 1 /**
Q 2   ******************************************************************************
3   * @file    stm32f0xx_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 __STM32F0xx_HAL_COMP_H
38 #define __STM32F0xx_HAL_COMP_H
39
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43
44 #if defined(STM32F051x8) || defined(STM32F058xx) || \
45     defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
46     defined(STM32F091xC) || defined(STM32F098xx)
47
48 /* Includes ------------------------------------------------------------------*/
49 #include "stm32f0xx_hal_def.h"
50
51 /** @addtogroup STM32F0xx_HAL_Driver
52   * @{
53   */
54
55 /** @addtogroup COMP COMP
56   * @{
57   */ 
58
59 /* Exported types ------------------------------------------------------------*/ 
60 /** @defgroup COMP_Exported_Types COMP Exported Types
61   * @{
62   */
63     
64 /** 
65   * @brief  COMP Init structure definition  
66   */ 
67 typedef struct
68 {
69
70   uint32_t InvertingInput;     /*!< Selects the inverting input of the comparator.
71                                     This parameter can be a value of @ref COMP_InvertingInput */
72
73   uint32_t NonInvertingInput;  /*!< Selects the non inverting input of the comparator.
74                                     This parameter can be a value of @ref COMP_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
79   uint32_t OutputPol;          /*!< Selects the output polarity of the comparator.
80                                     This parameter can be a value of @ref COMP_OutputPolarity */
81
82   uint32_t Hysteresis;         /*!< Selects the hysteresis voltage of the comparator.
83                                     This parameter can be a value of @ref COMP_Hysteresis */
84
85   uint32_t Mode;               /*!< Selects the operating comsumption mode of the comparator
86                                     to adjust the speed/consumption.
87                                     This parameter can be a value of @ref COMP_Mode */
88
89   uint32_t WindowMode;         /*!< Selects the window mode of the comparator 1 & 2.
90                                     This parameter can be a value of @ref COMP_WindowMode */
91   
92   uint32_t TriggerMode;        /*!< Selects the trigger mode of the comparator (interrupt mode).
93                                     This parameter can be a value of @ref COMP_TriggerMode */
94
95 }COMP_InitTypeDef;
96
97 /** 
98   * @brief  COMP Handle Structure definition  
99   */ 
100 typedef struct
101 {
102   COMP_TypeDef                *Instance; /*!< Register base address    */
103   COMP_InitTypeDef            Init;      /*!< COMP required parameters */
104   HAL_LockTypeDef             Lock;      /*!< Locking object           */
105   __IO uint32_t               State;     /*!< COMP communication state 
106                                               This parameter can be a value of @ref COMP_State  */
107 }COMP_HandleTypeDef;
108
109 /**
110   * @}
111   */
112   
113 /* Exported constants --------------------------------------------------------*/
114 /** @defgroup COMP_Exported_Constants COMP Exported Constants
115   * @{
116   */
117
118 /** @defgroup COMP_State COMP State
119   * @{
120   */
121 #define HAL_COMP_STATE_RESET             (0x00000000U)    /*!< COMP not yet initialized or disabled             */
122 #define HAL_COMP_STATE_READY             (0x00000001U)    /*!< COMP initialized and ready for use               */
123 #define HAL_COMP_STATE_READY_LOCKED      (0x00000011U)    /*!< COMP initialized but the configuration is locked */
124 #define HAL_COMP_STATE_BUSY              (0x00000002U)    /*!< COMP is running                                  */
125 #define HAL_COMP_STATE_BUSY_LOCKED       (0x00000012U)    /*!< COMP is running and the configuration is locked  */
126 /**
127   * @}
128   */
129
130 /** @defgroup COMP_OutputPolarity COMP OutputPolarity
131   * @{
132   */
133 #define COMP_OUTPUTPOL_NONINVERTED             (0x00000000U)  /*!< COMP output on GPIO isn't inverted */
134 #define COMP_OUTPUTPOL_INVERTED                COMP_CSR_COMP1POL       /*!< COMP output on GPIO is inverted  */
135 /**
136   * @}
137   */ 
138
139 /** @defgroup COMP_Hysteresis COMP Hysteresis
140   * @{
141   */
142 #define COMP_HYSTERESIS_NONE                   (0x00000000U)  /*!< No hysteresis */
143 #define COMP_HYSTERESIS_LOW                    COMP_CSR_COMP1HYST_0    /*!< Hysteresis level low */
144 #define COMP_HYSTERESIS_MEDIUM                 COMP_CSR_COMP1HYST_1    /*!< Hysteresis level medium */
145 #define COMP_HYSTERESIS_HIGH                   COMP_CSR_COMP1HYST      /*!< Hysteresis level high */
146 /**
147   * @}
148   */
149
150 /** @defgroup COMP_Mode COMP Mode
151   * @{
152   */
153 /* Please refer to the electrical characteristics in the device datasheet for
154    the power consumption values */
155 #define COMP_MODE_HIGHSPEED                    (0x00000000U) /*!< High Speed */
156 #define COMP_MODE_MEDIUMSPEED                  COMP_CSR_COMP1MODE_0   /*!< Medium Speed */
157 #define COMP_MODE_LOWPOWER                     COMP_CSR_COMP1MODE_1   /*!< Low power mode */
158 #define COMP_MODE_ULTRALOWPOWER                COMP_CSR_COMP1MODE     /*!< Ultra-low power mode */
159 /**
160   * @}
161   */
162
163 /** @defgroup COMP_InvertingInput COMP InvertingInput
164   * @{
165   */
166
167 #define COMP_INVERTINGINPUT_1_4VREFINT         (0x00000000U) /*!< 1/4 VREFINT connected to comparator inverting input */
168 #define COMP_INVERTINGINPUT_1_2VREFINT         COMP_CSR_COMP1INSEL_0                         /*!< 1/2 VREFINT connected to comparator inverting input    */
169 #define COMP_INVERTINGINPUT_3_4VREFINT         COMP_CSR_COMP1INSEL_1                         /*!< 3/4 VREFINT connected to comparator inverting input    */
170 #define COMP_INVERTINGINPUT_VREFINT            (COMP_CSR_COMP1INSEL_1|COMP_CSR_COMP1INSEL_0) /*!< VREFINT connected to comparator inverting input        */
171 #define COMP_INVERTINGINPUT_DAC1               COMP_CSR_COMP1INSEL_2                         /*!< DAC_OUT1 (PA4) connected to comparator inverting input */
172 #define COMP_INVERTINGINPUT_DAC1SWITCHCLOSED   (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1SW1)     /*!< DAC_OUT1 (PA4) connected to comparator inverting input 
173                                                                                                   and close switch (PA0 for COMP1 only) */
174 #define COMP_INVERTINGINPUT_DAC2               (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1INSEL_0) /*!< DAC_OUT2 (PA5) connected to comparator inverting input */
175 #define COMP_INVERTINGINPUT_IO1                (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1INSEL_1) /*!< IO (PA0 for COMP1 and PA2 for COMP2) connected to comparator inverting input */
176 /**
177   * @}
178   */ 
179
180 /** @defgroup COMP_NonInvertingInput COMP NonInvertingInput
181   * @{
182   */
183 #define COMP_NONINVERTINGINPUT_IO1               (0x00000000U) /*!< I/O1 (PA1 for COMP1, PA3 for COMP2) 
184                                                                              connected to comparator non inverting input */
185 #define COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED  COMP_CSR_COMP1SW1  /*!< DAC ouput connected to comparator COMP1 non inverting input */
186 /**
187   * @}
188   */
189
190 /** @defgroup COMP_Output COMP Output
191   * @{
192   */
193
194 /* Output Redirection common for COMP1 and COMP2 */
195 #define COMP_OUTPUT_NONE                       (0x00000000U)                          /*!< COMP output isn't connected to other peripherals */
196 #define COMP_OUTPUT_TIM1BKIN                   COMP_CSR_COMP1OUTSEL_0                          /*!< COMP output connected to TIM1 Break Input (BKIN) */
197 #define COMP_OUTPUT_TIM1IC1                    COMP_CSR_COMP1OUTSEL_1                          /*!< COMP output connected to TIM1 Input Capture 1 */
198 #define COMP_OUTPUT_TIM1OCREFCLR               (COMP_CSR_COMP1OUTSEL_1|COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM1 OCREF Clear */
199 #define COMP_OUTPUT_TIM2IC4                    COMP_CSR_COMP1OUTSEL_2                          /*!< COMP output connected to TIM2 Input Capture 4 */
200 #define COMP_OUTPUT_TIM2OCREFCLR               (COMP_CSR_COMP1OUTSEL_2|COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM2 OCREF Clear */
201 #define COMP_OUTPUT_TIM3IC1                    (COMP_CSR_COMP1OUTSEL_2|COMP_CSR_COMP1OUTSEL_1) /*!< COMP output connected to TIM3 Input Capture 1 */
202 #define COMP_OUTPUT_TIM3OCREFCLR               COMP_CSR_COMP1OUTSEL                            /*!< COMP output connected to TIM3 OCREF Clear */
203 /**
204   * @}
205   */ 
206
207 /** @defgroup COMP_OutputLevel COMP OutputLevel
208   * @{
209   */ 
210 /* When output polarity is not inverted, comparator output is low when
211    the non-inverting input is at a lower voltage than the inverting input*/
212 #define COMP_OUTPUTLEVEL_LOW                   (0x00000000U)
213 /* When output polarity is not inverted, comparator output is high when
214    the non-inverting input is at a higher voltage than the inverting input */
215 #define COMP_OUTPUTLEVEL_HIGH                  COMP_CSR_COMP1OUT
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 #define COMP_TRIGGERMODE_EVENT_RISING          (0x00000010U)  /*!< Event Mode with Rising edge trigger detection */
228 #define COMP_TRIGGERMODE_EVENT_FALLING         (0x00000020U)  /*!< Event Mode with Falling edge trigger detection */
229 #define COMP_TRIGGERMODE_EVENT_RISING_FALLING  (0x00000030U)  /*!< Event Mode with Rising/Falling edge trigger detection */
230 /**
231   * @}
232   */ 
233
234 /** @defgroup COMP_WindowMode COMP WindowMode
235   * @{
236   */
237 #define COMP_WINDOWMODE_DISABLE                (0x00000000U)  /*!< Window mode disabled */
238 #define COMP_WINDOWMODE_ENABLE                 COMP_CSR_WNDWEN         /*!< Window mode enabled: non inverting input of comparator 2
239                                                                             is connected to the non inverting input of comparator 1 (PA1) */
240 /**
241   * @}
242   */
243
244 /** @defgroup COMP_Flag COMP Flag
245   * @{
246   */
247 #define COMP_FLAG_LOCK                         ((uint32_t)COMP_CSR_COMPxLOCK)  /*!< Lock flag */
248
249 /**
250   * @}
251   */
252
253 /**
254   * @}
255   */ 
256   
257 /* Exported macros -----------------------------------------------------------*/
258 /** @defgroup COMP_Exported_Macros COMP Exported Macros
259   * @{
260   */
261
262 /** @brief  Reset COMP handle state
263   * @param  __HANDLE__ COMP handle.
264   * @retval None
265   */
266 #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
267
268 /**
269   * @brief  Enable the specified comparator.
270   * @param  __HANDLE__ COMP handle.
271   * @retval None
272   */
273 #define __HAL_COMP_ENABLE(__HANDLE__)                 (((__HANDLE__)->Instance == COMP1) ?    \
274                                                        SET_BIT(COMP->CSR, COMP_CSR_COMP1EN) : \
275                                                        SET_BIT(COMP->CSR, COMP_CSR_COMP2EN))
276
277 /**
278   * @brief  Disable the specified comparator.
279   * @param  __HANDLE__ COMP handle.
280   * @retval None
281   */
282 #define __HAL_COMP_DISABLE(__HANDLE__)                (((__HANDLE__)->Instance == COMP1) ?    \
283                                                        CLEAR_BIT(COMP->CSR, COMP_CSR_COMP1EN) : \
284                                                        CLEAR_BIT(COMP->CSR, COMP_CSR_COMP2EN))
285
286 /**
287   * @brief  Lock the specified comparator configuration.
288   * @param  __HANDLE__ COMP handle.
289   * @retval None
290   */
291 #define __HAL_COMP_LOCK(__HANDLE__)                   (((__HANDLE__)->Instance == COMP1) ?    \
292                                                        SET_BIT(COMP->CSR, COMP_CSR_COMP1LOCK) : \
293                                                        SET_BIT(COMP->CSR, COMP_CSR_COMP2LOCK))
294
295 /**
296   * @brief  Enable the COMP1 EXTI line rising edge trigger.
297   * @retval None
298   */                                         
299 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE()    SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
300
301 /**
302   * @brief  Disable the COMP1 EXTI line rising edge trigger.
303   * @retval None
304   */                                         
305 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE()   CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
306
307 /**
308   * @brief  Enable the COMP1 EXTI line falling edge trigger.
309   * @retval None
310   */                                         
311 #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE()   SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
312
313 /**
314   * @brief  Disable the COMP1 EXTI line falling edge trigger.
315   * @retval None
316   */                                         
317 #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE()  CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
318
319 /**
320   * @brief  Enable the COMP1 EXTI line rising & falling edge trigger.
321   * @retval None
322   */                                         
323 #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
324                                                                __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \
325                                                                __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \
326                                                              } while(0)
327
328 /**
329   * @brief  Disable the COMP1 EXTI line rising & falling edge trigger.
330   * @retval None
331   */                                         
332 #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE()  do { \
333                                                                __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \
334                                                                __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \
335                                                              } while(0)
336
337 /**
338   * @brief  Enable the COMP1 EXTI line in interrupt mode.
339   * @retval None
340   */                                         
341 #define __HAL_COMP_COMP1_EXTI_ENABLE_IT()             SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
342
343 /**
344   * @brief  Disable the COMP1 EXTI line in interrupt mode.
345   * @retval None
346   */
347 #define __HAL_COMP_COMP1_EXTI_DISABLE_IT()            CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
348
349 /**
350   * @brief  Generate a software interrupt on the COMP1 EXTI line.
351   * @retval None
352   */
353 #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT()         SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP1)
354
355 /**
356   * @brief  Enable the COMP1 EXTI Line in event mode.
357   * @retval None
358   */
359 #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT()           SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
360
361 /**
362   * @brief  Disable the COMP1 EXTI Line in event mode.
363   * @retval None
364   */
365 #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT()          CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
366
367 /**
368   * @brief  Check whether the COMP1 EXTI line flag is set or not.
369   * @retval RESET or SET
370   */
371 #define __HAL_COMP_COMP1_EXTI_GET_FLAG()              READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP1)
372      
373 /**
374   * @brief  Clear the COMP1 EXTI flag.
375   * @retval None
376   */
377 #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG()            WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP1)
378
379 /**
380   * @brief  Enable the COMP2 EXTI line rising edge trigger.
381   * @retval None
382   */                                         
383 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE()    SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
384
385 /**
386   * @brief  Disable the COMP2 EXTI line rising edge trigger.
387   * @retval None
388   */                                         
389 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE()   CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
390
391 /**
392   * @brief  Enable the COMP2 EXTI line falling edge trigger.
393   * @retval None
394   */                                         
395 #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE()   SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
396
397 /**
398   * @brief  Disable the COMP2 EXTI line falling edge trigger.
399   * @retval None
400   */                                         
401 #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE()  CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
402
403 /**
404   * @brief  Enable the COMP2 EXTI line rising & falling edge trigger.
405   * @retval None
406   */                                         
407 #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE()   do { \
408                                                                __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \
409                                                                __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \
410                                                              } while(0)
411
412 /**
413   * @brief  Disable the COMP2 EXTI line rising & falling edge trigger.
414   * @retval None
415   */                                         
416 #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE()   do { \
417                                                                __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \
418                                                                __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \
419                                                              } while(0)
420
421 /**
422   * @brief  Enable the COMP2 EXTI line in interrupt mode.
423   * @retval None
424   */                                         
425 #define __HAL_COMP_COMP2_EXTI_ENABLE_IT()             SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
426
427 /**
428   * @brief  Disable the COMP2 EXTI line in interrupt mode.
429   * @retval None
430   */
431 #define __HAL_COMP_COMP2_EXTI_DISABLE_IT()            CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
432
433 /**
434   * @brief  Generate a software interrupt on the COMP2 EXTI line.
435   * @retval None
436   */
437 #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT()         SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP2)
438
439 /**
440   * @brief  Enable the COMP2 EXTI Line in event mode.
441   * @retval None
442   */
443 #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT()           SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
444
445 /**
446   * @brief  Disable the COMP2 EXTI Line in event mode.
447   * @retval None
448   */
449 #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT()          CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
450
451 /**
452   * @brief  Check whether the COMP2 EXTI line flag is set or not.
453   * @retval RESET or SET
454   */
455 #define __HAL_COMP_COMP2_EXTI_GET_FLAG()              READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP2)
456      
457 /**
458   * @brief  Clear the COMP2 EXTI flag.
459   * @retval None
460   */
461 #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG()            WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP2)
462
463 /** @brief  Check whether the specified COMP flag is set or not.
464   * @param  __HANDLE__ specifies the COMP Handle.
465   * @param  __FLAG__ specifies the flag to check.
466   *        This parameter can be one of the following values:
467   *            @arg COMP_FLAG_LOCK:  lock flag
468   * @retval The new state of __FLAG__ (TRUE or FALSE).
469   */
470 #define __HAL_COMP_GET_FLAG(__HANDLE__, __FLAG__)     (((__HANDLE__)->Instance->CSR & (__FLAG__)) == (__FLAG__))   
471
472 /**
473   * @}
474   */ 
475
476 /* Exported functions --------------------------------------------------------*/
477 /** @addtogroup COMP_Exported_Functions COMP Exported Functions
478   * @{
479   */
480 /** @addtogroup COMP_Exported_Functions_Group1 Initialization/de-initialization functions 
481  *  @brief    Initialization and Configuration functions 
482  * @{
483  */ 
484 /* Initialization and de-initialization functions  ****************************/
485 HAL_StatusTypeDef     HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
486 HAL_StatusTypeDef     HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
487 void                  HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
488 void                  HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
489 /**
490   * @}
491   */
492
493 /** @addtogroup COMP_Exported_Functions_Group2 I/O operation functions 
494  *  @brief   Data transfers functions 
495  * @{
496  */   
497 /* IO operation functions *****************************************************/
498 HAL_StatusTypeDef     HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
499 HAL_StatusTypeDef     HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
500 HAL_StatusTypeDef     HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp);
501 HAL_StatusTypeDef     HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp);
502 void                  HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
503 /**
504   * @}
505   */
506
507 /** @addtogroup COMP_Exported_Functions_Group3 Peripheral Control functions 
508  *  @brief   management functions
509  * @{
510  */   
511 /* Peripheral Control functions ***********************************************/
512 HAL_StatusTypeDef     HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
513 uint32_t              HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
514
515 /* Callback in Interrupt mode */
516 void                  HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
517 /**
518   * @}
519   */
520
521 /** @addtogroup COMP_Exported_Functions_Group4 Peripheral State functions 
522  *  @brief   Peripheral State functions
523  * @{
524  */   
525 /* Peripheral State and Error functions ***************************************/
526 uint32_t HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
527 /**
528   * @}
529   */ 
530   
531 /**
532   * @}
533   */ 
534
535 /* Private types -------------------------------------------------------------*/
536 /* Private constants ---------------------------------------------------------*/
537 /** @defgroup COMP_Private_Constants COMP Private Constants
538   * @{
539   */
540 /** @defgroup COMP_ExtiLine COMP EXTI Lines
541   *        Elements values convention: XXXX0000
542   *           - XXXX : Interrupt mask in the EMR/IMR/RTSR/FTSR register
543   * @{   
544   */  
545 #define COMP_EXTI_LINE_COMP1             ((uint32_t)EXTI_IMR_MR21)  /*!< EXTI line 21 connected to COMP1 output */
546 #define COMP_EXTI_LINE_COMP2             ((uint32_t)EXTI_IMR_MR22)  /*!< EXTI line 22 connected to COMP2 output */
547
548 /**
549   * @}
550   */
551
552 /**
553   * @}
554   */
555
556 /* Private macros ------------------------------------------------------------*/
557 /** @defgroup COMP_Private_Macros COMP Private Macros
558   * @{
559   */
560 /** @defgroup COMP_GET_EXTI_LINE COMP Private macros to get EXTI line associated with Comparators 
561   * @{
562   */
563 /**
564   * @brief  Get the specified EXTI line for a comparator instance.
565   * @param  __INSTANCE__ specifies the COMP instance.
566   * @retval value of @ref COMP_ExtiLine
567   */
568 #define COMP_GET_EXTI_LINE(__INSTANCE__)             (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 : \
569                                                       COMP_EXTI_LINE_COMP2)
570 /**
571   * @}
572   */
573
574 /** @defgroup COMP_IS_COMP_Definitions COMP Private macros to check input parameters
575   * @{
576   */
577
578 #define IS_COMP_OUTPUTPOL(POL)  (((POL) == COMP_OUTPUTPOL_NONINVERTED)  || \
579                                  ((POL) == COMP_OUTPUTPOL_INVERTED))
580
581 #define IS_COMP_HYSTERESIS(HYSTERESIS)    (((HYSTERESIS) == COMP_HYSTERESIS_NONE)   || \
582                                            ((HYSTERESIS) == COMP_HYSTERESIS_LOW)    || \
583                                            ((HYSTERESIS) == COMP_HYSTERESIS_MEDIUM) || \
584                                            ((HYSTERESIS) == COMP_HYSTERESIS_HIGH))
585
586 #define IS_COMP_MODE(MODE)  (((MODE) == COMP_MODE_HIGHSPEED)     || \
587                              ((MODE) == COMP_MODE_MEDIUMSPEED)   || \
588                              ((MODE) == COMP_MODE_LOWPOWER)      || \
589                              ((MODE) == COMP_MODE_ULTRALOWPOWER))
590
591 #define IS_COMP_INVERTINGINPUT(INPUT) (((INPUT) == COMP_INVERTINGINPUT_1_4VREFINT)       || \
592                                        ((INPUT) == COMP_INVERTINGINPUT_1_2VREFINT)       || \
593                                        ((INPUT) == COMP_INVERTINGINPUT_3_4VREFINT)       || \
594                                        ((INPUT) == COMP_INVERTINGINPUT_VREFINT)          || \
595                                        ((INPUT) == COMP_INVERTINGINPUT_DAC1)             || \
596                                        ((INPUT) == COMP_INVERTINGINPUT_DAC1SWITCHCLOSED) || \
597                                        ((INPUT) == COMP_INVERTINGINPUT_DAC2)             || \
598                                        ((INPUT) == COMP_INVERTINGINPUT_IO1))
599
600 #define IS_COMP_NONINVERTINGINPUT(INPUT) (((INPUT) == COMP_NONINVERTINGINPUT_IO1) || \
601                                           ((INPUT) == COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED))
602
603 #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_OUTPUT_NONE)                || \
604                                 ((OUTPUT) == COMP_OUTPUT_TIM1BKIN)            || \
605                                 ((OUTPUT) == COMP_OUTPUT_TIM1IC1)             || \
606                                 ((OUTPUT) == COMP_OUTPUT_TIM1OCREFCLR)        || \
607                                 ((OUTPUT) == COMP_OUTPUT_TIM2IC4)             || \
608                                 ((OUTPUT) == COMP_OUTPUT_TIM2OCREFCLR)        || \
609                                 ((OUTPUT) == COMP_OUTPUT_TIM3IC1)             || \
610                                 ((OUTPUT) == COMP_OUTPUT_TIM3OCREFCLR))
611
612 #define IS_COMP_WINDOWMODE(WINDOWMODE) (((WINDOWMODE) == COMP_WINDOWMODE_DISABLE) || \
613                                         ((WINDOWMODE) == COMP_WINDOWMODE_ENABLE))
614
615 #define IS_COMP_TRIGGERMODE(__MODE__)  (((__MODE__) == COMP_TRIGGERMODE_NONE)                 || \
616                                         ((__MODE__) == COMP_TRIGGERMODE_IT_RISING)            || \
617                                         ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING)           || \
618                                         ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING)    || \
619                                         ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING)         || \
620                                         ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING)        || \
621                                         ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
622 /**
623   * @}
624   */
625
626 /** @defgroup COMP_Lock COMP Lock
627   * @{   
628   */  
629 #define COMP_LOCK_DISABLE                      (0x00000000U)
630 #define COMP_LOCK_ENABLE                       COMP_CSR_COMP1LOCK
631
632 #define COMP_STATE_BIT_LOCK                    (0x10U)
633 /**
634   * @}
635   */ 
636
637 /**
638   * @}
639   */
640
641 /* Private functions ---------------------------------------------------------*/
642
643 /**
644   * @}
645   */ 
646
647 /**
648   * @}
649   */ 
650   
651 #endif /* STM32F051x8 || STM32F058xx || */
652        /* STM32F071xB || STM32F072xB || STM32F078xx || */
653        /* STM32F091xC || STM32F098xx */
654
655 #ifdef __cplusplus
656 }
657 #endif
658
659 #endif /* __STM32F0xx_HAL_COMP_H */
660
661 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
662