Chapter 2. API Reference
All functions are provided in pairs to set a specific parameter and to get the current parameter’s value, e.g.,
touch_pad_set_voltage() and touch_pad_get_voltage().
Filtering of Measurements If measurements are noisy, you can filter them with provided API functions. The
ESP32-S2’s touch functionality provide two sets of APIs for doing this.
There is an internal touch channel that is not connected to any external GPIO. The measurements from this denoise
pad can be used to filters out interference introduced on all channels, such as noise introduced by the power supply
and external EMI. The denoise paramaters are set with the function touch_pad_denoise_set_config()
and started by with touch_pad_denoise_enable()
There is also a configurable hardware implemented IIR-filter (infinite impulse response). This IIR-
filter is configured with the function touch_pad_filter_set_config() and enabled by calling
touch_pad_filter_enable()
Touch Detection Touch detection is implemented in ESP32’s hardware based on the user-configured threshold
and raw measurements executed by FSM. Use the functions touch_pad_get_status() to check which pads
have been touched and touch_pad_clear_status() to clear the touch status information.
Hardware touch detection can also be wired to interrupts. This is described in the next section.
If measurements are noisy and capacity changes are small, hardware touch detection might be unreliable. To resolve
this issue, instead of using hardware detection / provided interrupts, implement measurement filtering and perform
touch detection in your own application. For sample implementation of both methods of touch detection, see pe-
ripherals/touch_sensor/touch_sensor_v2/touch_pad_interrupt.
Touch Triggered Interrupts Before enabling an interrupt on a touch detection, you should establish a touch de-
tection threshold. Use the functions described in Touch State Measurements to read and display sensor measurements
when a pad is touched and released. Apply a filter if measurements are noisy and relative capacity changes are small.
Depending on your application and environment conditions, test the influence of temperature and power supply volt-
age changes on measured values.
Once a detection threshold is established, it can be set during initialization with touch_pad_config() or at the
runtime with touch_pad_set_thresh().
Finally, configure and manage interrupt calls using the following functions:
• touch_pad_isr_register() / touch_pad_isr_deregister()
• touch_pad_intr_enable() / touch_pad_intr_disable()
When interrupts are operational, you can obtain the information from which particular pad an interrupt came by
invoking touch_pad_get_status() and clear the pad status with touch_pad_clear_status().
Application Examples
• Touch sensor read example: peripherals/touch_sensor/touch_sensor_v2/touch_pad_read.
• Touch sensor interrupt example: peripherals/touch_sensor/touch_sensor_v2/touch_pad_interrupt.
API Reference
Header File
• components/driver/esp32s2/include/driver/touch_sensor.h
Espressif Systems 399
Submit Document Feedback
Release v4.4