mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
Parent:
targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_comp.c@144:ef7eb2e8f9f7
Child:
156:95d6b41a828b
This updates the lib to the mbed lib v128

NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.

Who changed what in which revision?

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