mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu May 22 20:00:09 2014 +0100
Revision:
205:c41fc65bcfb4
Child:
218:44081b78fdc2
Synchronized with git revision ea4b6f76efab17a3f7d7777b0cc1ef05fec6d1cb

Full URL: https://github.com/mbedmicro/mbed/commit/ea4b6f76efab17a3f7d7777b0cc1ef05fec6d1cb/

[NUCLEO_F072RB] cmsis files

Who changed what in which revision?

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