mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_comp.c@634:ac7d6880524d, 2015-09-28 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Sep 28 20:15:09 2015 +0100
- Revision:
- 634:ac7d6880524d
- Parent:
- 632:7687fb9c4f91
Synchronized with git revision 9b7d23d47153c298a6d24de9a415202705889d11
Full URL: https://github.com/mbedmicro/mbed/commit/9b7d23d47153c298a6d24de9a415202705889d11/
Revert "[NUCLEO_F303K8] add support of the STM32F303K8"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 330:c80ac197fa6a | 1 | /** |
mbed_official | 330:c80ac197fa6a | 2 | ****************************************************************************** |
mbed_official | 330:c80ac197fa6a | 3 | * @file stm32f3xx_hal_comp.c |
mbed_official | 330:c80ac197fa6a | 4 | * @author MCD Application Team |
mbed_official | 634:ac7d6880524d | 5 | * @version V1.1.0 |
mbed_official | 634:ac7d6880524d | 6 | * @date 12-Sept-2014 |
mbed_official | 330:c80ac197fa6a | 7 | * @brief COMP HAL module driver. |
mbed_official | 330:c80ac197fa6a | 8 | * |
mbed_official | 330:c80ac197fa6a | 9 | * This file provides firmware functions to manage the following |
mbed_official | 330:c80ac197fa6a | 10 | * functionalities of the COMP peripheral: |
mbed_official | 330:c80ac197fa6a | 11 | * + Initialization/de-initialization functions |
mbed_official | 330:c80ac197fa6a | 12 | * + I/O operation functions |
mbed_official | 330:c80ac197fa6a | 13 | * + Peripheral Control functions |
mbed_official | 330:c80ac197fa6a | 14 | * + Peripheral State functions |
mbed_official | 330:c80ac197fa6a | 15 | * |
mbed_official | 330:c80ac197fa6a | 16 | @verbatim |
mbed_official | 330:c80ac197fa6a | 17 | ================================================================================ |
mbed_official | 330:c80ac197fa6a | 18 | ##### COMP Peripheral features ##### |
mbed_official | 330:c80ac197fa6a | 19 | ================================================================================ |
mbed_official | 330:c80ac197fa6a | 20 | |
mbed_official | 330:c80ac197fa6a | 21 | [..] |
mbed_official | 330:c80ac197fa6a | 22 | The STM32F3xx device family integrates up to 7 analog comparators COMP1, COMP2...COMP7: |
mbed_official | 330:c80ac197fa6a | 23 | (#) The non inverting input and inverting input can be set to GPIO pins |
mbed_official | 330:c80ac197fa6a | 24 | as shown in table1. COMP Inputs below for STM32F303xB/STM32F303xC as example. |
mbed_official | 330:c80ac197fa6a | 25 | For other STM32F3xx devices please refer to the COMP peripheral section in corresponding |
mbed_official | 330:c80ac197fa6a | 26 | Reference Manual. |
mbed_official | 330:c80ac197fa6a | 27 | |
mbed_official | 330:c80ac197fa6a | 28 | (#) The COMP output is available using HAL_COMP_GetOutputLevel() |
mbed_official | 330:c80ac197fa6a | 29 | and can be set on GPIO pins. Refer to table 2. COMP Outputs below for STM32F303xB/STM32F303xC as example. |
mbed_official | 330:c80ac197fa6a | 30 | For other STM32F3xx devices please refer to the COMP peripheral section in corresponding |
mbed_official | 330:c80ac197fa6a | 31 | Reference Manual. |
mbed_official | 330:c80ac197fa6a | 32 | |
mbed_official | 330:c80ac197fa6a | 33 | (#) The COMP output can be redirected to embedded timers (TIM1, TIM2, TIM3...) |
mbed_official | 330:c80ac197fa6a | 34 | Refer to table 3. COMP Outputs redirection to embedded timers below for STM32F303xB/STM32F303xC as example. |
mbed_official | 330:c80ac197fa6a | 35 | For other STM32F3xx devices please refer to the COMP peripheral section in corresponding |
mbed_official | 330:c80ac197fa6a | 36 | Reference Manual. |
mbed_official | 330:c80ac197fa6a | 37 | |
mbed_official | 330:c80ac197fa6a | 38 | (#) The comparators COMP1 and COMP2, COMP3 and COMP4, COMP5 and COMP6 can be combined in window |
mbed_official | 330:c80ac197fa6a | 39 | mode and only COMP1, COMP3 and COMP5 non inverting input can be used as non-inverting input. |
mbed_official | 330:c80ac197fa6a | 40 | |
mbed_official | 330:c80ac197fa6a | 41 | (#) The seven comparators have interrupt capability with wake-up |
mbed_official | 330:c80ac197fa6a | 42 | from Sleep and Stop modes (through the EXTI controller): |
mbed_official | 330:c80ac197fa6a | 43 | (++) COMP1 is internally connected to EXTI Line 21 |
mbed_official | 330:c80ac197fa6a | 44 | (++) COMP2 is internally connected to EXTI Line 22 |
mbed_official | 330:c80ac197fa6a | 45 | (++) COMP3 is internally connected to EXTI Line 29 |
mbed_official | 330:c80ac197fa6a | 46 | (++) COMP4 is internally connected to EXTI Line 30 |
mbed_official | 330:c80ac197fa6a | 47 | (++) COMP5 is internally connected to EXTI Line 31 |
mbed_official | 330:c80ac197fa6a | 48 | (++) COMP6 is internally connected to EXTI Line 32 |
mbed_official | 330:c80ac197fa6a | 49 | (++) COMP7 is internally connected to EXTI Line 33 |
mbed_official | 330:c80ac197fa6a | 50 | From the corresponding IRQ handler, the right interrupt source can be retrieved with the |
mbed_official | 330:c80ac197fa6a | 51 | macro __HAL_COMP_EXTI_GET_FLAG(). Possible values are: |
mbed_official | 330:c80ac197fa6a | 52 | (++) COMP_EXTI_LINE_COMP1_EVENT |
mbed_official | 330:c80ac197fa6a | 53 | (++) COMP_EXTI_LINE_COMP2_EVENT |
mbed_official | 330:c80ac197fa6a | 54 | (++) COMP_EXTI_LINE_COMP3_EVENT |
mbed_official | 330:c80ac197fa6a | 55 | (++) COMP_EXTI_LINE_COMP4_EVENT |
mbed_official | 330:c80ac197fa6a | 56 | (++) COMP_EXTI_LINE_COMP5_EVENT |
mbed_official | 330:c80ac197fa6a | 57 | (++) COMP_EXTI_LINE_COMP6_EVENT |
mbed_official | 330:c80ac197fa6a | 58 | (++) COMP_EXTI_LINE_COMP7_EVENT |
mbed_official | 330:c80ac197fa6a | 59 | |
mbed_official | 330:c80ac197fa6a | 60 | [..] Table 1. COMP Inputs for the STM32F303xB/STM32F303xC/STM32F303xE devices |
mbed_official | 330:c80ac197fa6a | 61 | +------------------------------------------------------------------------------------------+ |
mbed_official | 330:c80ac197fa6a | 62 | | | | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 | |
mbed_official | 330:c80ac197fa6a | 63 | |-----------------|----------------|---------------|---------------------------------------| |
mbed_official | 330:c80ac197fa6a | 64 | | | 1/4 VREFINT | OK | OK | OK | OK | OK | OK | OK | |
mbed_official | 330:c80ac197fa6a | 65 | | | 1/2 VREFINT | OK | OK | OK | OK | OK | OK | OK | |
mbed_official | 330:c80ac197fa6a | 66 | | | 3/4 VREFINT | OK | OK | OK | OK | OK | OK | OK | |
mbed_official | 330:c80ac197fa6a | 67 | | Inverting Input | VREFINT | OK | OK | OK | OK | OK | OK | OK | |
mbed_official | 330:c80ac197fa6a | 68 | | | DAC1 OUT (PA4) | OK | OK | OK | OK | OK | OK | OK | |
mbed_official | 330:c80ac197fa6a | 69 | | | DAC2 OUT (PA5) | OK | OK | OK | OK | OK | OK | OK | |
mbed_official | 330:c80ac197fa6a | 70 | | | IO1 | PA0 | PA2 | PD15 | PE8 | PD13 | PD10 | PC0 | |
mbed_official | 330:c80ac197fa6a | 71 | | | IO2 | --- | --- | PB12 | PB2 | PB10 | PB15 | --- | |
mbed_official | 330:c80ac197fa6a | 72 | |-----------------|----------------|-------|-------|-------|-------|-------|-------|-------| |
mbed_official | 330:c80ac197fa6a | 73 | | Non Inverting | IO1 | PA1 | PA7 | PB14 | PB0 | PD12 | PD11 | PA0 | |
mbed_official | 330:c80ac197fa6a | 74 | | Input | IO2 | --- | PA3 | PD14 | PE7 | PB13 | PB11 | PC1 | |
mbed_official | 330:c80ac197fa6a | 75 | +------------------------------------------------------------------------------------------+ |
mbed_official | 330:c80ac197fa6a | 76 | |
mbed_official | 330:c80ac197fa6a | 77 | [..] Table 2. COMP Outputs for the STM32F303xB/STM32F303xC/STM32F303xE devices |
mbed_official | 330:c80ac197fa6a | 78 | +-------------------------------------------------------+ |
mbed_official | 330:c80ac197fa6a | 79 | | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 | |
mbed_official | 330:c80ac197fa6a | 80 | |-------|-------|-------|-------|-------|-------|-------| |
mbed_official | 330:c80ac197fa6a | 81 | | PA0 | PA2 | PB1 | PC8 | PC7 | PA10 | PC2 | |
mbed_official | 330:c80ac197fa6a | 82 | | PF4 | PA7 | --- | PA8 | PA9 | PC6 | --- | |
mbed_official | 330:c80ac197fa6a | 83 | | PA6 | PA12 | --- | --- | --- | --- | --- | |
mbed_official | 330:c80ac197fa6a | 84 | | PA11 | PB9 | --- | --- | --- | --- | --- | |
mbed_official | 330:c80ac197fa6a | 85 | | PB8 | --- | --- | --- | --- | --- | --- | |
mbed_official | 330:c80ac197fa6a | 86 | +-------------------------------------------------------+ |
mbed_official | 330:c80ac197fa6a | 87 | |
mbed_official | 330:c80ac197fa6a | 88 | [..] Table 3. COMP Outputs redirection to embedded timers for the STM32F303xB/STM32F303xC devices |
mbed_official | 330:c80ac197fa6a | 89 | +----------------------------------------------------------------------------------------------------------------------+ |
mbed_official | 330:c80ac197fa6a | 90 | | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 | |
mbed_official | 330:c80ac197fa6a | 91 | |----------------|----------------|----------------|----------------|----------------|----------------|----------------| |
mbed_official | 330:c80ac197fa6a | 92 | | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | |
mbed_official | 330:c80ac197fa6a | 93 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 94 | | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | |
mbed_official | 330:c80ac197fa6a | 95 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 96 | | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | |
mbed_official | 330:c80ac197fa6a | 97 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 98 | | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | |
mbed_official | 330:c80ac197fa6a | 99 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 100 | | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | |
mbed_official | 330:c80ac197fa6a | 101 | | + | + | + | + | + | + | + | |
mbed_official | 330:c80ac197fa6a | 102 | | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | |
mbed_official | 330:c80ac197fa6a | 103 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 104 | | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM1 OCREFCLR | |
mbed_official | 330:c80ac197fa6a | 105 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 106 | | TIM1 IC1 | TIM1 IC1 | TIM2 OCREFCLR | TIM3 IC3 | TIM2 IC1 | TIM2 IC2 | TIM8 OCREFCLR | |
mbed_official | 330:c80ac197fa6a | 107 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 108 | | TIM2 IC4 | TIM2 IC4 | TIM3 IC2 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM2 OCREFCLR | TIM2 IC3 | |
mbed_official | 330:c80ac197fa6a | 109 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 110 | | TIM2 OCREFCLR | TIM2 OCREFCLR | TIM4 IC1 | TIM4 IC2 | TIM4 IC3 | TIM16 OCREFCLR| TIM1 IC2 | |
mbed_official | 330:c80ac197fa6a | 111 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 112 | | TIM3 IC1 | TIM3 IC1 | TIM15 IC1 | TIM15 OCREFCLR| TIM16 BKIN | TIM16 IC1 | TIM17 OCREFCLR| |
mbed_official | 330:c80ac197fa6a | 113 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 114 | | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM15 BKIN | TIM15 IC2 | TIM17 IC1 | TIM4 IC4 | TIM17 BKIN | |
mbed_official | 330:c80ac197fa6a | 115 | +----------------------------------------------------------------------------------------------------------------------+ |
mbed_official | 330:c80ac197fa6a | 116 | |
mbed_official | 330:c80ac197fa6a | 117 | [..] Table 4. COMP Outputs redirection to embedded timers for the STM32F303xE devices |
mbed_official | 330:c80ac197fa6a | 118 | +----------------------------------------------------------------------------------------------------------------------+ |
mbed_official | 330:c80ac197fa6a | 119 | | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 | |
mbed_official | 330:c80ac197fa6a | 120 | |----------------|----------------|----------------|----------------|----------------|----------------|----------------| |
mbed_official | 330:c80ac197fa6a | 121 | | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN (1) | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN (1) | |
mbed_official | 330:c80ac197fa6a | 122 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 123 | | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | |
mbed_official | 330:c80ac197fa6a | 124 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 125 | | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN (1) | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN (1) | |
mbed_official | 330:c80ac197fa6a | 126 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 127 | | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | |
mbed_official | 330:c80ac197fa6a | 128 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 129 | | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | |
mbed_official | 330:c80ac197fa6a | 130 | | + | + | + | + | + | + | + | |
mbed_official | 330:c80ac197fa6a | 131 | | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | |
mbed_official | 330:c80ac197fa6a | 132 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 133 | | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM1 OCREFCLR | |
mbed_official | 330:c80ac197fa6a | 134 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 135 | | TIM1 IC1 | TIM1 IC1 | TIM2 OCREFCLR | TIM3 IC3 | TIM2 IC1 | TIM2 IC2 | TIM8 OCREFCLR | |
mbed_official | 330:c80ac197fa6a | 136 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 137 | | TIM2 IC4 | TIM2 IC4 | TIM3 IC2 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM2 OCREFCLR | TIM2 IC3 | |
mbed_official | 330:c80ac197fa6a | 138 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 139 | | TIM2 OCREFCLR | TIM2 OCREFCLR | TIM4 IC1 | TIM4 IC2 | TIM4 IC3 | TIM16 OCREFCLR| TIM1 IC2 | |
mbed_official | 330:c80ac197fa6a | 140 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 141 | | TIM3 IC1 | TIM3 IC1 | TIM15 IC1 | TIM15 OCREFCLR| TIM16 BKIN | TIM16 IC1 | TIM17 OCREFCLR| |
mbed_official | 330:c80ac197fa6a | 142 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 143 | | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM15 BKIN | TIM15 IC2 | TIM17 IC1 | TIM4 IC4 | TIM17 BKIN | |
mbed_official | 330:c80ac197fa6a | 144 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 145 | | TIM20 BKIN | TIM20 BKIN | TIM20 BKIN | TIM20 BKIN (1)| TIM20 BKIN | TIM20 BKIN | TIM20 BKIN (1)| |
mbed_official | 330:c80ac197fa6a | 146 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 147 | | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | |
mbed_official | 330:c80ac197fa6a | 148 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 149 | | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | |
mbed_official | 330:c80ac197fa6a | 150 | | + | + | + | + | + | + | + | |
mbed_official | 330:c80ac197fa6a | 151 | | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | |
mbed_official | 330:c80ac197fa6a | 152 | | + | + | + | + | + | + | + | |
mbed_official | 330:c80ac197fa6a | 153 | | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | TIM20 BKIN2 | |
mbed_official | 330:c80ac197fa6a | 154 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 155 | +----------------------------------------------------------------------------------------------------------------------+ |
mbed_official | 330:c80ac197fa6a | 156 | (1):This connection consists of connecting both GPIO and COMP output to TIM1/8/20 BRK input through an OR gate, instead |
mbed_official | 330:c80ac197fa6a | 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 |
mbed_official | 330:c80ac197fa6a | 158 | add a digital filter (3 bits) on the COMP output. |
mbed_official | 330:c80ac197fa6a | 159 | |
mbed_official | 330:c80ac197fa6a | 160 | [..] Table 5. COMP Outputs blanking sources for the STM32F303xB/STM32F303xC/STM32F303xE devices |
mbed_official | 330:c80ac197fa6a | 161 | +----------------------------------------------------------------------------------------------------------------------+ |
mbed_official | 330:c80ac197fa6a | 162 | | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 | |
mbed_official | 330:c80ac197fa6a | 163 | |----------------|----------------|----------------|----------------|----------------|----------------|----------------| |
mbed_official | 330:c80ac197fa6a | 164 | | TIM1 OC5 | TIM1 OC5 | TIM1 OC5 | TIM3 OC4 | -------- | TIM8 OC5 | TIM1 OC5 | |
mbed_official | 330:c80ac197fa6a | 165 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 166 | | TIM2 OC3 | TIM2 OC3 | -------- | TIM8 OC5 | TIM3 OC3 | TIM2 OC4 | TIM8 OC5 | |
mbed_official | 330:c80ac197fa6a | 167 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 168 | | TIM3 OC3 | TIM3 OC3 | TIM2 OC4 | TIM15 OC1 | TIM8 OC5 | TIM15 OC2 | TIM15 OC2 | |
mbed_official | 330:c80ac197fa6a | 169 | | | | | | | | | |
mbed_official | 330:c80ac197fa6a | 170 | +----------------------------------------------------------------------------------------------------------------------+ |
mbed_official | 330:c80ac197fa6a | 171 | |
mbed_official | 330:c80ac197fa6a | 172 | ##### How to use this driver ##### |
mbed_official | 330:c80ac197fa6a | 173 | ================================================================================ |
mbed_official | 330:c80ac197fa6a | 174 | [..] |
mbed_official | 330:c80ac197fa6a | 175 | This driver provides functions to configure and program the Comparators of all STM32F3xx devices. |
mbed_official | 330:c80ac197fa6a | 176 | |
mbed_official | 330:c80ac197fa6a | 177 | To use the comparator, perform the following steps: |
mbed_official | 330:c80ac197fa6a | 178 | |
mbed_official | 330:c80ac197fa6a | 179 | (#) Fill in the HAL_COMP_MspInit() to |
mbed_official | 330:c80ac197fa6a | 180 | (++) Configure the comparator input in analog mode using HAL_GPIO_Init() |
mbed_official | 330:c80ac197fa6a | 181 | (++) Configure the comparator output in alternate function mode using HAL_GPIO_Init() to map the comparator |
mbed_official | 330:c80ac197fa6a | 182 | output to the GPIO pin |
mbed_official | 330:c80ac197fa6a | 183 | (++) If required enable the COMP interrupt by configuring and enabling EXTI line in Interrupt mode and |
mbed_official | 330:c80ac197fa6a | 184 | selecting the desired sensitivity level using HAL_GPIO_Init() function. After that enable the comparator |
mbed_official | 330:c80ac197fa6a | 185 | interrupt vector using HAL_NVIC_EnableIRQ() function. |
mbed_official | 330:c80ac197fa6a | 186 | |
mbed_official | 330:c80ac197fa6a | 187 | (#) Configure the comparator using HAL_COMP_Init() function: |
mbed_official | 330:c80ac197fa6a | 188 | (++) Select the inverting input |
mbed_official | 330:c80ac197fa6a | 189 | (++) Select the non-inverting input |
mbed_official | 330:c80ac197fa6a | 190 | (++) Select the output polarity |
mbed_official | 330:c80ac197fa6a | 191 | (++) Select the output redirection |
mbed_official | 330:c80ac197fa6a | 192 | (++) Select the hysteresis level |
mbed_official | 330:c80ac197fa6a | 193 | (++) Select the power mode |
mbed_official | 330:c80ac197fa6a | 194 | (++) Select the event/interrupt mode |
mbed_official | 330:c80ac197fa6a | 195 | |
mbed_official | 330:c80ac197fa6a | 196 | (#) Enable the comparator using HAL_COMP_Start() function or HAL_COMP_Start_IT() function for interrupt mode |
mbed_official | 330:c80ac197fa6a | 197 | |
mbed_official | 330:c80ac197fa6a | 198 | (#) Read the comparator output level with HAL_COMP_GetOutputLevel() |
mbed_official | 330:c80ac197fa6a | 199 | |
mbed_official | 330:c80ac197fa6a | 200 | @endverbatim |
mbed_official | 330:c80ac197fa6a | 201 | ****************************************************************************** |
mbed_official | 330:c80ac197fa6a | 202 | * @attention |
mbed_official | 330:c80ac197fa6a | 203 | * |
mbed_official | 634:ac7d6880524d | 204 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 330:c80ac197fa6a | 205 | * |
mbed_official | 330:c80ac197fa6a | 206 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 330:c80ac197fa6a | 207 | * are permitted provided that the following conditions are met: |
mbed_official | 330:c80ac197fa6a | 208 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 330:c80ac197fa6a | 209 | * this list of conditions and the following disclaimer. |
mbed_official | 330:c80ac197fa6a | 210 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 330:c80ac197fa6a | 211 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 330:c80ac197fa6a | 212 | * and/or other materials provided with the distribution. |
mbed_official | 330:c80ac197fa6a | 213 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 330:c80ac197fa6a | 214 | * may be used to endorse or promote products derived from this software |
mbed_official | 330:c80ac197fa6a | 215 | * without specific prior written permission. |
mbed_official | 330:c80ac197fa6a | 216 | * |
mbed_official | 330:c80ac197fa6a | 217 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 330:c80ac197fa6a | 218 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 330:c80ac197fa6a | 219 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 330:c80ac197fa6a | 220 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 330:c80ac197fa6a | 221 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 330:c80ac197fa6a | 222 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 330:c80ac197fa6a | 223 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 330:c80ac197fa6a | 224 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 330:c80ac197fa6a | 225 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 330:c80ac197fa6a | 226 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 330:c80ac197fa6a | 227 | * |
mbed_official | 330:c80ac197fa6a | 228 | ****************************************************************************** |
mbed_official | 330:c80ac197fa6a | 229 | */ |
mbed_official | 330:c80ac197fa6a | 230 | |
mbed_official | 330:c80ac197fa6a | 231 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 330:c80ac197fa6a | 232 | #include "stm32f3xx_hal.h" |
mbed_official | 330:c80ac197fa6a | 233 | |
mbed_official | 330:c80ac197fa6a | 234 | /** @addtogroup STM32F3xx_HAL_Driver |
mbed_official | 330:c80ac197fa6a | 235 | * @{ |
mbed_official | 330:c80ac197fa6a | 236 | */ |
mbed_official | 330:c80ac197fa6a | 237 | |
mbed_official | 330:c80ac197fa6a | 238 | /** @defgroup COMP COMP HAL module driver |
mbed_official | 330:c80ac197fa6a | 239 | * @brief COMP HAL module driver |
mbed_official | 330:c80ac197fa6a | 240 | * @{ |
mbed_official | 330:c80ac197fa6a | 241 | */ |
mbed_official | 330:c80ac197fa6a | 242 | |
mbed_official | 330:c80ac197fa6a | 243 | #ifdef HAL_COMP_MODULE_ENABLED |
mbed_official | 330:c80ac197fa6a | 244 | |
mbed_official | 330:c80ac197fa6a | 245 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 330:c80ac197fa6a | 246 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 330:c80ac197fa6a | 247 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 330:c80ac197fa6a | 248 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 330:c80ac197fa6a | 249 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 330:c80ac197fa6a | 250 | /* Exported functions --------------------------------------------------------*/ |
mbed_official | 330:c80ac197fa6a | 251 | |
mbed_official | 330:c80ac197fa6a | 252 | /** @defgroup COMP_Exported_Functions COMP Exported Functions |
mbed_official | 330:c80ac197fa6a | 253 | * @{ |
mbed_official | 330:c80ac197fa6a | 254 | */ |
mbed_official | 330:c80ac197fa6a | 255 | |
mbed_official | 330:c80ac197fa6a | 256 | /** @defgroup COMP_Exported_Functions_Group1 Initialization and de-initialization functions |
mbed_official | 330:c80ac197fa6a | 257 | * @brief Initialization and Configuration functions |
mbed_official | 330:c80ac197fa6a | 258 | * |
mbed_official | 330:c80ac197fa6a | 259 | @verbatim |
mbed_official | 330:c80ac197fa6a | 260 | =============================================================================== |
mbed_official | 330:c80ac197fa6a | 261 | ##### Initialization/de-initialization functions ##### |
mbed_official | 330:c80ac197fa6a | 262 | =============================================================================== |
mbed_official | 330:c80ac197fa6a | 263 | [..] This section provides functions to initialize and de-initialize comparators |
mbed_official | 330:c80ac197fa6a | 264 | |
mbed_official | 330:c80ac197fa6a | 265 | @endverbatim |
mbed_official | 330:c80ac197fa6a | 266 | * @{ |
mbed_official | 330:c80ac197fa6a | 267 | */ |
mbed_official | 330:c80ac197fa6a | 268 | |
mbed_official | 330:c80ac197fa6a | 269 | /** |
mbed_official | 330:c80ac197fa6a | 270 | * @brief Initializes the COMP according to the specified |
mbed_official | 330:c80ac197fa6a | 271 | * parameters in the COMP_InitTypeDef and create the associated handle. |
mbed_official | 330:c80ac197fa6a | 272 | * @note If the selected comparator is locked, initialization can't be performed. |
mbed_official | 330:c80ac197fa6a | 273 | * To unlock the configuration, perform a system reset. |
mbed_official | 330:c80ac197fa6a | 274 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 275 | * @retval HAL status |
mbed_official | 330:c80ac197fa6a | 276 | */ |
mbed_official | 330:c80ac197fa6a | 277 | HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 278 | { |
mbed_official | 330:c80ac197fa6a | 279 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 330:c80ac197fa6a | 280 | |
mbed_official | 330:c80ac197fa6a | 281 | /* Check the COMP handle allocation and lock status */ |
mbed_official | 634:ac7d6880524d | 282 | if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET)) |
mbed_official | 330:c80ac197fa6a | 283 | { |
mbed_official | 330:c80ac197fa6a | 284 | status = HAL_ERROR; |
mbed_official | 330:c80ac197fa6a | 285 | } |
mbed_official | 330:c80ac197fa6a | 286 | else |
mbed_official | 330:c80ac197fa6a | 287 | { |
mbed_official | 330:c80ac197fa6a | 288 | /* Check the parameter */ |
mbed_official | 330:c80ac197fa6a | 289 | assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance)); |
mbed_official | 330:c80ac197fa6a | 290 | assert_param(IS_COMP_INVERTINGINPUT(hcomp->Init.InvertingInput)); |
mbed_official | 330:c80ac197fa6a | 291 | assert_param(IS_COMP_NONINVERTINGINPUT(hcomp->Init.NonInvertingInput)); |
mbed_official | 330:c80ac197fa6a | 292 | assert_param(IS_COMP_NONINVERTINGINPUT_INSTANCE(hcomp->Instance, hcomp->Init.NonInvertingInput)); |
mbed_official | 330:c80ac197fa6a | 293 | assert_param(IS_COMP_OUTPUT(hcomp->Init.Output)); |
mbed_official | 330:c80ac197fa6a | 294 | assert_param(IS_COMP_OUTPUTPOL(hcomp->Init.OutputPol)); |
mbed_official | 330:c80ac197fa6a | 295 | assert_param(IS_COMP_HYSTERESIS(hcomp->Init.Hysteresis)); |
mbed_official | 330:c80ac197fa6a | 296 | assert_param(IS_COMP_MODE(hcomp->Init.Mode)); |
mbed_official | 330:c80ac197fa6a | 297 | assert_param(IS_COMP_BLANKINGSRCE(hcomp->Init.BlankingSrce)); |
mbed_official | 330:c80ac197fa6a | 298 | assert_param(IS_COMP_BLANKINGSRCE_INSTANCE(hcomp->Instance, hcomp->Init.BlankingSrce)); |
mbed_official | 330:c80ac197fa6a | 299 | |
mbed_official | 330:c80ac197fa6a | 300 | if(hcomp->Init.WindowMode != COMP_WINDOWMODE_DISABLED) |
mbed_official | 330:c80ac197fa6a | 301 | { |
mbed_official | 330:c80ac197fa6a | 302 | assert_param(IS_COMP_WINDOWMODE_INSTANCE(hcomp->Instance)); |
mbed_official | 330:c80ac197fa6a | 303 | } |
mbed_official | 330:c80ac197fa6a | 304 | |
mbed_official | 330:c80ac197fa6a | 305 | if(hcomp->State == HAL_COMP_STATE_RESET) |
mbed_official | 330:c80ac197fa6a | 306 | { |
mbed_official | 330:c80ac197fa6a | 307 | /* Init SYSCFG and the low level hardware to access comparators */ |
mbed_official | 330:c80ac197fa6a | 308 | __SYSCFG_CLK_ENABLE(); |
mbed_official | 330:c80ac197fa6a | 309 | |
mbed_official | 330:c80ac197fa6a | 310 | HAL_COMP_MspInit(hcomp); |
mbed_official | 330:c80ac197fa6a | 311 | } |
mbed_official | 330:c80ac197fa6a | 312 | |
mbed_official | 330:c80ac197fa6a | 313 | /* Set COMP parameters */ |
mbed_official | 330:c80ac197fa6a | 314 | /* Set COMPxINSEL bits according to hcomp->Init.InvertingInput value */ |
mbed_official | 330:c80ac197fa6a | 315 | /* Set COMPxNONINSEL bits according to hcomp->Init.NonInvertingInput value */ |
mbed_official | 330:c80ac197fa6a | 316 | /* Set COMPxBLANKING bits according to hcomp->Init.BlankingSrce value */ |
mbed_official | 330:c80ac197fa6a | 317 | /* Set COMPxOUTSEL bits according to hcomp->Init.Output value */ |
mbed_official | 330:c80ac197fa6a | 318 | /* Set COMPxPOL bit according to hcomp->Init.OutputPol value */ |
mbed_official | 330:c80ac197fa6a | 319 | /* Set COMPxHYST bits according to hcomp->Init.Hysteresis value */ |
mbed_official | 330:c80ac197fa6a | 320 | /* Set COMPxMODE bits according to hcomp->Init.Mode value */ |
mbed_official | 330:c80ac197fa6a | 321 | COMP_INIT(hcomp); |
mbed_official | 330:c80ac197fa6a | 322 | |
mbed_official | 330:c80ac197fa6a | 323 | /* Initialize the COMP state*/ |
mbed_official | 330:c80ac197fa6a | 324 | if(hcomp->State == HAL_COMP_STATE_RESET) |
mbed_official | 330:c80ac197fa6a | 325 | { |
mbed_official | 330:c80ac197fa6a | 326 | hcomp->State = HAL_COMP_STATE_READY; |
mbed_official | 330:c80ac197fa6a | 327 | } |
mbed_official | 330:c80ac197fa6a | 328 | } |
mbed_official | 330:c80ac197fa6a | 329 | |
mbed_official | 330:c80ac197fa6a | 330 | return status; |
mbed_official | 330:c80ac197fa6a | 331 | } |
mbed_official | 330:c80ac197fa6a | 332 | |
mbed_official | 330:c80ac197fa6a | 333 | /** |
mbed_official | 330:c80ac197fa6a | 334 | * @brief DeInitializes the COMP peripheral |
mbed_official | 330:c80ac197fa6a | 335 | * @note Deinitialization can't be performed if the COMP configuration is locked. |
mbed_official | 330:c80ac197fa6a | 336 | * To unlock the configuration, perform a system reset. |
mbed_official | 330:c80ac197fa6a | 337 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 338 | * @retval HAL status |
mbed_official | 330:c80ac197fa6a | 339 | */ |
mbed_official | 330:c80ac197fa6a | 340 | HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 341 | { |
mbed_official | 330:c80ac197fa6a | 342 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 330:c80ac197fa6a | 343 | |
mbed_official | 330:c80ac197fa6a | 344 | /* Check the COMP handle allocation and lock status */ |
mbed_official | 634:ac7d6880524d | 345 | if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET)) |
mbed_official | 330:c80ac197fa6a | 346 | { |
mbed_official | 330:c80ac197fa6a | 347 | status = HAL_ERROR; |
mbed_official | 330:c80ac197fa6a | 348 | } |
mbed_official | 330:c80ac197fa6a | 349 | else |
mbed_official | 330:c80ac197fa6a | 350 | { |
mbed_official | 330:c80ac197fa6a | 351 | /* Check the parameter */ |
mbed_official | 330:c80ac197fa6a | 352 | assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance)); |
mbed_official | 330:c80ac197fa6a | 353 | |
mbed_official | 330:c80ac197fa6a | 354 | /* Set COMP_CSR register to reset value */ |
mbed_official | 330:c80ac197fa6a | 355 | COMP_DEINIT(hcomp); |
mbed_official | 330:c80ac197fa6a | 356 | |
mbed_official | 330:c80ac197fa6a | 357 | /* DeInit the low level hardware: SYSCFG, GPIO, CLOCK and NVIC */ |
mbed_official | 330:c80ac197fa6a | 358 | HAL_COMP_MspDeInit(hcomp); |
mbed_official | 330:c80ac197fa6a | 359 | |
mbed_official | 330:c80ac197fa6a | 360 | hcomp->State = HAL_COMP_STATE_RESET; |
mbed_official | 330:c80ac197fa6a | 361 | } |
mbed_official | 330:c80ac197fa6a | 362 | |
mbed_official | 330:c80ac197fa6a | 363 | return status; |
mbed_official | 330:c80ac197fa6a | 364 | } |
mbed_official | 330:c80ac197fa6a | 365 | |
mbed_official | 330:c80ac197fa6a | 366 | /** |
mbed_official | 330:c80ac197fa6a | 367 | * @brief Initializes the COMP MSP. |
mbed_official | 330:c80ac197fa6a | 368 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 369 | * @retval None |
mbed_official | 330:c80ac197fa6a | 370 | */ |
mbed_official | 330:c80ac197fa6a | 371 | __weak void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 372 | { |
mbed_official | 330:c80ac197fa6a | 373 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 330:c80ac197fa6a | 374 | the HAL_COMP_MspInit could be implemented in the user file |
mbed_official | 330:c80ac197fa6a | 375 | */ |
mbed_official | 330:c80ac197fa6a | 376 | } |
mbed_official | 330:c80ac197fa6a | 377 | |
mbed_official | 330:c80ac197fa6a | 378 | /** |
mbed_official | 330:c80ac197fa6a | 379 | * @brief DeInitializes COMP MSP. |
mbed_official | 330:c80ac197fa6a | 380 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 381 | * @retval None |
mbed_official | 330:c80ac197fa6a | 382 | */ |
mbed_official | 330:c80ac197fa6a | 383 | __weak void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 384 | { |
mbed_official | 330:c80ac197fa6a | 385 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 330:c80ac197fa6a | 386 | the HAL_COMP_MspDeInit could be implenetd in the user file |
mbed_official | 330:c80ac197fa6a | 387 | */ |
mbed_official | 330:c80ac197fa6a | 388 | } |
mbed_official | 330:c80ac197fa6a | 389 | |
mbed_official | 330:c80ac197fa6a | 390 | /** |
mbed_official | 330:c80ac197fa6a | 391 | * @} |
mbed_official | 330:c80ac197fa6a | 392 | */ |
mbed_official | 330:c80ac197fa6a | 393 | |
mbed_official | 330:c80ac197fa6a | 394 | /** @defgroup COMP_Exported_Functions_Group2 Input and Output operation functions |
mbed_official | 330:c80ac197fa6a | 395 | * @brief Data transfers functions |
mbed_official | 330:c80ac197fa6a | 396 | * |
mbed_official | 330:c80ac197fa6a | 397 | @verbatim |
mbed_official | 330:c80ac197fa6a | 398 | =============================================================================== |
mbed_official | 330:c80ac197fa6a | 399 | ##### IO operation functions ##### |
mbed_official | 330:c80ac197fa6a | 400 | =============================================================================== |
mbed_official | 330:c80ac197fa6a | 401 | [..] |
mbed_official | 330:c80ac197fa6a | 402 | This subsection provides a set of functions allowing to manage the COMP data |
mbed_official | 330:c80ac197fa6a | 403 | transfers. |
mbed_official | 330:c80ac197fa6a | 404 | |
mbed_official | 330:c80ac197fa6a | 405 | @endverbatim |
mbed_official | 330:c80ac197fa6a | 406 | * @{ |
mbed_official | 330:c80ac197fa6a | 407 | */ |
mbed_official | 330:c80ac197fa6a | 408 | |
mbed_official | 330:c80ac197fa6a | 409 | /** |
mbed_official | 330:c80ac197fa6a | 410 | * @brief Start the comparator |
mbed_official | 330:c80ac197fa6a | 411 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 412 | * @retval HAL status |
mbed_official | 330:c80ac197fa6a | 413 | */ |
mbed_official | 330:c80ac197fa6a | 414 | HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 415 | { |
mbed_official | 330:c80ac197fa6a | 416 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 330:c80ac197fa6a | 417 | |
mbed_official | 330:c80ac197fa6a | 418 | /* Check the COMP handle allocation and lock status */ |
mbed_official | 634:ac7d6880524d | 419 | if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET)) |
mbed_official | 330:c80ac197fa6a | 420 | { |
mbed_official | 330:c80ac197fa6a | 421 | status = HAL_ERROR; |
mbed_official | 330:c80ac197fa6a | 422 | } |
mbed_official | 330:c80ac197fa6a | 423 | else |
mbed_official | 330:c80ac197fa6a | 424 | { |
mbed_official | 330:c80ac197fa6a | 425 | /* Check the parameter */ |
mbed_official | 330:c80ac197fa6a | 426 | assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance)); |
mbed_official | 330:c80ac197fa6a | 427 | |
mbed_official | 330:c80ac197fa6a | 428 | if(hcomp->State == HAL_COMP_STATE_READY) |
mbed_official | 330:c80ac197fa6a | 429 | { |
mbed_official | 330:c80ac197fa6a | 430 | /* Enable the selected comparator */ |
mbed_official | 330:c80ac197fa6a | 431 | COMP_START(hcomp); |
mbed_official | 330:c80ac197fa6a | 432 | |
mbed_official | 330:c80ac197fa6a | 433 | hcomp->State = HAL_COMP_STATE_BUSY; |
mbed_official | 330:c80ac197fa6a | 434 | } |
mbed_official | 330:c80ac197fa6a | 435 | else |
mbed_official | 330:c80ac197fa6a | 436 | { |
mbed_official | 330:c80ac197fa6a | 437 | status = HAL_ERROR; |
mbed_official | 330:c80ac197fa6a | 438 | } |
mbed_official | 330:c80ac197fa6a | 439 | } |
mbed_official | 330:c80ac197fa6a | 440 | |
mbed_official | 330:c80ac197fa6a | 441 | return status; |
mbed_official | 330:c80ac197fa6a | 442 | } |
mbed_official | 330:c80ac197fa6a | 443 | |
mbed_official | 330:c80ac197fa6a | 444 | /** |
mbed_official | 330:c80ac197fa6a | 445 | * @brief Stop the comparator |
mbed_official | 330:c80ac197fa6a | 446 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 447 | * @retval HAL status |
mbed_official | 330:c80ac197fa6a | 448 | */ |
mbed_official | 330:c80ac197fa6a | 449 | HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 450 | { |
mbed_official | 330:c80ac197fa6a | 451 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 330:c80ac197fa6a | 452 | |
mbed_official | 330:c80ac197fa6a | 453 | /* Check the COMP handle allocation and lock status */ |
mbed_official | 634:ac7d6880524d | 454 | if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET)) |
mbed_official | 330:c80ac197fa6a | 455 | { |
mbed_official | 330:c80ac197fa6a | 456 | status = HAL_ERROR; |
mbed_official | 330:c80ac197fa6a | 457 | } |
mbed_official | 330:c80ac197fa6a | 458 | else |
mbed_official | 330:c80ac197fa6a | 459 | { |
mbed_official | 330:c80ac197fa6a | 460 | /* Check the parameter */ |
mbed_official | 330:c80ac197fa6a | 461 | assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance)); |
mbed_official | 330:c80ac197fa6a | 462 | |
mbed_official | 330:c80ac197fa6a | 463 | if(hcomp->State == HAL_COMP_STATE_BUSY) |
mbed_official | 330:c80ac197fa6a | 464 | { |
mbed_official | 330:c80ac197fa6a | 465 | /* Disable the selected comparator */ |
mbed_official | 330:c80ac197fa6a | 466 | COMP_STOP(hcomp); |
mbed_official | 330:c80ac197fa6a | 467 | |
mbed_official | 330:c80ac197fa6a | 468 | hcomp->State = HAL_COMP_STATE_READY; |
mbed_official | 330:c80ac197fa6a | 469 | } |
mbed_official | 330:c80ac197fa6a | 470 | else |
mbed_official | 330:c80ac197fa6a | 471 | { |
mbed_official | 330:c80ac197fa6a | 472 | status = HAL_ERROR; |
mbed_official | 330:c80ac197fa6a | 473 | } |
mbed_official | 330:c80ac197fa6a | 474 | } |
mbed_official | 330:c80ac197fa6a | 475 | |
mbed_official | 330:c80ac197fa6a | 476 | return status; |
mbed_official | 330:c80ac197fa6a | 477 | } |
mbed_official | 330:c80ac197fa6a | 478 | |
mbed_official | 330:c80ac197fa6a | 479 | /** |
mbed_official | 330:c80ac197fa6a | 480 | * @brief Enables the interrupt and starts the comparator |
mbed_official | 330:c80ac197fa6a | 481 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 482 | * @retval HAL status. |
mbed_official | 330:c80ac197fa6a | 483 | */ |
mbed_official | 330:c80ac197fa6a | 484 | HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 485 | { |
mbed_official | 330:c80ac197fa6a | 486 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 330:c80ac197fa6a | 487 | uint32_t extiline = 0; |
mbed_official | 330:c80ac197fa6a | 488 | |
mbed_official | 330:c80ac197fa6a | 489 | /* Check the parameter */ |
mbed_official | 330:c80ac197fa6a | 490 | assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode)); |
mbed_official | 330:c80ac197fa6a | 491 | |
mbed_official | 330:c80ac197fa6a | 492 | status = HAL_COMP_Start(hcomp); |
mbed_official | 330:c80ac197fa6a | 493 | if(status == HAL_OK) |
mbed_official | 330:c80ac197fa6a | 494 | { |
mbed_official | 330:c80ac197fa6a | 495 | /* Check the Exti Line output configuration */ |
mbed_official | 330:c80ac197fa6a | 496 | extiline = __HAL_COMP_GET_EXTI_LINE(hcomp->Instance); |
mbed_official | 330:c80ac197fa6a | 497 | /* Configure the rising edge */ |
mbed_official | 330:c80ac197fa6a | 498 | if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_RISING) != RESET) |
mbed_official | 330:c80ac197fa6a | 499 | { |
mbed_official | 330:c80ac197fa6a | 500 | __HAL_COMP_EXTI_RISING_IT_ENABLE(extiline); |
mbed_official | 330:c80ac197fa6a | 501 | } |
mbed_official | 330:c80ac197fa6a | 502 | else |
mbed_official | 330:c80ac197fa6a | 503 | { |
mbed_official | 330:c80ac197fa6a | 504 | __HAL_COMP_EXTI_RISING_IT_DISABLE(extiline); |
mbed_official | 330:c80ac197fa6a | 505 | } |
mbed_official | 330:c80ac197fa6a | 506 | /* Configure the falling edge */ |
mbed_official | 330:c80ac197fa6a | 507 | if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_FALLING) != RESET) |
mbed_official | 330:c80ac197fa6a | 508 | { |
mbed_official | 330:c80ac197fa6a | 509 | __HAL_COMP_EXTI_FALLING_IT_ENABLE(extiline); |
mbed_official | 330:c80ac197fa6a | 510 | } |
mbed_official | 330:c80ac197fa6a | 511 | else |
mbed_official | 330:c80ac197fa6a | 512 | { |
mbed_official | 330:c80ac197fa6a | 513 | __HAL_COMP_EXTI_FALLING_IT_DISABLE(extiline); |
mbed_official | 330:c80ac197fa6a | 514 | } |
mbed_official | 330:c80ac197fa6a | 515 | /* Enable Exti interrupt mode */ |
mbed_official | 330:c80ac197fa6a | 516 | __HAL_COMP_EXTI_ENABLE_IT(extiline); |
mbed_official | 330:c80ac197fa6a | 517 | /* Clear COMP Exti pending bit */ |
mbed_official | 330:c80ac197fa6a | 518 | __HAL_COMP_EXTI_CLEAR_FLAG(extiline); |
mbed_official | 330:c80ac197fa6a | 519 | } |
mbed_official | 330:c80ac197fa6a | 520 | |
mbed_official | 330:c80ac197fa6a | 521 | return status; |
mbed_official | 330:c80ac197fa6a | 522 | } |
mbed_official | 330:c80ac197fa6a | 523 | |
mbed_official | 330:c80ac197fa6a | 524 | /** |
mbed_official | 330:c80ac197fa6a | 525 | * @brief Disable the interrupt and Stop the comparator |
mbed_official | 330:c80ac197fa6a | 526 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 527 | * @retval HAL status |
mbed_official | 330:c80ac197fa6a | 528 | */ |
mbed_official | 330:c80ac197fa6a | 529 | HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 530 | { |
mbed_official | 330:c80ac197fa6a | 531 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 330:c80ac197fa6a | 532 | |
mbed_official | 330:c80ac197fa6a | 533 | /* Disable the Exti Line interrupt mode */ |
mbed_official | 330:c80ac197fa6a | 534 | __HAL_COMP_EXTI_DISABLE_IT(__HAL_COMP_GET_EXTI_LINE(hcomp->Instance)); |
mbed_official | 330:c80ac197fa6a | 535 | |
mbed_official | 330:c80ac197fa6a | 536 | status = HAL_COMP_Stop(hcomp); |
mbed_official | 330:c80ac197fa6a | 537 | |
mbed_official | 330:c80ac197fa6a | 538 | return status; |
mbed_official | 330:c80ac197fa6a | 539 | } |
mbed_official | 330:c80ac197fa6a | 540 | |
mbed_official | 330:c80ac197fa6a | 541 | /** |
mbed_official | 330:c80ac197fa6a | 542 | * @brief Comparator IRQ Handler |
mbed_official | 330:c80ac197fa6a | 543 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 544 | * @retval HAL status |
mbed_official | 330:c80ac197fa6a | 545 | */ |
mbed_official | 330:c80ac197fa6a | 546 | void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 547 | { |
mbed_official | 330:c80ac197fa6a | 548 | uint32_t extiline = __HAL_COMP_GET_EXTI_LINE(hcomp->Instance); |
mbed_official | 330:c80ac197fa6a | 549 | |
mbed_official | 330:c80ac197fa6a | 550 | /* Check COMP Exti flag */ |
mbed_official | 330:c80ac197fa6a | 551 | if(__HAL_COMP_EXTI_GET_FLAG(extiline) != RESET) |
mbed_official | 330:c80ac197fa6a | 552 | { |
mbed_official | 330:c80ac197fa6a | 553 | /* Clear COMP Exti pending bit */ |
mbed_official | 330:c80ac197fa6a | 554 | __HAL_COMP_EXTI_CLEAR_FLAG(extiline); |
mbed_official | 330:c80ac197fa6a | 555 | |
mbed_official | 330:c80ac197fa6a | 556 | /* COMP trigger user callback */ |
mbed_official | 330:c80ac197fa6a | 557 | HAL_COMP_TriggerCallback(hcomp); |
mbed_official | 330:c80ac197fa6a | 558 | } |
mbed_official | 330:c80ac197fa6a | 559 | } |
mbed_official | 330:c80ac197fa6a | 560 | |
mbed_official | 330:c80ac197fa6a | 561 | /** |
mbed_official | 330:c80ac197fa6a | 562 | * @} |
mbed_official | 330:c80ac197fa6a | 563 | */ |
mbed_official | 330:c80ac197fa6a | 564 | |
mbed_official | 330:c80ac197fa6a | 565 | /** @defgroup COMP_Exported_Functions_Group3 Peripheral Control functions |
mbed_official | 330:c80ac197fa6a | 566 | * @brief management functions |
mbed_official | 330:c80ac197fa6a | 567 | * |
mbed_official | 330:c80ac197fa6a | 568 | @verbatim |
mbed_official | 330:c80ac197fa6a | 569 | =============================================================================== |
mbed_official | 330:c80ac197fa6a | 570 | ##### Peripheral Control functions ##### |
mbed_official | 330:c80ac197fa6a | 571 | =============================================================================== |
mbed_official | 330:c80ac197fa6a | 572 | [..] |
mbed_official | 330:c80ac197fa6a | 573 | This subsection provides a set of functions allowing to control the COMP data |
mbed_official | 330:c80ac197fa6a | 574 | transfers. |
mbed_official | 330:c80ac197fa6a | 575 | |
mbed_official | 330:c80ac197fa6a | 576 | @endverbatim |
mbed_official | 330:c80ac197fa6a | 577 | * @{ |
mbed_official | 330:c80ac197fa6a | 578 | */ |
mbed_official | 330:c80ac197fa6a | 579 | |
mbed_official | 330:c80ac197fa6a | 580 | /** |
mbed_official | 330:c80ac197fa6a | 581 | * @brief Lock the selected comparator configuration. |
mbed_official | 330:c80ac197fa6a | 582 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 583 | * @retval HAL status |
mbed_official | 330:c80ac197fa6a | 584 | */ |
mbed_official | 330:c80ac197fa6a | 585 | HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 586 | { |
mbed_official | 330:c80ac197fa6a | 587 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 330:c80ac197fa6a | 588 | |
mbed_official | 330:c80ac197fa6a | 589 | /* Check the COMP handle allocation and lock status */ |
mbed_official | 634:ac7d6880524d | 590 | if((hcomp == HAL_NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET)) |
mbed_official | 330:c80ac197fa6a | 591 | { |
mbed_official | 330:c80ac197fa6a | 592 | status = HAL_ERROR; |
mbed_official | 330:c80ac197fa6a | 593 | } |
mbed_official | 330:c80ac197fa6a | 594 | else |
mbed_official | 330:c80ac197fa6a | 595 | { |
mbed_official | 330:c80ac197fa6a | 596 | /* Check the parameter */ |
mbed_official | 330:c80ac197fa6a | 597 | assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance)); |
mbed_official | 330:c80ac197fa6a | 598 | |
mbed_official | 330:c80ac197fa6a | 599 | /* Set lock flag */ |
mbed_official | 330:c80ac197fa6a | 600 | hcomp->State |= COMP_STATE_BIT_LOCK; |
mbed_official | 330:c80ac197fa6a | 601 | |
mbed_official | 330:c80ac197fa6a | 602 | /* Set the lock bit corresponding to selected comparator */ |
mbed_official | 330:c80ac197fa6a | 603 | COMP_LOCK(hcomp); |
mbed_official | 330:c80ac197fa6a | 604 | } |
mbed_official | 330:c80ac197fa6a | 605 | |
mbed_official | 330:c80ac197fa6a | 606 | return status; |
mbed_official | 330:c80ac197fa6a | 607 | } |
mbed_official | 330:c80ac197fa6a | 608 | |
mbed_official | 330:c80ac197fa6a | 609 | /** |
mbed_official | 330:c80ac197fa6a | 610 | * @brief Return the output level (high or low) of the selected comparator. |
mbed_official | 330:c80ac197fa6a | 611 | * The output level depends on the selected polarity. |
mbed_official | 330:c80ac197fa6a | 612 | * If the polarity is not inverted: |
mbed_official | 330:c80ac197fa6a | 613 | * - Comparator output is low when the non-inverting input is at a lower |
mbed_official | 330:c80ac197fa6a | 614 | * voltage than the inverting input |
mbed_official | 330:c80ac197fa6a | 615 | * - Comparator output is high when the non-inverting input is at a higher |
mbed_official | 330:c80ac197fa6a | 616 | * voltage than the inverting input |
mbed_official | 330:c80ac197fa6a | 617 | * If the polarity is inverted: |
mbed_official | 330:c80ac197fa6a | 618 | * - Comparator output is high when the non-inverting input is at a lower |
mbed_official | 330:c80ac197fa6a | 619 | * voltage than the inverting input |
mbed_official | 330:c80ac197fa6a | 620 | * - Comparator output is low when the non-inverting input is at a higher |
mbed_official | 330:c80ac197fa6a | 621 | * voltage than the inverting input |
mbed_official | 330:c80ac197fa6a | 622 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 623 | * @retval Returns the selected comparator output level: COMP_OUTPUTLEVEL_LOW or COMP_OUTPUTLEVEL_HIGH. |
mbed_official | 330:c80ac197fa6a | 624 | * |
mbed_official | 330:c80ac197fa6a | 625 | */ |
mbed_official | 330:c80ac197fa6a | 626 | uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 627 | { |
mbed_official | 330:c80ac197fa6a | 628 | uint32_t level=0; |
mbed_official | 330:c80ac197fa6a | 629 | |
mbed_official | 330:c80ac197fa6a | 630 | /* Check the parameter */ |
mbed_official | 330:c80ac197fa6a | 631 | assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance)); |
mbed_official | 330:c80ac197fa6a | 632 | |
mbed_official | 330:c80ac197fa6a | 633 | level = READ_BIT(hcomp->Instance->CSR, COMP_CSR_COMPxOUT); |
mbed_official | 330:c80ac197fa6a | 634 | |
mbed_official | 330:c80ac197fa6a | 635 | if(level != 0) |
mbed_official | 330:c80ac197fa6a | 636 | { |
mbed_official | 330:c80ac197fa6a | 637 | return(COMP_OUTPUTLEVEL_HIGH); |
mbed_official | 330:c80ac197fa6a | 638 | } |
mbed_official | 330:c80ac197fa6a | 639 | return(COMP_OUTPUTLEVEL_LOW); |
mbed_official | 330:c80ac197fa6a | 640 | } |
mbed_official | 330:c80ac197fa6a | 641 | |
mbed_official | 330:c80ac197fa6a | 642 | /** |
mbed_official | 330:c80ac197fa6a | 643 | * @brief Comparator callback. |
mbed_official | 330:c80ac197fa6a | 644 | * @param hcomp: COMP handle |
mbed_official | 330:c80ac197fa6a | 645 | * @retval None |
mbed_official | 330:c80ac197fa6a | 646 | */ |
mbed_official | 330:c80ac197fa6a | 647 | __weak void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 648 | { |
mbed_official | 330:c80ac197fa6a | 649 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 330:c80ac197fa6a | 650 | the HAL_COMP_TriggerCallback should be implemented in the user file |
mbed_official | 330:c80ac197fa6a | 651 | */ |
mbed_official | 330:c80ac197fa6a | 652 | } |
mbed_official | 330:c80ac197fa6a | 653 | |
mbed_official | 330:c80ac197fa6a | 654 | |
mbed_official | 330:c80ac197fa6a | 655 | /** |
mbed_official | 330:c80ac197fa6a | 656 | * @} |
mbed_official | 330:c80ac197fa6a | 657 | */ |
mbed_official | 330:c80ac197fa6a | 658 | |
mbed_official | 330:c80ac197fa6a | 659 | /** @defgroup COMP_Exported_Functions_Group4 Peripheral State functions |
mbed_official | 330:c80ac197fa6a | 660 | * @brief Peripheral State functions |
mbed_official | 330:c80ac197fa6a | 661 | * |
mbed_official | 330:c80ac197fa6a | 662 | @verbatim |
mbed_official | 330:c80ac197fa6a | 663 | =============================================================================== |
mbed_official | 330:c80ac197fa6a | 664 | ##### Peripheral State functions ##### |
mbed_official | 330:c80ac197fa6a | 665 | =============================================================================== |
mbed_official | 330:c80ac197fa6a | 666 | [..] |
mbed_official | 330:c80ac197fa6a | 667 | This subsection permit to get in run-time the status of the peripheral |
mbed_official | 330:c80ac197fa6a | 668 | and the data flow. |
mbed_official | 330:c80ac197fa6a | 669 | |
mbed_official | 330:c80ac197fa6a | 670 | @endverbatim |
mbed_official | 330:c80ac197fa6a | 671 | * @{ |
mbed_official | 330:c80ac197fa6a | 672 | */ |
mbed_official | 330:c80ac197fa6a | 673 | |
mbed_official | 330:c80ac197fa6a | 674 | /** |
mbed_official | 330:c80ac197fa6a | 675 | * @brief Return the COMP state |
mbed_official | 330:c80ac197fa6a | 676 | * @param hcomp : COMP handle |
mbed_official | 330:c80ac197fa6a | 677 | * @retval HAL state |
mbed_official | 330:c80ac197fa6a | 678 | */ |
mbed_official | 330:c80ac197fa6a | 679 | HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp) |
mbed_official | 330:c80ac197fa6a | 680 | { |
mbed_official | 330:c80ac197fa6a | 681 | /* Check the COMP handle allocation */ |
mbed_official | 634:ac7d6880524d | 682 | if(hcomp == HAL_NULL) |
mbed_official | 330:c80ac197fa6a | 683 | { |
mbed_official | 330:c80ac197fa6a | 684 | return HAL_COMP_STATE_RESET; |
mbed_official | 330:c80ac197fa6a | 685 | } |
mbed_official | 330:c80ac197fa6a | 686 | |
mbed_official | 330:c80ac197fa6a | 687 | /* Check the parameter */ |
mbed_official | 330:c80ac197fa6a | 688 | assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance)); |
mbed_official | 330:c80ac197fa6a | 689 | |
mbed_official | 330:c80ac197fa6a | 690 | return hcomp->State; |
mbed_official | 330:c80ac197fa6a | 691 | } |
mbed_official | 330:c80ac197fa6a | 692 | /** |
mbed_official | 330:c80ac197fa6a | 693 | * @} |
mbed_official | 330:c80ac197fa6a | 694 | */ |
mbed_official | 330:c80ac197fa6a | 695 | |
mbed_official | 330:c80ac197fa6a | 696 | /** |
mbed_official | 330:c80ac197fa6a | 697 | * @} |
mbed_official | 330:c80ac197fa6a | 698 | */ |
mbed_official | 330:c80ac197fa6a | 699 | |
mbed_official | 330:c80ac197fa6a | 700 | #endif /* HAL_COMP_MODULE_ENABLED */ |
mbed_official | 330:c80ac197fa6a | 701 | /** |
mbed_official | 330:c80ac197fa6a | 702 | * @} |
mbed_official | 330:c80ac197fa6a | 703 | */ |
mbed_official | 330:c80ac197fa6a | 704 | |
mbed_official | 330:c80ac197fa6a | 705 | /** |
mbed_official | 330:c80ac197fa6a | 706 | * @} |
mbed_official | 330:c80ac197fa6a | 707 | */ |
mbed_official | 330:c80ac197fa6a | 708 | |
mbed_official | 330:c80ac197fa6a | 709 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |