mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Jan 06 16:15:36 2015 +0000
Revision:
441:d2c15dda23c1
Parent:
392:2b59412bb664
Synchronized with git revision 245a60b29caabb42eabdd19658eeac7c3f68313b

Full URL: https://github.com/mbedmicro/mbed/commit/245a60b29caabb42eabdd19658eeac7c3f68313b/

NUCLEO_F072RB/F091RC - adding target to rtos lib and exporter for coide and gcc_arm

Who changed what in which revision?

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