mbed library sources

Fork of mbed-src by mbed official

Committer:
moirans2
Date:
Wed Jan 14 20:53:08 2015 +0000
Revision:
445:9a3ffe6cfa19
Parent:
441:d2c15dda23c1
internal clock stm32L051

Who changed what in which revision?

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