mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Mon Sep 28 10:45:10 2015 +0100
Revision:
630:825f75ca301e
Parent:
441:d2c15dda23c1
Synchronized with git revision 54fbe4144faf309c37205a5d39fa665daa919f10

Full URL: https://github.com/mbedmicro/mbed/commit/54fbe4144faf309c37205a5d39fa665daa919f10/

NUCLEO_F031K6 : Add new target

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 630:825f75ca301e 5 * @version V1.3.0
mbed_official 630:825f75ca301e 6 * @date 26-June-2015
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 630:825f75ca301e 50 (#) Enable the TSC interface clock using __HAL_RCC_TSC_CLK_ENABLE() macro.
mbed_official 340:28d1f895c6fe 51
mbed_official 340:28d1f895c6fe 52 (#) GPIO pins configuration
mbed_official 630:825f75ca301e 53 (++) Enable the clock for the TSC GPIOs using __HAL_RCC_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 630:825f75ca301e 84 * <h2><center>&copy; COPYRIGHT(c) 2015 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 630:825f75ca301e 124 /** @defgroup TSC TSC
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 630:825f75ca301e 182
mbed_official 630:825f75ca301e 183 if(htsc->State == HAL_TSC_STATE_RESET)
mbed_official 630:825f75ca301e 184 {
mbed_official 630:825f75ca301e 185 /* Allocate lock resource and initialize it */
mbed_official 630:825f75ca301e 186 htsc->Lock = HAL_UNLOCKED;
mbed_official 630:825f75ca301e 187 }
mbed_official 630:825f75ca301e 188
mbed_official 340:28d1f895c6fe 189 /* Initialize the TSC state */
mbed_official 340:28d1f895c6fe 190 htsc->State = HAL_TSC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 191
mbed_official 340:28d1f895c6fe 192 /* Init the low level hardware : GPIO, CLOCK, CORTEX */
mbed_official 340:28d1f895c6fe 193 HAL_TSC_MspInit(htsc);
mbed_official 340:28d1f895c6fe 194
mbed_official 340:28d1f895c6fe 195 /*--------------------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 196 /* Set TSC parameters */
mbed_official 340:28d1f895c6fe 197
mbed_official 340:28d1f895c6fe 198 /* Enable TSC */
mbed_official 340:28d1f895c6fe 199 htsc->Instance->CR = TSC_CR_TSCE;
mbed_official 340:28d1f895c6fe 200
mbed_official 340:28d1f895c6fe 201 /* Set all functions */
mbed_official 340:28d1f895c6fe 202 htsc->Instance->CR |= (htsc->Init.CTPulseHighLength |
mbed_official 340:28d1f895c6fe 203 htsc->Init.CTPulseLowLength |
mbed_official 340:28d1f895c6fe 204 (uint32_t)(htsc->Init.SpreadSpectrumDeviation << 17) |
mbed_official 340:28d1f895c6fe 205 htsc->Init.SpreadSpectrumPrescaler |
mbed_official 340:28d1f895c6fe 206 htsc->Init.PulseGeneratorPrescaler |
mbed_official 340:28d1f895c6fe 207 htsc->Init.MaxCountValue |
mbed_official 340:28d1f895c6fe 208 htsc->Init.IODefaultMode |
mbed_official 340:28d1f895c6fe 209 htsc->Init.SynchroPinPolarity |
mbed_official 340:28d1f895c6fe 210 htsc->Init.AcquisitionMode);
mbed_official 340:28d1f895c6fe 211
mbed_official 340:28d1f895c6fe 212 /* Spread spectrum */
mbed_official 340:28d1f895c6fe 213 if (htsc->Init.SpreadSpectrum == ENABLE)
mbed_official 340:28d1f895c6fe 214 {
mbed_official 340:28d1f895c6fe 215 htsc->Instance->CR |= TSC_CR_SSE;
mbed_official 340:28d1f895c6fe 216 }
mbed_official 340:28d1f895c6fe 217
mbed_official 340:28d1f895c6fe 218 /* Disable Schmitt trigger hysteresis on all used TSC IOs */
mbed_official 340:28d1f895c6fe 219 htsc->Instance->IOHCR = (uint32_t)(~(htsc->Init.ChannelIOs | htsc->Init.ShieldIOs | htsc->Init.SamplingIOs));
mbed_official 340:28d1f895c6fe 220
mbed_official 340:28d1f895c6fe 221 /* Set channel and shield IOs */
mbed_official 340:28d1f895c6fe 222 htsc->Instance->IOCCR = (htsc->Init.ChannelIOs | htsc->Init.ShieldIOs);
mbed_official 340:28d1f895c6fe 223
mbed_official 340:28d1f895c6fe 224 /* Set sampling IOs */
mbed_official 340:28d1f895c6fe 225 htsc->Instance->IOSCR = htsc->Init.SamplingIOs;
mbed_official 340:28d1f895c6fe 226
mbed_official 340:28d1f895c6fe 227 /* Set the groups to be acquired */
mbed_official 340:28d1f895c6fe 228 htsc->Instance->IOGCSR = TSC_extract_groups(htsc->Init.ChannelIOs);
mbed_official 340:28d1f895c6fe 229
mbed_official 340:28d1f895c6fe 230 /* Clear interrupts */
mbed_official 340:28d1f895c6fe 231 htsc->Instance->IER &= (uint32_t)(~(TSC_IT_EOA | TSC_IT_MCE));
mbed_official 340:28d1f895c6fe 232
mbed_official 340:28d1f895c6fe 233 /* Clear flags */
mbed_official 340:28d1f895c6fe 234 htsc->Instance->ICR = (TSC_FLAG_EOA | TSC_FLAG_MCE);
mbed_official 340:28d1f895c6fe 235
mbed_official 340:28d1f895c6fe 236 /*--------------------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 237
mbed_official 340:28d1f895c6fe 238 /* Initialize the TSC state */
mbed_official 340:28d1f895c6fe 239 htsc->State = HAL_TSC_STATE_READY;
mbed_official 340:28d1f895c6fe 240
mbed_official 340:28d1f895c6fe 241 /* Return function status */
mbed_official 340:28d1f895c6fe 242 return HAL_OK;
mbed_official 340:28d1f895c6fe 243 }
mbed_official 340:28d1f895c6fe 244
mbed_official 340:28d1f895c6fe 245 /**
mbed_official 340:28d1f895c6fe 246 * @brief Deinitializes the TSC peripheral registers to their default reset values.
mbed_official 340:28d1f895c6fe 247 * @param htsc: TSC handle
mbed_official 340:28d1f895c6fe 248 * @retval HAL status
mbed_official 340:28d1f895c6fe 249 */
mbed_official 340:28d1f895c6fe 250 HAL_StatusTypeDef HAL_TSC_DeInit(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 251 {
mbed_official 340:28d1f895c6fe 252 /* Check TSC handle allocation */
mbed_official 441:d2c15dda23c1 253 if (htsc == NULL)
mbed_official 340:28d1f895c6fe 254 {
mbed_official 340:28d1f895c6fe 255 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 256 }
mbed_official 340:28d1f895c6fe 257
mbed_official 340:28d1f895c6fe 258 /* Check the parameters */
mbed_official 340:28d1f895c6fe 259 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 260
mbed_official 340:28d1f895c6fe 261 /* Change TSC state */
mbed_official 340:28d1f895c6fe 262 htsc->State = HAL_TSC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 263
mbed_official 340:28d1f895c6fe 264 /* DeInit the low level hardware */
mbed_official 340:28d1f895c6fe 265 HAL_TSC_MspDeInit(htsc);
mbed_official 340:28d1f895c6fe 266
mbed_official 340:28d1f895c6fe 267 /* Change TSC state */
mbed_official 340:28d1f895c6fe 268 htsc->State = HAL_TSC_STATE_RESET;
mbed_official 340:28d1f895c6fe 269
mbed_official 340:28d1f895c6fe 270 /* Process unlocked */
mbed_official 340:28d1f895c6fe 271 __HAL_UNLOCK(htsc);
mbed_official 340:28d1f895c6fe 272
mbed_official 340:28d1f895c6fe 273 /* Return function status */
mbed_official 340:28d1f895c6fe 274 return HAL_OK;
mbed_official 340:28d1f895c6fe 275 }
mbed_official 340:28d1f895c6fe 276
mbed_official 340:28d1f895c6fe 277 /**
mbed_official 340:28d1f895c6fe 278 * @brief Initializes the TSC MSP.
mbed_official 340:28d1f895c6fe 279 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 280 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 281 * @retval None
mbed_official 340:28d1f895c6fe 282 */
mbed_official 340:28d1f895c6fe 283 __weak void HAL_TSC_MspInit(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 284 {
mbed_official 340:28d1f895c6fe 285 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 286 the HAL_TSC_MspInit could be implemented in the user file.
mbed_official 340:28d1f895c6fe 287 */
mbed_official 340:28d1f895c6fe 288 }
mbed_official 340:28d1f895c6fe 289
mbed_official 340:28d1f895c6fe 290 /**
mbed_official 340:28d1f895c6fe 291 * @brief DeInitializes the TSC MSP.
mbed_official 340:28d1f895c6fe 292 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 293 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 294 * @retval None
mbed_official 340:28d1f895c6fe 295 */
mbed_official 340:28d1f895c6fe 296 __weak void HAL_TSC_MspDeInit(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 297 {
mbed_official 340:28d1f895c6fe 298 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 299 the HAL_TSC_MspDeInit could be implemented in the user file.
mbed_official 340:28d1f895c6fe 300 */
mbed_official 340:28d1f895c6fe 301 }
mbed_official 340:28d1f895c6fe 302
mbed_official 340:28d1f895c6fe 303 /**
mbed_official 340:28d1f895c6fe 304 * @}
mbed_official 340:28d1f895c6fe 305 */
mbed_official 340:28d1f895c6fe 306
mbed_official 340:28d1f895c6fe 307 /** @defgroup TSC_Exported_Functions_Group2 IO operation functions
mbed_official 340:28d1f895c6fe 308 * @brief IO operation functions
mbed_official 340:28d1f895c6fe 309 *
mbed_official 340:28d1f895c6fe 310 @verbatim
mbed_official 340:28d1f895c6fe 311 ===============================================================================
mbed_official 340:28d1f895c6fe 312 ##### IO operation functions #####
mbed_official 340:28d1f895c6fe 313 ===============================================================================
mbed_official 340:28d1f895c6fe 314 [..] This section provides functions allowing to:
mbed_official 340:28d1f895c6fe 315 (+) Start acquisition in polling mode.
mbed_official 340:28d1f895c6fe 316 (+) Start acquisition in interrupt mode.
mbed_official 340:28d1f895c6fe 317 (+) Stop conversion in polling mode.
mbed_official 340:28d1f895c6fe 318 (+) Stop conversion in interrupt mode.
mbed_official 340:28d1f895c6fe 319 (+) Get group acquisition status.
mbed_official 340:28d1f895c6fe 320 (+) Get group acquisition value.
mbed_official 340:28d1f895c6fe 321 @endverbatim
mbed_official 340:28d1f895c6fe 322 * @{
mbed_official 340:28d1f895c6fe 323 */
mbed_official 340:28d1f895c6fe 324
mbed_official 340:28d1f895c6fe 325 /**
mbed_official 340:28d1f895c6fe 326 * @brief Starts the acquisition.
mbed_official 340:28d1f895c6fe 327 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 328 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 329 * @retval HAL status
mbed_official 340:28d1f895c6fe 330 */
mbed_official 340:28d1f895c6fe 331 HAL_StatusTypeDef HAL_TSC_Start(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 332 {
mbed_official 340:28d1f895c6fe 333 /* Check the parameters */
mbed_official 340:28d1f895c6fe 334 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 335
mbed_official 340:28d1f895c6fe 336 /* Process locked */
mbed_official 340:28d1f895c6fe 337 __HAL_LOCK(htsc);
mbed_official 340:28d1f895c6fe 338
mbed_official 340:28d1f895c6fe 339 /* Change TSC state */
mbed_official 340:28d1f895c6fe 340 htsc->State = HAL_TSC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 341
mbed_official 340:28d1f895c6fe 342 /* Clear interrupts */
mbed_official 340:28d1f895c6fe 343 __HAL_TSC_DISABLE_IT(htsc, (TSC_IT_EOA | TSC_IT_MCE));
mbed_official 340:28d1f895c6fe 344
mbed_official 340:28d1f895c6fe 345 /* Clear flags */
mbed_official 340:28d1f895c6fe 346 __HAL_TSC_CLEAR_FLAG(htsc, (TSC_FLAG_EOA | TSC_FLAG_MCE));
mbed_official 340:28d1f895c6fe 347
mbed_official 340:28d1f895c6fe 348 /* Stop discharging the IOs */
mbed_official 340:28d1f895c6fe 349 __HAL_TSC_SET_IODEF_INFLOAT(htsc);
mbed_official 340:28d1f895c6fe 350
mbed_official 340:28d1f895c6fe 351 /* Launch the acquisition */
mbed_official 340:28d1f895c6fe 352 __HAL_TSC_START_ACQ(htsc);
mbed_official 340:28d1f895c6fe 353
mbed_official 340:28d1f895c6fe 354 /* Process unlocked */
mbed_official 340:28d1f895c6fe 355 __HAL_UNLOCK(htsc);
mbed_official 340:28d1f895c6fe 356
mbed_official 340:28d1f895c6fe 357 /* Return function status */
mbed_official 340:28d1f895c6fe 358 return HAL_OK;
mbed_official 340:28d1f895c6fe 359 }
mbed_official 340:28d1f895c6fe 360
mbed_official 340:28d1f895c6fe 361 /**
mbed_official 340:28d1f895c6fe 362 * @brief Enables the interrupt and starts the acquisition
mbed_official 340:28d1f895c6fe 363 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 364 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 365 * @retval HAL status.
mbed_official 340:28d1f895c6fe 366 */
mbed_official 340:28d1f895c6fe 367 HAL_StatusTypeDef HAL_TSC_Start_IT(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 368 {
mbed_official 340:28d1f895c6fe 369 /* Check the parameters */
mbed_official 340:28d1f895c6fe 370 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 371 assert_param(IS_TSC_MCE_IT(htsc->Init.MaxCountInterrupt));
mbed_official 340:28d1f895c6fe 372
mbed_official 340:28d1f895c6fe 373 /* Process locked */
mbed_official 340:28d1f895c6fe 374 __HAL_LOCK(htsc);
mbed_official 340:28d1f895c6fe 375
mbed_official 340:28d1f895c6fe 376 /* Change TSC state */
mbed_official 340:28d1f895c6fe 377 htsc->State = HAL_TSC_STATE_BUSY;
mbed_official 340:28d1f895c6fe 378
mbed_official 340:28d1f895c6fe 379 /* Enable end of acquisition interrupt */
mbed_official 340:28d1f895c6fe 380 __HAL_TSC_ENABLE_IT(htsc, TSC_IT_EOA);
mbed_official 340:28d1f895c6fe 381
mbed_official 340:28d1f895c6fe 382 /* Enable max count error interrupt (optional) */
mbed_official 340:28d1f895c6fe 383 if (htsc->Init.MaxCountInterrupt == ENABLE)
mbed_official 340:28d1f895c6fe 384 {
mbed_official 340:28d1f895c6fe 385 __HAL_TSC_ENABLE_IT(htsc, TSC_IT_MCE);
mbed_official 340:28d1f895c6fe 386 }
mbed_official 340:28d1f895c6fe 387 else
mbed_official 340:28d1f895c6fe 388 {
mbed_official 340:28d1f895c6fe 389 __HAL_TSC_DISABLE_IT(htsc, TSC_IT_MCE);
mbed_official 340:28d1f895c6fe 390 }
mbed_official 340:28d1f895c6fe 391
mbed_official 340:28d1f895c6fe 392 /* Clear flags */
mbed_official 340:28d1f895c6fe 393 __HAL_TSC_CLEAR_FLAG(htsc, (TSC_FLAG_EOA | TSC_FLAG_MCE));
mbed_official 340:28d1f895c6fe 394
mbed_official 340:28d1f895c6fe 395 /* Stop discharging the IOs */
mbed_official 340:28d1f895c6fe 396 __HAL_TSC_SET_IODEF_INFLOAT(htsc);
mbed_official 340:28d1f895c6fe 397
mbed_official 340:28d1f895c6fe 398 /* Launch the acquisition */
mbed_official 340:28d1f895c6fe 399 __HAL_TSC_START_ACQ(htsc);
mbed_official 340:28d1f895c6fe 400
mbed_official 340:28d1f895c6fe 401 /* Process unlocked */
mbed_official 340:28d1f895c6fe 402 __HAL_UNLOCK(htsc);
mbed_official 340:28d1f895c6fe 403
mbed_official 340:28d1f895c6fe 404 /* Return function status */
mbed_official 340:28d1f895c6fe 405 return HAL_OK;
mbed_official 340:28d1f895c6fe 406 }
mbed_official 340:28d1f895c6fe 407
mbed_official 340:28d1f895c6fe 408 /**
mbed_official 340:28d1f895c6fe 409 * @brief Stops the acquisition previously launched in polling mode
mbed_official 340:28d1f895c6fe 410 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 411 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 412 * @retval HAL status
mbed_official 340:28d1f895c6fe 413 */
mbed_official 340:28d1f895c6fe 414 HAL_StatusTypeDef HAL_TSC_Stop(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 415 {
mbed_official 340:28d1f895c6fe 416 /* Check the parameters */
mbed_official 340:28d1f895c6fe 417 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 418
mbed_official 340:28d1f895c6fe 419 /* Process locked */
mbed_official 340:28d1f895c6fe 420 __HAL_LOCK(htsc);
mbed_official 340:28d1f895c6fe 421
mbed_official 340:28d1f895c6fe 422 /* Stop the acquisition */
mbed_official 340:28d1f895c6fe 423 __HAL_TSC_STOP_ACQ(htsc);
mbed_official 340:28d1f895c6fe 424
mbed_official 340:28d1f895c6fe 425 /* Clear flags */
mbed_official 340:28d1f895c6fe 426 __HAL_TSC_CLEAR_FLAG(htsc, (TSC_FLAG_EOA | TSC_FLAG_MCE));
mbed_official 340:28d1f895c6fe 427
mbed_official 340:28d1f895c6fe 428 /* Change TSC state */
mbed_official 340:28d1f895c6fe 429 htsc->State = HAL_TSC_STATE_READY;
mbed_official 340:28d1f895c6fe 430
mbed_official 340:28d1f895c6fe 431 /* Process unlocked */
mbed_official 340:28d1f895c6fe 432 __HAL_UNLOCK(htsc);
mbed_official 340:28d1f895c6fe 433
mbed_official 340:28d1f895c6fe 434 /* Return function status */
mbed_official 340:28d1f895c6fe 435 return HAL_OK;
mbed_official 340:28d1f895c6fe 436 }
mbed_official 340:28d1f895c6fe 437
mbed_official 340:28d1f895c6fe 438 /**
mbed_official 340:28d1f895c6fe 439 * @brief Stops the acquisition previously launched in interrupt mode
mbed_official 340:28d1f895c6fe 440 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 441 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 442 * @retval HAL status
mbed_official 340:28d1f895c6fe 443 */
mbed_official 340:28d1f895c6fe 444 HAL_StatusTypeDef HAL_TSC_Stop_IT(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 445 {
mbed_official 340:28d1f895c6fe 446 /* Check the parameters */
mbed_official 340:28d1f895c6fe 447 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 448
mbed_official 340:28d1f895c6fe 449 /* Process locked */
mbed_official 340:28d1f895c6fe 450 __HAL_LOCK(htsc);
mbed_official 340:28d1f895c6fe 451
mbed_official 340:28d1f895c6fe 452 /* Stop the acquisition */
mbed_official 340:28d1f895c6fe 453 __HAL_TSC_STOP_ACQ(htsc);
mbed_official 340:28d1f895c6fe 454
mbed_official 340:28d1f895c6fe 455 /* Disable interrupts */
mbed_official 340:28d1f895c6fe 456 __HAL_TSC_DISABLE_IT(htsc, (TSC_IT_EOA | TSC_IT_MCE));
mbed_official 340:28d1f895c6fe 457
mbed_official 340:28d1f895c6fe 458 /* Clear flags */
mbed_official 340:28d1f895c6fe 459 __HAL_TSC_CLEAR_FLAG(htsc, (TSC_FLAG_EOA | TSC_FLAG_MCE));
mbed_official 340:28d1f895c6fe 460
mbed_official 340:28d1f895c6fe 461 /* Change TSC state */
mbed_official 340:28d1f895c6fe 462 htsc->State = HAL_TSC_STATE_READY;
mbed_official 340:28d1f895c6fe 463
mbed_official 340:28d1f895c6fe 464 /* Process unlocked */
mbed_official 340:28d1f895c6fe 465 __HAL_UNLOCK(htsc);
mbed_official 340:28d1f895c6fe 466
mbed_official 340:28d1f895c6fe 467 /* Return function status */
mbed_official 340:28d1f895c6fe 468 return HAL_OK;
mbed_official 340:28d1f895c6fe 469 }
mbed_official 340:28d1f895c6fe 470
mbed_official 340:28d1f895c6fe 471 /**
mbed_official 340:28d1f895c6fe 472 * @brief Gets the acquisition status for a group
mbed_official 340:28d1f895c6fe 473 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 474 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 475 * @param gx_index: Index of the group
mbed_official 340:28d1f895c6fe 476 * @retval Group status
mbed_official 340:28d1f895c6fe 477 */
mbed_official 340:28d1f895c6fe 478 TSC_GroupStatusTypeDef HAL_TSC_GroupGetStatus(TSC_HandleTypeDef* htsc, uint32_t gx_index)
mbed_official 340:28d1f895c6fe 479 {
mbed_official 340:28d1f895c6fe 480 /* Check the parameters */
mbed_official 340:28d1f895c6fe 481 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 482 assert_param(IS_GROUP_INDEX(gx_index));
mbed_official 340:28d1f895c6fe 483
mbed_official 340:28d1f895c6fe 484 /* Return the group status */
mbed_official 340:28d1f895c6fe 485 return(__HAL_TSC_GET_GROUP_STATUS(htsc, gx_index));
mbed_official 340:28d1f895c6fe 486 }
mbed_official 340:28d1f895c6fe 487
mbed_official 340:28d1f895c6fe 488 /**
mbed_official 340:28d1f895c6fe 489 * @brief Gets the acquisition measure for a group
mbed_official 340:28d1f895c6fe 490 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 491 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 492 * @param gx_index: Index of the group
mbed_official 340:28d1f895c6fe 493 * @retval Acquisition measure
mbed_official 340:28d1f895c6fe 494 */
mbed_official 340:28d1f895c6fe 495 uint32_t HAL_TSC_GroupGetValue(TSC_HandleTypeDef* htsc, uint32_t gx_index)
mbed_official 340:28d1f895c6fe 496 {
mbed_official 340:28d1f895c6fe 497 /* Check the parameters */
mbed_official 340:28d1f895c6fe 498 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 499 assert_param(IS_GROUP_INDEX(gx_index));
mbed_official 340:28d1f895c6fe 500
mbed_official 340:28d1f895c6fe 501 /* Return the group acquisition counter */
mbed_official 340:28d1f895c6fe 502 return htsc->Instance->IOGXCR[gx_index];
mbed_official 340:28d1f895c6fe 503 }
mbed_official 340:28d1f895c6fe 504
mbed_official 340:28d1f895c6fe 505 /**
mbed_official 340:28d1f895c6fe 506 * @}
mbed_official 340:28d1f895c6fe 507 */
mbed_official 340:28d1f895c6fe 508
mbed_official 340:28d1f895c6fe 509 /** @defgroup TSC_Exported_Functions_Group3 Peripheral Control functions
mbed_official 340:28d1f895c6fe 510 * @brief Peripheral Control functions
mbed_official 340:28d1f895c6fe 511 *
mbed_official 340:28d1f895c6fe 512 @verbatim
mbed_official 340:28d1f895c6fe 513 ===============================================================================
mbed_official 340:28d1f895c6fe 514 ##### Peripheral Control functions #####
mbed_official 340:28d1f895c6fe 515 ===============================================================================
mbed_official 340:28d1f895c6fe 516 [..] This section provides functions allowing to:
mbed_official 340:28d1f895c6fe 517 (+) Configure TSC IOs
mbed_official 340:28d1f895c6fe 518 (+) Discharge TSC IOs
mbed_official 340:28d1f895c6fe 519 @endverbatim
mbed_official 340:28d1f895c6fe 520 * @{
mbed_official 340:28d1f895c6fe 521 */
mbed_official 340:28d1f895c6fe 522
mbed_official 340:28d1f895c6fe 523 /**
mbed_official 340:28d1f895c6fe 524 * @brief Configures TSC IOs
mbed_official 340:28d1f895c6fe 525 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 526 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 527 * @param config: pointer to the configuration structure.
mbed_official 340:28d1f895c6fe 528 * @retval HAL status
mbed_official 340:28d1f895c6fe 529 */
mbed_official 340:28d1f895c6fe 530 HAL_StatusTypeDef HAL_TSC_IOConfig(TSC_HandleTypeDef* htsc, TSC_IOConfigTypeDef* config)
mbed_official 340:28d1f895c6fe 531 {
mbed_official 340:28d1f895c6fe 532 /* Check the parameters */
mbed_official 340:28d1f895c6fe 533 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 534
mbed_official 340:28d1f895c6fe 535 /* Process locked */
mbed_official 340:28d1f895c6fe 536 __HAL_LOCK(htsc);
mbed_official 340:28d1f895c6fe 537
mbed_official 340:28d1f895c6fe 538 /* Stop acquisition */
mbed_official 340:28d1f895c6fe 539 __HAL_TSC_STOP_ACQ(htsc);
mbed_official 340:28d1f895c6fe 540
mbed_official 340:28d1f895c6fe 541 /* Disable Schmitt trigger hysteresis on all used TSC IOs */
mbed_official 340:28d1f895c6fe 542 htsc->Instance->IOHCR = (uint32_t)(~(config->ChannelIOs | config->ShieldIOs | config->SamplingIOs));
mbed_official 340:28d1f895c6fe 543
mbed_official 340:28d1f895c6fe 544 /* Set channel and shield IOs */
mbed_official 340:28d1f895c6fe 545 htsc->Instance->IOCCR = (config->ChannelIOs | config->ShieldIOs);
mbed_official 340:28d1f895c6fe 546
mbed_official 340:28d1f895c6fe 547 /* Set sampling IOs */
mbed_official 340:28d1f895c6fe 548 htsc->Instance->IOSCR = config->SamplingIOs;
mbed_official 340:28d1f895c6fe 549
mbed_official 340:28d1f895c6fe 550 /* Set groups to be acquired */
mbed_official 340:28d1f895c6fe 551 htsc->Instance->IOGCSR = TSC_extract_groups(config->ChannelIOs);
mbed_official 340:28d1f895c6fe 552
mbed_official 340:28d1f895c6fe 553 /* Process unlocked */
mbed_official 340:28d1f895c6fe 554 __HAL_UNLOCK(htsc);
mbed_official 340:28d1f895c6fe 555
mbed_official 340:28d1f895c6fe 556 /* Return function status */
mbed_official 340:28d1f895c6fe 557 return HAL_OK;
mbed_official 340:28d1f895c6fe 558 }
mbed_official 340:28d1f895c6fe 559
mbed_official 340:28d1f895c6fe 560 /**
mbed_official 340:28d1f895c6fe 561 * @brief Discharge TSC IOs
mbed_official 340:28d1f895c6fe 562 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 563 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 564 * @param choice: enable or disable
mbed_official 340:28d1f895c6fe 565 * @retval HAL status
mbed_official 340:28d1f895c6fe 566 */
mbed_official 340:28d1f895c6fe 567 HAL_StatusTypeDef HAL_TSC_IODischarge(TSC_HandleTypeDef* htsc, uint32_t choice)
mbed_official 340:28d1f895c6fe 568 {
mbed_official 340:28d1f895c6fe 569 /* Check the parameters */
mbed_official 340:28d1f895c6fe 570 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 571
mbed_official 340:28d1f895c6fe 572 /* Process locked */
mbed_official 340:28d1f895c6fe 573 __HAL_LOCK(htsc);
mbed_official 340:28d1f895c6fe 574
mbed_official 340:28d1f895c6fe 575 if (choice == ENABLE)
mbed_official 340:28d1f895c6fe 576 {
mbed_official 340:28d1f895c6fe 577 __HAL_TSC_SET_IODEF_OUTPPLOW(htsc);
mbed_official 340:28d1f895c6fe 578 }
mbed_official 340:28d1f895c6fe 579 else
mbed_official 340:28d1f895c6fe 580 {
mbed_official 340:28d1f895c6fe 581 __HAL_TSC_SET_IODEF_INFLOAT(htsc);
mbed_official 340:28d1f895c6fe 582 }
mbed_official 340:28d1f895c6fe 583
mbed_official 340:28d1f895c6fe 584 /* Process unlocked */
mbed_official 340:28d1f895c6fe 585 __HAL_UNLOCK(htsc);
mbed_official 340:28d1f895c6fe 586
mbed_official 340:28d1f895c6fe 587 /* Return the group acquisition counter */
mbed_official 340:28d1f895c6fe 588 return HAL_OK;
mbed_official 340:28d1f895c6fe 589 }
mbed_official 340:28d1f895c6fe 590
mbed_official 340:28d1f895c6fe 591 /**
mbed_official 340:28d1f895c6fe 592 * @}
mbed_official 340:28d1f895c6fe 593 */
mbed_official 340:28d1f895c6fe 594
mbed_official 340:28d1f895c6fe 595 /** @defgroup TSC_Exported_Functions_Group4 State functions
mbed_official 340:28d1f895c6fe 596 * @brief State functions
mbed_official 340:28d1f895c6fe 597 *
mbed_official 340:28d1f895c6fe 598 @verbatim
mbed_official 340:28d1f895c6fe 599 ===============================================================================
mbed_official 340:28d1f895c6fe 600 ##### State functions #####
mbed_official 340:28d1f895c6fe 601 ===============================================================================
mbed_official 340:28d1f895c6fe 602 [..]
mbed_official 340:28d1f895c6fe 603 This subsection provides functions allowing to
mbed_official 340:28d1f895c6fe 604 (+) Get TSC state.
mbed_official 340:28d1f895c6fe 605 (+) Poll for acquisition completed.
mbed_official 340:28d1f895c6fe 606 (+) Handles TSC interrupt request.
mbed_official 340:28d1f895c6fe 607
mbed_official 340:28d1f895c6fe 608 @endverbatim
mbed_official 340:28d1f895c6fe 609 * @{
mbed_official 340:28d1f895c6fe 610 */
mbed_official 340:28d1f895c6fe 611
mbed_official 340:28d1f895c6fe 612 /**
mbed_official 340:28d1f895c6fe 613 * @brief Return the TSC state
mbed_official 340:28d1f895c6fe 614 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 615 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 616 * @retval HAL state
mbed_official 340:28d1f895c6fe 617 */
mbed_official 340:28d1f895c6fe 618 HAL_TSC_StateTypeDef HAL_TSC_GetState(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 619 {
mbed_official 340:28d1f895c6fe 620 /* Check the parameters */
mbed_official 340:28d1f895c6fe 621 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 622
mbed_official 340:28d1f895c6fe 623 if (htsc->State == HAL_TSC_STATE_BUSY)
mbed_official 340:28d1f895c6fe 624 {
mbed_official 340:28d1f895c6fe 625 /* Check end of acquisition flag */
mbed_official 340:28d1f895c6fe 626 if (__HAL_TSC_GET_FLAG(htsc, TSC_FLAG_EOA) != RESET)
mbed_official 340:28d1f895c6fe 627 {
mbed_official 340:28d1f895c6fe 628 /* Check max count error flag */
mbed_official 340:28d1f895c6fe 629 if (__HAL_TSC_GET_FLAG(htsc, TSC_FLAG_MCE) != RESET)
mbed_official 340:28d1f895c6fe 630 {
mbed_official 340:28d1f895c6fe 631 /* Change TSC state */
mbed_official 340:28d1f895c6fe 632 htsc->State = HAL_TSC_STATE_ERROR;
mbed_official 340:28d1f895c6fe 633 }
mbed_official 340:28d1f895c6fe 634 else
mbed_official 340:28d1f895c6fe 635 {
mbed_official 340:28d1f895c6fe 636 /* Change TSC state */
mbed_official 340:28d1f895c6fe 637 htsc->State = HAL_TSC_STATE_READY;
mbed_official 340:28d1f895c6fe 638 }
mbed_official 340:28d1f895c6fe 639 }
mbed_official 340:28d1f895c6fe 640 }
mbed_official 340:28d1f895c6fe 641
mbed_official 340:28d1f895c6fe 642 /* Return TSC state */
mbed_official 340:28d1f895c6fe 643 return htsc->State;
mbed_official 340:28d1f895c6fe 644 }
mbed_official 340:28d1f895c6fe 645
mbed_official 340:28d1f895c6fe 646 /**
mbed_official 340:28d1f895c6fe 647 * @brief Start acquisition and wait until completion
mbed_official 340:28d1f895c6fe 648 * @note There is no need of a timeout parameter as the max count error is already
mbed_official 340:28d1f895c6fe 649 * managed by the TSC peripheral.
mbed_official 340:28d1f895c6fe 650 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 651 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 652 * @retval HAL state
mbed_official 340:28d1f895c6fe 653 */
mbed_official 340:28d1f895c6fe 654 HAL_StatusTypeDef HAL_TSC_PollForAcquisition(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 655 {
mbed_official 340:28d1f895c6fe 656 /* Check the parameters */
mbed_official 340:28d1f895c6fe 657 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 658
mbed_official 340:28d1f895c6fe 659 /* Process locked */
mbed_official 340:28d1f895c6fe 660 __HAL_LOCK(htsc);
mbed_official 340:28d1f895c6fe 661
mbed_official 340:28d1f895c6fe 662 /* Check end of acquisition */
mbed_official 340:28d1f895c6fe 663 while (HAL_TSC_GetState(htsc) == HAL_TSC_STATE_BUSY)
mbed_official 340:28d1f895c6fe 664 {
mbed_official 340:28d1f895c6fe 665 /* The timeout (max count error) is managed by the TSC peripheral itself. */
mbed_official 340:28d1f895c6fe 666 }
mbed_official 340:28d1f895c6fe 667
mbed_official 340:28d1f895c6fe 668 /* Process unlocked */
mbed_official 340:28d1f895c6fe 669 __HAL_UNLOCK(htsc);
mbed_official 340:28d1f895c6fe 670
mbed_official 340:28d1f895c6fe 671 return HAL_OK;
mbed_official 340:28d1f895c6fe 672 }
mbed_official 340:28d1f895c6fe 673
mbed_official 340:28d1f895c6fe 674 /**
mbed_official 340:28d1f895c6fe 675 * @brief Handles TSC interrupt request
mbed_official 340:28d1f895c6fe 676 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 677 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 678 * @retval None
mbed_official 340:28d1f895c6fe 679 */
mbed_official 340:28d1f895c6fe 680 void HAL_TSC_IRQHandler(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 681 {
mbed_official 340:28d1f895c6fe 682 /* Check the parameters */
mbed_official 340:28d1f895c6fe 683 assert_param(IS_TSC_ALL_INSTANCE(htsc->Instance));
mbed_official 340:28d1f895c6fe 684
mbed_official 340:28d1f895c6fe 685 /* Check if the end of acquisition occured */
mbed_official 340:28d1f895c6fe 686 if (__HAL_TSC_GET_FLAG(htsc, TSC_FLAG_EOA) != RESET)
mbed_official 340:28d1f895c6fe 687 {
mbed_official 340:28d1f895c6fe 688 /* Clear EOA flag */
mbed_official 340:28d1f895c6fe 689 __HAL_TSC_CLEAR_FLAG(htsc, TSC_FLAG_EOA);
mbed_official 340:28d1f895c6fe 690 }
mbed_official 340:28d1f895c6fe 691
mbed_official 340:28d1f895c6fe 692 /* Check if max count error occured */
mbed_official 340:28d1f895c6fe 693 if (__HAL_TSC_GET_FLAG(htsc, TSC_FLAG_MCE) != RESET)
mbed_official 340:28d1f895c6fe 694 {
mbed_official 340:28d1f895c6fe 695 /* Clear MCE flag */
mbed_official 340:28d1f895c6fe 696 __HAL_TSC_CLEAR_FLAG(htsc, TSC_FLAG_MCE);
mbed_official 340:28d1f895c6fe 697 /* Change TSC state */
mbed_official 340:28d1f895c6fe 698 htsc->State = HAL_TSC_STATE_ERROR;
mbed_official 340:28d1f895c6fe 699 /* Conversion completed callback */
mbed_official 340:28d1f895c6fe 700 HAL_TSC_ErrorCallback(htsc);
mbed_official 340:28d1f895c6fe 701 }
mbed_official 340:28d1f895c6fe 702 else
mbed_official 340:28d1f895c6fe 703 {
mbed_official 340:28d1f895c6fe 704 /* Change TSC state */
mbed_official 340:28d1f895c6fe 705 htsc->State = HAL_TSC_STATE_READY;
mbed_official 340:28d1f895c6fe 706 /* Conversion completed callback */
mbed_official 340:28d1f895c6fe 707 HAL_TSC_ConvCpltCallback(htsc);
mbed_official 340:28d1f895c6fe 708 }
mbed_official 340:28d1f895c6fe 709 }
mbed_official 340:28d1f895c6fe 710
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 /** @defgroup TSC_Exported_Functions_Group5 Callback functions
mbed_official 340:28d1f895c6fe 716 * @brief Callback functions
mbed_official 340:28d1f895c6fe 717 * @{
mbed_official 340:28d1f895c6fe 718 */
mbed_official 340:28d1f895c6fe 719
mbed_official 340:28d1f895c6fe 720 /**
mbed_official 340:28d1f895c6fe 721 * @brief Acquisition completed callback in non blocking mode
mbed_official 340:28d1f895c6fe 722 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 723 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 724 * @retval None
mbed_official 340:28d1f895c6fe 725 */
mbed_official 340:28d1f895c6fe 726 __weak void HAL_TSC_ConvCpltCallback(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 727 {
mbed_official 340:28d1f895c6fe 728 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 729 the HAL_TSC_ConvCpltCallback could be implemented in the user file.
mbed_official 340:28d1f895c6fe 730 */
mbed_official 340:28d1f895c6fe 731 }
mbed_official 340:28d1f895c6fe 732
mbed_official 340:28d1f895c6fe 733 /**
mbed_official 340:28d1f895c6fe 734 * @brief Error callback in non blocking mode
mbed_official 340:28d1f895c6fe 735 * @param htsc: pointer to a TSC_HandleTypeDef structure that contains
mbed_official 340:28d1f895c6fe 736 * the configuration information for the specified TSC.
mbed_official 340:28d1f895c6fe 737 * @retval None
mbed_official 340:28d1f895c6fe 738 */
mbed_official 340:28d1f895c6fe 739 __weak void HAL_TSC_ErrorCallback(TSC_HandleTypeDef* htsc)
mbed_official 340:28d1f895c6fe 740 {
mbed_official 340:28d1f895c6fe 741 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 340:28d1f895c6fe 742 the HAL_TSC_ErrorCallback could be implemented in the user file.
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 */
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
mbed_official 340:28d1f895c6fe 754 /** @defgroup TSC_Private_Functions TSC Private Functions
mbed_official 340:28d1f895c6fe 755 * @{
mbed_official 340:28d1f895c6fe 756 */
mbed_official 340:28d1f895c6fe 757
mbed_official 340:28d1f895c6fe 758 /**
mbed_official 340:28d1f895c6fe 759 * @brief Utility function used to set the acquired groups mask
mbed_official 340:28d1f895c6fe 760 * @param iomask: Channels IOs mask
mbed_official 340:28d1f895c6fe 761 * @retval Acquired groups mask
mbed_official 340:28d1f895c6fe 762 */
mbed_official 340:28d1f895c6fe 763 static uint32_t TSC_extract_groups(uint32_t iomask)
mbed_official 340:28d1f895c6fe 764 {
mbed_official 340:28d1f895c6fe 765 uint32_t groups = 0;
mbed_official 340:28d1f895c6fe 766 uint32_t idx;
mbed_official 340:28d1f895c6fe 767
mbed_official 340:28d1f895c6fe 768 for (idx = 0; idx < TSC_NB_OF_GROUPS; idx++)
mbed_official 340:28d1f895c6fe 769 {
mbed_official 340:28d1f895c6fe 770 if ((iomask & ((uint32_t)0x0F << (idx * 4))) != RESET)
mbed_official 340:28d1f895c6fe 771 {
mbed_official 340:28d1f895c6fe 772 groups |= ((uint32_t)1 << idx);
mbed_official 340:28d1f895c6fe 773 }
mbed_official 340:28d1f895c6fe 774 }
mbed_official 340:28d1f895c6fe 775
mbed_official 340:28d1f895c6fe 776 return groups;
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 340:28d1f895c6fe 785 */
mbed_official 340:28d1f895c6fe 786
mbed_official 340:28d1f895c6fe 787 /**
mbed_official 340:28d1f895c6fe 788 * @}
mbed_official 340:28d1f895c6fe 789 */
mbed_official 340:28d1f895c6fe 790
mbed_official 441:d2c15dda23c1 791 #endif /* defined(STM32F051x8) || defined(STM32F071xB) || defined(STM32F091xC) || */
mbed_official 441:d2c15dda23c1 792 /* defined(STM32F042x6) || defined(STM32F072xB) || */
mbed_official 441:d2c15dda23c1 793 /* defined(STM32F048xx) || defined(STM32F058xx) || defined(STM32F078xx) || defined(STM32F098xx) */
mbed_official 441:d2c15dda23c1 794
mbed_official 441:d2c15dda23c1 795 #endif /* HAL_TSC_MODULE_ENABLED */
mbed_official 441:d2c15dda23c1 796
mbed_official 340:28d1f895c6fe 797 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/