2 ******************************************************************************
3 * @file stm32f3xx_hal_comp.c
4 * @author MCD Application Team
7 * @brief COMP HAL module driver.
9 * This file provides firmware functions to manage the following
10 * functionalities of the COMP peripheral:
11 * + Initialization/de-initialization functions
12 * + I/O operation functions
13 * + Peripheral Control functions
14 * + Peripheral State functions
17 ================================================================================
18 ##### COMP Peripheral features #####
19 ================================================================================
22 The STM32F3xx device family integrates up to 7 analog comparators COMP1, COMP2...COMP7:
23 (#) The non inverting input and inverting input can be set to GPIO pins
24 as shown in table1. COMP Inputs below for STM32F303xB/STM32F303xC as example.
25 For other STM32F3xx devices please refer to the COMP peripheral section in corresponding
28 (#) The COMP output is available using HAL_COMP_GetOutputLevel()
29 and can be set on GPIO pins. Refer to table 2. COMP Outputs below for STM32F303xB/STM32F303xC as example.
30 For other STM32F3xx devices please refer to the COMP peripheral section in corresponding
33 (#) The COMP output can be redirected to embedded timers (TIM1, TIM2, TIM3...)
34 Refer to table 3. COMP Outputs redirection to embedded timers below for STM32F303xB/STM32F303xC as example.
35 For other STM32F3xx devices please refer to the COMP peripheral section in corresponding
38 (#) The comparators COMP1 and COMP2, COMP3 and COMP4, COMP5 and COMP6 can be combined in window
39 mode and only COMP1, COMP3 and COMP5 non inverting input can be used as non-inverting input.
41 (#) The seven comparators have interrupt capability with wake-up
42 from Sleep and Stop modes (through the EXTI controller):
43 (++) COMP1 is internally connected to EXTI Line 21
44 (++) COMP2 is internally connected to EXTI Line 22
45 (++) COMP3 is internally connected to EXTI Line 29
46 (++) COMP4 is internally connected to EXTI Line 30
47 (++) COMP5 is internally connected to EXTI Line 31
48 (++) COMP6 is internally connected to EXTI Line 32
49 (++) COMP7 is internally connected to EXTI Line 33
50 From the corresponding IRQ handler, the right interrupt source can be retrieved with the
51 macro __HAL_COMP_EXTI_GET_FLAG(). Possible values are:
52 (++) COMP_EXTI_LINE_COMP1_EVENT
53 (++) COMP_EXTI_LINE_COMP2_EVENT
54 (++) COMP_EXTI_LINE_COMP3_EVENT
55 (++) COMP_EXTI_LINE_COMP4_EVENT
56 (++) COMP_EXTI_LINE_COMP5_EVENT
57 (++) COMP_EXTI_LINE_COMP6_EVENT
58 (++) COMP_EXTI_LINE_COMP7_EVENT
60 [..] Table 1. COMP Inputs for the STM32F303xB/STM32F303xC/STM32F303xE devices
61 +------------------------------------------------------------------------------------------+
62 | | | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
63 |-----------------|----------------|---------------|---------------------------------------|
64 | | 1/4 VREFINT | OK | OK | OK | OK | OK | OK | OK |
65 | | 1/2 VREFINT | OK | OK | OK | OK | OK | OK | OK |
66 | | 3/4 VREFINT | OK | OK | OK | OK | OK | OK | OK |
67 | Inverting Input | VREFINT | OK | OK | OK | OK | OK | OK | OK |
68 | | DAC1 OUT (PA4) | OK | OK | OK | OK | OK | OK | OK |
69 | | DAC2 OUT (PA5) | OK | OK | OK | OK | OK | OK | OK |
70 | | IO1 | PA0 | PA2 | PD15 | PE8 | PD13 | PD10 | PC0 |
71 | | IO2 | --- | --- | PB12 | PB2 | PB10 | PB15 | --- |
72 |-----------------|----------------|-------|-------|-------|-------|-------|-------|-------|
73 | Non Inverting | IO1 | PA1 | PA7 | PB14 | PB0 | PD12 | PD11 | PA0 |
74 | Input | IO2 | --- | PA3 | PD14 | PE7 | PB13 | PB11 | PC1 |
75 +------------------------------------------------------------------------------------------+
77 [..] Table 2. COMP Outputs for the STM32F303xB/STM32F303xC/STM32F303xE devices
78 +-------------------------------------------------------+
79 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
80 |-------|-------|-------|-------|-------|-------|-------|
81 | PA0 | PA2 | PB1 | PC8 | PC7 | PA10 | PC2 |
82 | PF4 | PA7 | --- | PA8 | PA9 | PC6 | --- |
83 | PA6 | PA12 | --- | --- | --- | --- | --- |
84 | PA11 | PB9 | --- | --- | --- | --- | --- |
85 | PB8 | --- | --- | --- | --- | --- | --- |
86 +-------------------------------------------------------+
88 [..] Table 3. COMP Outputs redirection to embedded timers for the STM32F303xB/STM32F303xC devices
89 +----------------------------------------------------------------------------------------------------------------------+
90 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
91 |----------------|----------------|----------------|----------------|----------------|----------------|----------------|
92 | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN |
94 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
96 | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN |
98 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 |
100 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
101 | + | + | + | + | + | + | + |
102 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 |
104 | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM1 OCREFCLR |
106 | TIM1 IC1 | TIM1 IC1 | TIM2 OCREFCLR | TIM3 IC3 | TIM2 IC1 | TIM2 IC2 | TIM8 OCREFCLR |
108 | TIM2 IC4 | TIM2 IC4 | TIM3 IC2 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM2 OCREFCLR | TIM2 IC3 |
110 | TIM2 OCREFCLR | TIM2 OCREFCLR | TIM4 IC1 | TIM4 IC2 | TIM4 IC3 | TIM16 OCREFCLR| TIM1 IC2 |
112 | TIM3 IC1 | TIM3 IC1 | TIM15 IC1 | TIM15 OCREFCLR| TIM16 BKIN | TIM16 IC1 | TIM17 OCREFCLR|
114 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM15 BKIN | TIM15 IC2 | TIM17 IC1 | TIM4 IC4 | TIM17 BKIN |
115 +----------------------------------------------------------------------------------------------------------------------+
117 [..] Table 4. COMP Outputs redirection to embedded timers for the STM32F303xE devices
118 +----------------------------------------------------------------------------------------------------------------------+
119 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
120 |----------------|----------------|----------------|----------------|----------------|----------------|----------------|
121 | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN (1) | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN (1) |
123 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
125 | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN (1) | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN (1) |
127 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 |
129 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
130 | + | + | + | + | + | + | + |
131 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 |
133 | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM1 OCREFCLR |
135 | TIM1 IC1 | TIM1 IC1 | TIM2 OCREFCLR | TIM3 IC3 | TIM2 IC1 | TIM2 IC2 | TIM8 OCREFCLR |
137 | TIM2 IC4 | TIM2 IC4 | TIM3 IC2 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM2 OCREFCLR | TIM2 IC3 |
139 | TIM2 OCREFCLR | TIM2 OCREFCLR | TIM4 IC1 | TIM4 IC2 | TIM4 IC3 | TIM16 OCREFCLR| TIM1 IC2 |
141 | TIM3 IC1 | TIM3 IC1 | TIM15 IC1 | TIM15 OCREFCLR| TIM16 BKIN | TIM16 IC1 | TIM17 OCREFCLR|
143 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM15 BKIN | TIM15 IC2 | TIM17 IC1 | TIM4 IC4 | TIM17 BKIN |
145 | TIM20 BKIN | TIM20 BKIN | TIM20 BKIN | TIM20 BKIN (1)| TIM20 BKIN | TIM20 BKIN | TIM20 BKIN (1)|
147 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 |
149 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
150 | + | + | + | + | + | + | + |
151 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 |
152 | + | + | + | + | + | + | + |
153 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 |
155 +----------------------------------------------------------------------------------------------------------------------+
156 (1):This connection consists of connecting both GPIO and COMP output to TIM1/8/20 BRK input through an OR gate, instead
157 of connecting the GPIO to the TIM1/8/20 BRK input and the COMP output to the TIM1/8/20 BRK_ACTH input. The aim is to
158 add a digital filter (3 bits) on the COMP output.
160 [..] Table 5. COMP Outputs blanking sources for the STM32F303xB/STM32F303xC/STM32F303xE devices
161 +----------------------------------------------------------------------------------------------------------------------+
162 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
163 |----------------|----------------|----------------|----------------|----------------|----------------|----------------|
164 | TIM1 OC5 | TIM1 OC5 | TIM1 OC5 | TIM3 OC4 | -------- | TIM8 OC5 | TIM1 OC5 |
166 | TIM2 OC3 | TIM2 OC3 | -------- | TIM8 OC5 | TIM3 OC3 | TIM2 OC4 | TIM8 OC5 |
168 | TIM3 OC3 | TIM3 OC3 | TIM2 OC4 | TIM15 OC1 | TIM8 OC5 | TIM15 OC2 | TIM15 OC2 |
170 +----------------------------------------------------------------------------------------------------------------------+
172 ##### How to use this driver #####
173 ================================================================================
175 This driver provides functions to configure and program the Comparators of all STM32F3xx devices.
177 To use the comparator, perform the following steps:
179 (#) Fill in the HAL_COMP_MspInit() to
180 (++) Configure the comparator input in analog mode using HAL_GPIO_Init()
181 (++) Configure the comparator output in alternate function mode using HAL_GPIO_Init() to map the comparator
182 output to the GPIO pin
183 (++) If required enable the COMP interrupt by configuring and enabling EXTI line in Interrupt mode and
184 selecting the desired sensitivity level using HAL_GPIO_Init() function. After that enable the comparator
185 interrupt vector using HAL_NVIC_EnableIRQ() function.
187 (#) Configure the comparator using HAL_COMP_Init() function:
188 (++) Select the inverting input
189 (++) Select the non-inverting input
190 (++) Select the output polarity
191 (++) Select the output redirection
192 (++) Select the hysteresis level
193 (++) Select the power mode
194 (++) Select the event/interrupt mode
196 (#) Enable the comparator using HAL_COMP_Start() function or HAL_COMP_Start_IT() function for interrupt mode
198 (#) Read the comparator output level with HAL_COMP_GetOutputLevel()
201 ******************************************************************************
204 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
206 * Redistribution and use in source and binary forms, with or without modification,
207 * are permitted provided that the following conditions are met:
208 * 1. Redistributions of source code must retain the above copyright notice,
209 * this list of conditions and the following disclaimer.
210 * 2. Redistributions in binary form must reproduce the above copyright notice,
211 * this list of conditions and the following disclaimer in the documentation
212 * and/or other materials provided with the distribution.
213 * 3. Neither the name of STMicroelectronics nor the names of its contributors
214 * may be used to endorse or promote products derived from this software
215 * without specific prior written permission.
217 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
218 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
219 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
220 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
221 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
222 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
223 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
224 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
225 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
226 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
228 ******************************************************************************
231 /* Includes ------------------------------------------------------------------*/
232 #include "stm32f3xx_hal.h"
234 /** @addtogroup STM32F3xx_HAL_Driver
238 /** @defgroup COMP COMP HAL module driver
239 * @brief COMP HAL module driver
243 #ifdef HAL_COMP_MODULE_ENABLED
245 /* Private typedef -----------------------------------------------------------*/
246 /* Private define ------------------------------------------------------------*/
247 /* Private macro -------------------------------------------------------------*/
248 /* Private variables ---------------------------------------------------------*/
249 /* Private function prototypes -----------------------------------------------*/
250 /* Exported functions --------------------------------------------------------*/
252 /** @defgroup COMP_Exported_Functions COMP Exported Functions
256 /** @defgroup COMP_Exported_Functions_Group1 Initialization and de-initialization functions
257 * @brief Initialization and Configuration functions
260 ===============================================================================
261 ##### Initialization/de-initialization functions #####
262 ===============================================================================
263 [..] This section provides functions to initialize and de-initialize comparators
270 * @brief Initializes the COMP according to the specified
271 * parameters in the COMP_InitTypeDef and create the associated handle.
272 * @note If the selected comparator is locked, initialization can't be performed.
273 * To unlock the configuration, perform a system reset.
274 * @param hcomp: COMP handle
277 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
279 HAL_StatusTypeDef status = HAL_OK;
281 /* Check the COMP handle allocation and lock status */
282 if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
288 /* Check the parameter */
289 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
290 assert_param(IS_COMP_INVERTINGINPUT(hcomp->Init.InvertingInput));
291 assert_param(IS_COMP_NONINVERTINGINPUT(hcomp->Init.NonInvertingInput));
292 assert_param(IS_COMP_NONINVERTINGINPUT_INSTANCE(hcomp->Instance, hcomp->Init.NonInvertingInput));
293 assert_param(IS_COMP_OUTPUT(hcomp->Init.Output));
294 assert_param(IS_COMP_OUTPUTPOL(hcomp->Init.OutputPol));
295 assert_param(IS_COMP_HYSTERESIS(hcomp->Init.Hysteresis));
296 assert_param(IS_COMP_MODE(hcomp->Init.Mode));
297 assert_param(IS_COMP_BLANKINGSRCE(hcomp->Init.BlankingSrce));
298 assert_param(IS_COMP_BLANKINGSRCE_INSTANCE(hcomp->Instance, hcomp->Init.BlankingSrce));
300 if(hcomp->Init.WindowMode != COMP_WINDOWMODE_DISABLED)
302 assert_param(IS_COMP_WINDOWMODE_INSTANCE(hcomp->Instance));
305 if(hcomp->State == HAL_COMP_STATE_RESET)
307 /* Init SYSCFG and the low level hardware to access comparators */
308 __SYSCFG_CLK_ENABLE();
310 HAL_COMP_MspInit(hcomp);
313 /* Set COMP parameters */
314 /* Set COMPxINSEL bits according to hcomp->Init.InvertingInput value */
315 /* Set COMPxNONINSEL bits according to hcomp->Init.NonInvertingInput value */
316 /* Set COMPxBLANKING bits according to hcomp->Init.BlankingSrce value */
317 /* Set COMPxOUTSEL bits according to hcomp->Init.Output value */
318 /* Set COMPxPOL bit according to hcomp->Init.OutputPol value */
319 /* Set COMPxHYST bits according to hcomp->Init.Hysteresis value */
320 /* Set COMPxMODE bits according to hcomp->Init.Mode value */
323 /* Initialize the COMP state*/
324 if(hcomp->State == HAL_COMP_STATE_RESET)
326 hcomp->State = HAL_COMP_STATE_READY;
334 * @brief DeInitializes the COMP peripheral
335 * @note Deinitialization can't be performed if the COMP configuration is locked.
336 * To unlock the configuration, perform a system reset.
337 * @param hcomp: COMP handle
340 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
342 HAL_StatusTypeDef status = HAL_OK;
344 /* Check the COMP handle allocation and lock status */
345 if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
351 /* Check the parameter */
352 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
354 /* Set COMP_CSR register to reset value */
357 /* DeInit the low level hardware: SYSCFG, GPIO, CLOCK and NVIC */
358 HAL_COMP_MspDeInit(hcomp);
360 hcomp->State = HAL_COMP_STATE_RESET;
367 * @brief Initializes the COMP MSP.
368 * @param hcomp: COMP handle
371 __weak void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp)
373 /* NOTE : This function Should not be modified, when the callback is needed,
374 the HAL_COMP_MspInit could be implemented in the user file
379 * @brief DeInitializes COMP MSP.
380 * @param hcomp: COMP handle
383 __weak void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp)
385 /* NOTE : This function Should not be modified, when the callback is needed,
386 the HAL_COMP_MspDeInit could be implenetd in the user file
394 /** @defgroup COMP_Exported_Functions_Group2 Input and Output operation functions
395 * @brief Data transfers functions
398 ===============================================================================
399 ##### IO operation functions #####
400 ===============================================================================
402 This subsection provides a set of functions allowing to manage the COMP data
410 * @brief Start the comparator
411 * @param hcomp: COMP handle
414 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp)
416 HAL_StatusTypeDef status = HAL_OK;
418 /* Check the COMP handle allocation and lock status */
419 if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
425 /* Check the parameter */
426 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
428 if(hcomp->State == HAL_COMP_STATE_READY)
430 /* Enable the selected comparator */
433 hcomp->State = HAL_COMP_STATE_BUSY;
445 * @brief Stop the comparator
446 * @param hcomp: COMP handle
449 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp)
451 HAL_StatusTypeDef status = HAL_OK;
453 /* Check the COMP handle allocation and lock status */
454 if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
460 /* Check the parameter */
461 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
463 if(hcomp->State == HAL_COMP_STATE_BUSY)
465 /* Disable the selected comparator */
468 hcomp->State = HAL_COMP_STATE_READY;
480 * @brief Enables the interrupt and starts the comparator
481 * @param hcomp: COMP handle
482 * @retval HAL status.
484 HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp)
486 HAL_StatusTypeDef status = HAL_OK;
487 uint32_t extiline = 0;
489 /* Check the parameter */
490 assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode));
492 status = HAL_COMP_Start(hcomp);
495 /* Check the Exti Line output configuration */
496 extiline = __HAL_COMP_GET_EXTI_LINE(hcomp->Instance);
497 /* Configure the rising edge */
498 if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_RISING) != RESET)
500 __HAL_COMP_EXTI_RISING_IT_ENABLE(extiline);
504 __HAL_COMP_EXTI_RISING_IT_DISABLE(extiline);
506 /* Configure the falling edge */
507 if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_FALLING) != RESET)
509 __HAL_COMP_EXTI_FALLING_IT_ENABLE(extiline);
513 __HAL_COMP_EXTI_FALLING_IT_DISABLE(extiline);
515 /* Enable Exti interrupt mode */
516 __HAL_COMP_EXTI_ENABLE_IT(extiline);
517 /* Clear COMP Exti pending bit */
518 __HAL_COMP_EXTI_CLEAR_FLAG(extiline);
525 * @brief Disable the interrupt and Stop the comparator
526 * @param hcomp: COMP handle
529 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp)
531 HAL_StatusTypeDef status = HAL_OK;
533 /* Disable the Exti Line interrupt mode */
534 __HAL_COMP_EXTI_DISABLE_IT(__HAL_COMP_GET_EXTI_LINE(hcomp->Instance));
536 status = HAL_COMP_Stop(hcomp);
542 * @brief Comparator IRQ Handler
543 * @param hcomp: COMP handle
546 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp)
548 uint32_t extiline = __HAL_COMP_GET_EXTI_LINE(hcomp->Instance);
550 /* Check COMP Exti flag */
551 if(__HAL_COMP_EXTI_GET_FLAG(extiline) != RESET)
553 /* Clear COMP Exti pending bit */
554 __HAL_COMP_EXTI_CLEAR_FLAG(extiline);
556 /* COMP trigger user callback */
557 HAL_COMP_TriggerCallback(hcomp);
565 /** @defgroup COMP_Exported_Functions_Group3 Peripheral Control functions
566 * @brief management functions
569 ===============================================================================
570 ##### Peripheral Control functions #####
571 ===============================================================================
573 This subsection provides a set of functions allowing to control the COMP data
581 * @brief Lock the selected comparator configuration.
582 * @param hcomp: COMP handle
585 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp)
587 HAL_StatusTypeDef status = HAL_OK;
589 /* Check the COMP handle allocation and lock status */
590 if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
596 /* Check the parameter */
597 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
600 hcomp->State |= COMP_STATE_BIT_LOCK;
602 /* Set the lock bit corresponding to selected comparator */
610 * @brief Return the output level (high or low) of the selected comparator.
611 * The output level depends on the selected polarity.
612 * If the polarity is not inverted:
613 * - Comparator output is low when the non-inverting input is at a lower
614 * voltage than the inverting input
615 * - Comparator output is high when the non-inverting input is at a higher
616 * voltage than the inverting input
617 * If the polarity is inverted:
618 * - Comparator output is high when the non-inverting input is at a lower
619 * voltage than the inverting input
620 * - Comparator output is low when the non-inverting input is at a higher
621 * voltage than the inverting input
622 * @param hcomp: COMP handle
623 * @retval Returns the selected comparator output level: COMP_OUTPUTLEVEL_LOW or COMP_OUTPUTLEVEL_HIGH.
626 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp)
630 /* Check the parameter */
631 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
633 level = READ_BIT(hcomp->Instance->CSR, COMP_CSR_COMPxOUT);
637 return(COMP_OUTPUTLEVEL_HIGH);
639 return(COMP_OUTPUTLEVEL_LOW);
643 * @brief Comparator callback.
644 * @param hcomp: COMP handle
647 __weak void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
649 /* NOTE : This function should not be modified, when the callback is needed,
650 the HAL_COMP_TriggerCallback should be implemented in the user file
659 /** @defgroup COMP_Exported_Functions_Group4 Peripheral State functions
660 * @brief Peripheral State functions
663 ===============================================================================
664 ##### Peripheral State functions #####
665 ===============================================================================
667 This subsection permit to get in run-time the status of the peripheral
675 * @brief Return the COMP state
676 * @param hcomp : COMP handle
679 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp)
681 /* Check the COMP handle allocation */
682 if(hcomp == HAL_NULL)
684 return HAL_COMP_STATE_RESET;
687 /* Check the parameter */
688 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
700 #endif /* HAL_COMP_MODULE_ENABLED */
709 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/