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