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