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:
Wed Nov 05 14:30:08 2014 +0000
Revision:
387:643a59b3dbac
Parent:
382:ee426a420dbb
Child:
489:119543c9f674
Synchronized with git revision cfeccf154f8f92c3ea9c0c881c577c154537aecc

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

Exporters: STM32L053R8 - IAR exporter

Who changed what in which revision?

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