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