Senior Design: Sound Monitor / STM32L4xx_HAL_Driver
Committer:
EricLew
Date:
Mon Nov 02 19:37:23 2015 +0000
Revision:
0:80ee8f3b695e
Errors are with definitions of LCD and QSPI functions. I believe all .h and .c files are  uploaded, but there may need to be certain functions called.

Who changed what in which revision?

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