mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
237:f3da66175598
test with CLOCK_SETUP = 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 237:f3da66175598 1 /**
mbed_official 237:f3da66175598 2 ******************************************************************************
mbed_official 237:f3da66175598 3 * @file stm32f3xx_hal_tsc.c
mbed_official 237:f3da66175598 4 * @author MCD Application Team
mbed_official 237:f3da66175598 5 * @version V1.0.1
mbed_official 237:f3da66175598 6 * @date 18-June-2014
mbed_official 237:f3da66175598 7 * @brief This file provides firmware functions to manage the following
mbed_official 237:f3da66175598 8 * functionalities of the Touch Sensing Controller (TSC) peripheral:
mbed_official 237:f3da66175598 9 * + Initialization and DeInitialization
mbed_official 237:f3da66175598 10 * + Channel IOs, Shield IOs and Sampling IOs configuration
mbed_official 237:f3da66175598 11 * + Start and Stop an acquisition
mbed_official 237:f3da66175598 12 * + Read acquisition result
mbed_official 237:f3da66175598 13 * + Interrupts and flags management
mbed_official 237:f3da66175598 14 *
mbed_official 237:f3da66175598 15 @verbatim
mbed_official 237:f3da66175598 16 ================================================================================
mbed_official 237:f3da66175598 17 ##### TSC specific features #####
mbed_official 237:f3da66175598 18 ================================================================================
mbed_official 237:f3da66175598 19 [..]
mbed_official 237:f3da66175598 20 (#) Proven and robust surface charge transfer acquisition principle
mbed_official 237:f3da66175598 21
mbed_official 237:f3da66175598 22 (#) Supports up to 3 capacitive sensing channels per group
mbed_official 237:f3da66175598 23
mbed_official 237:f3da66175598 24 (#) Capacitive sensing channels can be acquired in parallel offering a very good
mbed_official 237:f3da66175598 25 response time
mbed_official 237:f3da66175598 26
mbed_official 237:f3da66175598 27 (#) Spread spectrum feature to improve system robustness in noisy environments
mbed_official 237:f3da66175598 28
mbed_official 237:f3da66175598 29 (#) Full hardware management of the charge transfer acquisition sequence
mbed_official 237:f3da66175598 30
mbed_official 237:f3da66175598 31 (#) Programmable charge transfer frequency
mbed_official 237:f3da66175598 32
mbed_official 237:f3da66175598 33 (#) Programmable sampling capacitor I/O pin
mbed_official 237:f3da66175598 34
mbed_official 237:f3da66175598 35 (#) Programmable channel I/O pin
mbed_official 237:f3da66175598 36
mbed_official 237:f3da66175598 37 (#) Programmable max count value to avoid long acquisition when a channel is faulty
mbed_official 237:f3da66175598 38
mbed_official 237:f3da66175598 39 (#) Dedicated end of acquisition and max count error flags with interrupt capability
mbed_official 237:f3da66175598 40
mbed_official 237:f3da66175598 41 (#) One sampling capacitor for up to 3 capacitive sensing channels to reduce the system
mbed_official 237:f3da66175598 42 components
mbed_official 237:f3da66175598 43
mbed_official 237:f3da66175598 44 (#) Compatible with proximity, touchkey, linear and rotary touch sensor implementation
mbed_official 237:f3da66175598 45
mbed_official 237:f3da66175598 46
mbed_official 237:f3da66175598 47 ##### How to use this driver #####
mbed_official 237:f3da66175598 48 ================================================================================
mbed_official 237:f3da66175598 49 [..]
mbed_official 237:f3da66175598 50 (#) Enable the TSC interface clock using __TSC_CLK_ENABLE() macro.
mbed_official 237:f3da66175598 51
mbed_official 237:f3da66175598 52 (#) GPIO pins configuration
mbed_official 237:f3da66175598 53 (++) Enable the clock for the TSC GPIOs using __GPIOx_CLK_ENABLE() macro.
mbed_official 237:f3da66175598 54 (++) Configure the TSC pins used as sampling IOs in alternate function output Open-Drain mode,
mbed_official 237:f3da66175598 55 and TSC pins used as channel/shield IOs in alternate function output Push-Pull mode
mbed_official 237:f3da66175598 56 using HAL_GPIO_Init() function.
mbed_official 237:f3da66175598 57 (++) Configure the alternate function on all the TSC pins using HAL_xxxx() function.
mbed_official 237:f3da66175598 58
mbed_official 237:f3da66175598 59 (#) Interrupts configuration
mbed_official 237:f3da66175598 60 (++) Configure the NVIC (if the interrupt model is used) using HAL_xxx() function.
mbed_official 237:f3da66175598 61
mbed_official 237:f3da66175598 62 (#) TSC configuration
mbed_official 237:f3da66175598 63 (++) Configure all TSC parameters and used TSC IOs using HAL_TSC_Init() function.
mbed_official 237:f3da66175598 64
mbed_official 237:f3da66175598 65 *** Acquisition sequence ***
mbed_official 237:f3da66175598 66 ===================================
mbed_official 237:f3da66175598 67 [..]
mbed_official 237:f3da66175598 68 (+) Discharge all IOs using HAL_TSC_IODischarge() function.
mbed_official 237:f3da66175598 69 (+) Wait a certain time allowing a good discharge of all capacitors. This delay depends
mbed_official 237:f3da66175598 70 of the sampling capacitor and electrodes design.
mbed_official 237:f3da66175598 71 (+) Select the channel IOs to be acquired using HAL_TSC_IOConfig() function.
mbed_official 237:f3da66175598 72 (+) Launch the acquisition using either HAL_TSC_Start() or HAL_TSC_Start_IT() function.
mbed_official 237:f3da66175598 73 If the synchronized mode is selected, the acquisition will start as soon as the signal
mbed_official 237:f3da66175598 74 is received on the synchro pin.
mbed_official 237:f3da66175598 75 (+) Wait the end of acquisition using either HAL_TSC_PollForAcquisition() or
mbed_official 237:f3da66175598 76 HAL_TSC_GetState() function or using WFI instruction for example.
mbed_official 237:f3da66175598 77 (+) Check the group acquisition status using HAL_TSC_GroupGetStatus() function.
mbed_official 237:f3da66175598 78 (+) Read the acquisition value using HAL_TSC_GroupGetValue() function.
mbed_official 237:f3da66175598 79
mbed_official 237:f3da66175598 80 @endverbatim
mbed_official 237:f3da66175598 81 ******************************************************************************
mbed_official 237:f3da66175598 82 * @attention
mbed_official 237:f3da66175598 83 *
mbed_official 237:f3da66175598 84 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 237:f3da66175598 85 *
mbed_official 237:f3da66175598 86 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 237:f3da66175598 87 * are permitted provided that the following conditions are met:
mbed_official 237:f3da66175598 88 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 237:f3da66175598 89 * this list of conditions and the following disclaimer.
mbed_official 237:f3da66175598 90 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 237:f3da66175598 91 * this list of conditions and the following disclaimer in the documentation
mbed_official 237:f3da66175598 92 * and/or other materials provided with the distribution.
mbed_official 237:f3da66175598 93 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 237:f3da66175598 94 * may be used to endorse or promote products derived from this software
mbed_official 237:f3da66175598 95 * without specific prior written permission.
mbed_official 237:f3da66175598 96 *
mbed_official 237:f3da66175598 97 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 237:f3da66175598 98 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 237:f3da66175598 99 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 237:f3da66175598 100 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 237:f3da66175598 101 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 237:f3da66175598 102 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 237:f3da66175598 103 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 237:f3da66175598 104 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 237:f3da66175598 105 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 237:f3da66175598 106 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 237:f3da66175598 107 *
mbed_official 237:f3da66175598 108 ******************************************************************************
mbed_official 237:f3da66175598 109 */
mbed_official 237:f3da66175598 110
mbed_official 237:f3da66175598 111 /* Includes ------------------------------------------------------------------*/
mbed_official 237:f3da66175598 112 #include "stm32f3xx_hal.h"
mbed_official 237:f3da66175598 113
mbed_official 237:f3da66175598 114 /** @addtogroup STM32F3xx_HAL_Driver
mbed_official 237:f3da66175598 115 * @{
mbed_official 237:f3da66175598 116 */
mbed_official 237:f3da66175598 117
mbed_official 237:f3da66175598 118 /** @defgroup TSC
mbed_official 237:f3da66175598 119 * @brief HAL TSC module driver
mbed_official 237:f3da66175598 120 * @{
mbed_official 237:f3da66175598 121 */
mbed_official 237:f3da66175598 122
mbed_official 237:f3da66175598 123 #ifdef HAL_TSC_MODULE_ENABLED
mbed_official 237:f3da66175598 124
mbed_official 237:f3da66175598 125 /* Private typedef -----------------------------------------------------------*/
mbed_official 237:f3da66175598 126 /* Private define ------------------------------------------------------------*/
mbed_official 237:f3da66175598 127 /* Private macro -------------------------------------------------------------*/
mbed_official 237:f3da66175598 128 /* Private variables ---------------------------------------------------------*/
mbed_official 237:f3da66175598 129 /* Private function prototypes -----------------------------------------------*/
mbed_official 237:f3da66175598 130 static uint32_t TSC_extract_groups(uint32_t iomask);
mbed_official 237:f3da66175598 131 /* Private functions ---------------------------------------------------------*/
mbed_official 237:f3da66175598 132
mbed_official 237:f3da66175598 133 /** @defgroup TSC_Private_Functions
mbed_official 237:f3da66175598 134 * @{
mbed_official 237:f3da66175598 135 */
mbed_official 237:f3da66175598 136
mbed_official 237:f3da66175598 137 /** @defgroup TSC_Group1 Initialization/de-initialization functions
mbed_official 237:f3da66175598 138 * @brief Initialization and Configuration functions
mbed_official 237:f3da66175598 139 *
mbed_official 237:f3da66175598 140 @verbatim
mbed_official 237:f3da66175598 141 ===============================================================================
mbed_official 237:f3da66175598 142 ##### Initialization and de-initialization functions #####
mbed_official 237:f3da66175598 143 ===============================================================================
mbed_official 237:f3da66175598 144 [..] This section provides functions allowing to:
mbed_official 237:f3da66175598 145 (+) Initialize and configure the TSC.
mbed_official 237:f3da66175598 146 (+) De-initialize the TSC.
mbed_official 237:f3da66175598 147 @endverbatim
mbed_official 237:f3da66175598 148 * @{
mbed_official 237:f3da66175598 149 */
mbed_official 237:f3da66175598 150
mbed_official 237:f3da66175598 151 /**
mbed_official 237:f3da66175598 152 * @brief Initializes the TSC peripheral according to the specified parameters
mbed_official 237:f3da66175598 153 * in the TSC_InitTypeDef structure.
mbed_official 237:f3da66175598 154 * @param htsc: TSC handle
mbed_official 237:f3da66175598 155 * @retval HAL status
mbed_official 237:f3da66175598 156 */
mbed_official 237:f3da66175598 157 HAL_StatusTypeDef HAL_TSC_Init(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 158 {
mbed_official 237:f3da66175598 159 /* Check TSC handle allocation */
mbed_official 237:f3da66175598 160 if (htsc == NULL)
mbed_official 237:f3da66175598 161 {
mbed_official 237:f3da66175598 162 return HAL_ERROR;
mbed_official 237:f3da66175598 163 }
mbed_official 237:f3da66175598 164
mbed_official 237:f3da66175598 165 /* Check the parameters */
mbed_official 237:f3da66175598 166 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 167 assert_param(IS_TSC_CTPH(htsc->Init.CTPulseHighLength));
mbed_official 237:f3da66175598 168 assert_param(IS_TSC_CTPL(htsc->Init.CTPulseLowLength));
mbed_official 237:f3da66175598 169 assert_param(IS_TSC_SS(htsc->Init.SpreadSpectrum));
mbed_official 237:f3da66175598 170 assert_param(IS_TSC_SSD(htsc->Init.SpreadSpectrumDeviation));
mbed_official 237:f3da66175598 171 assert_param(IS_TSC_SS_PRESC(htsc->Init.SpreadSpectrumPrescaler));
mbed_official 237:f3da66175598 172 assert_param(IS_TSC_PG_PRESC(htsc->Init.PulseGeneratorPrescaler));
mbed_official 237:f3da66175598 173 assert_param(IS_TSC_MCV(htsc->Init.MaxCountValue));
mbed_official 237:f3da66175598 174 assert_param(IS_TSC_IODEF(htsc->Init.IODefaultMode));
mbed_official 237:f3da66175598 175 assert_param(IS_TSC_SYNC_POL(htsc->Init.SynchroPinPolarity));
mbed_official 237:f3da66175598 176 assert_param(IS_TSC_ACQ_MODE(htsc->Init.AcquisitionMode));
mbed_official 237:f3da66175598 177 assert_param(IS_TSC_MCE_IT(htsc->Init.MaxCountInterrupt));
mbed_official 237:f3da66175598 178
mbed_official 237:f3da66175598 179 /* Initialize the TSC state */
mbed_official 237:f3da66175598 180 htsc->State = HAL_TSC_STATE_BUSY;
mbed_official 237:f3da66175598 181
mbed_official 237:f3da66175598 182 /* Init the low level hardware : GPIO, CLOCK, CORTEX */
mbed_official 237:f3da66175598 183 HAL_TSC_MspInit(htsc);
mbed_official 237:f3da66175598 184
mbed_official 237:f3da66175598 185 /*--------------------------------------------------------------------------*/
mbed_official 237:f3da66175598 186 /* Set TSC parameters */
mbed_official 237:f3da66175598 187
mbed_official 237:f3da66175598 188 /* Enable TSC */
mbed_official 237:f3da66175598 189 htsc->Instance->CR = TSC_CR_TSCE;
mbed_official 237:f3da66175598 190
mbed_official 237:f3da66175598 191 /* Set all functions */
mbed_official 237:f3da66175598 192 htsc->Instance->CR |= (htsc->Init.CTPulseHighLength |
mbed_official 237:f3da66175598 193 htsc->Init.CTPulseLowLength |
mbed_official 237:f3da66175598 194 (uint32_t)(htsc->Init.SpreadSpectrumDeviation << 17) |
mbed_official 237:f3da66175598 195 htsc->Init.SpreadSpectrumPrescaler |
mbed_official 237:f3da66175598 196 htsc->Init.PulseGeneratorPrescaler |
mbed_official 237:f3da66175598 197 htsc->Init.MaxCountValue |
mbed_official 237:f3da66175598 198 htsc->Init.IODefaultMode |
mbed_official 237:f3da66175598 199 htsc->Init.SynchroPinPolarity |
mbed_official 237:f3da66175598 200 htsc->Init.AcquisitionMode);
mbed_official 237:f3da66175598 201
mbed_official 237:f3da66175598 202 /* Spread spectrum */
mbed_official 237:f3da66175598 203 if (htsc->Init.SpreadSpectrum == ENABLE)
mbed_official 237:f3da66175598 204 {
mbed_official 237:f3da66175598 205 htsc->Instance->CR |= TSC_CR_SSE;
mbed_official 237:f3da66175598 206 }
mbed_official 237:f3da66175598 207
mbed_official 237:f3da66175598 208 /* Disable Schmitt trigger hysteresis on all used TSC IOs */
mbed_official 237:f3da66175598 209 htsc->Instance->IOHCR = (uint32_t)(~(htsc->Init.ChannelIOs | htsc->Init.ShieldIOs | htsc->Init.SamplingIOs));
mbed_official 237:f3da66175598 210
mbed_official 237:f3da66175598 211 /* Set channel and shield IOs */
mbed_official 237:f3da66175598 212 htsc->Instance->IOCCR = (htsc->Init.ChannelIOs | htsc->Init.ShieldIOs);
mbed_official 237:f3da66175598 213
mbed_official 237:f3da66175598 214 /* Set sampling IOs */
mbed_official 237:f3da66175598 215 htsc->Instance->IOSCR = htsc->Init.SamplingIOs;
mbed_official 237:f3da66175598 216
mbed_official 237:f3da66175598 217 /* Set the groups to be acquired */
mbed_official 237:f3da66175598 218 htsc->Instance->IOGCSR = TSC_extract_groups(htsc->Init.ChannelIOs);
mbed_official 237:f3da66175598 219
mbed_official 237:f3da66175598 220 /* Disable interrupts */
mbed_official 237:f3da66175598 221 htsc->Instance->IER &= (uint32_t)(~(TSC_IT_EOA | TSC_IT_MCE));
mbed_official 237:f3da66175598 222
mbed_official 237:f3da66175598 223 /* Clear flags */
mbed_official 237:f3da66175598 224 htsc->Instance->ICR = (TSC_FLAG_EOA | TSC_FLAG_MCE);
mbed_official 237:f3da66175598 225
mbed_official 237:f3da66175598 226 /*--------------------------------------------------------------------------*/
mbed_official 237:f3da66175598 227
mbed_official 237:f3da66175598 228 /* Initialize the TSC state */
mbed_official 237:f3da66175598 229 htsc->State = HAL_TSC_STATE_READY;
mbed_official 237:f3da66175598 230
mbed_official 237:f3da66175598 231 /* Return function status */
mbed_official 237:f3da66175598 232 return HAL_OK;
mbed_official 237:f3da66175598 233 }
mbed_official 237:f3da66175598 234
mbed_official 237:f3da66175598 235 /**
mbed_official 237:f3da66175598 236 * @brief Deinitializes the TSC peripheral registers to their default reset values.
mbed_official 237:f3da66175598 237 * @param htsc: TSC handle
mbed_official 237:f3da66175598 238 * @retval HAL status
mbed_official 237:f3da66175598 239 */
mbed_official 237:f3da66175598 240 HAL_StatusTypeDef HAL_TSC_DeInit(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 241 {
mbed_official 237:f3da66175598 242 /* Check TSC handle allocation */
mbed_official 237:f3da66175598 243 if (htsc == NULL)
mbed_official 237:f3da66175598 244 {
mbed_official 237:f3da66175598 245 return HAL_ERROR;
mbed_official 237:f3da66175598 246 }
mbed_official 237:f3da66175598 247
mbed_official 237:f3da66175598 248 /* Check the parameters */
mbed_official 237:f3da66175598 249 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 250
mbed_official 237:f3da66175598 251 /* Change TSC state */
mbed_official 237:f3da66175598 252 htsc->State = HAL_TSC_STATE_BUSY;
mbed_official 237:f3da66175598 253
mbed_official 237:f3da66175598 254 /* DeInit the low level hardware */
mbed_official 237:f3da66175598 255 HAL_TSC_MspDeInit(htsc);
mbed_official 237:f3da66175598 256
mbed_official 237:f3da66175598 257 /* Change TSC state */
mbed_official 237:f3da66175598 258 htsc->State = HAL_TSC_STATE_RESET;
mbed_official 237:f3da66175598 259
mbed_official 237:f3da66175598 260 /* Process unlocked */
mbed_official 237:f3da66175598 261 __HAL_UNLOCK(htsc);
mbed_official 237:f3da66175598 262
mbed_official 237:f3da66175598 263 /* Return function status */
mbed_official 237:f3da66175598 264 return HAL_OK;
mbed_official 237:f3da66175598 265 }
mbed_official 237:f3da66175598 266
mbed_official 237:f3da66175598 267 /**
mbed_official 237:f3da66175598 268 * @brief Initializes the TSC MSP.
mbed_official 237:f3da66175598 269 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 270 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 271 * @retval None
mbed_official 237:f3da66175598 272 */
mbed_official 237:f3da66175598 273 __weak void HAL_TSC_MspInit(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 274 {
mbed_official 237:f3da66175598 275 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 276 the HAL_TSC_MspInit could be implemented in the user file.
mbed_official 237:f3da66175598 277 */
mbed_official 237:f3da66175598 278 }
mbed_official 237:f3da66175598 279
mbed_official 237:f3da66175598 280 /**
mbed_official 237:f3da66175598 281 * @brief DeInitializes the TSC MSP.
mbed_official 237:f3da66175598 282 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 283 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 284 * @retval None
mbed_official 237:f3da66175598 285 */
mbed_official 237:f3da66175598 286 __weak void HAL_TSC_MspDeInit(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 287 {
mbed_official 237:f3da66175598 288 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 289 the HAL_TSC_MspDeInit could be implemented in the user file.
mbed_official 237:f3da66175598 290 */
mbed_official 237:f3da66175598 291 }
mbed_official 237:f3da66175598 292
mbed_official 237:f3da66175598 293 /**
mbed_official 237:f3da66175598 294 * @}
mbed_official 237:f3da66175598 295 */
mbed_official 237:f3da66175598 296
mbed_official 237:f3da66175598 297 /** @defgroup HAL_TSC_Group2 IO operation functions
mbed_official 237:f3da66175598 298 * @brief IO operation functions
mbed_official 237:f3da66175598 299 *
mbed_official 237:f3da66175598 300 @verbatim
mbed_official 237:f3da66175598 301 ===============================================================================
mbed_official 237:f3da66175598 302 ##### I/O Operation functions #####
mbed_official 237:f3da66175598 303 ===============================================================================
mbed_official 237:f3da66175598 304 [..] This section provides functions allowing to:
mbed_official 237:f3da66175598 305 (+) Start acquisition in polling mode.
mbed_official 237:f3da66175598 306 (+) Start acquisition in interrupt mode.
mbed_official 237:f3da66175598 307 (+) Stop conversion in polling mode.
mbed_official 237:f3da66175598 308 (+) Stop conversion in interrupt mode.
mbed_official 237:f3da66175598 309 (+) Get group acquisition status.
mbed_official 237:f3da66175598 310 (+) Get group acquisition value.
mbed_official 237:f3da66175598 311 @endverbatim
mbed_official 237:f3da66175598 312 * @{
mbed_official 237:f3da66175598 313 */
mbed_official 237:f3da66175598 314
mbed_official 237:f3da66175598 315 /**
mbed_official 237:f3da66175598 316 * @brief Starts the acquisition.
mbed_official 237:f3da66175598 317 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 318 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 319 * @retval HAL status
mbed_official 237:f3da66175598 320 */
mbed_official 237:f3da66175598 321 HAL_StatusTypeDef HAL_TSC_Start(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 322 {
mbed_official 237:f3da66175598 323 /* Check the parameters */
mbed_official 237:f3da66175598 324 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 325
mbed_official 237:f3da66175598 326 /* Process locked */
mbed_official 237:f3da66175598 327 __HAL_LOCK(htsc);
mbed_official 237:f3da66175598 328
mbed_official 237:f3da66175598 329 /* Change TSC state */
mbed_official 237:f3da66175598 330 htsc->State = HAL_TSC_STATE_BUSY;
mbed_official 237:f3da66175598 331
mbed_official 237:f3da66175598 332 /* Clear interrupts */
mbed_official 237:f3da66175598 333 __HAL_TSC_DISABLE_IT(htsc, (TSC_IT_EOA | TSC_IT_MCE));
mbed_official 237:f3da66175598 334
mbed_official 237:f3da66175598 335 /* Clear flags */
mbed_official 237:f3da66175598 336 __HAL_TSC_CLEAR_FLAG(htsc, (TSC_FLAG_EOA | TSC_FLAG_MCE));
mbed_official 237:f3da66175598 337
mbed_official 237:f3da66175598 338 /* Stop discharging the IOs */
mbed_official 237:f3da66175598 339 __HAL_TSC_SET_IODEF_INFLOAT(htsc);
mbed_official 237:f3da66175598 340
mbed_official 237:f3da66175598 341 /* Launch the acquisition */
mbed_official 237:f3da66175598 342 __HAL_TSC_START_ACQ(htsc);
mbed_official 237:f3da66175598 343
mbed_official 237:f3da66175598 344 /* Process unlocked */
mbed_official 237:f3da66175598 345 __HAL_UNLOCK(htsc);
mbed_official 237:f3da66175598 346
mbed_official 237:f3da66175598 347 /* Return function status */
mbed_official 237:f3da66175598 348 return HAL_OK;
mbed_official 237:f3da66175598 349 }
mbed_official 237:f3da66175598 350
mbed_official 237:f3da66175598 351 /**
mbed_official 237:f3da66175598 352 * @brief Enables the interrupt and starts the acquisition
mbed_official 237:f3da66175598 353 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 354 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 355 * @retval HAL status.
mbed_official 237:f3da66175598 356 */
mbed_official 237:f3da66175598 357 HAL_StatusTypeDef HAL_TSC_Start_IT(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 358 {
mbed_official 237:f3da66175598 359 /* Check the parameters */
mbed_official 237:f3da66175598 360 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 361 assert_param(IS_TSC_MCE_IT(htsc->Init.MaxCountInterrupt));
mbed_official 237:f3da66175598 362
mbed_official 237:f3da66175598 363 /* Process locked */
mbed_official 237:f3da66175598 364 __HAL_LOCK(htsc);
mbed_official 237:f3da66175598 365
mbed_official 237:f3da66175598 366 /* Change TSC state */
mbed_official 237:f3da66175598 367 htsc->State = HAL_TSC_STATE_BUSY;
mbed_official 237:f3da66175598 368
mbed_official 237:f3da66175598 369 /* Enable end of acquisition interrupt */
mbed_official 237:f3da66175598 370 __HAL_TSC_ENABLE_IT(htsc, TSC_IT_EOA);
mbed_official 237:f3da66175598 371
mbed_official 237:f3da66175598 372 /* Enable max count error interrupt (optional) */
mbed_official 237:f3da66175598 373 if (htsc->Init.MaxCountInterrupt == ENABLE)
mbed_official 237:f3da66175598 374 {
mbed_official 237:f3da66175598 375 __HAL_TSC_ENABLE_IT(htsc, TSC_IT_MCE);
mbed_official 237:f3da66175598 376 }
mbed_official 237:f3da66175598 377 else
mbed_official 237:f3da66175598 378 {
mbed_official 237:f3da66175598 379 __HAL_TSC_DISABLE_IT(htsc, TSC_IT_MCE);
mbed_official 237:f3da66175598 380 }
mbed_official 237:f3da66175598 381
mbed_official 237:f3da66175598 382 /* Clear flags */
mbed_official 237:f3da66175598 383 __HAL_TSC_CLEAR_FLAG(htsc, (TSC_FLAG_EOA | TSC_FLAG_MCE));
mbed_official 237:f3da66175598 384
mbed_official 237:f3da66175598 385 /* Stop discharging the IOs */
mbed_official 237:f3da66175598 386 __HAL_TSC_SET_IODEF_INFLOAT(htsc);
mbed_official 237:f3da66175598 387
mbed_official 237:f3da66175598 388 /* Launch the acquisition */
mbed_official 237:f3da66175598 389 __HAL_TSC_START_ACQ(htsc);
mbed_official 237:f3da66175598 390
mbed_official 237:f3da66175598 391 /* Process unlocked */
mbed_official 237:f3da66175598 392 __HAL_UNLOCK(htsc);
mbed_official 237:f3da66175598 393
mbed_official 237:f3da66175598 394 /* Return function status */
mbed_official 237:f3da66175598 395 return HAL_OK;
mbed_official 237:f3da66175598 396 }
mbed_official 237:f3da66175598 397
mbed_official 237:f3da66175598 398 /**
mbed_official 237:f3da66175598 399 * @brief Stops the acquisition previously launched in polling mode
mbed_official 237:f3da66175598 400 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 401 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 402 * @retval HAL status
mbed_official 237:f3da66175598 403 */
mbed_official 237:f3da66175598 404 HAL_StatusTypeDef HAL_TSC_Stop(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 405 {
mbed_official 237:f3da66175598 406 /* Check the parameters */
mbed_official 237:f3da66175598 407 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 408
mbed_official 237:f3da66175598 409 /* Process locked */
mbed_official 237:f3da66175598 410 __HAL_LOCK(htsc);
mbed_official 237:f3da66175598 411
mbed_official 237:f3da66175598 412 /* Stop the acquisition */
mbed_official 237:f3da66175598 413 __HAL_TSC_STOP_ACQ(htsc);
mbed_official 237:f3da66175598 414
mbed_official 237:f3da66175598 415 /* Clear flags */
mbed_official 237:f3da66175598 416 __HAL_TSC_CLEAR_FLAG(htsc, (TSC_FLAG_EOA | TSC_FLAG_MCE));
mbed_official 237:f3da66175598 417
mbed_official 237:f3da66175598 418 /* Change TSC state */
mbed_official 237:f3da66175598 419 htsc->State = HAL_TSC_STATE_READY;
mbed_official 237:f3da66175598 420
mbed_official 237:f3da66175598 421 /* Process unlocked */
mbed_official 237:f3da66175598 422 __HAL_UNLOCK(htsc);
mbed_official 237:f3da66175598 423
mbed_official 237:f3da66175598 424 /* Return function status */
mbed_official 237:f3da66175598 425 return HAL_OK;
mbed_official 237:f3da66175598 426 }
mbed_official 237:f3da66175598 427
mbed_official 237:f3da66175598 428 /**
mbed_official 237:f3da66175598 429 * @brief Stops the acquisition previously launched in interrupt mode
mbed_official 237:f3da66175598 430 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 431 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 432 * @retval HAL status
mbed_official 237:f3da66175598 433 */
mbed_official 237:f3da66175598 434 HAL_StatusTypeDef HAL_TSC_Stop_IT(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 435 {
mbed_official 237:f3da66175598 436 /* Check the parameters */
mbed_official 237:f3da66175598 437 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 438
mbed_official 237:f3da66175598 439 /* Process locked */
mbed_official 237:f3da66175598 440 __HAL_LOCK(htsc);
mbed_official 237:f3da66175598 441
mbed_official 237:f3da66175598 442 /* Stop the acquisition */
mbed_official 237:f3da66175598 443 __HAL_TSC_STOP_ACQ(htsc);
mbed_official 237:f3da66175598 444
mbed_official 237:f3da66175598 445 /* Disable interrupts */
mbed_official 237:f3da66175598 446 __HAL_TSC_DISABLE_IT(htsc, (TSC_IT_EOA | TSC_IT_MCE));
mbed_official 237:f3da66175598 447
mbed_official 237:f3da66175598 448 /* Clear flags */
mbed_official 237:f3da66175598 449 __HAL_TSC_CLEAR_FLAG(htsc, (TSC_FLAG_EOA | TSC_FLAG_MCE));
mbed_official 237:f3da66175598 450
mbed_official 237:f3da66175598 451 /* Change TSC state */
mbed_official 237:f3da66175598 452 htsc->State = HAL_TSC_STATE_READY;
mbed_official 237:f3da66175598 453
mbed_official 237:f3da66175598 454 /* Process unlocked */
mbed_official 237:f3da66175598 455 __HAL_UNLOCK(htsc);
mbed_official 237:f3da66175598 456
mbed_official 237:f3da66175598 457 /* Return function status */
mbed_official 237:f3da66175598 458 return HAL_OK;
mbed_official 237:f3da66175598 459 }
mbed_official 237:f3da66175598 460
mbed_official 237:f3da66175598 461 /**
mbed_official 237:f3da66175598 462 * @brief Gets the acquisition status for a group
mbed_official 237:f3da66175598 463 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 464 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 465 * @param gx_index: Index of the group
mbed_official 237:f3da66175598 466 * @retval Group status
mbed_official 237:f3da66175598 467 */
mbed_official 237:f3da66175598 468 TSC_GroupStatusTypeDef HAL_TSC_GroupGetStatus(TSC_HandleTypeDef* htsc, uint32_t gx_index)
mbed_official 237:f3da66175598 469 {
mbed_official 237:f3da66175598 470 /* Check the parameters */
mbed_official 237:f3da66175598 471 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 472 assert_param(IS_GROUP_INDEX(gx_index));
mbed_official 237:f3da66175598 473
mbed_official 237:f3da66175598 474 /* Return the group status */
mbed_official 237:f3da66175598 475 return(__HAL_TSC_GET_GROUP_STATUS(htsc, gx_index));
mbed_official 237:f3da66175598 476 }
mbed_official 237:f3da66175598 477
mbed_official 237:f3da66175598 478 /**
mbed_official 237:f3da66175598 479 * @brief Gets the acquisition measure for a group
mbed_official 237:f3da66175598 480 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 481 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 482 * @param gx_index: Index of the group
mbed_official 237:f3da66175598 483 * @retval Acquisition measure
mbed_official 237:f3da66175598 484 */
mbed_official 237:f3da66175598 485 uint32_t HAL_TSC_GroupGetValue(TSC_HandleTypeDef* htsc, uint32_t gx_index)
mbed_official 237:f3da66175598 486 {
mbed_official 237:f3da66175598 487 /* Check the parameters */
mbed_official 237:f3da66175598 488 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 489 assert_param(IS_GROUP_INDEX(gx_index));
mbed_official 237:f3da66175598 490
mbed_official 237:f3da66175598 491 /* Return the group acquisition counter */
mbed_official 237:f3da66175598 492 return htsc->Instance->IOGXCR[gx_index];
mbed_official 237:f3da66175598 493 }
mbed_official 237:f3da66175598 494
mbed_official 237:f3da66175598 495 /**
mbed_official 237:f3da66175598 496 * @}
mbed_official 237:f3da66175598 497 */
mbed_official 237:f3da66175598 498
mbed_official 237:f3da66175598 499 /** @defgroup HAL_TSC_Group3 Peripheral Control functions
mbed_official 237:f3da66175598 500 * @brief Peripheral Control functions
mbed_official 237:f3da66175598 501 *
mbed_official 237:f3da66175598 502 @verbatim
mbed_official 237:f3da66175598 503 ===============================================================================
mbed_official 237:f3da66175598 504 ##### Peripheral Control functions #####
mbed_official 237:f3da66175598 505 ===============================================================================
mbed_official 237:f3da66175598 506 [..] This section provides functions allowing to:
mbed_official 237:f3da66175598 507 (+) Configure TSC IOs
mbed_official 237:f3da66175598 508 (+) Discharge TSC IOs
mbed_official 237:f3da66175598 509 @endverbatim
mbed_official 237:f3da66175598 510 * @{
mbed_official 237:f3da66175598 511 */
mbed_official 237:f3da66175598 512
mbed_official 237:f3da66175598 513 /**
mbed_official 237:f3da66175598 514 * @brief Configures TSC IOs
mbed_official 237:f3da66175598 515 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 516 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 517 * @param config: pointer to the configuration structure.
mbed_official 237:f3da66175598 518 * @retval HAL status
mbed_official 237:f3da66175598 519 */
mbed_official 237:f3da66175598 520 HAL_StatusTypeDef HAL_TSC_IOConfig(TSC_HandleTypeDef* htsc, TSC_IOConfigTypeDef* config)
mbed_official 237:f3da66175598 521 {
mbed_official 237:f3da66175598 522 /* Check the parameters */
mbed_official 237:f3da66175598 523 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 524
mbed_official 237:f3da66175598 525 /* Process locked */
mbed_official 237:f3da66175598 526 __HAL_LOCK(htsc);
mbed_official 237:f3da66175598 527
mbed_official 237:f3da66175598 528 /* Stop acquisition */
mbed_official 237:f3da66175598 529 __HAL_TSC_STOP_ACQ(htsc);
mbed_official 237:f3da66175598 530
mbed_official 237:f3da66175598 531 /* Disable Schmitt trigger hysteresis on all used TSC IOs */
mbed_official 237:f3da66175598 532 htsc->Instance->IOHCR = (uint32_t)(~(config->ChannelIOs | config->ShieldIOs | config->SamplingIOs));
mbed_official 237:f3da66175598 533
mbed_official 237:f3da66175598 534 /* Set channel and shield IOs */
mbed_official 237:f3da66175598 535 htsc->Instance->IOCCR = (config->ChannelIOs | config->ShieldIOs);
mbed_official 237:f3da66175598 536
mbed_official 237:f3da66175598 537 /* Set sampling IOs */
mbed_official 237:f3da66175598 538 htsc->Instance->IOSCR = config->SamplingIOs;
mbed_official 237:f3da66175598 539
mbed_official 237:f3da66175598 540 /* Set groups to be acquired */
mbed_official 237:f3da66175598 541 htsc->Instance->IOGCSR = TSC_extract_groups(config->ChannelIOs);
mbed_official 237:f3da66175598 542
mbed_official 237:f3da66175598 543 /* Process unlocked */
mbed_official 237:f3da66175598 544 __HAL_UNLOCK(htsc);
mbed_official 237:f3da66175598 545
mbed_official 237:f3da66175598 546 /* Return function status */
mbed_official 237:f3da66175598 547 return HAL_OK;
mbed_official 237:f3da66175598 548 }
mbed_official 237:f3da66175598 549
mbed_official 237:f3da66175598 550 /**
mbed_official 237:f3da66175598 551 * @brief Discharge TSC IOs
mbed_official 237:f3da66175598 552 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 553 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 554 * @param choice: enable or disable
mbed_official 237:f3da66175598 555 * @retval HAL status
mbed_official 237:f3da66175598 556 */
mbed_official 237:f3da66175598 557 HAL_StatusTypeDef HAL_TSC_IODischarge(TSC_HandleTypeDef* htsc, uint32_t choice)
mbed_official 237:f3da66175598 558 {
mbed_official 237:f3da66175598 559 /* Check the parameters */
mbed_official 237:f3da66175598 560 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 561
mbed_official 237:f3da66175598 562 /* Process locked */
mbed_official 237:f3da66175598 563 __HAL_LOCK(htsc);
mbed_official 237:f3da66175598 564
mbed_official 237:f3da66175598 565 if (choice == ENABLE)
mbed_official 237:f3da66175598 566 {
mbed_official 237:f3da66175598 567 __HAL_TSC_SET_IODEF_OUTPPLOW(htsc);
mbed_official 237:f3da66175598 568 }
mbed_official 237:f3da66175598 569 else
mbed_official 237:f3da66175598 570 {
mbed_official 237:f3da66175598 571 __HAL_TSC_SET_IODEF_INFLOAT(htsc);
mbed_official 237:f3da66175598 572 }
mbed_official 237:f3da66175598 573
mbed_official 237:f3da66175598 574 /* Process unlocked */
mbed_official 237:f3da66175598 575 __HAL_UNLOCK(htsc);
mbed_official 237:f3da66175598 576
mbed_official 237:f3da66175598 577 /* Return the group acquisition counter */
mbed_official 237:f3da66175598 578 return HAL_OK;
mbed_official 237:f3da66175598 579 }
mbed_official 237:f3da66175598 580
mbed_official 237:f3da66175598 581 /**
mbed_official 237:f3da66175598 582 * @}
mbed_official 237:f3da66175598 583 */
mbed_official 237:f3da66175598 584
mbed_official 237:f3da66175598 585 /** @defgroup HAL_TSC_Group4 State functions
mbed_official 237:f3da66175598 586 * @brief State functions
mbed_official 237:f3da66175598 587 *
mbed_official 237:f3da66175598 588 @verbatim
mbed_official 237:f3da66175598 589 ===============================================================================
mbed_official 237:f3da66175598 590 ##### State functions #####
mbed_official 237:f3da66175598 591 ===============================================================================
mbed_official 237:f3da66175598 592 [..]
mbed_official 237:f3da66175598 593 This subsection provides functions allowing to
mbed_official 237:f3da66175598 594 (+) Get TSC state.
mbed_official 237:f3da66175598 595 (+) Poll for acquisition completed.
mbed_official 237:f3da66175598 596 (+) Handles TSC interrupt request.
mbed_official 237:f3da66175598 597
mbed_official 237:f3da66175598 598 @endverbatim
mbed_official 237:f3da66175598 599 * @{
mbed_official 237:f3da66175598 600 */
mbed_official 237:f3da66175598 601
mbed_official 237:f3da66175598 602 /**
mbed_official 237:f3da66175598 603 * @brief Return the TSC state
mbed_official 237:f3da66175598 604 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 605 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 606 * @retval HAL state
mbed_official 237:f3da66175598 607 */
mbed_official 237:f3da66175598 608 HAL_TSC_StateTypeDef HAL_TSC_GetState(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 609 {
mbed_official 237:f3da66175598 610 /* Check the parameters */
mbed_official 237:f3da66175598 611 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 612
mbed_official 237:f3da66175598 613 if (htsc->State == HAL_TSC_STATE_BUSY)
mbed_official 237:f3da66175598 614 {
mbed_official 237:f3da66175598 615 /* Check end of acquisition flag */
mbed_official 237:f3da66175598 616 if (__HAL_TSC_GET_FLAG(htsc, TSC_FLAG_EOA) != RESET)
mbed_official 237:f3da66175598 617 {
mbed_official 237:f3da66175598 618 /* Check max count error flag */
mbed_official 237:f3da66175598 619 if (__HAL_TSC_GET_FLAG(htsc, TSC_FLAG_MCE) != RESET)
mbed_official 237:f3da66175598 620 {
mbed_official 237:f3da66175598 621 /* Change TSC state */
mbed_official 237:f3da66175598 622 htsc->State = HAL_TSC_STATE_ERROR;
mbed_official 237:f3da66175598 623 }
mbed_official 237:f3da66175598 624 else
mbed_official 237:f3da66175598 625 {
mbed_official 237:f3da66175598 626 /* Change TSC state */
mbed_official 237:f3da66175598 627 htsc->State = HAL_TSC_STATE_READY;
mbed_official 237:f3da66175598 628 }
mbed_official 237:f3da66175598 629 }
mbed_official 237:f3da66175598 630 }
mbed_official 237:f3da66175598 631
mbed_official 237:f3da66175598 632 /* Return TSC state */
mbed_official 237:f3da66175598 633 return htsc->State;
mbed_official 237:f3da66175598 634 }
mbed_official 237:f3da66175598 635
mbed_official 237:f3da66175598 636 /**
mbed_official 237:f3da66175598 637 * @brief Start acquisition and wait until completion
mbed_official 237:f3da66175598 638 * @note There is no need of a timeout parameter as the max count error is already
mbed_official 237:f3da66175598 639 * managed by the TSC peripheral.
mbed_official 237:f3da66175598 640 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 641 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 642 * @retval HAL state
mbed_official 237:f3da66175598 643 */
mbed_official 237:f3da66175598 644 HAL_StatusTypeDef HAL_TSC_PollForAcquisition(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 645 {
mbed_official 237:f3da66175598 646 /* Check the parameters */
mbed_official 237:f3da66175598 647 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 648
mbed_official 237:f3da66175598 649 /* Process locked */
mbed_official 237:f3da66175598 650 __HAL_LOCK(htsc);
mbed_official 237:f3da66175598 651
mbed_official 237:f3da66175598 652 /* Check end of acquisition */
mbed_official 237:f3da66175598 653 while (HAL_TSC_GetState(htsc) == HAL_TSC_STATE_BUSY)
mbed_official 237:f3da66175598 654 {
mbed_official 237:f3da66175598 655 /* The timeout (max count error) is managed by the TSC peripheral itself. */
mbed_official 237:f3da66175598 656 }
mbed_official 237:f3da66175598 657
mbed_official 237:f3da66175598 658 /* Process unlocked */
mbed_official 237:f3da66175598 659 __HAL_UNLOCK(htsc);
mbed_official 237:f3da66175598 660
mbed_official 237:f3da66175598 661 return HAL_OK;
mbed_official 237:f3da66175598 662 }
mbed_official 237:f3da66175598 663
mbed_official 237:f3da66175598 664 /**
mbed_official 237:f3da66175598 665 * @brief Handles TSC interrupt request
mbed_official 237:f3da66175598 666 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 667 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 668 * @retval None
mbed_official 237:f3da66175598 669 */
mbed_official 237:f3da66175598 670 void HAL_TSC_IRQHandler(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 671 {
mbed_official 237:f3da66175598 672 /* Check the parameters */
mbed_official 237:f3da66175598 673 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 237:f3da66175598 674
mbed_official 237:f3da66175598 675 /* Check if the end of acquisition occured */
mbed_official 237:f3da66175598 676 if (__HAL_TSC_GET_FLAG(htsc, TSC_FLAG_EOA) != RESET)
mbed_official 237:f3da66175598 677 {
mbed_official 237:f3da66175598 678 /* Clear EOA flag */
mbed_official 237:f3da66175598 679 __HAL_TSC_CLEAR_FLAG(htsc, TSC_FLAG_EOA);
mbed_official 237:f3da66175598 680 }
mbed_official 237:f3da66175598 681
mbed_official 237:f3da66175598 682 /* Check if max count error occured */
mbed_official 237:f3da66175598 683 if (__HAL_TSC_GET_FLAG(htsc, TSC_FLAG_MCE) != RESET)
mbed_official 237:f3da66175598 684 {
mbed_official 237:f3da66175598 685 /* Clear MCE flag */
mbed_official 237:f3da66175598 686 __HAL_TSC_CLEAR_FLAG(htsc, TSC_FLAG_MCE);
mbed_official 237:f3da66175598 687 /* Change TSC state */
mbed_official 237:f3da66175598 688 htsc->State = HAL_TSC_STATE_ERROR;
mbed_official 237:f3da66175598 689 /* Conversion completed callback */
mbed_official 237:f3da66175598 690 HAL_TSC_ErrorCallback(htsc);
mbed_official 237:f3da66175598 691 }
mbed_official 237:f3da66175598 692 else
mbed_official 237:f3da66175598 693 {
mbed_official 237:f3da66175598 694 /* Change TSC state */
mbed_official 237:f3da66175598 695 htsc->State = HAL_TSC_STATE_READY;
mbed_official 237:f3da66175598 696 /* Conversion completed callback */
mbed_official 237:f3da66175598 697 HAL_TSC_ConvCpltCallback(htsc);
mbed_official 237:f3da66175598 698 }
mbed_official 237:f3da66175598 699 }
mbed_official 237:f3da66175598 700
mbed_official 237:f3da66175598 701 /**
mbed_official 237:f3da66175598 702 * @}
mbed_official 237:f3da66175598 703 */
mbed_official 237:f3da66175598 704
mbed_official 237:f3da66175598 705 /**
mbed_official 237:f3da66175598 706 * @brief Acquisition completed callback in non blocking mode
mbed_official 237:f3da66175598 707 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 708 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 709 * @retval None
mbed_official 237:f3da66175598 710 */
mbed_official 237:f3da66175598 711 __weak void HAL_TSC_ConvCpltCallback(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 712 {
mbed_official 237:f3da66175598 713 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 714 the HAL_TSC_ConvCpltCallback could be implemented in the user file.
mbed_official 237:f3da66175598 715 */
mbed_official 237:f3da66175598 716 }
mbed_official 237:f3da66175598 717
mbed_official 237:f3da66175598 718 /**
mbed_official 237:f3da66175598 719 * @brief Error callback in non blocking mode
mbed_official 237:f3da66175598 720 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 721 * the configuration information for the specified TSC.
mbed_official 237:f3da66175598 722 * @retval None
mbed_official 237:f3da66175598 723 */
mbed_official 237:f3da66175598 724 __weak void HAL_TSC_ErrorCallback(TSC_HandleTypeDef* htsc)
mbed_official 237:f3da66175598 725 {
mbed_official 237:f3da66175598 726 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 727 the HAL_TSC_ErrorCallback could be implemented in the user file.
mbed_official 237:f3da66175598 728 */
mbed_official 237:f3da66175598 729 }
mbed_official 237:f3da66175598 730
mbed_official 237:f3da66175598 731 /**
mbed_official 237:f3da66175598 732 * @brief Utility function used to set the acquired groups mask
mbed_official 237:f3da66175598 733 * @param iomask: Channels IOs mask
mbed_official 237:f3da66175598 734 * @retval Acquired groups mask
mbed_official 237:f3da66175598 735 */
mbed_official 237:f3da66175598 736 static uint32_t TSC_extract_groups(uint32_t iomask)
mbed_official 237:f3da66175598 737 {
mbed_official 237:f3da66175598 738 uint32_t groups = 0;
mbed_official 237:f3da66175598 739 uint32_t idx;
mbed_official 237:f3da66175598 740
mbed_official 237:f3da66175598 741 for (idx = 0; idx < TSC_NB_OF_GROUPS; idx++)
mbed_official 237:f3da66175598 742 {
mbed_official 237:f3da66175598 743 if ((iomask & ((uint32_t)0x0F << (idx * 4))) != RESET)
mbed_official 237:f3da66175598 744 {
mbed_official 237:f3da66175598 745 groups |= ((uint32_t)1 << idx);
mbed_official 237:f3da66175598 746 }
mbed_official 237:f3da66175598 747 }
mbed_official 237:f3da66175598 748
mbed_official 237:f3da66175598 749 return groups;
mbed_official 237:f3da66175598 750 }
mbed_official 237:f3da66175598 751
mbed_official 237:f3da66175598 752 /**
mbed_official 237:f3da66175598 753 * @}
mbed_official 237:f3da66175598 754 */
mbed_official 237:f3da66175598 755
mbed_official 237:f3da66175598 756 #endif /* HAL_TSC_MODULE_ENABLED */
mbed_official 237:f3da66175598 757
mbed_official 237:f3da66175598 758 /**
mbed_official 237:f3da66175598 759 * @}
mbed_official 237:f3da66175598 760 */
mbed_official 237:f3da66175598 761
mbed_official 237:f3da66175598 762 /**
mbed_official 237:f3da66175598 763 * @}
mbed_official 237:f3da66175598 764 */
mbed_official 237:f3da66175598 765
mbed_official 237:f3da66175598 766 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/