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