anyThing Connected Team / mbed-dev

Dependents:   BREAK_SENSOR_LED

Fork of mbed-dev by mbed official

Committer:
Anythingconnected
Date:
Mon Dec 18 10:14:27 2017 +0000
Revision:
180:d79f997829d6
Parent:
151:5eaa88a5bcc7
Getting byte by byte read to work

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /**
<> 144:ef7eb2e8f9f7 2 ******************************************************************************
<> 144:ef7eb2e8f9f7 3 * @file stm32l0xx_hal_comp.c
<> 144:ef7eb2e8f9f7 4 * @author MCD Application Team
<> 151:5eaa88a5bcc7 5 * @version V1.7.0
<> 151:5eaa88a5bcc7 6 * @date 31-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:
<> 151:5eaa88a5bcc7 10 * + Initialization and de-initialization functions
<> 151:5eaa88a5bcc7 11 * + Start/Stop operation functions in polling mode
<> 151:5eaa88a5bcc7 12 * + Start/Stop operation functions in interrupt mode (through EXTI interrupt)
<> 151:5eaa88a5bcc7 13 * + Peripheral control functions
<> 151:5eaa88a5bcc7 14 * + Peripheral state functions
<> 144:ef7eb2e8f9f7 15 *
<> 144:ef7eb2e8f9f7 16 @verbatim
<> 144:ef7eb2e8f9f7 17 ================================================================================
<> 144:ef7eb2e8f9f7 18 ##### COMP Peripheral features #####
<> 144:ef7eb2e8f9f7 19 ================================================================================
<> 144:ef7eb2e8f9f7 20
<> 144:ef7eb2e8f9f7 21 [..]
<> 151:5eaa88a5bcc7 22 The STM32L0xx device family integrates two analog comparators instances
<> 151:5eaa88a5bcc7 23 COMP1 and COMP2:
<> 151:5eaa88a5bcc7 24 (#) The COMP input minus (inverting input) and input plus (non inverting input)
<> 151:5eaa88a5bcc7 25 can be set to internal references or to GPIO pins
<> 151:5eaa88a5bcc7 26 (refer to GPIO list in reference manual).
<> 144:ef7eb2e8f9f7 27
<> 151:5eaa88a5bcc7 28 (#) The COMP output level is available using HAL_COMP_GetOutputLevel()
<> 151:5eaa88a5bcc7 29 and can be redirected to other peripherals: GPIO pins (in mode
<> 151:5eaa88a5bcc7 30 alternate functions for comparator), timers.
<> 151:5eaa88a5bcc7 31 (refer to GPIO list in reference manual).
<> 144:ef7eb2e8f9f7 32
<> 151:5eaa88a5bcc7 33 (#) Pairs of comparators instances can be combined in window mode
<> 151:5eaa88a5bcc7 34 (2 consecutive instances odd and even COMP<x> and COMP<x+1>).
<> 144:ef7eb2e8f9f7 35
<> 151:5eaa88a5bcc7 36 (#) The comparators have interrupt capability through the EXTI controller
<> 151:5eaa88a5bcc7 37 with wake-up from sleep and stop modes:
<> 144:ef7eb2e8f9f7 38 (++) COMP1 is internally connected to EXTI Line 21
<> 144:ef7eb2e8f9f7 39 (++) COMP2 is internally connected to EXTI Line 22
<> 144:ef7eb2e8f9f7 40
<> 151:5eaa88a5bcc7 41 From the corresponding IRQ handler, the right interrupt source can be retrieved
<> 151:5eaa88a5bcc7 42 using macro __HAL_COMP_COMP1_EXTI_GET_FLAG() and __HAL_COMP_COMP2_EXTI_GET_FLAG().
<> 144:ef7eb2e8f9f7 43
<> 144:ef7eb2e8f9f7 44 ##### How to use this driver #####
<> 144:ef7eb2e8f9f7 45 ================================================================================
<> 144:ef7eb2e8f9f7 46 [..]
<> 151:5eaa88a5bcc7 47 This driver provides functions to configure and program the comparator instances
<> 151:5eaa88a5bcc7 48 of STM32L0xx devices.
<> 144:ef7eb2e8f9f7 49
<> 144:ef7eb2e8f9f7 50 To use the comparator, perform the following steps:
<> 151:5eaa88a5bcc7 51
<> 151:5eaa88a5bcc7 52 (#) Initialize the COMP low level resources by implementing the HAL_COMP_MspInit():
<> 151:5eaa88a5bcc7 53 (++) Configure the GPIO connected to comparator inputs plus and minus in analog mode
<> 151:5eaa88a5bcc7 54 using HAL_GPIO_Init().
<> 151:5eaa88a5bcc7 55 (++) If needed, configure the GPIO connected to comparator output in alternate function mode
<> 151:5eaa88a5bcc7 56 using HAL_GPIO_Init().
<> 144:ef7eb2e8f9f7 57 (++) If required enable the COMP interrupt by configuring and enabling EXTI line in Interrupt mode and
<> 144:ef7eb2e8f9f7 58 selecting the desired sensitivity level using HAL_GPIO_Init() function. After that enable the comparator
<> 144:ef7eb2e8f9f7 59 interrupt vector using HAL_NVIC_EnableIRQ() function.
<> 151:5eaa88a5bcc7 60
<> 144:ef7eb2e8f9f7 61 (#) Configure the comparator using HAL_COMP_Init() function:
<> 151:5eaa88a5bcc7 62 (++) Select the input minus (inverting input)
<> 151:5eaa88a5bcc7 63 (++) Select the input plus (non-inverting input)
<> 144:ef7eb2e8f9f7 64 (++) Select the output polarity
<> 144:ef7eb2e8f9f7 65 (++) Select the power mode
<> 144:ef7eb2e8f9f7 66 (++) Select the window mode
<> 151:5eaa88a5bcc7 67
<> 151:5eaa88a5bcc7 68 -@@- HAL_COMP_Init() calls internally __HAL_RCC_SYSCFG_CLK_ENABLE()
<> 151:5eaa88a5bcc7 69 to enable internal control clock of the comparators.
<> 151:5eaa88a5bcc7 70 However, this is a legacy strategy. In future STM32 families,
<> 151:5eaa88a5bcc7 71 COMP clock enable must be implemented by user in "HAL_COMP_MspInit()".
<> 151:5eaa88a5bcc7 72 Therefore, for compatibility anticipation, it is recommended to
<> 151:5eaa88a5bcc7 73 implement __HAL_RCC_SYSCFG_CLK_ENABLE() in "HAL_COMP_MspInit()".
<> 151:5eaa88a5bcc7 74
<> 151:5eaa88a5bcc7 75 (#) Reconfiguration on-the-fly of comparator can be done by calling again
<> 151:5eaa88a5bcc7 76 function HAL_COMP_Init() with new input structure parameters values.
<> 151:5eaa88a5bcc7 77
<> 151:5eaa88a5bcc7 78 (#) Enable the comparator using HAL_COMP_Start() function.
<> 151:5eaa88a5bcc7 79
<> 151:5eaa88a5bcc7 80 (#) Use HAL_COMP_TriggerCallback() or HAL_COMP_GetOutputLevel() functions
<> 151:5eaa88a5bcc7 81 to manage comparator outputs (events and output level).
<> 151:5eaa88a5bcc7 82
<> 151:5eaa88a5bcc7 83 (#) Disable the comparator using HAL_COMP_Stop() function.
<> 151:5eaa88a5bcc7 84
<> 151:5eaa88a5bcc7 85 (#) De-initialize the comparator using HAL_COMP_DeInit() function.
<> 151:5eaa88a5bcc7 86
<> 151:5eaa88a5bcc7 87 (#) For safety purpose, comparator configuration can be locked using HAL_COMP_Lock() function.
<> 151:5eaa88a5bcc7 88 The only way to unlock the comparator is a device hardware reset.
<> 144:ef7eb2e8f9f7 89
<> 144:ef7eb2e8f9f7 90 @endverbatim
<> 144:ef7eb2e8f9f7 91 ******************************************************************************
<> 151:5eaa88a5bcc7 92
<> 151:5eaa88a5bcc7 93 Table 1. COMP inputs and output for STM32L0xx devices
<> 151:5eaa88a5bcc7 94 +---------------------------------------------------------+
<> 151:5eaa88a5bcc7 95 | | | COMP1 | COMP2 |
<> 151:5eaa88a5bcc7 96 |----------------|----------------|-----------|-----------|
<> 151:5eaa88a5bcc7 97 | | IO1 | PA1 | PA3 |
<> 151:5eaa88a5bcc7 98 | Input plus | IO2 | --- | PA4 |
<> 151:5eaa88a5bcc7 99 | | IO3 | --- | PB5 |
<> 151:5eaa88a5bcc7 100 | | IO4 | --- | PB6 |
<> 151:5eaa88a5bcc7 101 | | IO5 | --- | PB7 |
<> 151:5eaa88a5bcc7 102 |----------------|----------------|-----------------------|
<> 151:5eaa88a5bcc7 103 | | 1/4 VrefInt | --- | Available |
<> 151:5eaa88a5bcc7 104 | | 1/2 VrefInt | --- | Available |
<> 151:5eaa88a5bcc7 105 | | 3/4 VrefInt | --- | Available |
<> 151:5eaa88a5bcc7 106 | Input minus | VrefInt | Available | Available |
<> 151:5eaa88a5bcc7 107 | | DAC1 channel 1 | Available | Available |
<> 151:5eaa88a5bcc7 108 | | DAC1 channel 2 | Available | Available |
<> 151:5eaa88a5bcc7 109 | | IO1 | PA0 | PA2 |
<> 151:5eaa88a5bcc7 110 | | IO2 | PA5 | PA5 |
<> 151:5eaa88a5bcc7 111 | | IO3 | --- | PB3 |
<> 151:5eaa88a5bcc7 112 +---------------------------------------------------------+
<> 151:5eaa88a5bcc7 113 | Output | | PA0 (1) | PA2 (1) |
<> 151:5eaa88a5bcc7 114 | | | PA6 (1) | PA7 (1) |
<> 151:5eaa88a5bcc7 115 | | | PA11 (1) | PA12 (1) |
<> 151:5eaa88a5bcc7 116 | | | LPTIM | LPTIM |
<> 151:5eaa88a5bcc7 117 | | | TIM (2) | TIM (2) |
<> 151:5eaa88a5bcc7 118 +-----------------------------------------------------------+
<> 151:5eaa88a5bcc7 119 (1) GPIO must be set to alternate function for comparator
<> 151:5eaa88a5bcc7 120 (2) Comparators output to timers is set in timers instances.
<> 151:5eaa88a5bcc7 121
<> 151:5eaa88a5bcc7 122 ******************************************************************************
<> 144:ef7eb2e8f9f7 123 * @attention
<> 144:ef7eb2e8f9f7 124 *
<> 144:ef7eb2e8f9f7 125 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
<> 144:ef7eb2e8f9f7 126 *
<> 144:ef7eb2e8f9f7 127 * Redistribution and use in source and binary forms, with or without modification,
<> 144:ef7eb2e8f9f7 128 * are permitted provided that the following conditions are met:
<> 144:ef7eb2e8f9f7 129 * 1. Redistributions of source code must retain the above copyright notice,
<> 144:ef7eb2e8f9f7 130 * this list of conditions and the following disclaimer.
<> 144:ef7eb2e8f9f7 131 * 2. Redistributions in binary form must reproduce the above copyright notice,
<> 144:ef7eb2e8f9f7 132 * this list of conditions and the following disclaimer in the documentation
<> 144:ef7eb2e8f9f7 133 * and/or other materials provided with the distribution.
<> 144:ef7eb2e8f9f7 134 * 3. Neither the name of STMicroelectronics nor the names of its contributors
<> 144:ef7eb2e8f9f7 135 * may be used to endorse or promote products derived from this software
<> 144:ef7eb2e8f9f7 136 * without specific prior written permission.
<> 144:ef7eb2e8f9f7 137 *
<> 144:ef7eb2e8f9f7 138 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
<> 144:ef7eb2e8f9f7 139 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<> 144:ef7eb2e8f9f7 140 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 144:ef7eb2e8f9f7 141 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
<> 144:ef7eb2e8f9f7 142 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<> 144:ef7eb2e8f9f7 143 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
<> 144:ef7eb2e8f9f7 144 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
<> 144:ef7eb2e8f9f7 145 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
<> 144:ef7eb2e8f9f7 146 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<> 144:ef7eb2e8f9f7 147 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 144:ef7eb2e8f9f7 148 *
<> 144:ef7eb2e8f9f7 149 ******************************************************************************
<> 144:ef7eb2e8f9f7 150 */
<> 144:ef7eb2e8f9f7 151
<> 144:ef7eb2e8f9f7 152 /* Includes ------------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 153 #include "stm32l0xx_hal.h"
<> 144:ef7eb2e8f9f7 154
<> 144:ef7eb2e8f9f7 155 /** @addtogroup STM32L0xx_HAL_Driver
<> 144:ef7eb2e8f9f7 156 * @{
<> 144:ef7eb2e8f9f7 157 */
<> 144:ef7eb2e8f9f7 158
<> 151:5eaa88a5bcc7 159 /** @defgroup COMP COMP
<> 144:ef7eb2e8f9f7 160 * @brief COMP HAL module driver
<> 144:ef7eb2e8f9f7 161 * @{
<> 144:ef7eb2e8f9f7 162 */
<> 144:ef7eb2e8f9f7 163
<> 151:5eaa88a5bcc7 164 #ifdef HAL_COMP_MODULE_ENABLED
<> 151:5eaa88a5bcc7 165
<> 144:ef7eb2e8f9f7 166 /* Private typedef -----------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 167 /* Private define ------------------------------------------------------------*/
<> 151:5eaa88a5bcc7 168 /** @addtogroup COMP_Private_Constants
<> 151:5eaa88a5bcc7 169 * @{
<> 151:5eaa88a5bcc7 170 */
<> 151:5eaa88a5bcc7 171
<> 151:5eaa88a5bcc7 172 /* Delay for COMP startup time. */
<> 151:5eaa88a5bcc7 173 /* Note: Delay required to reach propagation delay specification. */
<> 151:5eaa88a5bcc7 174 /* Literal set to maximum value (refer to device datasheet, */
<> 151:5eaa88a5bcc7 175 /* parameter "tSTART"). */
<> 151:5eaa88a5bcc7 176 /* Unit: us */
<> 151:5eaa88a5bcc7 177 #define COMP_DELAY_STARTUP_US ((uint32_t) 25U) /*!< Delay for COMP startup time */
<> 144:ef7eb2e8f9f7 178
<> 151:5eaa88a5bcc7 179 /* Delay for COMP voltage scaler stabilization time (voltage from VrefInt, */
<> 151:5eaa88a5bcc7 180 /* delay based on VrefInt startup time). */
<> 151:5eaa88a5bcc7 181 /* Literal set to maximum value (refer to device datasheet, */
<> 151:5eaa88a5bcc7 182 /* parameter "TVREFINT"). */
<> 151:5eaa88a5bcc7 183 /* Unit: us */
<> 151:5eaa88a5bcc7 184 #define COMP_DELAY_VOLTAGE_SCALER_STAB_US ((uint32_t)3000U) /*!< Delay for COMP voltage scaler stabilization time */
<> 144:ef7eb2e8f9f7 185
<> 151:5eaa88a5bcc7 186 #define COMP_OUTPUT_LEVEL_BITOFFSET_POS ((uint32_t) 30U)
<> 151:5eaa88a5bcc7 187
<> 151:5eaa88a5bcc7 188 #define C_REV_ID_A 0x1000U /* Cut1.0 */
<> 151:5eaa88a5bcc7 189 #define C_REV_ID_Z 0x1008U /* Cut1.1 */
<> 151:5eaa88a5bcc7 190 #define C_REV_ID_Y 0x1003U /* Cut1.2 */
<> 151:5eaa88a5bcc7 191
<> 151:5eaa88a5bcc7 192 #define C_DEV_ID_L073 0x447U
<> 151:5eaa88a5bcc7 193 #define C_DEV_ID_L053 0x417U
<> 151:5eaa88a5bcc7 194
<> 144:ef7eb2e8f9f7 195 /**
<> 144:ef7eb2e8f9f7 196 * @}
<> 144:ef7eb2e8f9f7 197 */
<> 144:ef7eb2e8f9f7 198
<> 151:5eaa88a5bcc7 199 /* Private macro -------------------------------------------------------------*/
<> 151:5eaa88a5bcc7 200 /* Private variables ---------------------------------------------------------*/
<> 151:5eaa88a5bcc7 201 /* Private function prototypes -----------------------------------------------*/
<> 151:5eaa88a5bcc7 202 /* Exported functions --------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 203
<> 151:5eaa88a5bcc7 204 /** @defgroup COMP_Exported_Functions COMP Exported Functions
<> 144:ef7eb2e8f9f7 205 * @{
<> 144:ef7eb2e8f9f7 206 */
<> 144:ef7eb2e8f9f7 207
<> 151:5eaa88a5bcc7 208 /** @defgroup COMP_Exported_Functions_Group1 Initialization/de-initialization functions
<> 151:5eaa88a5bcc7 209 * @brief Initialization and de-initialization functions.
<> 144:ef7eb2e8f9f7 210 *
<> 144:ef7eb2e8f9f7 211 @verbatim
<> 144:ef7eb2e8f9f7 212 ===============================================================================
<> 144:ef7eb2e8f9f7 213 ##### Initialization and de-initialization functions #####
<> 144:ef7eb2e8f9f7 214 ===============================================================================
<> 144:ef7eb2e8f9f7 215 [..] This section provides functions to initialize and de-initialize comparators
<> 144:ef7eb2e8f9f7 216
<> 144:ef7eb2e8f9f7 217 @endverbatim
<> 144:ef7eb2e8f9f7 218 * @{
<> 144:ef7eb2e8f9f7 219 */
<> 144:ef7eb2e8f9f7 220
<> 144:ef7eb2e8f9f7 221 /**
<> 151:5eaa88a5bcc7 222 * @brief Initialize the COMP according to the specified
<> 151:5eaa88a5bcc7 223 * parameters in the COMP_InitTypeDef and initialize the associated handle.
<> 144:ef7eb2e8f9f7 224 * @note If the selected comparator is locked, initialization can't be performed.
<> 144:ef7eb2e8f9f7 225 * To unlock the configuration, perform a system reset.
<> 144:ef7eb2e8f9f7 226 * @note When the LPTIM connection is enabled, the following pins LPTIM_IN1(PB5, PC0)
<> 151:5eaa88a5bcc7 227 and LPTIM_IN2(PB7, PC2) should not be configured in alternate function.
<> 151:5eaa88a5bcc7 228 * @param hcomp COMP handle
<> 144:ef7eb2e8f9f7 229 * @retval HAL status
<> 144:ef7eb2e8f9f7 230 */
<> 144:ef7eb2e8f9f7 231 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
<> 144:ef7eb2e8f9f7 232 {
<> 151:5eaa88a5bcc7 233 uint32_t tmp_csr = 0U;
<> 151:5eaa88a5bcc7 234 uint32_t exti_line = 0U;
<> 151:5eaa88a5bcc7 235 uint32_t comp_voltage_scaler_not_initialized = 0U;
<> 151:5eaa88a5bcc7 236 __IO uint32_t wait_loop_index = 0U;
<> 151:5eaa88a5bcc7 237 HAL_StatusTypeDef status = HAL_OK;
<> 144:ef7eb2e8f9f7 238
<> 144:ef7eb2e8f9f7 239 /* Check the COMP handle allocation and lock status */
<> 151:5eaa88a5bcc7 240 if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
<> 144:ef7eb2e8f9f7 241 {
<> 144:ef7eb2e8f9f7 242 status = HAL_ERROR;
<> 144:ef7eb2e8f9f7 243 }
<> 144:ef7eb2e8f9f7 244 else
<> 144:ef7eb2e8f9f7 245 {
<> 151:5eaa88a5bcc7 246 /* Check the parameters */
<> 144:ef7eb2e8f9f7 247 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 151:5eaa88a5bcc7 248 assert_param(IS_COMP_INPUT_PLUS(hcomp->Instance, hcomp->Init.NonInvertingInput));
<> 151:5eaa88a5bcc7 249 assert_param(IS_COMP_INPUT_MINUS(hcomp->Instance, hcomp->Init.InvertingInput));
<> 144:ef7eb2e8f9f7 250 assert_param(IS_COMP_OUTPUTPOL(hcomp->Init.OutputPol));
<> 151:5eaa88a5bcc7 251 assert_param(IS_COMP_POWERMODE(hcomp->Init.Mode));
<> 151:5eaa88a5bcc7 252 assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode));
<> 151:5eaa88a5bcc7 253 assert_param(IS_COMP_WINDOWMODE(hcomp->Init.WindowMode));
<> 144:ef7eb2e8f9f7 254
<> 144:ef7eb2e8f9f7 255 if(hcomp->State == HAL_COMP_STATE_RESET)
<> 144:ef7eb2e8f9f7 256 {
<> 144:ef7eb2e8f9f7 257 /* Allocate lock resource and initialize it */
<> 144:ef7eb2e8f9f7 258 hcomp->Lock = HAL_UNLOCKED;
<> 151:5eaa88a5bcc7 259
<> 144:ef7eb2e8f9f7 260 /* Init SYSCFG and the low level hardware to access comparators */
<> 151:5eaa88a5bcc7 261 /* Note: HAL_COMP_Init() calls __HAL_RCC_SYSCFG_CLK_ENABLE() */
<> 151:5eaa88a5bcc7 262 /* to enable internal control clock of the comparators. */
<> 151:5eaa88a5bcc7 263 /* However, this is a legacy strategy. In future STM32 families, */
<> 151:5eaa88a5bcc7 264 /* COMP clock enable must be implemented by user */
<> 151:5eaa88a5bcc7 265 /* in "HAL_COMP_MspInit()". */
<> 151:5eaa88a5bcc7 266 /* Therefore, for compatibility anticipation, it is recommended */
<> 151:5eaa88a5bcc7 267 /* to implement __HAL_RCC_SYSCFG_CLK_ENABLE() */
<> 151:5eaa88a5bcc7 268 /* in "HAL_COMP_MspInit()". */
<> 151:5eaa88a5bcc7 269 __HAL_RCC_SYSCFG_CLK_ENABLE();
<> 151:5eaa88a5bcc7 270
<> 151:5eaa88a5bcc7 271 /* Init the low level hardware */
<> 144:ef7eb2e8f9f7 272 HAL_COMP_MspInit(hcomp);
<> 144:ef7eb2e8f9f7 273 }
<> 144:ef7eb2e8f9f7 274
<> 151:5eaa88a5bcc7 275 /* Set COMP parameters */
<> 151:5eaa88a5bcc7 276 tmp_csr = (hcomp->Init.InvertingInput |
<> 151:5eaa88a5bcc7 277 hcomp->Init.OutputPol );
<> 151:5eaa88a5bcc7 278
<> 151:5eaa88a5bcc7 279 /* Configuration specific to comparator instance: COMP2 */
<> 151:5eaa88a5bcc7 280 if ((hcomp->Instance) == COMP2)
<> 144:ef7eb2e8f9f7 281 {
<> 151:5eaa88a5bcc7 282 /* Comparator input plus configuration is available on COMP2 only */
<> 151:5eaa88a5bcc7 283 /* Comparator power mode configuration is available on COMP2 only */
<> 151:5eaa88a5bcc7 284 tmp_csr |= (hcomp->Init.NonInvertingInput |
<> 151:5eaa88a5bcc7 285 hcomp->Init.Mode );
<> 151:5eaa88a5bcc7 286
<> 151:5eaa88a5bcc7 287 /* COMP2 specificity: when using VrefInt or subdivision of VrefInt, */
<> 151:5eaa88a5bcc7 288 /* specific path must be enabled. */
<> 151:5eaa88a5bcc7 289 if((hcomp->Init.InvertingInput == COMP_INPUT_MINUS_VREFINT) ||
<> 151:5eaa88a5bcc7 290 (hcomp->Init.InvertingInput == COMP_INPUT_MINUS_1_4VREFINT) ||
<> 151:5eaa88a5bcc7 291 (hcomp->Init.InvertingInput == COMP_INPUT_MINUS_1_2VREFINT) ||
<> 151:5eaa88a5bcc7 292 (hcomp->Init.InvertingInput == COMP_INPUT_MINUS_3_4VREFINT) )
<> 151:5eaa88a5bcc7 293 {
<> 151:5eaa88a5bcc7 294 /* Memorize voltage scaler state before initialization */
<> 151:5eaa88a5bcc7 295 comp_voltage_scaler_not_initialized = (READ_BIT(SYSCFG->CFGR3, SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP) == 0U);
<> 151:5eaa88a5bcc7 296
<> 151:5eaa88a5bcc7 297 SET_BIT(SYSCFG->CFGR3, SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP );
<> 151:5eaa88a5bcc7 298
<> 151:5eaa88a5bcc7 299 /* Delay for COMP scaler bridge voltage stabilization */
<> 151:5eaa88a5bcc7 300 /* Apply the delay if voltage scaler bridge is enabled for the first time */
<> 151:5eaa88a5bcc7 301 if (comp_voltage_scaler_not_initialized != 0U)
<> 151:5eaa88a5bcc7 302 {
<> 151:5eaa88a5bcc7 303 /* Wait loop initialization and execution */
<> 151:5eaa88a5bcc7 304 /* Note: Variable divided by 2 to compensate partially */
<> 151:5eaa88a5bcc7 305 /* CPU processing cycles. */
<> 151:5eaa88a5bcc7 306 wait_loop_index = (COMP_DELAY_VOLTAGE_SCALER_STAB_US * (SystemCoreClock / (1000000U * 2U)));
<> 151:5eaa88a5bcc7 307 while(wait_loop_index != 0U)
<> 151:5eaa88a5bcc7 308 {
<> 151:5eaa88a5bcc7 309 wait_loop_index--;
<> 151:5eaa88a5bcc7 310 }
<> 151:5eaa88a5bcc7 311 }
<> 151:5eaa88a5bcc7 312 }
<> 144:ef7eb2e8f9f7 313 }
<> 151:5eaa88a5bcc7 314
<> 151:5eaa88a5bcc7 315 /* Set comparator output connection to LPTIM */
<> 151:5eaa88a5bcc7 316 if (hcomp->Init.LPTIMConnection != COMP_LPTIMCONNECTION_DISABLED)
<> 144:ef7eb2e8f9f7 317 {
<> 151:5eaa88a5bcc7 318 /* LPTIM connexion requested on COMP1 */
<> 151:5eaa88a5bcc7 319 if ((hcomp->Instance) == COMP1)
<> 151:5eaa88a5bcc7 320 {
<> 151:5eaa88a5bcc7 321 /* Note : COMP1 can be connected to the input 1 of LPTIM if requested */
<> 151:5eaa88a5bcc7 322 assert_param(IS_COMP1_LPTIMCONNECTION(hcomp->Init.LPTIMConnection));
<> 151:5eaa88a5bcc7 323 if (hcomp->Init.LPTIMConnection == COMP_LPTIMCONNECTION_IN1_ENABLED)
<> 151:5eaa88a5bcc7 324 {
<> 151:5eaa88a5bcc7 325 tmp_csr |= (COMP_CSR_COMP1LPTIM1IN1);
<> 151:5eaa88a5bcc7 326 }
<> 151:5eaa88a5bcc7 327 }
<> 151:5eaa88a5bcc7 328 else
<> 144:ef7eb2e8f9f7 329 {
<> 144:ef7eb2e8f9f7 330 /* Check the MCU_ID in order to allow or not the COMP2 connection to LPTIM-input2 */
<> 144:ef7eb2e8f9f7 331 if (((HAL_GetDEVID() == C_DEV_ID_L073) && (HAL_GetREVID() == C_REV_ID_A))
<> 144:ef7eb2e8f9f7 332 ||
<> 144:ef7eb2e8f9f7 333 ((HAL_GetDEVID() == C_DEV_ID_L053) && (HAL_GetREVID() == C_REV_ID_A))
<> 144:ef7eb2e8f9f7 334 ||
<> 144:ef7eb2e8f9f7 335 ((HAL_GetDEVID() == C_DEV_ID_L053) && (HAL_GetREVID() == C_REV_ID_Z)))
<> 144:ef7eb2e8f9f7 336 {
<> 144:ef7eb2e8f9f7 337 /* Note : COMP2 can be connected only to input 1 of LPTIM if requested */
<> 144:ef7eb2e8f9f7 338 assert_param(IS_COMP2_LPTIMCONNECTION_RESTRICTED(hcomp->Init.LPTIMConnection));
<> 151:5eaa88a5bcc7 339
<> 151:5eaa88a5bcc7 340 tmp_csr |= (COMP_CSR_COMP2LPTIM1IN1);
<> 144:ef7eb2e8f9f7 341 }
<> 151:5eaa88a5bcc7 342 /* LPTIM connexion requested on COMP2 */
<> 144:ef7eb2e8f9f7 343 else
<> 144:ef7eb2e8f9f7 344 {
<> 144:ef7eb2e8f9f7 345 /* Note : COMP2 can be connected to input 1 or input2 of LPTIM if requested */
<> 144:ef7eb2e8f9f7 346 assert_param(IS_COMP2_LPTIMCONNECTION(hcomp->Init.LPTIMConnection));
<> 144:ef7eb2e8f9f7 347 switch (hcomp->Init.LPTIMConnection)
<> 144:ef7eb2e8f9f7 348 {
<> 144:ef7eb2e8f9f7 349 case COMP_LPTIMCONNECTION_IN1_ENABLED :
<> 151:5eaa88a5bcc7 350 tmp_csr |= (COMP_CSR_COMP2LPTIM1IN1);
<> 144:ef7eb2e8f9f7 351 break;
<> 144:ef7eb2e8f9f7 352 case COMP_LPTIMCONNECTION_IN2_ENABLED :
<> 151:5eaa88a5bcc7 353 tmp_csr |= (COMP_CSR_COMP2LPTIM1IN2);
<> 144:ef7eb2e8f9f7 354 break;
<> 144:ef7eb2e8f9f7 355 default :
<> 144:ef7eb2e8f9f7 356 break;
<> 144:ef7eb2e8f9f7 357 }
<> 144:ef7eb2e8f9f7 358 }
<> 144:ef7eb2e8f9f7 359 }
<> 151:5eaa88a5bcc7 360 }
<> 151:5eaa88a5bcc7 361
<> 151:5eaa88a5bcc7 362 /* Update comparator register */
<> 151:5eaa88a5bcc7 363 if ((hcomp->Instance) == COMP1)
<> 151:5eaa88a5bcc7 364 {
<> 151:5eaa88a5bcc7 365 MODIFY_REG(hcomp->Instance->CSR,
<> 151:5eaa88a5bcc7 366 COMP_CSR_COMP1INNSEL | COMP_CSR_COMP1WM |
<> 151:5eaa88a5bcc7 367 COMP_CSR_COMP1LPTIM1IN1 | COMP_CSR_COMP1POLARITY ,
<> 151:5eaa88a5bcc7 368 tmp_csr
<> 151:5eaa88a5bcc7 369 );
<> 151:5eaa88a5bcc7 370 }
<> 151:5eaa88a5bcc7 371 else /* Instance == COMP2 */
<> 151:5eaa88a5bcc7 372 {
<> 151:5eaa88a5bcc7 373 MODIFY_REG(hcomp->Instance->CSR,
<> 151:5eaa88a5bcc7 374 COMP_CSR_COMP2SPEED | COMP_CSR_COMP2INNSEL |
<> 151:5eaa88a5bcc7 375 COMP_CSR_COMP2INPSEL | COMP_CSR_COMP2POLARITY |
<> 151:5eaa88a5bcc7 376 COMP_CSR_COMP2LPTIM1IN2 | COMP_CSR_COMP2LPTIM1IN1 ,
<> 151:5eaa88a5bcc7 377 tmp_csr
<> 151:5eaa88a5bcc7 378 );
<> 151:5eaa88a5bcc7 379 }
<> 151:5eaa88a5bcc7 380
<> 151:5eaa88a5bcc7 381 /* Set window mode */
<> 151:5eaa88a5bcc7 382 /* Note: Window mode bit is located into 1 out of the 2 pairs of COMP */
<> 151:5eaa88a5bcc7 383 /* instances. Therefore, this function can update another COMP */
<> 151:5eaa88a5bcc7 384 /* instance that the one currently selected. */
<> 151:5eaa88a5bcc7 385 if(hcomp->Init.WindowMode == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)
<> 151:5eaa88a5bcc7 386 {
<> 151:5eaa88a5bcc7 387 SET_BIT(COMP12_COMMON->CSR, COMP_CSR_WINMODE);
<> 151:5eaa88a5bcc7 388 }
<> 151:5eaa88a5bcc7 389 else
<> 151:5eaa88a5bcc7 390 {
<> 151:5eaa88a5bcc7 391 CLEAR_BIT(COMP12_COMMON->CSR, COMP_CSR_WINMODE);
<> 151:5eaa88a5bcc7 392 }
<> 151:5eaa88a5bcc7 393
<> 151:5eaa88a5bcc7 394 /* Get the EXTI line corresponding to the selected COMP instance */
<> 151:5eaa88a5bcc7 395 exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
<> 151:5eaa88a5bcc7 396
<> 151:5eaa88a5bcc7 397 /* Manage EXTI settings */
<> 151:5eaa88a5bcc7 398 if((hcomp->Init.TriggerMode & (COMP_EXTI_IT | COMP_EXTI_EVENT)) != RESET)
<> 151:5eaa88a5bcc7 399 {
<> 151:5eaa88a5bcc7 400 /* Configure EXTI rising edge */
<> 151:5eaa88a5bcc7 401 if((hcomp->Init.TriggerMode & COMP_EXTI_RISING) != RESET)
<> 144:ef7eb2e8f9f7 402 {
<> 151:5eaa88a5bcc7 403 SET_BIT(EXTI->RTSR, exti_line);
<> 151:5eaa88a5bcc7 404 }
<> 151:5eaa88a5bcc7 405 else
<> 151:5eaa88a5bcc7 406 {
<> 151:5eaa88a5bcc7 407 CLEAR_BIT(EXTI->RTSR, exti_line);
<> 151:5eaa88a5bcc7 408 }
<> 151:5eaa88a5bcc7 409
<> 151:5eaa88a5bcc7 410 /* Configure EXTI falling edge */
<> 151:5eaa88a5bcc7 411 if((hcomp->Init.TriggerMode & COMP_EXTI_FALLING) != RESET)
<> 151:5eaa88a5bcc7 412 {
<> 151:5eaa88a5bcc7 413 SET_BIT(EXTI->FTSR, exti_line);
<> 151:5eaa88a5bcc7 414 }
<> 151:5eaa88a5bcc7 415 else
<> 151:5eaa88a5bcc7 416 {
<> 151:5eaa88a5bcc7 417 CLEAR_BIT(EXTI->FTSR, exti_line);
<> 151:5eaa88a5bcc7 418 }
<> 151:5eaa88a5bcc7 419
<> 151:5eaa88a5bcc7 420 /* Clear COMP EXTI pending bit (if any) */
<> 151:5eaa88a5bcc7 421 WRITE_REG(EXTI->PR, exti_line);
<> 151:5eaa88a5bcc7 422
<> 151:5eaa88a5bcc7 423 /* Configure EXTI event mode */
<> 151:5eaa88a5bcc7 424 if((hcomp->Init.TriggerMode & COMP_EXTI_EVENT) != RESET)
<> 151:5eaa88a5bcc7 425 {
<> 151:5eaa88a5bcc7 426 SET_BIT(EXTI->EMR, exti_line);
<> 151:5eaa88a5bcc7 427 }
<> 151:5eaa88a5bcc7 428 else
<> 151:5eaa88a5bcc7 429 {
<> 151:5eaa88a5bcc7 430 CLEAR_BIT(EXTI->EMR, exti_line);
<> 151:5eaa88a5bcc7 431 }
<> 151:5eaa88a5bcc7 432
<> 151:5eaa88a5bcc7 433 /* Configure EXTI interrupt mode */
<> 151:5eaa88a5bcc7 434 if((hcomp->Init.TriggerMode & COMP_EXTI_IT) != RESET)
<> 151:5eaa88a5bcc7 435 {
<> 151:5eaa88a5bcc7 436 SET_BIT(EXTI->IMR, exti_line);
<> 151:5eaa88a5bcc7 437 }
<> 151:5eaa88a5bcc7 438 else
<> 151:5eaa88a5bcc7 439 {
<> 151:5eaa88a5bcc7 440 CLEAR_BIT(EXTI->IMR, exti_line);
<> 144:ef7eb2e8f9f7 441 }
<> 144:ef7eb2e8f9f7 442 }
<> 151:5eaa88a5bcc7 443 else
<> 151:5eaa88a5bcc7 444 {
<> 151:5eaa88a5bcc7 445 /* Disable EXTI event generation */
<> 151:5eaa88a5bcc7 446 CLEAR_BIT(EXTI->EMR, exti_line);
<> 151:5eaa88a5bcc7 447 }
<> 151:5eaa88a5bcc7 448
<> 151:5eaa88a5bcc7 449 /* Set HAL COMP handle state */
<> 151:5eaa88a5bcc7 450 /* Note: Transition from state reset to state ready, */
<> 151:5eaa88a5bcc7 451 /* otherwise (coming from state ready or busy) no state update. */
<> 151:5eaa88a5bcc7 452 if (hcomp->State == HAL_COMP_STATE_RESET)
<> 151:5eaa88a5bcc7 453 {
<> 151:5eaa88a5bcc7 454 hcomp->State = HAL_COMP_STATE_READY;
<> 151:5eaa88a5bcc7 455 }
<> 144:ef7eb2e8f9f7 456 }
<> 144:ef7eb2e8f9f7 457
<> 144:ef7eb2e8f9f7 458 return status;
<> 144:ef7eb2e8f9f7 459 }
<> 144:ef7eb2e8f9f7 460
<> 144:ef7eb2e8f9f7 461 /**
<> 151:5eaa88a5bcc7 462 * @brief DeInitialize the COMP peripheral.
<> 151:5eaa88a5bcc7 463 * @note Deinitialization cannot be performed if the COMP configuration is locked.
<> 144:ef7eb2e8f9f7 464 * To unlock the configuration, perform a system reset.
<> 151:5eaa88a5bcc7 465 * @param hcomp COMP handle
<> 144:ef7eb2e8f9f7 466 * @retval HAL status
<> 144:ef7eb2e8f9f7 467 */
<> 144:ef7eb2e8f9f7 468 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
<> 144:ef7eb2e8f9f7 469 {
<> 144:ef7eb2e8f9f7 470 HAL_StatusTypeDef status = HAL_OK;
<> 151:5eaa88a5bcc7 471
<> 144:ef7eb2e8f9f7 472 /* Check the COMP handle allocation and lock status */
<> 151:5eaa88a5bcc7 473 if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
<> 144:ef7eb2e8f9f7 474 {
<> 144:ef7eb2e8f9f7 475 status = HAL_ERROR;
<> 144:ef7eb2e8f9f7 476 }
<> 144:ef7eb2e8f9f7 477 else
<> 144:ef7eb2e8f9f7 478 {
<> 144:ef7eb2e8f9f7 479 /* Check the parameter */
<> 144:ef7eb2e8f9f7 480 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 151:5eaa88a5bcc7 481
<> 144:ef7eb2e8f9f7 482 /* Set COMP_CSR register to reset value */
<> 151:5eaa88a5bcc7 483 WRITE_REG(hcomp->Instance->CSR, 0x00000000U);
<> 151:5eaa88a5bcc7 484
<> 144:ef7eb2e8f9f7 485 /* DeInit the low level hardware: SYSCFG, GPIO, CLOCK and NVIC */
<> 144:ef7eb2e8f9f7 486 HAL_COMP_MspDeInit(hcomp);
<> 151:5eaa88a5bcc7 487
<> 151:5eaa88a5bcc7 488 /* Set HAL COMP handle state */
<> 144:ef7eb2e8f9f7 489 hcomp->State = HAL_COMP_STATE_RESET;
<> 144:ef7eb2e8f9f7 490
<> 144:ef7eb2e8f9f7 491 /* Release Lock */
<> 144:ef7eb2e8f9f7 492 __HAL_UNLOCK(hcomp);
<> 144:ef7eb2e8f9f7 493 }
<> 144:ef7eb2e8f9f7 494
<> 144:ef7eb2e8f9f7 495 return status;
<> 144:ef7eb2e8f9f7 496 }
<> 144:ef7eb2e8f9f7 497
<> 144:ef7eb2e8f9f7 498 /**
<> 151:5eaa88a5bcc7 499 * @brief Initialize the COMP MSP.
<> 151:5eaa88a5bcc7 500 * @param hcomp COMP handle
<> 144:ef7eb2e8f9f7 501 * @retval None
<> 144:ef7eb2e8f9f7 502 */
<> 144:ef7eb2e8f9f7 503 __weak void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp)
<> 144:ef7eb2e8f9f7 504 {
<> 144:ef7eb2e8f9f7 505 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 506 UNUSED(hcomp);
<> 151:5eaa88a5bcc7 507
<> 151:5eaa88a5bcc7 508 /* NOTE : This function should not be modified, when the callback is needed,
<> 151:5eaa88a5bcc7 509 the HAL_COMP_MspInit could be implemented in the user file
<> 144:ef7eb2e8f9f7 510 */
<> 144:ef7eb2e8f9f7 511 }
<> 144:ef7eb2e8f9f7 512
<> 144:ef7eb2e8f9f7 513 /**
<> 151:5eaa88a5bcc7 514 * @brief DeInitialize the COMP MSP.
<> 151:5eaa88a5bcc7 515 * @param hcomp COMP handle
<> 144:ef7eb2e8f9f7 516 * @retval None
<> 144:ef7eb2e8f9f7 517 */
<> 144:ef7eb2e8f9f7 518 __weak void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp)
<> 144:ef7eb2e8f9f7 519 {
<> 144:ef7eb2e8f9f7 520 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 521 UNUSED(hcomp);
<> 151:5eaa88a5bcc7 522
<> 151:5eaa88a5bcc7 523 /* NOTE : This function should not be modified, when the callback is needed,
<> 151:5eaa88a5bcc7 524 the HAL_COMP_MspDeInit could be implemented in the user file
<> 144:ef7eb2e8f9f7 525 */
<> 144:ef7eb2e8f9f7 526 }
<> 144:ef7eb2e8f9f7 527
<> 144:ef7eb2e8f9f7 528 /**
<> 144:ef7eb2e8f9f7 529 * @}
<> 144:ef7eb2e8f9f7 530 */
<> 144:ef7eb2e8f9f7 531
<> 151:5eaa88a5bcc7 532 /** @defgroup COMP_Exported_Functions_Group2 Start-Stop operation functions
<> 151:5eaa88a5bcc7 533 * @brief Start-Stop operation functions.
<> 144:ef7eb2e8f9f7 534 *
<> 144:ef7eb2e8f9f7 535 @verbatim
<> 144:ef7eb2e8f9f7 536 ===============================================================================
<> 144:ef7eb2e8f9f7 537 ##### IO operation functions #####
<> 144:ef7eb2e8f9f7 538 ===============================================================================
<> 151:5eaa88a5bcc7 539 [..] This section provides functions allowing to:
<> 151:5eaa88a5bcc7 540 (+) Start a comparator instance.
<> 151:5eaa88a5bcc7 541 (+) Stop a comparator instance.
<> 144:ef7eb2e8f9f7 542
<> 144:ef7eb2e8f9f7 543 @endverbatim
<> 144:ef7eb2e8f9f7 544 * @{
<> 144:ef7eb2e8f9f7 545 */
<> 144:ef7eb2e8f9f7 546
<> 144:ef7eb2e8f9f7 547 /**
<> 151:5eaa88a5bcc7 548 * @brief Start the comparator.
<> 151:5eaa88a5bcc7 549 * @param hcomp COMP handle
<> 144:ef7eb2e8f9f7 550 * @retval HAL status
<> 144:ef7eb2e8f9f7 551 */
<> 144:ef7eb2e8f9f7 552 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp)
<> 151:5eaa88a5bcc7 553 {
<> 151:5eaa88a5bcc7 554 __IO uint32_t wait_loop_index = 0U;
<> 144:ef7eb2e8f9f7 555 HAL_StatusTypeDef status = HAL_OK;
<> 144:ef7eb2e8f9f7 556
<> 144:ef7eb2e8f9f7 557 /* Check the COMP handle allocation and lock status */
<> 151:5eaa88a5bcc7 558 if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
<> 144:ef7eb2e8f9f7 559 {
<> 144:ef7eb2e8f9f7 560 status = HAL_ERROR;
<> 144:ef7eb2e8f9f7 561 }
<> 144:ef7eb2e8f9f7 562 else
<> 144:ef7eb2e8f9f7 563 {
<> 144:ef7eb2e8f9f7 564 /* Check the parameter */
<> 144:ef7eb2e8f9f7 565 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 144:ef7eb2e8f9f7 566
<> 144:ef7eb2e8f9f7 567 if(hcomp->State == HAL_COMP_STATE_READY)
<> 144:ef7eb2e8f9f7 568 {
<> 144:ef7eb2e8f9f7 569 /* Enable the selected comparator */
<> 151:5eaa88a5bcc7 570 SET_BIT(hcomp->Instance->CSR, COMP_CSR_COMPxEN);
<> 151:5eaa88a5bcc7 571
<> 151:5eaa88a5bcc7 572 /* Set HAL COMP handle state */
<> 151:5eaa88a5bcc7 573 hcomp->State = HAL_COMP_STATE_BUSY;
<> 151:5eaa88a5bcc7 574
<> 151:5eaa88a5bcc7 575 /* Delay for COMP startup time */
<> 151:5eaa88a5bcc7 576 /* Wait loop initialization and execution */
<> 151:5eaa88a5bcc7 577 /* Note: Variable divided by 2 to compensate partially */
<> 151:5eaa88a5bcc7 578 /* CPU processing cycles. */
<> 151:5eaa88a5bcc7 579 wait_loop_index = (COMP_DELAY_STARTUP_US * (SystemCoreClock / (1000000U * 2U)));
<> 151:5eaa88a5bcc7 580 while(wait_loop_index != 0U)
<> 151:5eaa88a5bcc7 581 {
<> 151:5eaa88a5bcc7 582 wait_loop_index--;
<> 151:5eaa88a5bcc7 583 }
<> 144:ef7eb2e8f9f7 584 }
<> 144:ef7eb2e8f9f7 585 else
<> 144:ef7eb2e8f9f7 586 {
<> 144:ef7eb2e8f9f7 587 status = HAL_ERROR;
<> 144:ef7eb2e8f9f7 588 }
<> 144:ef7eb2e8f9f7 589 }
<> 144:ef7eb2e8f9f7 590
<> 144:ef7eb2e8f9f7 591 return status;
<> 144:ef7eb2e8f9f7 592 }
<> 144:ef7eb2e8f9f7 593
<> 144:ef7eb2e8f9f7 594 /**
<> 151:5eaa88a5bcc7 595 * @brief Stop the comparator.
<> 151:5eaa88a5bcc7 596 * @param hcomp COMP handle
<> 144:ef7eb2e8f9f7 597 * @retval HAL status
<> 144:ef7eb2e8f9f7 598 */
<> 144:ef7eb2e8f9f7 599 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp)
<> 151:5eaa88a5bcc7 600 {
<> 144:ef7eb2e8f9f7 601 HAL_StatusTypeDef status = HAL_OK;
<> 144:ef7eb2e8f9f7 602
<> 144:ef7eb2e8f9f7 603 /* Check the COMP handle allocation and lock status */
<> 151:5eaa88a5bcc7 604 if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
<> 144:ef7eb2e8f9f7 605 {
<> 144:ef7eb2e8f9f7 606 status = HAL_ERROR;
<> 144:ef7eb2e8f9f7 607 }
<> 144:ef7eb2e8f9f7 608 else
<> 144:ef7eb2e8f9f7 609 {
<> 144:ef7eb2e8f9f7 610 /* Check the parameter */
<> 144:ef7eb2e8f9f7 611 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 151:5eaa88a5bcc7 612
<> 151:5eaa88a5bcc7 613 if((hcomp->State == HAL_COMP_STATE_BUSY) ||
<> 151:5eaa88a5bcc7 614 (hcomp->State == HAL_COMP_STATE_READY) )
<> 144:ef7eb2e8f9f7 615 {
<> 144:ef7eb2e8f9f7 616 /* Disable the selected comparator */
<> 151:5eaa88a5bcc7 617 CLEAR_BIT(hcomp->Instance->CSR, COMP_CSR_COMPxEN);
<> 144:ef7eb2e8f9f7 618
<> 151:5eaa88a5bcc7 619 /* Set HAL COMP handle state */
<> 144:ef7eb2e8f9f7 620 hcomp->State = HAL_COMP_STATE_READY;
<> 144:ef7eb2e8f9f7 621 }
<> 144:ef7eb2e8f9f7 622 else
<> 144:ef7eb2e8f9f7 623 {
<> 144:ef7eb2e8f9f7 624 status = HAL_ERROR;
<> 144:ef7eb2e8f9f7 625 }
<> 144:ef7eb2e8f9f7 626 }
<> 144:ef7eb2e8f9f7 627
<> 144:ef7eb2e8f9f7 628 return status;
<> 144:ef7eb2e8f9f7 629 }
<> 144:ef7eb2e8f9f7 630
<> 144:ef7eb2e8f9f7 631 /**
<> 151:5eaa88a5bcc7 632 * @brief Comparator IRQ handler.
<> 151:5eaa88a5bcc7 633 * @param hcomp COMP handle
<> 151:5eaa88a5bcc7 634 * @retval None
<> 151:5eaa88a5bcc7 635 */
<> 151:5eaa88a5bcc7 636 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp)
<> 151:5eaa88a5bcc7 637 {
<> 151:5eaa88a5bcc7 638 /* Get the EXTI line corresponding to the selected COMP instance */
<> 151:5eaa88a5bcc7 639 uint32_t exti_line = COMP_GET_EXTI_LINE(hcomp->Instance);
<> 151:5eaa88a5bcc7 640
<> 151:5eaa88a5bcc7 641 /* Check COMP EXTI flag */
<> 151:5eaa88a5bcc7 642 if(READ_BIT(EXTI->PR, exti_line) != RESET)
<> 151:5eaa88a5bcc7 643 {
<> 151:5eaa88a5bcc7 644 /* Clear COMP EXTI pending bit */
<> 151:5eaa88a5bcc7 645 WRITE_REG(EXTI->PR, exti_line);
<> 151:5eaa88a5bcc7 646
<> 151:5eaa88a5bcc7 647 /* COMP trigger user callback */
<> 151:5eaa88a5bcc7 648 HAL_COMP_TriggerCallback(hcomp);
<> 151:5eaa88a5bcc7 649 }
<> 151:5eaa88a5bcc7 650 }
<> 151:5eaa88a5bcc7 651
<> 151:5eaa88a5bcc7 652 /**
<> 151:5eaa88a5bcc7 653 * @}
<> 144:ef7eb2e8f9f7 654 */
<> 151:5eaa88a5bcc7 655
<> 151:5eaa88a5bcc7 656 /** @defgroup COMP_Exported_Functions_Group3 Peripheral Control functions
<> 151:5eaa88a5bcc7 657 * @brief Management functions.
<> 151:5eaa88a5bcc7 658 *
<> 151:5eaa88a5bcc7 659 @verbatim
<> 151:5eaa88a5bcc7 660 ===============================================================================
<> 151:5eaa88a5bcc7 661 ##### Peripheral Control functions #####
<> 151:5eaa88a5bcc7 662 ===============================================================================
<> 151:5eaa88a5bcc7 663 [..]
<> 151:5eaa88a5bcc7 664 This subsection provides a set of functions allowing to control the comparators.
<> 151:5eaa88a5bcc7 665
<> 151:5eaa88a5bcc7 666 @endverbatim
<> 151:5eaa88a5bcc7 667 * @{
<> 151:5eaa88a5bcc7 668 */
<> 151:5eaa88a5bcc7 669
<> 151:5eaa88a5bcc7 670 /**
<> 151:5eaa88a5bcc7 671 * @brief Lock the selected comparator configuration.
<> 151:5eaa88a5bcc7 672 * @note A system reset is required to unlock the comparator configuration.
<> 151:5eaa88a5bcc7 673 * @note Locking the comparator from reset state is possible
<> 151:5eaa88a5bcc7 674 * if __HAL_RCC_SYSCFG_CLK_ENABLE() is being called before.
<> 151:5eaa88a5bcc7 675 * @param hcomp COMP handle
<> 151:5eaa88a5bcc7 676 * @retval HAL status
<> 151:5eaa88a5bcc7 677 */
<> 151:5eaa88a5bcc7 678 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp)
<> 151:5eaa88a5bcc7 679 {
<> 144:ef7eb2e8f9f7 680 HAL_StatusTypeDef status = HAL_OK;
<> 144:ef7eb2e8f9f7 681
<> 144:ef7eb2e8f9f7 682 /* Check the COMP handle allocation and lock status */
<> 151:5eaa88a5bcc7 683 if((hcomp == NULL) || (__HAL_COMP_IS_LOCKED(hcomp)))
<> 144:ef7eb2e8f9f7 684 {
<> 144:ef7eb2e8f9f7 685 status = HAL_ERROR;
<> 144:ef7eb2e8f9f7 686 }
<> 144:ef7eb2e8f9f7 687 else
<> 144:ef7eb2e8f9f7 688 {
<> 144:ef7eb2e8f9f7 689 /* Check the parameter */
<> 144:ef7eb2e8f9f7 690 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 151:5eaa88a5bcc7 691
<> 151:5eaa88a5bcc7 692 /* Set HAL COMP handle state */
<> 151:5eaa88a5bcc7 693 hcomp->State = ((HAL_COMP_StateTypeDef)(hcomp->State | COMP_STATE_BITFIELD_LOCK));
<> 144:ef7eb2e8f9f7 694 }
<> 144:ef7eb2e8f9f7 695
<> 144:ef7eb2e8f9f7 696 if(status == HAL_OK)
<> 144:ef7eb2e8f9f7 697 {
<> 144:ef7eb2e8f9f7 698 /* Set the lock bit corresponding to selected comparator */
<> 144:ef7eb2e8f9f7 699 __HAL_COMP_LOCK(hcomp);
<> 144:ef7eb2e8f9f7 700 }
<> 144:ef7eb2e8f9f7 701
<> 144:ef7eb2e8f9f7 702 return status;
<> 144:ef7eb2e8f9f7 703 }
<> 144:ef7eb2e8f9f7 704
<> 144:ef7eb2e8f9f7 705 /**
<> 144:ef7eb2e8f9f7 706 * @brief Return the output level (high or low) of the selected comparator.
<> 144:ef7eb2e8f9f7 707 * The output level depends on the selected polarity.
<> 144:ef7eb2e8f9f7 708 * If the polarity is not inverted:
<> 151:5eaa88a5bcc7 709 * - Comparator output is low when the input plus is at a lower
<> 151:5eaa88a5bcc7 710 * voltage than the input minus
<> 151:5eaa88a5bcc7 711 * - Comparator output is high when the input plus is at a higher
<> 151:5eaa88a5bcc7 712 * voltage than the input minus
<> 144:ef7eb2e8f9f7 713 * If the polarity is inverted:
<> 151:5eaa88a5bcc7 714 * - Comparator output is high when the input plus is at a lower
<> 151:5eaa88a5bcc7 715 * voltage than the input minus
<> 151:5eaa88a5bcc7 716 * - Comparator output is low when the input plus is at a higher
<> 151:5eaa88a5bcc7 717 * voltage than the input minus
<> 151:5eaa88a5bcc7 718 * @param hcomp COMP handle
<> 151:5eaa88a5bcc7 719 * @retval Returns the selected comparator output level:
<> 151:5eaa88a5bcc7 720 * @arg @ref COMP_OUTPUT_LEVEL_LOW
<> 151:5eaa88a5bcc7 721 * @arg @ref COMP_OUTPUT_LEVEL_HIGH
<> 144:ef7eb2e8f9f7 722 *
<> 144:ef7eb2e8f9f7 723 */
<> 144:ef7eb2e8f9f7 724 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp)
<> 144:ef7eb2e8f9f7 725 {
<> 144:ef7eb2e8f9f7 726 /* Check the parameter */
<> 144:ef7eb2e8f9f7 727 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 144:ef7eb2e8f9f7 728
<> 151:5eaa88a5bcc7 729 return (uint32_t)(READ_BIT(hcomp->Instance->CSR, COMP_CSR_COMPxOUTVALUE)
<> 151:5eaa88a5bcc7 730 >> COMP_OUTPUT_LEVEL_BITOFFSET_POS);
<> 144:ef7eb2e8f9f7 731 }
<> 144:ef7eb2e8f9f7 732
<> 144:ef7eb2e8f9f7 733 /**
<> 144:ef7eb2e8f9f7 734 * @brief Comparator callback.
<> 151:5eaa88a5bcc7 735 * @param hcomp COMP handle
<> 144:ef7eb2e8f9f7 736 * @retval None
<> 144:ef7eb2e8f9f7 737 */
<> 144:ef7eb2e8f9f7 738 __weak void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
<> 144:ef7eb2e8f9f7 739 {
<> 144:ef7eb2e8f9f7 740 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 741 UNUSED(hcomp);
<> 151:5eaa88a5bcc7 742
<> 144:ef7eb2e8f9f7 743 /* NOTE : This function should not be modified, when the callback is needed,
<> 144:ef7eb2e8f9f7 744 the HAL_COMP_TriggerCallback should be implemented in the user file
<> 144:ef7eb2e8f9f7 745 */
<> 144:ef7eb2e8f9f7 746 }
<> 144:ef7eb2e8f9f7 747
<> 144:ef7eb2e8f9f7 748
<> 144:ef7eb2e8f9f7 749 /**
<> 144:ef7eb2e8f9f7 750 * @}
<> 144:ef7eb2e8f9f7 751 */
<> 144:ef7eb2e8f9f7 752
<> 151:5eaa88a5bcc7 753 /** @defgroup COMP_Exported_Functions_Group4 Peripheral State functions
<> 151:5eaa88a5bcc7 754 * @brief Peripheral State functions.
<> 144:ef7eb2e8f9f7 755 *
<> 144:ef7eb2e8f9f7 756 @verbatim
<> 144:ef7eb2e8f9f7 757 ===============================================================================
<> 144:ef7eb2e8f9f7 758 ##### Peripheral State functions #####
<> 144:ef7eb2e8f9f7 759 ===============================================================================
<> 144:ef7eb2e8f9f7 760 [..]
<> 151:5eaa88a5bcc7 761 This subsection permit to get in run-time the status of the peripheral.
<> 144:ef7eb2e8f9f7 762
<> 144:ef7eb2e8f9f7 763 @endverbatim
<> 144:ef7eb2e8f9f7 764 * @{
<> 144:ef7eb2e8f9f7 765 */
<> 144:ef7eb2e8f9f7 766
<> 144:ef7eb2e8f9f7 767 /**
<> 151:5eaa88a5bcc7 768 * @brief Return the COMP handle state.
<> 151:5eaa88a5bcc7 769 * @param hcomp COMP handle
<> 144:ef7eb2e8f9f7 770 * @retval HAL state
<> 144:ef7eb2e8f9f7 771 */
<> 144:ef7eb2e8f9f7 772 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp)
<> 144:ef7eb2e8f9f7 773 {
<> 144:ef7eb2e8f9f7 774 /* Check the COMP handle allocation */
<> 144:ef7eb2e8f9f7 775 if(hcomp == NULL)
<> 144:ef7eb2e8f9f7 776 {
<> 144:ef7eb2e8f9f7 777 return HAL_COMP_STATE_RESET;
<> 144:ef7eb2e8f9f7 778 }
<> 144:ef7eb2e8f9f7 779
<> 144:ef7eb2e8f9f7 780 /* Check the parameter */
<> 144:ef7eb2e8f9f7 781 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 144:ef7eb2e8f9f7 782
<> 151:5eaa88a5bcc7 783 /* Return HAL COMP handle state */
<> 144:ef7eb2e8f9f7 784 return hcomp->State;
<> 144:ef7eb2e8f9f7 785 }
<> 144:ef7eb2e8f9f7 786
<> 144:ef7eb2e8f9f7 787 /**
<> 144:ef7eb2e8f9f7 788 * @}
<> 144:ef7eb2e8f9f7 789 */
<> 144:ef7eb2e8f9f7 790
<> 144:ef7eb2e8f9f7 791 /**
<> 144:ef7eb2e8f9f7 792 * @}
<> 144:ef7eb2e8f9f7 793 */
<> 144:ef7eb2e8f9f7 794
<> 144:ef7eb2e8f9f7 795 #endif /* HAL_COMP_MODULE_ENABLED */
<> 151:5eaa88a5bcc7 796 /**
<> 151:5eaa88a5bcc7 797 * @}
<> 151:5eaa88a5bcc7 798 */
<> 144:ef7eb2e8f9f7 799
<> 144:ef7eb2e8f9f7 800 /**
<> 144:ef7eb2e8f9f7 801 * @}
<> 144:ef7eb2e8f9f7 802 */
<> 144:ef7eb2e8f9f7 803
<> 144:ef7eb2e8f9f7 804 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/