2 ******************************************************************************
3 * @file stm32l1xx_hal_comp.c
4 * @author MCD Application Team
6 * @date 5-September-2014
7 * @brief COMP HAL module driver.
9 * This file provides firmware functions to manage the following
10 * functionalities of the COMP peripheral:
11 * + Initialization and de-initialization functions
12 * + I/O operation functions
13 * + Peripheral Control functions
14 * + Peripheral State functions
17 ================================================================================
18 ##### COMP Peripheral features #####
19 ================================================================================
22 The STM32L1xx device family integrates 2 analog comparators COMP1 and
24 (#) The non inverting input and inverting input can be set to GPIO pins.
25 Refer to "table1. COMP Inputs" below.
26 HAL COMP driver configures the Routing Interface (RI) to connect the
27 selected I/O pins to comparator input.
28 Caution: Comparator COMP1 and ADC cannot be used at the same time as
29 ADC since they share the ADC switch matrix: COMP1 non-inverting
30 input is routed through ADC switch matrix. Except if ADC is intented
31 to measure voltage on COMP1 non-inverting input: it can be performed
34 (#) The COMP output is available using HAL_COMP_GetOutputLevel().
36 (#) The COMP output can be redirected to embedded timers (TIM2, TIM3,
38 COMP output cannot be redirected to any I/O pin.
39 Refer to "table 2. COMP Outputs redirection to embedded timers" below.
41 (#) The comparators COMP1 and COMP2 can be combined in window mode.
42 In this mode, COMP2 non inverting input is used as common
45 (#) The 2 comparators have interrupt capability with wake-up
46 from Sleep and Stop modes (through the EXTI controller):
47 (++) COMP1 is internally connected to EXTI Line 21
48 (++) COMP2 is internally connected to EXTI Line 22
50 From the corresponding IRQ handler, the right interrupt source can be
51 retrieved with macro __HAL_COMP_EXTI_GET_FLAG(). Possible values are:
52 (++) COMP_EXTI_LINE_COMP1_EVENT
53 (++) COMP_EXTI_LINE_COMP2_EVENT
55 (#) The comparators also offer the possibility to ouput the voltage
56 reference (VrefInt), used on inverting inputs, on I/O pin through
57 a buffer. To use it, refer to macro "__HAL_VREFINT_OUT_ENABLE()".
60 [..] Table 1. COMP Inputs for the STM32L1xx devices
61 +----------------------------------------------------------------------+
63 |-----------------|--------------------------------|---------|---------|
64 | | 1/4 VREFINT | -- | OK |
65 | | 1/2 VREFINT | -- | OK |
66 | | 3/4 VREFINT | -- | OK |
67 | Inverting | VREFINT | OK | OK |
68 | input | DAC Ch1 OUT (PA4) | -- | OK |
69 | | DAC Ch2 OUT (PA5) | -- | OK |
70 | | IO: PB3 | -- | OK |
71 |-----------------|--------------------------------|---------|---------|
73 | | PB4, 5, 6*, 7* | --- | OK |
74 | Non-inverting | PA0*, 1*, 2*, 3*, 4, 5, 6, 7 | OK | --- |
75 | input | PB0, 1, 12, 13, 14, 15 | OK | --- |
76 | | PC0, 1, 2, 3, 4, 5 | OK | --- |
77 | | PE7, 8, 9, 10 | OK | --- |
78 | | PF6, 7, 8, 9, 10 | OK | --- |
79 | | OPAMP1 output | OK | --- |
80 | | OPAMP2 output | OK | --- |
81 | | OPAMP3 output** | OK | --- |
82 +----------------------------------------------------------------------+
83 *: Available on devices category Cat.3, Cat.4, Cat.5 only.
84 **: Available on devices category Cat.4 only.
86 [..] Table 2. COMP Outputs redirection to embedded timers
87 +-----------------------------------+
89 |-----------------|-----------------|
92 | (no redirection | TIM3 IC4 |
93 | to timers) | TIM3 OCREF CLR |
97 +-----------------------------------+
100 ##### How to use this driver #####
101 ================================================================================
103 This driver provides functions to configure and program the Comparators of all STM32L1xx devices.
105 To use the comparator, perform the following steps:
107 (#) Initialize the COMP low level resources by implementing the HAL_COMP_MspInit().
108 (++) Configure the comparator input I/O pin using HAL_GPIO_Init():
109 - For all inputs: I/O pin in analog mode (Schmitt trigger disabled)
110 - Possible alternate configuration, for non-inverting inputs of comparator 2: I/O pin in floating mode (Schmitt trigger enabled).
111 It is recommended to use analog configuration to avoid any overconsumption around VDD/2.
112 (++) Enable COMP Peripheral clock using macro __COMP_CLK_ENABLE()
113 (++) If required enable the COMP interrupt (EXTI line Interrupt): enable
114 the comparator interrupt vector using HAL_NVIC_EnableIRQ(COMP_IRQn)
115 and HAL_NVIC_SetPriority(COMP_IRQn, xxx, xxx) functions.
117 (#) Configure the comparator using HAL_COMP_Init() function:
118 (++) Select the inverting input (COMP2 only)
119 (++) Select the non-inverting input
120 (++) Select the output redirection to timers (COMP2 only)
121 (++) Select the speed mode (COMP2 only)
122 (++) Select the window mode (related to COMP1 and COMP2, but selected
124 (++) Select the pull-up/down resistors on non-inverting input (COMP1 only)
126 (#) Enable the comparator using HAL_COMP_Start() or HAL_COMP_Start_IT()
129 (#) If needed, use HAL_COMP_GetOutputLevel() or HAL_COMP_TriggerCallback()
130 functions to manage comparator actions (output level or events)
132 (#) Disable the comparator using HAL_COMP_Stop() or HAL_COMP_Stop_IT()
135 (#) De-initialize the comparator using HAL_COMP_DeInit() function
139 ******************************************************************************
142 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
144 * Redistribution and use in source and binary forms, with or without modification,
145 * are permitted provided that the following conditions are met:
146 * 1. Redistributions of source code must retain the above copyright notice,
147 * this list of conditions and the following disclaimer.
148 * 2. Redistributions in binary form must reproduce the above copyright notice,
149 * this list of conditions and the following disclaimer in the documentation
150 * and/or other materials provided with the distribution.
151 * 3. Neither the name of STMicroelectronics nor the names of its contributors
152 * may be used to endorse or promote products derived from this software
153 * without specific prior written permission.
155 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
156 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
157 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
158 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
159 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
160 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
161 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
162 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
163 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
164 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
166 ******************************************************************************
169 /* Includes ------------------------------------------------------------------*/
170 #include "stm32l1xx_hal.h"
172 /** @addtogroup STM32L1xx_HAL_Driver
176 /** @defgroup COMP COMP
177 * @brief COMP HAL module driver
181 #ifdef HAL_COMP_MODULE_ENABLED
183 /* Private typedef -----------------------------------------------------------*/
184 /* Private define ------------------------------------------------------------*/
186 /** @defgroup COMP_Private_Constants COMP Private Constants
189 /* Delay for COMP startup time. */
190 /* Maximum delay is 10us for comparator 1 and 25us for comparator 2 in slow */
191 /* mode (refer to device datasheet, parameter tSTART). */
192 /* Delay in CPU cycles, fixed to worst case: maximum CPU frequency 32MHz to */
193 /* have the minimum number of CPU cycles to fulfill this delay. */
194 /* - Comparator 1: delay minimum of 320 CPU cyles. Wait loop takes 3 CPU */
195 /* cycles per iteration, therefore total wait iterations */
196 /* number must be initialized at 106 iterations. */
197 /* - Comparator 2: delay minimum of 800 CPU cyles. Wait loop takes 3 CPU */
198 /* cycles per iteration, therefore total wait iterations */
199 /* number must be initialized at 266 iterations. */
200 #define COMP1_START_DELAY_CPU_CYCLES ((uint32_t)106)
201 #define COMP2_START_DELAY_CPU_CYCLES ((uint32_t)266)
203 /* Comparator status "locked": to update COMP handle state (software lock */
204 /* only on COMP of STM32L1xx devices) by bitfield: */
205 /* states HAL_COMP_STATE_READY_LOCKED, HAL_COMP_STATE_BUSY_LOCKED. */
206 #define COMP_STATE_BIT_LOCK ((uint32_t) 0x00000010)
213 /* Private macro -------------------------------------------------------------*/
214 /* Private variables ---------------------------------------------------------*/
215 /* Private function prototypes -----------------------------------------------*/
216 /* Private functions ---------------------------------------------------------*/
218 /** @defgroup COMP_Exported_Functions COMP Exported Functions
222 /** @defgroup COMP_Exported_Functions_Group1 Initialization and de-initialization functions
223 * @brief Initialization and Configuration functions
226 ===============================================================================
227 ##### Initialization and de-initialization functions #####
228 ===============================================================================
229 [..] This section provides functions to initialize and de-initialize comparators
236 * @brief Initializes the COMP according to the specified
237 * parameters in the COMP_InitTypeDef and create the associated handle.
238 * @note If the selected comparator is locked, initialization can't be performed.
239 * To unlock the configuration, perform a system reset.
240 * @param hcomp: COMP handle
243 HAL_StatusTypeDef
HAL_COMP_Init(COMP_HandleTypeDef
*hcomp
)
245 HAL_StatusTypeDef status
= HAL_OK
;
247 /* Check the COMP handle allocation and lock status */
248 if((hcomp
== HAL_NULL
) || ((hcomp
->State
& COMP_STATE_BIT_LOCK
) != RESET
))
254 /* Check the parameter */
255 assert_param(IS_COMP_ALL_INSTANCE(hcomp
->Instance
));
257 if (hcomp
->Instance
== COMP1
)
259 assert_param(IS_COMP_NONINVERTINGINPUTPULL(hcomp
->Init
.NonInvertingInputPull
));
261 else /* if (hcomp->Instance == COMP2) */
263 assert_param(IS_COMP_INVERTINGINPUT(hcomp
->Init
.InvertingInput
));
264 assert_param(IS_COMP_OUTPUT(hcomp
->Init
.Output
));
265 assert_param(IS_COMP_MODE(hcomp
->Init
.Mode
));
266 assert_param(IS_COMP_WINDOWMODE(hcomp
->Init
.WindowMode
));
269 /* In window mode, non-inverting inputs of the 2 comparators are */
270 /* connected together and are using inputs of COMP2 only. If COMP1 is */
271 /* selected, this parameter is discarded. */
272 if ((hcomp
->Init
.WindowMode
== COMP_WINDOWMODE_DISABLED
) ||
273 (hcomp
->Instance
== COMP2
) )
275 assert_param(IS_COMP_NONINVERTINGINPUT(hcomp
->Init
.NonInvertingInput
));
279 /* Enable SYSCFG clock and the low level hardware to access comparators */
280 if(hcomp
->State
== HAL_COMP_STATE_RESET
)
282 /* Enable SYSCFG clock to control the routing Interface (RI) */
283 __SYSCFG_CLK_ENABLE();
285 /* Init the low level hardware */
286 HAL_COMP_MspInit(hcomp
);
289 /* Configuration of comparator: */
290 /* - Output selection */
291 /* - Inverting input selection */
293 /* - Mode fast/slow speed */
294 /* - Inverting input pull-up/down resistors */
296 /* Configuration depending on comparator instance */
297 if (hcomp
->Instance
== COMP1
)
299 MODIFY_REG(COMP
->CSR
, COMP_CSR_400KPD
| COMP_CSR_10KPD
| COMP_CSR_400KPU
| COMP_CSR_10KPU
,
300 hcomp
->Init
.NonInvertingInputPull
);
302 else /* if (hcomp->Instance == COMP2) */
304 /* Note: If comparator 2 is not enabled, inverting input (parameter */
305 /* "hcomp->Init.InvertingInput") is configured into function */
306 /* "HAL_COMP_Start()" since inverting input selection also */
307 /* enables the comparator 2. */
308 /* If comparator 2 is already enabled, inverting input is */
309 /* reconfigured on the fly. */
310 if (__COMP_IS_ENABLED(hcomp
) == RESET
)
312 MODIFY_REG(COMP
->CSR
, COMP_CSR_OUTSEL
|
316 hcomp
->Init
.WindowMode
|
321 MODIFY_REG(COMP
->CSR
, COMP_CSR_OUTSEL
|
326 hcomp
->Init
.InvertingInput
|
327 hcomp
->Init
.WindowMode
|
332 /* Configure Routing Interface (RI) switches for comparator non-inverting */
334 /* Except in 2 cases: */
335 /* - if non-inverting input has no selection: it can be the case for */
336 /* COMP1 in window mode. */
337 /* - particular case for PC3: if switch COMP1_SW1 is closed */
338 /* (by macro "__HAL_OPAMP_OPAMP3OUT_CONNECT_ADC_COMP1()" or */
339 /* "__HAL_RI_SWITCH_COMP1_SW1_CLOSE()"), connection between pin PC3 */
340 /* (or OPAMP3, if available) and COMP1 is done directly, without going */
341 /* through ADC switch matrix. */
342 if (__COMP_ROUTING_INTERFACE_TOBECONFIGURED(hcomp
))
344 if (hcomp
->Instance
== COMP1
)
346 /* Enable the switch control mode */
347 __HAL_RI_SWITCHCONTROLMODE_ENABLE();
349 /* Close the analog switch of ADC switch matrix to COMP1 (ADC */
350 /* channel 26: Vcomp) */
351 __HAL_RI_IOSWITCH_CLOSE(RI_IOSWITCH_VCOMP
);
354 /* Close the I/O analog switch corresponding to comparator */
355 /* non-inverting input selected. */
356 __HAL_RI_IOSWITCH_CLOSE(hcomp
->Init
.NonInvertingInput
);
360 /* Initialize the COMP state*/
361 if(hcomp
->State
== HAL_COMP_STATE_RESET
)
363 hcomp
->State
= HAL_COMP_STATE_READY
;
372 * @brief DeInitializes the COMP peripheral
373 * @note Deinitialization can't be performed if the COMP configuration is locked.
374 * To unlock the configuration, perform a system reset.
375 * @param hcomp: COMP handle
378 HAL_StatusTypeDef
HAL_COMP_DeInit(COMP_HandleTypeDef
*hcomp
)
380 HAL_StatusTypeDef status
= HAL_OK
;
382 /* Check the COMP handle allocation and lock status */
383 if((hcomp
== HAL_NULL
) || ((hcomp
->State
& COMP_STATE_BIT_LOCK
) != RESET
))
389 /* Check the parameter */
390 assert_param(IS_COMP_ALL_INSTANCE(hcomp
->Instance
));
392 /* Reset configuration depending on comparator instance */
393 if (hcomp
->Instance
== COMP1
)
395 CLEAR_BIT(COMP
->CSR
, COMP_CSR_400KPD
| COMP_CSR_10KPD
| COMP_CSR_400KPU
| COMP_CSR_10KPU
);
397 else /* if (hcomp->Instance == COMP2) */
399 CLEAR_BIT(COMP
->CSR
, COMP_CSR_OUTSEL
|
406 /* Restore default state of Routing Interface (RI) switches for */
407 /* comparator non-inverting input. */
408 if (hcomp
->Init
.NonInvertingInput
!= COMP_NONINVERTINGINPUT_NONE
)
410 /* Open the I/O analog switch corresponding to comparator */
411 /* non-inverting input selected. */
412 __HAL_RI_IOSWITCH_OPEN(hcomp
->Init
.NonInvertingInput
);
414 if (hcomp
->Instance
== COMP1
)
416 /* Open the analog switch of ADC switch matrix to COMP1 (ADC */
417 /* channel 26: Vcomp) */
418 __HAL_RI_IOSWITCH_OPEN(RI_IOSWITCH_VCOMP
);
420 /* Disable the switch control mode */
421 __HAL_RI_SWITCHCONTROLMODE_DISABLE();
425 /* DeInit the low level hardware: SYSCFG, GPIO, CLOCK and NVIC */
426 HAL_COMP_MspDeInit(hcomp
);
428 hcomp
->State
= HAL_COMP_STATE_RESET
;
430 /* Process unlocked */
438 * @brief Initializes the COMP MSP.
439 * @param hcomp: COMP handle
442 __weak
void HAL_COMP_MspInit(COMP_HandleTypeDef
*hcomp
)
444 /* NOTE : This function Should not be modified, when the callback is needed,
445 the HAL_COMP_MspInit could be implenetd in the user file
450 * @brief DeInitializes COMP MSP.
451 * @param hcomp: COMP handle
454 __weak
void HAL_COMP_MspDeInit(COMP_HandleTypeDef
*hcomp
)
456 /* NOTE : This function Should not be modified, when the callback is needed,
457 the HAL_COMP_MspDeInit could be implenetd in the user file
465 /** @defgroup COMP_Exported_Functions_Group2 I/O operation functions
466 * @brief I/O operation functions
469 ===============================================================================
470 ##### IO operation functions #####
471 ===============================================================================
473 This subsection provides a set of functions allowing to manage the COMP
474 start and stop actions with or without interruption on ExtI line.
481 * @brief Start the comparator
482 * @param hcomp: COMP handle
485 HAL_StatusTypeDef
HAL_COMP_Start(COMP_HandleTypeDef
*hcomp
)
487 HAL_StatusTypeDef status
= HAL_OK
;
488 uint32_t wait_loop_cycles
= 0;
489 __IO
uint32_t wait_loop_index
= 0;
491 /* Check the COMP handle allocation and lock status */
492 if((hcomp
== HAL_NULL
) || ((hcomp
->State
& COMP_STATE_BIT_LOCK
) != RESET
))
498 /* Check the parameter */
499 assert_param(IS_COMP_ALL_INSTANCE(hcomp
->Instance
));
501 if(hcomp
->State
== HAL_COMP_STATE_READY
)
504 /* Note: For comparator 2, inverting input (parameter */
505 /* "hcomp->Init.InvertingInput") is configured into this */
506 /* function instead of function "HAL_COMP_Init()" since */
507 /* inverting input selection also enables the comparator 2. */
508 __HAL_COMP_ENABLE(hcomp
);
510 /* Set delay for COMP startup time */
511 if (hcomp
->Instance
== COMP1
)
513 wait_loop_cycles
= COMP1_START_DELAY_CPU_CYCLES
;
515 else /* if (hcomp->Instance == COMP2) */
517 wait_loop_cycles
= COMP2_START_DELAY_CPU_CYCLES
;
520 /* Delay for COMP startup time. */
521 /* Delay fixed to worst case: maximum CPU frequency */
522 while(wait_loop_index
< wait_loop_cycles
)
527 /* Update COMP state */
528 hcomp
->State
= HAL_COMP_STATE_BUSY
;
541 * @brief Stop the comparator
542 * @param hcomp: COMP handle
545 HAL_StatusTypeDef
HAL_COMP_Stop(COMP_HandleTypeDef
*hcomp
)
547 HAL_StatusTypeDef status
= HAL_OK
;
549 /* Check the COMP handle allocation and lock status */
550 if((hcomp
== HAL_NULL
) || ((hcomp
->State
& COMP_STATE_BIT_LOCK
) != RESET
))
556 /* Check the parameter */
557 assert_param(IS_COMP_ALL_INSTANCE(hcomp
->Instance
));
559 if(hcomp
->State
== HAL_COMP_STATE_BUSY
)
561 /* Disable the selected comparator */
562 __HAL_COMP_DISABLE(hcomp
);
564 /* Update COMP state */
565 hcomp
->State
= HAL_COMP_STATE_READY
;
577 * @brief Enables the interrupt and starts the comparator
578 * @param hcomp: COMP handle
579 * @retval HAL status.
581 HAL_StatusTypeDef
HAL_COMP_Start_IT(COMP_HandleTypeDef
*hcomp
)
583 HAL_StatusTypeDef status
= HAL_OK
;
584 uint32_t extiline
= 0;
586 status
= HAL_COMP_Start(hcomp
);
589 /* Check the parameter */
590 assert_param(IS_COMP_TRIGGERMODE(hcomp
->Init
.TriggerMode
));
592 /* Get the Exti Line output configuration */
593 extiline
= __HAL_COMP_GET_EXTI_LINE(hcomp
->Instance
);
595 /* Configure the rising edge */
596 /* COMP TriggerMode set to COMP_TRIGGERMODE_IT_RISING or */
597 /* COMP_TRIGGERMODE_IT_RISING_FALLING. */
598 if((hcomp
->Init
.TriggerMode
& COMP_TRIGGERMODE_IT_RISING
) != RESET
)
600 __HAL_COMP_EXTI_RISING_IT_ENABLE(extiline
);
604 __HAL_COMP_EXTI_RISING_IT_DISABLE(extiline
);
607 /* Configure the falling edge */
608 /* COMP TriggerMode set to COMP_TRIGGERMODE_IT_FALLING or */
609 /* COMP_TRIGGERMODE_IT_RISING_FALLING. */
610 if((hcomp
->Init
.TriggerMode
& COMP_TRIGGERMODE_IT_FALLING
) != RESET
)
612 __HAL_COMP_EXTI_FALLING_IT_ENABLE(extiline
);
616 __HAL_COMP_EXTI_FALLING_IT_DISABLE(extiline
);
619 /* Enable Exti interrupt mode */
620 __HAL_COMP_EXTI_ENABLE_IT(extiline
);
621 /* Clear COMP Exti pending bit */
622 __HAL_COMP_EXTI_CLEAR_FLAG(extiline
);
629 * @brief Disable the interrupt and Stop the comparator
630 * @param hcomp: COMP handle
633 HAL_StatusTypeDef
HAL_COMP_Stop_IT(COMP_HandleTypeDef
*hcomp
)
635 HAL_StatusTypeDef status
= HAL_OK
;
637 /* Disable the Exti Line interrupt mode */
638 __HAL_COMP_EXTI_DISABLE_IT(__HAL_COMP_GET_EXTI_LINE(hcomp
->Instance
));
640 status
= HAL_COMP_Stop(hcomp
);
646 * @brief Comparator IRQ Handler
647 * @param hcomp: COMP handle
650 void HAL_COMP_IRQHandler(COMP_HandleTypeDef
*hcomp
)
652 uint32_t extiline
= __HAL_COMP_GET_EXTI_LINE(hcomp
->Instance
);
654 /* Check COMP Exti flag */
655 if(__HAL_COMP_EXTI_GET_FLAG(extiline
) != RESET
)
657 /* Clear COMP Exti pending bit */
658 __HAL_COMP_EXTI_CLEAR_FLAG(extiline
);
660 /* COMP trigger user callback */
661 HAL_COMP_TriggerCallback(hcomp
);
669 /** @defgroup COMP_Exported_Functions_Group3 Peripheral Control functions
670 * @brief Peripheral Control functions
673 ===============================================================================
674 ##### Peripheral Control functions #####
675 ===============================================================================
677 This subsection provides a set of functions allowing to control the COMP
678 management functions: Lock status, comparator output level check, IRQ
679 callback (in case of usage of comparator with interruption on ExtI line).
686 * @brief Lock the selected comparator configuration.
687 * Caution: On STM32L1, HAL COMP lock is software lock only (not
688 * hardware lock as on some other STM32 devices)
689 * @param hcomp: COMP handle
692 HAL_StatusTypeDef
HAL_COMP_Lock(COMP_HandleTypeDef
*hcomp
)
694 HAL_StatusTypeDef status
= HAL_OK
;
696 /* Check the COMP handle allocation and lock status */
697 if((hcomp
== HAL_NULL
) || ((hcomp
->State
& COMP_STATE_BIT_LOCK
) != RESET
))
703 /* Check the parameter */
704 assert_param(IS_COMP_ALL_INSTANCE(hcomp
->Instance
));
707 hcomp
->State
|= COMP_STATE_BIT_LOCK
;
714 * @brief Return the output level (high or low) of the selected comparator.
715 * The output level depends on the selected polarity.
716 * - Comparator output is low when the non-inverting input is at a lower
717 * voltage than the inverting input
718 * - Comparator output is high when the non-inverting input is at a higher
719 * voltage than the inverting input
720 * @param hcomp: COMP handle
721 * @retval Returns the selected comparator output level: COMP_OUTPUTLEVEL_LOW or COMP_OUTPUTLEVEL_HIGH.
724 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef
*hcomp
)
728 /* Check the parameter */
729 assert_param(IS_COMP_ALL_INSTANCE(hcomp
->Instance
));
731 /* Read output level of the selected comparator */
732 if(READ_BIT(COMP
->CSR
, __COMP_CSR_CMPXOUT(hcomp
)) == RESET
)
734 level
= COMP_OUTPUTLEVEL_LOW
;
738 level
= COMP_OUTPUTLEVEL_HIGH
;
745 * @brief Comparator callback.
746 * @param hcomp: COMP handle
749 __weak
void HAL_COMP_TriggerCallback(COMP_HandleTypeDef
*hcomp
)
751 /* NOTE : This function should not be modified, when the callback is needed,
752 the HAL_COMP_TriggerCallback should be implemented in the user file
761 /** @defgroup COMP_Exported_Functions_Group4 Peripheral State functions
762 * @brief Peripheral State functions
765 ===============================================================================
766 ##### Peripheral State functions #####
767 ===============================================================================
769 This subsection permit to get in run-time the status of the peripheral.
776 * @brief Return the COMP state
777 * @param hcomp : COMP handle
780 HAL_COMP_StateTypeDef
HAL_COMP_GetState(COMP_HandleTypeDef
*hcomp
)
782 /* Check the COMP handle allocation */
783 if(hcomp
== HAL_NULL
)
785 return HAL_COMP_STATE_RESET
;
788 /* Check the parameter */
789 assert_param(IS_COMP_ALL_INSTANCE(hcomp
->Instance
));
801 #endif /* HAL_COMP_MODULE_ENABLED */
810 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/