Subversion Repositories ScreenTimer

Rev

Details | Last modification | View Log | RSS feed

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