Subversion Repositories DashDisplay

Rev

Rev 56 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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