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