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