Touch Sensor

Introduction

A touch sensor system is built on a substrate which carries electrodes and relevant connections under a protective flat surface. When a user touches the surface, the capacitance variation is used to evaluate if the touch was valid.

ESP32 can handle up to 10 capacitive touch pads / GPIOs. The sensing pads can be arranged in different combinations (e.g., matrix, slider), so that a larger area or more points can be detected. The touch pad sensing process is under the control of a hardware-implemented finite-state machine (FSM) which is initiated by software or a dedicated hardware timer.

Design, operation, and control registers of a touch sensor are discussed in ESP32 Technical Reference Manual (PDF). Please refer to this manual for additional details on how this subsystem works.

In-depth design details of touch sensors and firmware development guidelines for ESP32 are available in Touch Sensor Application Note. If you want to test touch sensors in various configurations without building them on your own, check the Guide for ESP32-Sense Development Kit.

Functionality Overview

Description of API is broken down into groups of functions to provide a quick overview of the following features:

  • Initialization of touch pad driver

  • Configuration of touch pad GPIO pins

  • Taking measurements

  • Adjusting parameters of measurements

  • Filtering measurements

  • Touch detection methods

  • Setting up interrupts to report touch detection

  • Waking up from Sleep mode on interrupt

For detailed description of a particular function, please go to Section API Reference. Practical implementation of this API is covered in Section Application Examples.

Initialization

Before using a touch pad, you need to initialize the touch pad driver by calling the function touch_pad_init(). This function sets several .._DEFAULT driver parameters listed in API Reference under Macros. It also removes the information about which pads have been touched before, if any, and disables interrupts.

If the driver is not required anymore, deinitialize it by calling touch_pad_deinit().

Configuration

Enabling the touch sensor functionality for a particular GPIO is done with touch_pad_config().

Use the function touch_pad_set_fsm_mode() to select if touch pad measurement (operated by FSM) should be started automatically by a hardware timer, or by software. If software mode is selected, use touch_pad_sw_start() to start the FSM.

Touch State Measurements

The following two functions come in handy to read raw or filtered measurements from the sensor:

They can also be used, for example, to evaluate a particular touch pad design by checking the range of sensor readings when a pad is touched or released. This information can be then used to establish a touch threshold.

Note

Before using touch_pad_read_filtered(), you need to initialize and configure the filter by calling specific filter functions described in Section Filtering of Measurements.

For the demonstration of how to use both read functions, check the application example peripherals/touch_pad_read.

Optimization of Measurements

A touch sensor has several configurable parameters to match the characteristics of a particular touch pad design. For instance, to sense smaller capacity changes, it is possible to narrow down the reference voltage range within which the touch pads are charged / discharged. The high and low reference voltages are set using the function touch_pad_set_voltage().

Besides the ability to discern smaller capacity changes, a positive side effect is reduction of power consumption for low power applications. A likely negative effect is an increase in measurement noise. If the dynamic range of obtained readings is still satisfactory, then further reduction of power consumption might be done by reducing the measurement time with touch_pad_set_meas_time().

The following list summarizes available measurement parameters and corresponding ‘set’ functions:

Relationship between the voltage range (high / low reference voltages), speed (slope), and measurement time is shown in the figure below.

Touch Pad - relationship between measurement parameters

Touch pad - relationship between measurement parameters

The last chart Output represents the touch sensor reading, i.e., the count of pulses collected within the measurement time.

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. Before using the filter, please start it by calling touch_pad_filter_start().

The filter type is IIR (infinite impulse response), and it has a configurable period that can be set with the function touch_pad_set_filter_period().

You can stop the filter with touch_pad_filter_stop(). If not required anymore, the filter can be deleted by invoking touch_pad_filter_delete().

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 peripherals/touch_pad_interrupt.

Touch Triggered Interrupts

Before enabling an interrupt on a touch detection, you should establish a touch detection 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 voltage 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().

In the next step, configure how interrupts are triggered. They can be triggered below or above the threshold, which is set with the function touch_pad_set_trigger_mode().

Finally, configure and manage interrupt calls using the following functions:

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().

Note

Interrupts on touch detection operate on raw / unfiltered measurements checked against user established threshold and are implemented in hardware. Enabling the software filtering API (see Filtering of Measurements) does not affect this process.

Wakeup from Sleep Mode

If touch pad interrupts are used to wake up the chip from a sleep mode, you can select a certain configuration of pads (SET1 or both SET1 and SET2) that should be touched to trigger the interrupt and cause the subsequent wakeup. To do so, use the function touch_pad_set_trigger_source().

Configuration of required bit patterns of pads may be managed for each ‘SET’ with:

Application Examples

API Reference

Functions

esp_err_t touch_pad_init()

Initialize touch module.

Note

The default FSM mode is ‘TOUCH_FSM_MODE_SW’. If you want to use interrupt trigger mode, then set it using function ‘touch_pad_set_fsm_mode’ to ‘TOUCH_FSM_MODE_TIMER’ after calling ‘touch_pad_init’.

Return

  • ESP_OK Success

  • ESP_FAIL Touch pad init error

esp_err_t touch_pad_deinit()

Un-install touch pad driver.

Note

After this function is called, other touch functions are prohibited from being called.

Return

  • ESP_OK Success

  • ESP_FAIL Touch pad driver not initialized

esp_err_t touch_pad_config(touch_pad_t touch_num, uint16_t threshold)

Configure touch pad interrupt threshold.

Note

If FSM mode is set to TOUCH_FSM_MODE_TIMER, this function will be blocked for one measurement cycle and wait for data to be valid.

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG if argument wrong

  • ESP_FAIL if touch pad not initialized

Parameters
  • touch_num: touch pad index

  • threshold: interrupt threshold,

esp_err_t touch_pad_read(touch_pad_t touch_num, uint16_t *touch_value)

get touch sensor counter value. Each touch sensor has a counter to count the number of charge/discharge cycles. When the pad is not ‘touched’, we can get a number of the counter. When the pad is ‘touched’, the value in counter will get smaller because of the larger equivalent capacitance.

Note

This API requests hardware measurement once. If IIR filter mode is enabled, please use ‘touch_pad_read_raw_data’ interface instead.

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG Touch pad parameter error

  • ESP_ERR_INVALID_STATE This touch pad hardware connection is error, the value of “touch_value” is 0.

  • ESP_FAIL Touch pad not initialized

Parameters
  • touch_num: touch pad index

  • touch_value: pointer to accept touch sensor value

esp_err_t touch_pad_read_filtered(touch_pad_t touch_num, uint16_t *touch_value)

get filtered touch sensor counter value by IIR filter.

Note

touch_pad_filter_start has to be called before calling touch_pad_read_filtered. This function can be called from ISR

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG Touch pad parameter error

  • ESP_ERR_INVALID_STATE This touch pad hardware connection is error, the value of “touch_value” is 0.

  • ESP_FAIL Touch pad not initialized

Parameters
  • touch_num: touch pad index

  • touch_value: pointer to accept touch sensor value

esp_err_t touch_pad_read_raw_data(touch_pad_t touch_num, uint16_t *touch_value)

get raw data (touch sensor counter value) from IIR filter process. Need not request hardware measurements.

Note

touch_pad_filter_start has to be called before calling touch_pad_read_raw_data. This function can be called from ISR

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG Touch pad parameter error

  • ESP_ERR_INVALID_STATE This touch pad hardware connection is error, the value of “touch_value” is 0.

  • ESP_FAIL Touch pad not initialized

Parameters
  • touch_num: touch pad index

  • touch_value: pointer to accept touch sensor value

esp_err_t touch_pad_set_filter_read_cb(filter_cb_t read_cb)

Register the callback function that is called after each IIR filter calculation.

Note

The ‘read_cb’ callback is called in timer task in each filtering cycle.

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG set error

Parameters
  • read_cb: Pointer to filtered callback function. If the argument passed in is NULL, the callback will stop.

esp_err_t touch_pad_isr_register(intr_handler_t fn, void *arg)

Register touch-pad ISR. The handler will be attached to the same CPU core that this function is running on.

Return

  • ESP_OK Success ;

  • ESP_ERR_INVALID_ARG GPIO error

  • ESP_ERR_NO_MEM No memory

Parameters
  • fn: Pointer to ISR handler

  • arg: Parameter for ISR

esp_err_t touch_pad_isr_deregister(void (*fn)(void *), void *arg, )

Deregister the handler previously registered using touch_pad_isr_handler_register.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_STATE if a handler matching both fn and arg isn’t registered

Parameters
  • fn: handler function to call (as passed to touch_pad_isr_handler_register)

  • arg: argument of the handler (as passed to touch_pad_isr_handler_register)

esp_err_t touch_pad_set_meas_time(uint16_t sleep_cycle, uint16_t meas_cycle)

Set touch sensor measurement and sleep time.

Return

  • ESP_OK on success

Parameters
  • sleep_cycle: The touch sensor will sleep after each measurement. sleep_cycle decide the interval between each measurement. t_sleep = sleep_cycle / (RTC_SLOW_CLK frequency). The approximate frequency value of RTC_SLOW_CLK can be obtained using rtc_clk_slow_freq_get_hz function.

  • meas_cycle: The duration of the touch sensor measurement. t_meas = meas_cycle / 8M, the maximum measure time is 0xffff / 8M = 8.19 ms

esp_err_t touch_pad_get_meas_time(uint16_t *sleep_cycle, uint16_t *meas_cycle)

Get touch sensor measurement and sleep time.

Return

  • ESP_OK on success

Parameters
  • sleep_cycle: Pointer to accept sleep cycle number

  • meas_cycle: Pointer to accept measurement cycle count.

esp_err_t touch_pad_set_voltage(touch_high_volt_t refh, touch_low_volt_t refl, touch_volt_atten_t atten)

Set touch sensor reference voltage, if the voltage gap between high and low reference voltage get less, the charging and discharging time would be faster, accordingly, the counter value would be larger. In the case of detecting very slight change of capacitance, we can narrow down the gap so as to increase the sensitivity. On the other hand, narrow voltage gap would also introduce more noise, but we can use a software filter to pre-process the counter value.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • refh: the value of DREFH

  • refl: the value of DREFL

  • atten: the attenuation on DREFH

esp_err_t touch_pad_get_voltage(touch_high_volt_t *refh, touch_low_volt_t *refl, touch_volt_atten_t *atten)

Get touch sensor reference voltage,.

Return

  • ESP_OK on success

Parameters
  • refh: pointer to accept DREFH value

  • refl: pointer to accept DREFL value

  • atten: pointer to accept the attenuation on DREFH

esp_err_t touch_pad_set_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t slope, touch_tie_opt_t opt)

Set touch sensor charge/discharge speed for each pad. If the slope is 0, the counter would always be zero. If the slope is 1, the charging and discharging would be slow, accordingly, the counter value would be small. If the slope is set 7, which is the maximum value, the charging and discharging would be fast, accordingly, the counter value would be larger.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • touch_num: touch pad index

  • slope: touch pad charge/discharge speed

  • opt: the initial voltage

esp_err_t touch_pad_get_cnt_mode(touch_pad_t touch_num, touch_cnt_slope_t *slope, touch_tie_opt_t *opt)

Get touch sensor charge/discharge speed for each pad.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • touch_num: touch pad index

  • slope: pointer to accept touch pad charge/discharge slope

  • opt: pointer to accept the initial voltage

esp_err_t touch_pad_io_init(touch_pad_t touch_num)

Initialize touch pad GPIO.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • touch_num: touch pad index

esp_err_t touch_pad_set_fsm_mode(touch_fsm_mode_t mode)

Set touch sensor FSM mode, the test action can be triggered by the timer, as well as by the software.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • mode: FSM mode

esp_err_t touch_pad_get_fsm_mode(touch_fsm_mode_t *mode)

Get touch sensor FSM mode.

Return

  • ESP_OK on success

Parameters
  • mode: pointer to accept FSM mode

esp_err_t touch_pad_sw_start()

Trigger a touch sensor measurement, only support in SW mode of FSM.

Return

  • ESP_OK on success

esp_err_t touch_pad_set_thresh(touch_pad_t touch_num, uint16_t threshold)

Set touch sensor interrupt threshold.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • touch_num: touch pad index

  • threshold: threshold of touchpad count, refer to touch_pad_set_trigger_mode to see how to set trigger mode.

esp_err_t touch_pad_get_thresh(touch_pad_t touch_num, uint16_t *threshold)

Get touch sensor interrupt threshold.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • touch_num: touch pad index

  • threshold: pointer to accept threshold

esp_err_t touch_pad_set_trigger_mode(touch_trigger_mode_t mode)

Set touch sensor interrupt trigger mode. Interrupt can be triggered either when counter result is less than threshold or when counter result is more than threshold.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • mode: touch sensor interrupt trigger mode

esp_err_t touch_pad_get_trigger_mode(touch_trigger_mode_t *mode)

Get touch sensor interrupt trigger mode.

Return

  • ESP_OK on success

Parameters
  • mode: pointer to accept touch sensor interrupt trigger mode

esp_err_t touch_pad_set_trigger_source(touch_trigger_src_t src)

Set touch sensor interrupt trigger source. There are two sets of touch signals. Set1 and set2 can be mapped to several touch signals. Either set will be triggered if at least one of its touch signal is ‘touched’. The interrupt can be configured to be generated if set1 is triggered, or only if both sets are triggered.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • src: touch sensor interrupt trigger source

esp_err_t touch_pad_get_trigger_source(touch_trigger_src_t *src)

Get touch sensor interrupt trigger source.

Return

  • ESP_OK on success

Parameters
  • src: pointer to accept touch sensor interrupt trigger source

esp_err_t touch_pad_set_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint16_t en_mask)

Set touch sensor group mask. Touch pad module has two sets of signals, ‘Touched’ signal is triggered only if at least one of touch pad in this group is “touched”. This function will set the register bits according to the given bitmask.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • set1_mask: bitmask of touch sensor signal group1, it’s a 10-bit value

  • set2_mask: bitmask of touch sensor signal group2, it’s a 10-bit value

  • en_mask: bitmask of touch sensor work enable, it’s a 10-bit value

esp_err_t touch_pad_get_group_mask(uint16_t *set1_mask, uint16_t *set2_mask, uint16_t *en_mask)

Get touch sensor group mask.

Return

  • ESP_OK on success

Parameters
  • set1_mask: pointer to accept bitmask of touch sensor signal group1, it’s a 10-bit value

  • set2_mask: pointer to accept bitmask of touch sensor signal group2, it’s a 10-bit value

  • en_mask: pointer to accept bitmask of touch sensor work enable, it’s a 10-bit value

esp_err_t touch_pad_clear_group_mask(uint16_t set1_mask, uint16_t set2_mask, uint16_t en_mask)

Clear touch sensor group mask. Touch pad module has two sets of signals, Interrupt is triggered only if at least one of touch pad in this group is “touched”. This function will clear the register bits according to the given bitmask.

Return

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if argument is wrong

Parameters
  • set1_mask: bitmask touch sensor signal group1, it’s a 10-bit value

  • set2_mask: bitmask touch sensor signal group2, it’s a 10-bit value

  • en_mask: bitmask of touch sensor work enable, it’s a 10-bit value

esp_err_t touch_pad_clear_status()

To clear the touch status register, usually use this function in touch ISR to clear status.

Return

  • ESP_OK on success

uint32_t touch_pad_get_status()

Get the touch sensor status, usually used in ISR to decide which pads are ‘touched’.

Return

  • touch status

esp_err_t touch_pad_intr_enable()

To enable touch pad interrupt.

Return

  • ESP_OK on success

esp_err_t touch_pad_intr_disable()

To disable touch pad interrupt.

Return

  • ESP_OK on success

esp_err_t touch_pad_set_filter_period(uint32_t new_period_ms)

set touch pad filter calibration period, in ms. Need to call touch_pad_filter_start before all touch filter APIs

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_STATE driver state error

  • ESP_ERR_INVALID_ARG parameter error

Parameters
  • new_period_ms: filter period, in ms

esp_err_t touch_pad_get_filter_period(uint32_t *p_period_ms)

get touch pad filter calibration period, in ms Need to call touch_pad_filter_start before all touch filter APIs

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_STATE driver state error

  • ESP_ERR_INVALID_ARG parameter error

Parameters
  • p_period_ms: pointer to accept period

esp_err_t touch_pad_filter_start(uint32_t filter_period_ms)

start touch pad filter function This API will start a filter to process the noise in order to prevent false triggering when detecting slight change of capacitance. Need to call touch_pad_filter_start before all touch filter APIs

Note

This filter uses FreeRTOS timer, which is dispatched from a task with priority 1 by default on CPU 0. So if some application task with higher priority takes a lot of CPU0 time, then the quality of data obtained from this filter will be affected. You can adjust FreeRTOS timer task priority in menuconfig.

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG parameter error

  • ESP_ERR_NO_MEM No memory for driver

  • ESP_ERR_INVALID_STATE driver state error

Parameters
  • filter_period_ms: filter calibration period, in ms

esp_err_t touch_pad_filter_stop()

stop touch pad filter function Need to call touch_pad_filter_start before all touch filter APIs

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_STATE driver state error

esp_err_t touch_pad_filter_delete()

delete touch pad filter driver and release the memory Need to call touch_pad_filter_start before all touch filter APIs

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_STATE driver state error

esp_err_t touch_pad_get_wakeup_status(touch_pad_t *pad_num)

Get the touch pad which caused wakeup from sleep.

Return

  • ESP_OK Success

  • ESP_FAIL get status err

Parameters
  • pad_num: pointer to touch pad which caused wakeup

Macros

TOUCH_PAD_SLEEP_CYCLE_DEFAULT

The timer frequency is RTC_SLOW_CLK (can be 150k or 32k depending on the options), max value is 0xffff

TOUCH_PAD_MEASURE_CYCLE_DEFAULT

The timer frequency is 8Mhz, the max value is 0x7fff

TOUCH_PAD_MEASURE_WAIT_DEFAULT

The timer frequency is 8Mhz, the max value is 0xff

TOUCH_FSM_MODE_DEFAULT

The touch FSM my be started by the software or timer

TOUCH_TRIGGER_MODE_DEFAULT

Interrupts can be triggered if sensor value gets below or above threshold

TOUCH_TRIGGER_SOURCE_DEFAULT

The wakeup trigger source can be SET1 or both SET1 and SET2

TOUCH_PAD_BIT_MASK_MAX

Type Definitions

typedef intr_handle_t touch_isr_handle_t
typedef void (*filter_cb_t)(uint16_t *raw_value, uint16_t *filtered_value)

Callback function that is called after each IIR filter calculation.

Note

This callback is called in timer task in each filtering cycle.

Note

This callback should not be blocked.

Parameters
  • raw_value: The latest raw data(touch sensor counter value) that points to all channels(raw_value[0..TOUCH_PAD_MAX-1]).

  • filtered_value: The latest IIR filtered data(calculated from raw data) that points to all channels(filtered_value[0..TOUCH_PAD_MAX-1]).

Enumerations

enum touch_pad_t

Values:

TOUCH_PAD_NUM0 = 0

Touch pad channel 0 is GPIO4

TOUCH_PAD_NUM1

Touch pad channel 1 is GPIO0

TOUCH_PAD_NUM2

Touch pad channel 2 is GPIO2

TOUCH_PAD_NUM3

Touch pad channel 3 is GPIO15

TOUCH_PAD_NUM4

Touch pad channel 4 is GPIO13

TOUCH_PAD_NUM5

Touch pad channel 5 is GPIO12

TOUCH_PAD_NUM6

Touch pad channel 6 is GPIO14

TOUCH_PAD_NUM7

Touch pad channel 7 is GPIO27

TOUCH_PAD_NUM8

Touch pad channel 8 is GPIO33

TOUCH_PAD_NUM9

Touch pad channel 9 is GPIO32

TOUCH_PAD_MAX
enum touch_high_volt_t

Values:

TOUCH_HVOLT_KEEP = -1

Touch sensor high reference voltage, no change

TOUCH_HVOLT_2V4 = 0

Touch sensor high reference voltage, 2.4V

TOUCH_HVOLT_2V5

Touch sensor high reference voltage, 2.5V

TOUCH_HVOLT_2V6

Touch sensor high reference voltage, 2.6V

TOUCH_HVOLT_2V7

Touch sensor high reference voltage, 2.7V

TOUCH_HVOLT_MAX
enum touch_low_volt_t

Values:

TOUCH_LVOLT_KEEP = -1

Touch sensor low reference voltage, no change

TOUCH_LVOLT_0V5 = 0

Touch sensor low reference voltage, 0.5V

TOUCH_LVOLT_0V6

Touch sensor low reference voltage, 0.6V

TOUCH_LVOLT_0V7

Touch sensor low reference voltage, 0.7V

TOUCH_LVOLT_0V8

Touch sensor low reference voltage, 0.8V

TOUCH_LVOLT_MAX
enum touch_volt_atten_t

Values:

TOUCH_HVOLT_ATTEN_KEEP = -1

Touch sensor high reference voltage attenuation, no change

TOUCH_HVOLT_ATTEN_1V5 = 0

Touch sensor high reference voltage attenuation, 1.5V attenuation

TOUCH_HVOLT_ATTEN_1V

Touch sensor high reference voltage attenuation, 1.0V attenuation

TOUCH_HVOLT_ATTEN_0V5

Touch sensor high reference voltage attenuation, 0.5V attenuation

TOUCH_HVOLT_ATTEN_0V

Touch sensor high reference voltage attenuation, 0V attenuation

TOUCH_HVOLT_ATTEN_MAX
enum touch_cnt_slope_t

Values:

TOUCH_PAD_SLOPE_0 = 0

Touch sensor charge / discharge speed, always zero

TOUCH_PAD_SLOPE_1 = 1

Touch sensor charge / discharge speed, slowest

TOUCH_PAD_SLOPE_2 = 2

Touch sensor charge / discharge speed

TOUCH_PAD_SLOPE_3 = 3

Touch sensor charge / discharge speed

TOUCH_PAD_SLOPE_4 = 4

Touch sensor charge / discharge speed

TOUCH_PAD_SLOPE_5 = 5

Touch sensor charge / discharge speed

TOUCH_PAD_SLOPE_6 = 6

Touch sensor charge / discharge speed

TOUCH_PAD_SLOPE_7 = 7

Touch sensor charge / discharge speed, fast

TOUCH_PAD_SLOPE_MAX
enum touch_trigger_mode_t

Values:

TOUCH_TRIGGER_BELOW = 0

Touch interrupt will happen if counter value is less than threshold.

TOUCH_TRIGGER_ABOVE = 1

Touch interrupt will happen if counter value is larger than threshold.

TOUCH_TRIGGER_MAX
enum touch_trigger_src_t

Values:

TOUCH_TRIGGER_SOURCE_BOTH = 0

wakeup interrupt is generated if both SET1 and SET2 are “touched”

TOUCH_TRIGGER_SOURCE_SET1 = 1

wakeup interrupt is generated if SET1 is “touched”

TOUCH_TRIGGER_SOURCE_MAX
enum touch_tie_opt_t

Values:

TOUCH_PAD_TIE_OPT_LOW = 0

Initial level of charging voltage, low level

TOUCH_PAD_TIE_OPT_HIGH = 1

Initial level of charging voltage, high level

TOUCH_PAD_TIE_OPT_MAX
enum touch_fsm_mode_t

Values:

TOUCH_FSM_MODE_TIMER = 0

To start touch FSM by timer

TOUCH_FSM_MODE_SW

To start touch FSM by software trigger

TOUCH_FSM_MODE_MAX

GPIO Lookup Macros

Some useful macros can be used to specified the GPIO number of a touch pad channel, or vice versa. e.g.

  1. TOUCH_PAD_NUM5_GPIO_NUM is the GPIO number of channel 5 (12);

  2. TOUCH_PAD_GPIO4_CHANNEL is the channel number of GPIO 4 (channel 0).

Macros

TOUCH_PAD_GPIO4_CHANNEL
TOUCH_PAD_NUM0_GPIO_NUM
TOUCH_PAD_GPIO0_CHANNEL
TOUCH_PAD_NUM1_GPIO_NUM
TOUCH_PAD_GPIO2_CHANNEL
TOUCH_PAD_NUM2_GPIO_NUM
TOUCH_PAD_GPIO15_CHANNEL
TOUCH_PAD_NUM3_GPIO_NUM
TOUCH_PAD_GPIO13_CHANNEL
TOUCH_PAD_NUM4_GPIO_NUM
TOUCH_PAD_GPIO12_CHANNEL
TOUCH_PAD_NUM5_GPIO_NUM
TOUCH_PAD_GPIO14_CHANNEL
TOUCH_PAD_NUM6_GPIO_NUM
TOUCH_PAD_GPIO27_CHANNEL
TOUCH_PAD_NUM7_GPIO_NUM
TOUCH_PAD_GPIO33_CHANNEL
TOUCH_PAD_NUM8_GPIO_NUM
TOUCH_PAD_GPIO32_CHANNEL
TOUCH_PAD_NUM9_GPIO_NUM