Subversion Repositories DashDisplay

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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