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