Holtek Ht32 Mcu Touch Key Library User Guide

Holtek Ht32 Mcu Touch Key Library User Guide

Holtek-LOGO

Holtek HT32 MCU Touch Key Library

Holtek-HT32-MCU-Touch-Key-Library-PRO

Introduction

The HT32 touch key library developed by Best Solution is a library that integrates into the MCU all of the touch key underlying driver library files. The library has pre-configured the touch-related MCU hardware, and provides intuitive and flexible touch key sensitivity settings, while integrating common functions such as key detection and power-saving sleep modes. Using the HT32 touch key library simplifies the use of the MCU touch functions, allowing users to get started quickly and reducing the development period. This document will describe in detail the environmental configuration and library usage.

Environmental Configuration

Obtain HT32 Touch Key Library
Contact Best Solution’s FAE or refer to its website: http://www.bestsolution.com.tw/EN/
Or download the library from the Holtek website: https://www.holtek.com

Obtain HT32 Firmware Library
Refer to the following link to quickly obtain the firmware library: https://www.holtek.com/productdetail/-/vg/HT32F54231_41_43_53
Open the link, select the Documents option as shown in Figure 1, where the red box indicates the location of the HT32 compressed files. Note that only the firmware library of version v022 or above supports the HT32 touch key library.Holtek-HT32-MCU-Touch-Key-Library-1

Keil Project Configuration 

  1. The user’s PC needs to have the Keil development tool installed.
  2. Unzip the firmware library. The files are listed as shown in Figure 2. Click on Holtek.HT32_DFP.latest to install it, after which the installation completion screen, as shown in Figure 3, will appear.Holtek-HT32-MCU-Touch-Key-Library-2
  3. Unzip the HT32 touch key library which includes two folders, example and library.Holtek-HT32-MCU-Touch-Key-Library-3
  4. Copy the example and library folders to the HT32_STD_xxxxx_FWLib_v022_XXXX folder.
  5. Execute ..\example\TouchKey\TouchKey_LIB\_CreateProject.bat (Figure 6).Holtek-HT32-MCU-Touch-Key-Library-4
  6. An interface, as shown in Figure 7, will appear. Input the number corresponding to the user’s IDE, after which a “*” sign will appear before the selected IDE, as shown in Figure 8. Input “N” to go to next step.Holtek-HT32-MCU-Touch-Key-Library-5
  7. As shown below, input “*” to create projects for all IC types or input the IC name to create a project for the selected IC.Holtek-HT32-MCU-Touch-Key-Library-6
  8. After finishing steps 1~7, as shown in Figure 11, select the desired IC project such as Project_54xxx.uvprojx from the ..\example\TouchKey\TouchKey_LIB\MDK_ARMv5\ path.Holtek-HT32-MCU-Touch-Key-Library-7
    Note that only the MCU with the largest resources in each series is used to create the project. For example, to use the HT32F54231 users must select the HT32F54241 project.

Considerations
As the touch key program may enter the sleep state, it is required to set the project to power on reset, otherwise it will not be available for programming. The setting steps are as follows.

  1. Step 1: Click the button in the Keil5 tool menu, as shown below.Holtek-HT32-MCU-Touch-Key-Library-8
  2. Step 2: Select Debug–> Settings.Holtek-HT32-MCU-Touch-Key-Library-9
  3. Step 3: Select “under Reset” in the Connect field.Holtek-HT32-MCU-Touch-Key-Library-10

Library Files Description

Library Used Resources 

Keil ProjectUsable ICROM/RAM ResourcesUsed IPMax. Number of Keys
 HT32F54241HT32F54241 HT32F54231 7148B / 2256BTouch key

BFTM0 RTC

 24
 HT32F54253HT32F54243 HT32F54253 7140B / 2528BTouch key BFTM0

RTC

 28
  1. The RTC is used to wake up MCU from the sleep state and used as time base for sleep state processing.
  2. When the program is loaded into the IC, the Keil will determine whether the ROM or RAM size has been exceeded.
  3. For the specific use of resources, refer to the actual library version.

Environment and File Description
The HT32 touch key library is located in the following path. ..\example\TouchKey\TouchKey_LIB\MDK_ARMv5\Project_542xx.uvprojx project (Figure15). After the HT32 touch key library project is opened, the main screen is shown as Figure 16.Holtek-HT32-MCU-Touch-Key-Library-11

The relevant files are described as follows, among which are the ht32_TouchKey_conf.h and system_ht32f5xxxx_09.c files, included in the Configuration Wizard. See Figure 17.

File NameDescription
main.cProject main program file
ht32f5xxxx_01_it.cInterrupt main program file
ht32_TouchKey_Lib_Mx_Keil.libTouch control library file
*ht32_TouchKey_conf.hTouch control parameter file
ht32_TouchKey.hExternal declaration definition file
ht32_TouchKey_BSconf.hUnderlying main parameter file (not recommended to modify)
ht32_board_config.hHardware definition file (not recommended to modify)
*system_ht32f5xxxx_09.cClock source and system clock parameter file

Holtek-HT32-MCU-Touch-Key-Library-12

Configuration Wizard Parameters

  1. ht32_TouchKey_conf.h Configuration Wizard parameters:
    NameFunction
    PowerSaveActivate the default sleep procedure defined in main.c
    TKL_HighSensitiveTouch sensitivity setting: high or low sensitivity; default to high sensitivity after being enabled
    TKL_keyDebounceKey debounce time setting
    TKL_RefCalTimeCalibration time. The shorter the time, the more effective it will be in resisting environmental interference, however it will result in lower key sensitivities.
    TKL_MaxOnHoldTimeThe maximum time that the key is pressed. The key is automatically released after being pressed for n seconds.
    KEYn_ENEnable or disable KEYn
    KeynThresholdKEYn threshold value. The smaller the value, the more sensitive the key will be.
  2. system_ht32f5xxxx_09.c Configuration Wizard parameters:
    NameFunction
    Enable High Speed External Crystal Oscillator – HSEEnable or disable HSE (external high speed oscillator)
    Enable Low Speed External Crystal Oscillator – LSEEnable or disable LSE (external low speed oscillator)
    Enable PLLEnable or disable PLL
    PLL Clock SourceSelect clock source for PLL
    SystemCoreClockConfiguration (CK_AHB)Select clock source for system CK_AHB
Description of Touch Key Lib Interface Functions

Description of Get Functions

ItemDescription
Function NameTKL_Get_Standby
Input Parameter
Return ValueCounting value (500~60000)
DescriptionUsed to obtain the count-down counter value

 

ItemDescription
Function NameTKL_Get_KeyRCCValue
Input ParameterKey value (0 ~ max. key value), frequency (0, 1)
Return ValueCapacitance value (0~1023)
DescriptionUsed to obtain the capacitance value of the specified key

 

ItemDescription
Function NameTKL_GetKeyRef
Input ParameterKey value (0 ~ max. key value)
Return ValueReference value (0~65535)
DescriptionUsed to obtain the reference value of the specified key

 

ItemDescription
Function NameTKL_GetKeyThreshold
Input ParameterKey value (0 ~ max. key value)
Return ValueThreshold value (0~255)
DescriptionUsed to obtain the threshold value of the specified key

 

ItemDescription
Function NameTKL_Get_AllKeyState
Input Parameter
 Return ValueKey state (32-bit)

BITn stands for KEYn state

Bit0 = 1 means that KEY0 is pressed, Bit0 = 0 means that KEY0 is not pressed

DescriptionUsed to obtain all key states

Description of Set Functions 

ItemDescription
Function NameTKL_Set_KeyThreshold
Input ParameterKey value (0 ~ max. key value), threshold value (10~127)
Return Value
DescriptionUsed to set the threshold value of the specified key

 

ItemDescription
Function NameTKL_Set_Standby
Input ParameterSleep time (500~60000)
Return Value
DescriptionUsed to set the count-down counter (not recommended to use this function)

Description of State and Command Functions 

ItemDescription
Function NameTKL_Is_Time
Input ParameterPreset constant (kT2mS, kT4mS…kT2048mS)
Return Value
 DescriptionTime flag for user reference.

In the following example, the program enters the function every 2ms.Holtek-HT32-MCU-Touch-Key-Library-13

 

ItemDescription
Function NameTKL_Is_AnyKeyPress
Input Parameter
Return Value1 = one or more key has been triggered; 0 = no key has been triggered
DescriptionUsed to obtain the key press flag

 

ItemDescription
Function NameTKL_Is_KeyPress
Input ParameterKey value (0 ~ max. key value)
Return Value1 = key has been triggered; 0 = key has not been triggered
DescriptionUsed to obtain the state flag of the specified key

 

ItemDescription
Function NameTKL_Is_Active
Input Parameter
Return Value1 = LIB initialisation has finished; 0 = LIB initialisation has not finished
DescriptionUsed to obtain the LIB initialisation state flag

 

ItemDescription
Function NameTKL_Is_Standby
Input Parameter
Return Value1 = allowed to enter sleep state; 0 = not allowed to enter sleep state
 DescriptionUsed to obtain the sleep state flag.

*When a value of 0 is returned, then entering the sleep state may result in an unexpected state.

 

ItemDescription
Function NameTKL_Is_KeyScanCycle
Input Parameter
Return Value1 = scan has finished; 0 = presently scanning
DescriptionUsed to obtain the scan flag

 

ItemDescription
Function NameTKL_Reset
Input Parameter
Return Value
 DescriptionUsed to compel LIB to execute a reset action.

*Flags used by LIB and RAM will be initialised.

*Parameters and AFIO are excluded.

Description of Touch Key Lib Initialisation Functions

These functions are located in main.c. It is not recommended to modify their contents.

NameFunction
GPIO_Configuration()I/O port configurations
RTC_Configuration()Touch keys are woken up by the RTC
BFTM_Configuration()Touch key library time bases are implemented by BFTM
TKL_Configuration()Touch key configurations

Key State Query
As shown below, the main program includes a touch key example which will not be activated by default. To activate this function, modify (0) after #if to (1).Holtek-HT32-MCU-Touch-Key-Library-14

Sleep Mode Description

  1. In ht32_TouchKey_conf.h, select PowerSave to enable the sleep modes.Holtek-HT32-MCU-Touch-Key-Library-15
  2. After the sleep modes have been enabled, the touch keys will enter the sleep state if the keys have not experienced any touch conditions for a certain period of time.
  3. A standby time count function is used for down-counting, the current time is obtained using TKL_Get_Standby and the time parameter is set using TKL_Set_Standby.
  4. There are three sleep mode options.
    ModeDescription
    USE_SLEEP_MODEEnter Sleep Mode
    USE_DEEP_SLEEP1_MODEEnter Deep Sleep1 Mode
    USE_DEEP_SLEEP2_MODEEnter Deep Sleep2 Mode
  5. As shown below, set the required sleep mode using “#define” in the main file.Holtek-HT32-MCU-Touch-Key-Library-16

Conclusion
This document has provided instructions for setting up the entire HT32 touch key development environment, assisting users to get started quickly. In addition, the resources used by the library, as well as various functions and parameters, have been explained in detail, allowing for an easier development process.

Reference Material

For more details, refer to the Holtek website: www.holtek.com or consult the Best Solution website: http://www.bestsolution.com.tw/EN/

Versions and Modification Information:

DateAuthorReleaseDescription
2022.03.16谢东霖、梁德浩V1.00First version

Disclaimer

All information, trademarks, logos, graphics, videos, audio clips, links and other items appearing on this website (‘Information’) are for reference only and is subject to change at any time without prior notice and at the discretion of Holtek Semiconductor Inc. and its related companies (hereinafter ‘Holtek’, ‘the company’, ‘us’, ‘we’ or ‘our’). Whilst Holtek endeavors to ensure the accuracy of the Information on this website, no express or implied warranty is given by Holtek to the accuracy of the Information. Holtek will bear no responsibility for any incorrectness or leakage.
Holtek will not be liable for any damages (including but not limited to computer virus, system problems or data loss) whatsoever arising in using or in connection with the use of this website by any party. There may be links in this area, which allow you to visit the websites of other companies. These websites are not controlled by Holtek. Holtek will bear no responsibility and no guarantee to whatsoever Information displayed at such sites. Hyperlinks to other websites are at your own risk.

Limitation of Liability
In no event shall Holtek Limited be liable to any other party for any loss or damage whatsoever or howsoever caused directly or indirectly in connection with your access to or use of this website, the content thereon or any goods, materials or services.

Governing Law
The Disclaimer contained in the website shall be governed by and interpreted in accordance with the laws of the Republic of China. Users will submit to the non-exclusive jurisdiction of the Republic of China courts.

Update of Disclaimer
Holtek reserves the right to update the Disclaimer at any time with or without prior notice, all changes are effective immediately upon posting to the website.

References

Documents / Resouces

Download manual
Here you can download full pdf version of manual, it may contain additional safety instructions, warranty information, FCC rules, etc.


Related Manuals