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:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

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