mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Mon Sep 28 10:45:10 2015 +0100
Revision:
630:825f75ca301e
Parent:
441:d2c15dda23c1
Synchronized with git revision 54fbe4144faf309c37205a5d39fa665daa919f10

Full URL: https://github.com/mbedmicro/mbed/commit/54fbe4144faf309c37205a5d39fa665daa919f10/

NUCLEO_F031K6 : Add new target

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