My Project
Loading...
Searching...
No Matches
stm32f3xx_hal_tsc.c File Reference

This file provides firmware functions to manage the following functionalities of the Touch Sensing Controller (TSC) peripheral: More...

#include "stm32f3xx_hal.h"

Detailed Description

This file provides firmware functions to manage the following functionalities of the Touch Sensing Controller (TSC) peripheral:

Author
MCD Application Team
  • Initialization and De-initialization
  • Channel IOs, Shield IOs and Sampling IOs configuration
  • Start and Stop an acquisition
  • Read acquisition result
  • Interrupts and flags management
Attention

Copyright (c) 2016 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

================================================================================
                       ##### TSC specific features #####
================================================================================
  [..]
  (#) Proven and robust surface charge transfer acquisition principle

  (#) Supports up to 3 capacitive sensing channels per group

  (#) Capacitive sensing channels can be acquired in parallel offering a very good
      response time

  (#) Spread spectrum feature to improve system robustness in noisy environments

  (#) Full hardware management of the charge transfer acquisition sequence

  (#) Programmable charge transfer frequency

  (#) Programmable sampling capacitor I/O pin

  (#) Programmable channel I/O pin

  (#) Programmable max count value to avoid long acquisition when a channel is faulty

  (#) Dedicated end of acquisition and max count error flags with interrupt capability

  (#) One sampling capacitor for up to 3 capacitive sensing channels to reduce the system
      components

  (#) Compatible with proximity, touchkey, linear and rotary touch sensor implementation

                          ##### How to use this driver #####
================================================================================
  [..]
    (#) Enable the TSC interface clock using __HAL_RCC_TSC_CLK_ENABLE() macro.

    (#) GPIO pins configuration
      (++) Enable the clock for the TSC GPIOs using __HAL_RCC_GPIOx_CLK_ENABLE() macro.
      (++) Configure the TSC pins used as sampling IOs in alternate function output Open-Drain mode,
           and TSC pins used as channel/shield IOs in alternate function output Push-Pull mode
           using HAL_GPIO_Init() function.

    (#) Interrupts configuration
      (++) Configure the NVIC (if the interrupt model is used) using HAL_NVIC_SetPriority()
           and HAL_NVIC_EnableIRQ() and function.

    (#) TSC configuration
      (++) Configure all TSC parameters and used TSC IOs using HAL_TSC_Init() function.

 [..]   TSC peripheral alternate functions are mapped on AF9.

  *** Acquisition sequence ***
  ===================================
  [..]
    (+) Discharge all IOs using HAL_TSC_IODischarge() function.
    (+) Wait a certain time allowing a good discharge of all capacitors. This delay depends
        of the sampling capacitor and electrodes design.
    (+) Select the channel IOs to be acquired using HAL_TSC_IOConfig() function.
    (+) Launch the acquisition using either HAL_TSC_Start() or HAL_TSC_Start_IT() function.
        If the synchronized mode is selected, the acquisition will start as soon as the signal
        is received on the synchro pin.
    (+) Wait the end of acquisition using either HAL_TSC_PollForAcquisition() or
        HAL_TSC_GetState() function or using WFI instruction for example.
    (+) Check the group acquisition status using HAL_TSC_GroupGetStatus() function.
    (+) Read the acquisition value using HAL_TSC_GroupGetValue() function.

     *** Callback registration ***
     =============================================

  [..]
     The compilation flag USE_HAL_TSC_REGISTER_CALLBACKS when set to 1
     allows the user to configure dynamically the driver callbacks.
     Use Functions HAL_TSC_RegisterCallback() to register an interrupt callback.

  [..]
     Function HAL_TSC_RegisterCallback() allows to register following callbacks:
       (+) ConvCpltCallback   : callback for conversion complete process.
       (+) ErrorCallback      : callback for error detection.
       (+) MspInitCallback    : callback for Msp Init.
       (+) MspDeInitCallback  : callback for Msp DeInit.
  [..]
     This function takes as parameters the HAL peripheral handle, the Callback ID
     and a pointer to the user callback function.

  [..]
     Use function HAL_TSC_UnRegisterCallback to reset a callback to the default
     weak function.
     HAL_TSC_UnRegisterCallback takes as parameters the HAL peripheral handle,
     and the Callback ID.
  [..]
     This function allows to reset following callbacks:
       (+) ConvCpltCallback   : callback for conversion complete process.
       (+) ErrorCallback      : callback for error detection.
       (+) MspInitCallback    : callback for Msp Init.
       (+) MspDeInitCallback  : callback for Msp DeInit.

  [..]
     By default, after the HAL_TSC_Init() and when the state is HAL_TSC_STATE_RESET
     all callbacks are set to the corresponding weak functions:
     examples HAL_TSC_ConvCpltCallback(), HAL_TSC_ErrorCallback().
     Exception done for MspInit and MspDeInit functions that are
     reset to the legacy weak functions in the HAL_TSC_Init()/ HAL_TSC_DeInit() only when
     these callbacks are null (not registered beforehand).
     If MspInit or MspDeInit are not null, the HAL_TSC_Init()/ HAL_TSC_DeInit()
     keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.

  [..]
     Callbacks can be registered/unregistered in HAL_TSC_STATE_READY state only.
     Exception done MspInit/MspDeInit functions that can be registered/unregistered
     in HAL_TSC_STATE_READY or HAL_TSC_STATE_RESET state,
     thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
     Then, the user first registers the MspInit/MspDeInit user callbacks
     using HAL_TSC_RegisterCallback() before calling HAL_TSC_DeInit()
     or HAL_TSC_Init() function.

  [..]
     When the compilation flag USE_HAL_TSC_REGISTER_CALLBACKS is set to 0 or
     not defined, the callback registration feature is not available and all callbacks
     are set to the corresponding weak functions.

Table 1. IOs for the STM32F3xx devices +-----------------------------—+

IOs TSC functions
PA0 (AF) TSC_G1_IO1
PA1 (AF) TSC_G1_IO2
PA2 (AF) TSC_G1_IO3
PA3 (AF) TSC_G1_IO4
-----------— --------------—
PA4 (AF) TSC_G2_IO1
PA5 (AF) TSC_G2_IO2
PA6 (AF) TSC_G2_IO3
PA7 (AF) TSC_G2_IO4
-----------— --------------—
PC5 (AF) TSC_G3_IO1
PB0 (AF) TSC_G3_IO2
PB1 (AF) TSC_G3_IO3
PB2 (AF) TSC_G3_IO4
-----------— --------------—
PA9 (AF) TSC_G4_IO1
PA10 (AF) TSC_G4_IO2
PA13 (AF) TSC_G4_IO3
PA14 (AF) TSC_G4_IO4
-----------— --------------—
PB3 (AF) TSC_G5_IO1
PB4 (AF) TSC_G5_IO2
PB6 (AF) TSC_G5_IO3
PB7 (AF) TSC_G5_IO4
-----------— --------------—
PB11 (AF) TSC_G6_IO1
PB12 (AF) TSC_G6_IO2
PB13 (AF) TSC_G6_IO3
PB14 (AF) TSC_G6_IO4
-----------— --------------—
PE2 (AF) TSC_G7_IO1
PE3 (AF) TSC_G7_IO2
PE4 (AF) TSC_G7_IO3
PE5 (AF) TSC_G7_IO4
-----------— --------------—
PD12 (AF) TSC_G8_IO1
PD13 (AF) TSC_G8_IO2
PD14 (AF) TSC_G8_IO3
PD15 (AF) TSC_G8_IO4
-----------— --------------—
PB8 (AF) TSC_SYNC
PB10 (AF)

+-----------------------------—+