mbed official / mbed-dev

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

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
Child:
184:08ed48f1de7f
This updates the lib to the mbed lib v128

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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /**
<> 149:156823d33999 2 ******************************************************************************
<> 149:156823d33999 3 * @file stm32l1xx_hal_comp.c
<> 149:156823d33999 4 * @author MCD Application Team
<> 149:156823d33999 5 * @version V1.2.0
<> 149:156823d33999 6 * @date 01-July-2016
<> 149:156823d33999 7 * @brief COMP HAL module driver.
<> 149:156823d33999 8 * This file provides firmware functions to manage the following
<> 149:156823d33999 9 * functionalities of the COMP peripheral:
<> 149:156823d33999 10 * + Initialization and de-initialization functions
<> 149:156823d33999 11 * + I/O operation functions
<> 149:156823d33999 12 * + Peripheral Control functions
<> 149:156823d33999 13 * + Peripheral State functions
<> 149:156823d33999 14 *
<> 149:156823d33999 15 @verbatim
<> 149:156823d33999 16 ================================================================================
<> 149:156823d33999 17 ##### COMP Peripheral features #####
<> 149:156823d33999 18 ================================================================================
<> 149:156823d33999 19 [..]
<> 149:156823d33999 20 The STM32L1xx device family integrates 2 analog comparators COMP1 and
<> 149:156823d33999 21 COMP2:
<> 149:156823d33999 22 (#) The non inverting input and inverting input can be set to GPIO pins.
<> 149:156823d33999 23 HAL COMP driver configures the Routing Interface (RI) to connect the
<> 149:156823d33999 24 selected I/O pins to comparator input.
<> 149:156823d33999 25 Caution: Comparator COMP1 and ADC cannot be used at the same time as
<> 149:156823d33999 26 ADC since they share the ADC switch matrix: COMP1 non-inverting
<> 149:156823d33999 27 input is routed through ADC switch matrix. Except if ADC is intended
<> 149:156823d33999 28 to measure voltage on COMP1 non-inverting input: it can be performed
<> 149:156823d33999 29 on ADC channel VCOMP.
<> 149:156823d33999 30
<> 149:156823d33999 31 (#) The COMP output is available using HAL_COMP_GetOutputLevel().
<> 149:156823d33999 32
<> 149:156823d33999 33 (#) The COMP output can be redirected to embedded timers (TIM2, TIM3,
<> 149:156823d33999 34 TIM4, TIM10).
<> 149:156823d33999 35 COMP output cannot be redirected to any I/O pin.
<> 149:156823d33999 36
<> 149:156823d33999 37 (#) The comparators COMP1 and COMP2 can be combined in window mode.
<> 149:156823d33999 38 In this mode, COMP2 non inverting input is used as common
<> 149:156823d33999 39 non-inverting input.
<> 149:156823d33999 40
<> 149:156823d33999 41 (#) The 2 comparators have interrupt capability with wake-up
<> 149:156823d33999 42 from Sleep and Stop modes (through the EXTI controller):
<> 149:156823d33999 43 (++) COMP1 is internally connected to EXTI Line 21
<> 149:156823d33999 44 (++) COMP2 is internally connected to EXTI Line 22
<> 149:156823d33999 45
<> 149:156823d33999 46 From the corresponding IRQ handler, the right interrupt source can be retrieved with the
<> 149:156823d33999 47 macros __HAL_COMP_COMP1_EXTI_GET_FLAG() and __HAL_COMP_COMP2_EXTI_GET_FLAG().
<> 149:156823d33999 48
<> 149:156823d33999 49 (#) The comparators also offer the possibility to output the voltage
<> 149:156823d33999 50 reference (VrefInt), used on inverting inputs, on I/O pin through
<> 149:156823d33999 51 a buffer. To use it, refer to macro "__HAL_SYSCFG_VREFINT_OUT_ENABLE()".
<> 149:156823d33999 52
<> 149:156823d33999 53 ##### How to use this driver #####
<> 149:156823d33999 54 ================================================================================
<> 149:156823d33999 55 [..]
<> 149:156823d33999 56 This driver provides functions to configure and program the Comparators of all STM32L1xx devices.
<> 149:156823d33999 57
<> 149:156823d33999 58 To use the comparator, perform the following steps:
<> 149:156823d33999 59
<> 149:156823d33999 60 (#) Initialize the COMP low level resources by implementing the HAL_COMP_MspInit().
<> 149:156823d33999 61 (++) Configure the comparator input I/O pin using HAL_GPIO_Init():
<> 149:156823d33999 62 - For all inputs: I/O pin in analog mode (Schmitt trigger disabled)
<> 149:156823d33999 63 - Possible alternate configuration, for non-inverting inputs of comparator 2: I/O pin in floating mode (Schmitt trigger enabled).
<> 149:156823d33999 64 It is recommended to use analog configuration to avoid any overconsumption around VDD/2.
<> 149:156823d33999 65 (++) Enable COMP Peripheral clock using macro __HAL_RCC_COMP_CLK_ENABLE()
<> 149:156823d33999 66 (++) If required enable the COMP interrupt (EXTI line Interrupt): enable
<> 149:156823d33999 67 the comparator interrupt vector using HAL_NVIC_EnableIRQ(COMP_IRQn)
<> 149:156823d33999 68 and HAL_NVIC_SetPriority(COMP_IRQn, xxx, xxx) functions.
<> 149:156823d33999 69
<> 149:156823d33999 70 (#) Configure the comparator using HAL_COMP_Init() function:
<> 149:156823d33999 71 (++) Select the inverting input (COMP2 only)
<> 149:156823d33999 72 (++) Select the non-inverting input
<> 149:156823d33999 73 (++) Select the output redirection to timers (COMP2 only)
<> 149:156823d33999 74 (++) Select the speed mode (COMP2 only)
<> 149:156823d33999 75 (++) Select the window mode (related to COMP1 and COMP2, but selected
<> 149:156823d33999 76 by COMP2 only)
<> 149:156823d33999 77 (++) Select the pull-up/down resistors on non-inverting input (COMP1 only)
<> 149:156823d33999 78
<> 149:156823d33999 79 (#) Enable the comparator using HAL_COMP_Start() or HAL_COMP_Start_IT()
<> 149:156823d33999 80 function
<> 149:156823d33999 81
<> 149:156823d33999 82 (#) If needed, use HAL_COMP_GetOutputLevel() or HAL_COMP_TriggerCallback()
<> 149:156823d33999 83 functions to manage comparator actions (output level or events)
<> 149:156823d33999 84
<> 149:156823d33999 85 (#) Disable the comparator using HAL_COMP_Stop() or HAL_COMP_Stop_IT()
<> 149:156823d33999 86 function
<> 149:156823d33999 87
<> 149:156823d33999 88 (#) De-initialize the comparator using HAL_COMP_DeInit() function
<> 149:156823d33999 89
<> 149:156823d33999 90
<> 149:156823d33999 91 @endverbatim
<> 149:156823d33999 92 ******************************************************************************
<> 149:156823d33999 93 * @attention
<> 149:156823d33999 94 *
<> 149:156823d33999 95 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
<> 149:156823d33999 96 *
<> 149:156823d33999 97 * Redistribution and use in source and binary forms, with or without modification,
<> 149:156823d33999 98 * are permitted provided that the following conditions are met:
<> 149:156823d33999 99 * 1. Redistributions of source code must retain the above copyright notice,
<> 149:156823d33999 100 * this list of conditions and the following disclaimer.
<> 149:156823d33999 101 * 2. Redistributions in binary form must reproduce the above copyright notice,
<> 149:156823d33999 102 * this list of conditions and the following disclaimer in the documentation
<> 149:156823d33999 103 * and/or other materials provided with the distribution.
<> 149:156823d33999 104 * 3. Neither the name of STMicroelectronics nor the names of its contributors
<> 149:156823d33999 105 * may be used to endorse or promote products derived from this software
<> 149:156823d33999 106 * without specific prior written permission.
<> 149:156823d33999 107 *
<> 149:156823d33999 108 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
<> 149:156823d33999 109 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<> 149:156823d33999 110 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 149:156823d33999 111 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
<> 149:156823d33999 112 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<> 149:156823d33999 113 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
<> 149:156823d33999 114 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
<> 149:156823d33999 115 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
<> 149:156823d33999 116 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<> 149:156823d33999 117 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 149:156823d33999 118 *
<> 149:156823d33999 119 ******************************************************************************
<> 149:156823d33999 120 */
<> 149:156823d33999 121
<> 149:156823d33999 122 /*
<> 149:156823d33999 123 Additionnal remark:
<> 149:156823d33999 124 Table 1. COMP Inputs for the STM32L1xx devices
<> 149:156823d33999 125 +----------------------------------------------------------------------+
<> 149:156823d33999 126 | | | COMP1 | COMP2 |
<> 149:156823d33999 127 |-----------------|--------------------------------|---------|---------|
<> 149:156823d33999 128 | | 1/4 VREFINT | -- | OK |
<> 149:156823d33999 129 | | 1/2 VREFINT | -- | OK |
<> 149:156823d33999 130 | | 3/4 VREFINT | -- | OK |
<> 149:156823d33999 131 | Inverting | VREFINT | OK | OK |
<> 149:156823d33999 132 | input | DAC Ch1 OUT (PA4) | -- | OK |
<> 149:156823d33999 133 | | DAC Ch2 OUT (PA5) | -- | OK |
<> 149:156823d33999 134 | | IO: PB3 | -- | OK |
<> 149:156823d33999 135 |-----------------|--------------------------------|---------|---------|
<> 149:156823d33999 136 | | IO: | | |
<> 149:156823d33999 137 | | PB4, 5, 6*, 7* | --- | OK |
<> 149:156823d33999 138 | Non-inverting | PA0*, 1*, 2*, 3*, 4, 5, 6, 7 | OK | --- |
<> 149:156823d33999 139 | input | PB0, 1, 12, 13, 14, 15 | OK | --- |
<> 149:156823d33999 140 | | PC0, 1, 2, 3, 4, 5 | OK | --- |
<> 149:156823d33999 141 | | PE7, 8, 9, 10 | OK | --- |
<> 149:156823d33999 142 | | PF6, 7, 8, 9, 10 | OK | --- |
<> 149:156823d33999 143 | | OPAMP1 output | OK | --- |
<> 149:156823d33999 144 | | OPAMP2 output | OK | --- |
<> 149:156823d33999 145 | | OPAMP3 output** | OK | --- |
<> 149:156823d33999 146 +----------------------------------------------------------------------+
<> 149:156823d33999 147 *: Available on devices category Cat.3, Cat.4, Cat.5 only.
<> 149:156823d33999 148 **: Available on devices category Cat.4 only.
<> 149:156823d33999 149
<> 149:156823d33999 150 [..] Table 2. COMP Outputs redirection to embedded timers
<> 149:156823d33999 151 +-----------------------------------+
<> 149:156823d33999 152 | COMP1 | COMP2 |
<> 149:156823d33999 153 |-----------------|-----------------|
<> 149:156823d33999 154 | | TIM2 IC4 |
<> 149:156823d33999 155 | | TIM2 OCREF CLR |
<> 149:156823d33999 156 | (no redirection | TIM3 IC4 |
<> 149:156823d33999 157 | to timers) | TIM3 OCREF CLR |
<> 149:156823d33999 158 | | TIM4 IC4 |
<> 149:156823d33999 159 | | TIM4 OCREF CLR |
<> 149:156823d33999 160 | | TIM10 IC1 |
<> 149:156823d33999 161 +-----------------------------------+
<> 149:156823d33999 162 */
<> 149:156823d33999 163
<> 149:156823d33999 164 /* Includes ------------------------------------------------------------------*/
<> 149:156823d33999 165 #include "stm32l1xx_hal.h"
<> 149:156823d33999 166
<> 149:156823d33999 167 /** @addtogroup STM32L1xx_HAL_Driver
<> 149:156823d33999 168 * @{
<> 149:156823d33999 169 */
<> 149:156823d33999 170
<> 149:156823d33999 171 /** @defgroup COMP COMP
<> 149:156823d33999 172 * @brief COMP HAL module driver
<> 149:156823d33999 173 * @{
<> 149:156823d33999 174 */
<> 149:156823d33999 175
<> 149:156823d33999 176 #ifdef HAL_COMP_MODULE_ENABLED
<> 149:156823d33999 177
<> 149:156823d33999 178 /* Private typedef -----------------------------------------------------------*/
<> 149:156823d33999 179 /* Private define ------------------------------------------------------------*/
<> 149:156823d33999 180
<> 149:156823d33999 181 /** @defgroup COMP_Private_Constants COMP Private Constants
<> 149:156823d33999 182 * @{
<> 149:156823d33999 183 */
<> 149:156823d33999 184 /* Delay for COMP start-up time. */
<> 149:156823d33999 185 /* Maximum delay is 10us for comparator 1 and 25us for comparator 2 in slow */
<> 149:156823d33999 186 /* mode (refer to device datasheet, parameter tSTART). */
<> 149:156823d33999 187 /* Delay in CPU cycles, fixed to worst case: maximum CPU frequency 32MHz to */
<> 149:156823d33999 188 /* have the minimum number of CPU cycles to fulfill this delay. */
<> 149:156823d33999 189 /* - Comparator 1: delay minimum of 320 CPU cycles. Wait loop takes 3 CPU */
<> 149:156823d33999 190 /* cycles per iteration, therefore total wait iterations */
<> 149:156823d33999 191 /* number must be initialized at 106 iterations. */
<> 149:156823d33999 192 /* - Comparator 2: delay minimum of 800 CPU cycles. Wait loop takes 3 CPU */
<> 149:156823d33999 193 /* cycles per iteration, therefore total wait iterations */
<> 149:156823d33999 194 /* number must be initialized at 266 iterations. */
<> 149:156823d33999 195 #define COMP1_START_DELAY_CPU_CYCLES ((uint32_t)106)
<> 149:156823d33999 196 #define COMP2_START_DELAY_CPU_CYCLES ((uint32_t)266)
<> 149:156823d33999 197
<> 149:156823d33999 198 /* Comparator status "locked": to update COMP handle state (software lock */
<> 149:156823d33999 199 /* only on COMP of STM32L1xx devices) by bitfield: */
<> 149:156823d33999 200 /* states HAL_COMP_STATE_READY_LOCKED, HAL_COMP_STATE_BUSY_LOCKED. */
<> 149:156823d33999 201 #define COMP_STATE_BIT_LOCK ((uint32_t) 0x00000010)
<> 149:156823d33999 202
<> 149:156823d33999 203 /**
<> 149:156823d33999 204 * @}
<> 149:156823d33999 205 */
<> 149:156823d33999 206
<> 149:156823d33999 207
<> 149:156823d33999 208 /* Private macro -------------------------------------------------------------*/
<> 149:156823d33999 209 /* Private variables ---------------------------------------------------------*/
<> 149:156823d33999 210 /* Private function prototypes -----------------------------------------------*/
<> 149:156823d33999 211 /* Private functions ---------------------------------------------------------*/
<> 149:156823d33999 212
<> 149:156823d33999 213 /** @defgroup COMP_Exported_Functions COMP Exported Functions
<> 149:156823d33999 214 * @{
<> 149:156823d33999 215 */
<> 149:156823d33999 216
<> 149:156823d33999 217 /** @defgroup COMP_Exported_Functions_Group1 Initialization and de-initialization functions
<> 149:156823d33999 218 * @brief Initialization and Configuration functions
<> 149:156823d33999 219 *
<> 149:156823d33999 220 @verbatim
<> 149:156823d33999 221 ===============================================================================
<> 149:156823d33999 222 ##### Initialization and de-initialization functions #####
<> 149:156823d33999 223 ===============================================================================
<> 149:156823d33999 224 [..] This section provides functions to initialize and de-initialize comparators
<> 149:156823d33999 225
<> 149:156823d33999 226 @endverbatim
<> 149:156823d33999 227 * @{
<> 149:156823d33999 228 */
<> 149:156823d33999 229
<> 149:156823d33999 230 /**
<> 149:156823d33999 231 * @brief Initializes the COMP according to the specified
<> 149:156823d33999 232 * parameters in the COMP_InitTypeDef and create the associated handle.
<> 149:156823d33999 233 * @note If the selected comparator is locked, initialization can't be performed.
<> 149:156823d33999 234 * To unlock the configuration, perform a system reset.
<> 149:156823d33999 235 * @param hcomp: COMP handle
<> 149:156823d33999 236 * @retval HAL status
<> 149:156823d33999 237 */
<> 149:156823d33999 238 HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 239 {
<> 149:156823d33999 240 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 241
<> 149:156823d33999 242 /* Check the COMP handle allocation and lock status */
<> 149:156823d33999 243 if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
<> 149:156823d33999 244 {
<> 149:156823d33999 245 status = HAL_ERROR;
<> 149:156823d33999 246 }
<> 149:156823d33999 247 else
<> 149:156823d33999 248 {
<> 149:156823d33999 249 /* Check the parameter */
<> 149:156823d33999 250 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 149:156823d33999 251
<> 149:156823d33999 252 if (hcomp->Instance == COMP1)
<> 149:156823d33999 253 {
<> 149:156823d33999 254 assert_param(IS_COMP_NONINVERTINGINPUTPULL(hcomp->Init.NonInvertingInputPull));
<> 149:156823d33999 255 }
<> 149:156823d33999 256 else /* if (hcomp->Instance == COMP2) */
<> 149:156823d33999 257 {
<> 149:156823d33999 258 assert_param(IS_COMP_INVERTINGINPUT(hcomp->Init.InvertingInput));
<> 149:156823d33999 259 assert_param(IS_COMP_OUTPUT(hcomp->Init.Output));
<> 149:156823d33999 260 assert_param(IS_COMP_MODE(hcomp->Init.Mode));
<> 149:156823d33999 261 assert_param(IS_COMP_WINDOWMODE(hcomp->Init.WindowMode));
<> 149:156823d33999 262 }
<> 149:156823d33999 263
<> 149:156823d33999 264 /* In window mode, non-inverting inputs of the 2 comparators are */
<> 149:156823d33999 265 /* connected together and are using inputs of COMP2 only. If COMP1 is */
<> 149:156823d33999 266 /* selected, this parameter is discarded. */
<> 149:156823d33999 267 if ((hcomp->Init.WindowMode == COMP_WINDOWMODE_DISABLE) ||
<> 149:156823d33999 268 (hcomp->Instance == COMP2) )
<> 149:156823d33999 269 {
<> 149:156823d33999 270 assert_param(IS_COMP_NONINVERTINGINPUT(hcomp->Init.NonInvertingInput));
<> 149:156823d33999 271 }
<> 149:156823d33999 272
<> 149:156823d33999 273
<> 149:156823d33999 274 /* Enable SYSCFG clock and the low level hardware to access comparators */
<> 149:156823d33999 275 if(hcomp->State == HAL_COMP_STATE_RESET)
<> 149:156823d33999 276 {
<> 149:156823d33999 277 /* Allocate lock resource and initialize it */
<> 149:156823d33999 278 hcomp->Lock = HAL_UNLOCKED;
<> 149:156823d33999 279
<> 149:156823d33999 280 /* Enable SYSCFG clock to control the routing Interface (RI) */
<> 149:156823d33999 281 __HAL_RCC_SYSCFG_CLK_ENABLE();
<> 149:156823d33999 282
<> 149:156823d33999 283 /* Init the low level hardware */
<> 149:156823d33999 284 HAL_COMP_MspInit(hcomp);
<> 149:156823d33999 285 }
<> 149:156823d33999 286
<> 149:156823d33999 287 /* Configuration of comparator: */
<> 149:156823d33999 288 /* - Output selection */
<> 149:156823d33999 289 /* - Inverting input selection */
<> 149:156823d33999 290 /* - Window mode */
<> 149:156823d33999 291 /* - Mode fast/slow speed */
<> 149:156823d33999 292 /* - Inverting input pull-up/down resistors */
<> 149:156823d33999 293
<> 149:156823d33999 294 /* Configuration depending on comparator instance */
<> 149:156823d33999 295 if (hcomp->Instance == COMP1)
<> 149:156823d33999 296 {
<> 149:156823d33999 297 MODIFY_REG(COMP->CSR, COMP_CSR_400KPD | COMP_CSR_10KPD | COMP_CSR_400KPU | COMP_CSR_10KPU,
<> 149:156823d33999 298 hcomp->Init.NonInvertingInputPull );
<> 149:156823d33999 299 }
<> 149:156823d33999 300 else /* if (hcomp->Instance == COMP2) */
<> 149:156823d33999 301 {
<> 149:156823d33999 302 /* Note: If comparator 2 is not enabled, inverting input (parameter */
<> 149:156823d33999 303 /* "hcomp->Init.InvertingInput") is configured into function */
<> 149:156823d33999 304 /* "HAL_COMP_Start()" since inverting input selection also */
<> 149:156823d33999 305 /* enables the comparator 2. */
<> 149:156823d33999 306 /* If comparator 2 is already enabled, inverting input is */
<> 149:156823d33999 307 /* reconfigured on the fly. */
<> 149:156823d33999 308 if (__COMP_IS_ENABLED(hcomp) == RESET)
<> 149:156823d33999 309 {
<> 149:156823d33999 310 MODIFY_REG(COMP->CSR, COMP_CSR_OUTSEL |
<> 149:156823d33999 311 COMP_CSR_WNDWE |
<> 149:156823d33999 312 COMP_CSR_SPEED ,
<> 149:156823d33999 313 hcomp->Init.Output |
<> 149:156823d33999 314 hcomp->Init.WindowMode |
<> 149:156823d33999 315 hcomp->Init.Mode );
<> 149:156823d33999 316 }
<> 149:156823d33999 317 else
<> 149:156823d33999 318 {
<> 149:156823d33999 319 MODIFY_REG(COMP->CSR, COMP_CSR_OUTSEL |
<> 149:156823d33999 320 COMP_CSR_INSEL |
<> 149:156823d33999 321 COMP_CSR_WNDWE |
<> 149:156823d33999 322 COMP_CSR_SPEED ,
<> 149:156823d33999 323 hcomp->Init.Output |
<> 149:156823d33999 324 hcomp->Init.InvertingInput |
<> 149:156823d33999 325 hcomp->Init.WindowMode |
<> 149:156823d33999 326 hcomp->Init.Mode );
<> 149:156823d33999 327 }
<> 149:156823d33999 328 }
<> 149:156823d33999 329
<> 149:156823d33999 330 /* Configure Routing Interface (RI) switches for comparator non-inverting */
<> 149:156823d33999 331 /* input. */
<> 149:156823d33999 332 /* Except in 2 cases: */
<> 149:156823d33999 333 /* - if non-inverting input has no selection: it can be the case for */
<> 149:156823d33999 334 /* COMP1 in window mode. */
<> 149:156823d33999 335 /* - particular case for PC3: if switch COMP1_SW1 is closed */
<> 149:156823d33999 336 /* (by macro "__HAL_OPAMP_OPAMP3OUT_CONNECT_ADC_COMP1()" or */
<> 149:156823d33999 337 /* "__HAL_RI_SWITCH_COMP1_SW1_CLOSE()"), connection between pin PC3 */
<> 149:156823d33999 338 /* (or OPAMP3, if available) and COMP1 is done directly, without going */
<> 149:156823d33999 339 /* through ADC switch matrix. */
<> 149:156823d33999 340 if (__COMP_ROUTING_INTERFACE_TOBECONFIGURED(hcomp))
<> 149:156823d33999 341 {
<> 149:156823d33999 342 if (hcomp->Instance == COMP1)
<> 149:156823d33999 343 {
<> 149:156823d33999 344 /* Enable the switch control mode */
<> 149:156823d33999 345 __HAL_RI_SWITCHCONTROLMODE_ENABLE();
<> 149:156823d33999 346
<> 149:156823d33999 347 /* Close the analog switch of ADC switch matrix to COMP1 (ADC */
<> 149:156823d33999 348 /* channel 26: Vcomp) */
<> 149:156823d33999 349 __HAL_RI_IOSWITCH_CLOSE(RI_IOSWITCH_VCOMP);
<> 149:156823d33999 350 }
<> 149:156823d33999 351
<> 149:156823d33999 352 /* Close the I/O analog switch corresponding to comparator */
<> 149:156823d33999 353 /* non-inverting input selected. */
<> 149:156823d33999 354 __HAL_RI_IOSWITCH_CLOSE(hcomp->Init.NonInvertingInput);
<> 149:156823d33999 355 }
<> 149:156823d33999 356
<> 149:156823d33999 357
<> 149:156823d33999 358 /* Initialize the COMP state*/
<> 149:156823d33999 359 if(hcomp->State == HAL_COMP_STATE_RESET)
<> 149:156823d33999 360 {
<> 149:156823d33999 361 hcomp->State = HAL_COMP_STATE_READY;
<> 149:156823d33999 362 }
<> 149:156823d33999 363 }
<> 149:156823d33999 364
<> 149:156823d33999 365 return status;
<> 149:156823d33999 366 }
<> 149:156823d33999 367
<> 149:156823d33999 368
<> 149:156823d33999 369 /**
<> 149:156823d33999 370 * @brief DeInitializes the COMP peripheral
<> 149:156823d33999 371 * @note Deinitialization can't be performed if the COMP configuration is locked.
<> 149:156823d33999 372 * To unlock the configuration, perform a system reset.
<> 149:156823d33999 373 * @param hcomp: COMP handle
<> 149:156823d33999 374 * @retval HAL status
<> 149:156823d33999 375 */
<> 149:156823d33999 376 HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 377 {
<> 149:156823d33999 378 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 379
<> 149:156823d33999 380 /* Check the COMP handle allocation and lock status */
<> 149:156823d33999 381 if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
<> 149:156823d33999 382 {
<> 149:156823d33999 383 status = HAL_ERROR;
<> 149:156823d33999 384 }
<> 149:156823d33999 385 else
<> 149:156823d33999 386 {
<> 149:156823d33999 387 /* Check the parameter */
<> 149:156823d33999 388 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 149:156823d33999 389
<> 149:156823d33999 390 /* Reset configuration depending on comparator instance */
<> 149:156823d33999 391 if (hcomp->Instance == COMP1)
<> 149:156823d33999 392 {
<> 149:156823d33999 393 CLEAR_BIT(COMP->CSR , COMP_CSR_400KPD | COMP_CSR_10KPD | COMP_CSR_400KPU | COMP_CSR_10KPU);
<> 149:156823d33999 394 }
<> 149:156823d33999 395 else /* if (hcomp->Instance == COMP2) */
<> 149:156823d33999 396 {
<> 149:156823d33999 397 CLEAR_BIT(COMP->CSR , COMP_CSR_OUTSEL |
<> 149:156823d33999 398 COMP_CSR_WNDWE |
<> 149:156823d33999 399 COMP_CSR_INSEL |
<> 149:156823d33999 400 COMP_CSR_SPEED );
<> 149:156823d33999 401 }
<> 149:156823d33999 402
<> 149:156823d33999 403
<> 149:156823d33999 404 /* Restore default state of Routing Interface (RI) switches for */
<> 149:156823d33999 405 /* comparator non-inverting input. */
<> 149:156823d33999 406 if (hcomp->Init.NonInvertingInput != COMP_NONINVERTINGINPUT_NONE)
<> 149:156823d33999 407 {
<> 149:156823d33999 408 /* Open the I/O analog switch corresponding to comparator */
<> 149:156823d33999 409 /* non-inverting input selected. */
<> 149:156823d33999 410 __HAL_RI_IOSWITCH_OPEN(hcomp->Init.NonInvertingInput);
<> 149:156823d33999 411 }
<> 149:156823d33999 412 if (hcomp->Instance == COMP1)
<> 149:156823d33999 413 {
<> 149:156823d33999 414 /* Open the analog switch of ADC switch matrix to COMP1 (ADC */
<> 149:156823d33999 415 /* channel 26: Vcomp) */
<> 149:156823d33999 416 __HAL_RI_IOSWITCH_OPEN(RI_IOSWITCH_VCOMP);
<> 149:156823d33999 417
<> 149:156823d33999 418 /* Disable the switch control mode */
<> 149:156823d33999 419 __HAL_RI_SWITCHCONTROLMODE_DISABLE();
<> 149:156823d33999 420 }
<> 149:156823d33999 421
<> 149:156823d33999 422
<> 149:156823d33999 423 /* DeInit the low level hardware: SYSCFG, GPIO, CLOCK and NVIC */
<> 149:156823d33999 424 HAL_COMP_MspDeInit(hcomp);
<> 149:156823d33999 425
<> 149:156823d33999 426 hcomp->State = HAL_COMP_STATE_RESET;
<> 149:156823d33999 427
<> 149:156823d33999 428 /* Process unlocked */
<> 149:156823d33999 429 __HAL_UNLOCK(hcomp);
<> 149:156823d33999 430 }
<> 149:156823d33999 431
<> 149:156823d33999 432 return status;
<> 149:156823d33999 433 }
<> 149:156823d33999 434
<> 149:156823d33999 435 /**
<> 149:156823d33999 436 * @brief Initializes the COMP MSP.
<> 149:156823d33999 437 * @param hcomp: COMP handle
<> 149:156823d33999 438 * @retval None
<> 149:156823d33999 439 */
<> 149:156823d33999 440 __weak void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 441 {
<> 149:156823d33999 442 /* Prevent unused argument(s) compilation warning */
<> 149:156823d33999 443 UNUSED(hcomp);
<> 149:156823d33999 444
<> 149:156823d33999 445 /* NOTE : This function Should not be modified, when the callback is needed,
<> 149:156823d33999 446 the HAL_COMP_MspInit could be implenetd in the user file
<> 149:156823d33999 447 */
<> 149:156823d33999 448 }
<> 149:156823d33999 449
<> 149:156823d33999 450 /**
<> 149:156823d33999 451 * @brief DeInitializes COMP MSP.
<> 149:156823d33999 452 * @param hcomp: COMP handle
<> 149:156823d33999 453 * @retval None
<> 149:156823d33999 454 */
<> 149:156823d33999 455 __weak void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 456 {
<> 149:156823d33999 457 /* Prevent unused argument(s) compilation warning */
<> 149:156823d33999 458 UNUSED(hcomp);
<> 149:156823d33999 459
<> 149:156823d33999 460 /* NOTE : This function Should not be modified, when the callback is needed,
<> 149:156823d33999 461 the HAL_COMP_MspDeInit could be implenetd in the user file
<> 149:156823d33999 462 */
<> 149:156823d33999 463 }
<> 149:156823d33999 464
<> 149:156823d33999 465 /**
<> 149:156823d33999 466 * @}
<> 149:156823d33999 467 */
<> 149:156823d33999 468
<> 149:156823d33999 469 /** @defgroup COMP_Exported_Functions_Group2 I/O operation functions
<> 149:156823d33999 470 * @brief I/O operation functions
<> 149:156823d33999 471 *
<> 149:156823d33999 472 @verbatim
<> 149:156823d33999 473 ===============================================================================
<> 149:156823d33999 474 ##### IO operation functions #####
<> 149:156823d33999 475 ===============================================================================
<> 149:156823d33999 476 [..]
<> 149:156823d33999 477 This subsection provides a set of functions allowing to manage the COMP
<> 149:156823d33999 478 start and stop actions with or without interruption on ExtI line.
<> 149:156823d33999 479
<> 149:156823d33999 480 @endverbatim
<> 149:156823d33999 481 * @{
<> 149:156823d33999 482 */
<> 149:156823d33999 483
<> 149:156823d33999 484 /**
<> 149:156823d33999 485 * @brief Start the comparator
<> 149:156823d33999 486 * @param hcomp: COMP handle
<> 149:156823d33999 487 * @retval HAL status
<> 149:156823d33999 488 */
<> 149:156823d33999 489 HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 490 {
<> 149:156823d33999 491 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 492 uint32_t wait_loop_cycles = 0;
<> 149:156823d33999 493 __IO uint32_t wait_loop_index = 0;
<> 149:156823d33999 494
<> 149:156823d33999 495 /* Check the COMP handle allocation and lock status */
<> 149:156823d33999 496 if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
<> 149:156823d33999 497 {
<> 149:156823d33999 498 status = HAL_ERROR;
<> 149:156823d33999 499 }
<> 149:156823d33999 500 else
<> 149:156823d33999 501 {
<> 149:156823d33999 502 /* Check the parameter */
<> 149:156823d33999 503 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 149:156823d33999 504
<> 149:156823d33999 505 if(hcomp->State == HAL_COMP_STATE_READY)
<> 149:156823d33999 506 {
<> 149:156823d33999 507
<> 149:156823d33999 508 /* Note: For comparator 2, inverting input (parameter */
<> 149:156823d33999 509 /* "hcomp->Init.InvertingInput") is configured into this */
<> 149:156823d33999 510 /* function instead of function "HAL_COMP_Init()" since */
<> 149:156823d33999 511 /* inverting input selection also enables the comparator 2. */
<> 149:156823d33999 512 __HAL_COMP_ENABLE(hcomp);
<> 149:156823d33999 513
<> 149:156823d33999 514 /* Set delay for COMP start-up time */
<> 149:156823d33999 515 if (hcomp->Instance == COMP1)
<> 149:156823d33999 516 {
<> 149:156823d33999 517 wait_loop_cycles = COMP1_START_DELAY_CPU_CYCLES;
<> 149:156823d33999 518 }
<> 149:156823d33999 519 else /* if (hcomp->Instance == COMP2) */
<> 149:156823d33999 520 {
<> 149:156823d33999 521 wait_loop_cycles = COMP2_START_DELAY_CPU_CYCLES;
<> 149:156823d33999 522 }
<> 149:156823d33999 523
<> 149:156823d33999 524 /* Delay for COMP start-up time. */
<> 149:156823d33999 525 /* Delay fixed to worst case: maximum CPU frequency */
<> 149:156823d33999 526 while(wait_loop_index < wait_loop_cycles)
<> 149:156823d33999 527 {
<> 149:156823d33999 528 wait_loop_index++;
<> 149:156823d33999 529 }
<> 149:156823d33999 530
<> 149:156823d33999 531 /* Update COMP state */
<> 149:156823d33999 532 hcomp->State = HAL_COMP_STATE_BUSY;
<> 149:156823d33999 533
<> 149:156823d33999 534 }
<> 149:156823d33999 535 else
<> 149:156823d33999 536 {
<> 149:156823d33999 537 status = HAL_ERROR;
<> 149:156823d33999 538 }
<> 149:156823d33999 539 }
<> 149:156823d33999 540
<> 149:156823d33999 541 return status;
<> 149:156823d33999 542 }
<> 149:156823d33999 543
<> 149:156823d33999 544 /**
<> 149:156823d33999 545 * @brief Stop the comparator
<> 149:156823d33999 546 * @param hcomp: COMP handle
<> 149:156823d33999 547 * @retval HAL status
<> 149:156823d33999 548 */
<> 149:156823d33999 549 HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 550 {
<> 149:156823d33999 551 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 552
<> 149:156823d33999 553 /* Check the COMP handle allocation and lock status */
<> 149:156823d33999 554 if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
<> 149:156823d33999 555 {
<> 149:156823d33999 556 status = HAL_ERROR;
<> 149:156823d33999 557 }
<> 149:156823d33999 558 else
<> 149:156823d33999 559 {
<> 149:156823d33999 560 /* Check the parameter */
<> 149:156823d33999 561 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 149:156823d33999 562
<> 149:156823d33999 563 if(hcomp->State == HAL_COMP_STATE_BUSY)
<> 149:156823d33999 564 {
<> 149:156823d33999 565 /* Disable the selected comparator */
<> 149:156823d33999 566 __HAL_COMP_DISABLE(hcomp);
<> 149:156823d33999 567
<> 149:156823d33999 568 /* Update COMP state */
<> 149:156823d33999 569 hcomp->State = HAL_COMP_STATE_READY;
<> 149:156823d33999 570 }
<> 149:156823d33999 571 else
<> 149:156823d33999 572 {
<> 149:156823d33999 573 status = HAL_ERROR;
<> 149:156823d33999 574 }
<> 149:156823d33999 575 }
<> 149:156823d33999 576
<> 149:156823d33999 577 return status;
<> 149:156823d33999 578 }
<> 149:156823d33999 579
<> 149:156823d33999 580 /**
<> 149:156823d33999 581 * @brief Enables the interrupt and starts the comparator
<> 149:156823d33999 582 * @param hcomp: COMP handle
<> 149:156823d33999 583 * @retval HAL status.
<> 149:156823d33999 584 */
<> 149:156823d33999 585 HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 586 {
<> 149:156823d33999 587 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 588 uint32_t extiline = 0;
<> 149:156823d33999 589
<> 149:156823d33999 590 status = HAL_COMP_Start(hcomp);
<> 149:156823d33999 591 if(status == HAL_OK)
<> 149:156823d33999 592 {
<> 149:156823d33999 593 /* Check the parameter */
<> 149:156823d33999 594 assert_param(IS_COMP_TRIGGERMODE(hcomp->Init.TriggerMode));
<> 149:156823d33999 595
<> 149:156823d33999 596 /* Get the Exti Line output configuration */
<> 149:156823d33999 597 extiline = COMP_GET_EXTI_LINE(hcomp->Instance);
<> 149:156823d33999 598
<> 149:156823d33999 599 /* Configure the trigger rising edge */
<> 149:156823d33999 600 if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_RISING) != RESET)
<> 149:156823d33999 601 {
<> 149:156823d33999 602 SET_BIT(EXTI->RTSR, extiline);
<> 149:156823d33999 603 }
<> 149:156823d33999 604 else
<> 149:156823d33999 605 {
<> 149:156823d33999 606 CLEAR_BIT(EXTI->RTSR, extiline);
<> 149:156823d33999 607 }
<> 149:156823d33999 608
<> 149:156823d33999 609 /* Configure the trigger falling edge */
<> 149:156823d33999 610 if((hcomp->Init.TriggerMode & COMP_TRIGGERMODE_IT_FALLING) != RESET)
<> 149:156823d33999 611 {
<> 149:156823d33999 612 SET_BIT(EXTI->FTSR, extiline);
<> 149:156823d33999 613 }
<> 149:156823d33999 614 else
<> 149:156823d33999 615 {
<> 149:156823d33999 616 CLEAR_BIT(EXTI->FTSR, extiline);
<> 149:156823d33999 617 }
<> 149:156823d33999 618
<> 149:156823d33999 619 /* Clear COMP EXTI pending bit */
<> 149:156823d33999 620 WRITE_REG(EXTI->PR, extiline);
<> 149:156823d33999 621
<> 149:156823d33999 622 /* Enable EXTI interrupt mode */
<> 149:156823d33999 623 SET_BIT(EXTI->IMR, extiline);
<> 149:156823d33999 624
<> 149:156823d33999 625 }
<> 149:156823d33999 626
<> 149:156823d33999 627 return status;
<> 149:156823d33999 628 }
<> 149:156823d33999 629
<> 149:156823d33999 630 /**
<> 149:156823d33999 631 * @brief Disable the interrupt and Stop the comparator
<> 149:156823d33999 632 * @param hcomp: COMP handle
<> 149:156823d33999 633 * @retval HAL status
<> 149:156823d33999 634 */
<> 149:156823d33999 635 HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 636 {
<> 149:156823d33999 637 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 638
<> 149:156823d33999 639 /* Disable the EXTI Line interrupt mode */
<> 149:156823d33999 640 CLEAR_BIT(EXTI->IMR, COMP_GET_EXTI_LINE(hcomp->Instance));
<> 149:156823d33999 641
<> 149:156823d33999 642 status = HAL_COMP_Stop(hcomp);
<> 149:156823d33999 643
<> 149:156823d33999 644 return status;
<> 149:156823d33999 645 }
<> 149:156823d33999 646
<> 149:156823d33999 647 /**
<> 149:156823d33999 648 * @brief Comparator IRQ Handler
<> 149:156823d33999 649 * @param hcomp: COMP handle
<> 149:156823d33999 650 * @retval HAL status
<> 149:156823d33999 651 */
<> 149:156823d33999 652 void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 653 {
<> 149:156823d33999 654 uint32_t extiline = COMP_GET_EXTI_LINE(hcomp->Instance);
<> 149:156823d33999 655
<> 149:156823d33999 656 /* Check COMP Exti flag */
<> 149:156823d33999 657 if(READ_BIT(EXTI->PR, extiline) != RESET)
<> 149:156823d33999 658 {
<> 149:156823d33999 659 /* Clear COMP EXTI pending bit */
<> 149:156823d33999 660 WRITE_REG(EXTI->PR, extiline);
<> 149:156823d33999 661
<> 149:156823d33999 662 /* COMP trigger user callback */
<> 149:156823d33999 663 HAL_COMP_TriggerCallback(hcomp);
<> 149:156823d33999 664 }
<> 149:156823d33999 665 }
<> 149:156823d33999 666
<> 149:156823d33999 667 /**
<> 149:156823d33999 668 * @}
<> 149:156823d33999 669 */
<> 149:156823d33999 670
<> 149:156823d33999 671 /** @defgroup COMP_Exported_Functions_Group3 Peripheral Control functions
<> 149:156823d33999 672 * @brief Peripheral Control functions
<> 149:156823d33999 673 *
<> 149:156823d33999 674 @verbatim
<> 149:156823d33999 675 ===============================================================================
<> 149:156823d33999 676 ##### Peripheral Control functions #####
<> 149:156823d33999 677 ===============================================================================
<> 149:156823d33999 678 [..]
<> 149:156823d33999 679 This subsection provides a set of functions allowing to control the COMP
<> 149:156823d33999 680 management functions: Lock status, comparator output level check, IRQ
<> 149:156823d33999 681 callback (in case of usage of comparator with interruption on ExtI line).
<> 149:156823d33999 682
<> 149:156823d33999 683 @endverbatim
<> 149:156823d33999 684 * @{
<> 149:156823d33999 685 */
<> 149:156823d33999 686
<> 149:156823d33999 687 /**
<> 149:156823d33999 688 * @brief Lock the selected comparator configuration.
<> 149:156823d33999 689 * Caution: On STM32L1, HAL COMP lock is software lock only (not
<> 149:156823d33999 690 * hardware lock as on some other STM32 devices)
<> 149:156823d33999 691 * @param hcomp: COMP handle
<> 149:156823d33999 692 * @retval HAL status
<> 149:156823d33999 693 */
<> 149:156823d33999 694 HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 695 {
<> 149:156823d33999 696 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 697
<> 149:156823d33999 698 /* Check the COMP handle allocation and lock status */
<> 149:156823d33999 699 if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
<> 149:156823d33999 700 {
<> 149:156823d33999 701 status = HAL_ERROR;
<> 149:156823d33999 702 }
<> 149:156823d33999 703 else
<> 149:156823d33999 704 {
<> 149:156823d33999 705 /* Check the parameter */
<> 149:156823d33999 706 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 149:156823d33999 707
<> 149:156823d33999 708 /* Set lock flag on state */
<> 149:156823d33999 709 switch(hcomp->State)
<> 149:156823d33999 710 {
<> 149:156823d33999 711 case HAL_COMP_STATE_BUSY:
<> 149:156823d33999 712 hcomp->State = HAL_COMP_STATE_BUSY_LOCKED;
<> 149:156823d33999 713 break;
<> 149:156823d33999 714 case HAL_COMP_STATE_READY:
<> 149:156823d33999 715 hcomp->State = HAL_COMP_STATE_READY_LOCKED;
<> 149:156823d33999 716 break;
<> 149:156823d33999 717 default:
<> 149:156823d33999 718 /* unexpected state */
<> 149:156823d33999 719 status = HAL_ERROR;
<> 149:156823d33999 720 break;
<> 149:156823d33999 721 }
<> 149:156823d33999 722 }
<> 149:156823d33999 723
<> 149:156823d33999 724 return status;
<> 149:156823d33999 725 }
<> 149:156823d33999 726
<> 149:156823d33999 727 /**
<> 149:156823d33999 728 * @brief Return the output level (high or low) of the selected comparator.
<> 149:156823d33999 729 * The output level depends on the selected polarity.
<> 149:156823d33999 730 * - Comparator output is low when the non-inverting input is at a lower
<> 149:156823d33999 731 * voltage than the inverting input
<> 149:156823d33999 732 * - Comparator output is high when the non-inverting input is at a higher
<> 149:156823d33999 733 * voltage than the inverting input
<> 149:156823d33999 734 * @param hcomp: COMP handle
<> 149:156823d33999 735 * @retval Returns the selected comparator output level: COMP_OUTPUTLEVEL_LOW or COMP_OUTPUTLEVEL_HIGH.
<> 149:156823d33999 736 *
<> 149:156823d33999 737 */
<> 149:156823d33999 738 uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 739 {
<> 149:156823d33999 740 uint32_t level = 0;
<> 149:156823d33999 741
<> 149:156823d33999 742 /* Check the parameter */
<> 149:156823d33999 743 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 149:156823d33999 744
<> 149:156823d33999 745 /* Read output level of the selected comparator */
<> 149:156823d33999 746 if(READ_BIT(COMP->CSR, __COMP_CSR_CMPXOUT(hcomp)) == RESET)
<> 149:156823d33999 747 {
<> 149:156823d33999 748 level = COMP_OUTPUTLEVEL_LOW;
<> 149:156823d33999 749 }
<> 149:156823d33999 750 else
<> 149:156823d33999 751 {
<> 149:156823d33999 752 level = COMP_OUTPUTLEVEL_HIGH;
<> 149:156823d33999 753 }
<> 149:156823d33999 754
<> 149:156823d33999 755 return(level);
<> 149:156823d33999 756 }
<> 149:156823d33999 757
<> 149:156823d33999 758 /**
<> 149:156823d33999 759 * @brief Comparator callback.
<> 149:156823d33999 760 * @param hcomp: COMP handle
<> 149:156823d33999 761 * @retval None
<> 149:156823d33999 762 */
<> 149:156823d33999 763 __weak void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 764 {
<> 149:156823d33999 765 /* Prevent unused argument(s) compilation warning */
<> 149:156823d33999 766 UNUSED(hcomp);
<> 149:156823d33999 767
<> 149:156823d33999 768 /* NOTE : This function should not be modified, when the callback is needed,
<> 149:156823d33999 769 the HAL_COMP_TriggerCallback should be implemented in the user file
<> 149:156823d33999 770 */
<> 149:156823d33999 771 }
<> 149:156823d33999 772
<> 149:156823d33999 773
<> 149:156823d33999 774 /**
<> 149:156823d33999 775 * @}
<> 149:156823d33999 776 */
<> 149:156823d33999 777
<> 149:156823d33999 778 /** @defgroup COMP_Exported_Functions_Group4 Peripheral State functions
<> 149:156823d33999 779 * @brief Peripheral State functions
<> 149:156823d33999 780 *
<> 149:156823d33999 781 @verbatim
<> 149:156823d33999 782 ===============================================================================
<> 149:156823d33999 783 ##### Peripheral State functions #####
<> 149:156823d33999 784 ===============================================================================
<> 149:156823d33999 785 [..]
<> 149:156823d33999 786 This subsection permit to get in run-time the status of the peripheral.
<> 149:156823d33999 787
<> 149:156823d33999 788 @endverbatim
<> 149:156823d33999 789 * @{
<> 149:156823d33999 790 */
<> 149:156823d33999 791
<> 149:156823d33999 792 /**
<> 149:156823d33999 793 * @brief Return the COMP state
<> 149:156823d33999 794 * @param hcomp : COMP handle
<> 149:156823d33999 795 * @retval HAL state
<> 149:156823d33999 796 */
<> 149:156823d33999 797 HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp)
<> 149:156823d33999 798 {
<> 149:156823d33999 799 /* Check the COMP handle allocation */
<> 149:156823d33999 800 if(hcomp == NULL)
<> 149:156823d33999 801 {
<> 149:156823d33999 802 return HAL_COMP_STATE_RESET;
<> 149:156823d33999 803 }
<> 149:156823d33999 804
<> 149:156823d33999 805 /* Check the parameter */
<> 149:156823d33999 806 assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
<> 149:156823d33999 807
<> 149:156823d33999 808 return hcomp->State;
<> 149:156823d33999 809 }
<> 149:156823d33999 810 /**
<> 149:156823d33999 811 * @}
<> 149:156823d33999 812 */
<> 149:156823d33999 813
<> 149:156823d33999 814 /**
<> 149:156823d33999 815 * @}
<> 149:156823d33999 816 */
<> 149:156823d33999 817
<> 149:156823d33999 818 #endif /* HAL_COMP_MODULE_ENABLED */
<> 149:156823d33999 819 /**
<> 149:156823d33999 820 * @}
<> 149:156823d33999 821 */
<> 149:156823d33999 822
<> 149:156823d33999 823 /**
<> 149:156823d33999 824 * @}
<> 149:156823d33999 825 */
<> 149:156823d33999 826
<> 149:156823d33999 827 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/