L4 HAL Drivers

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

Who changed what in which revision?

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