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:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

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