arch/xtensa/esp32s3: Add initial support for touch pad polling

This commit is contained in:
Lucas Saavedra Vaz 2023-01-10 10:26:42 -03:00 committed by Xiang Xiao
parent 24995f6918
commit 2b7d8981e2
5 changed files with 3408 additions and 0 deletions

View file

@ -106,3 +106,8 @@ ifeq ($(CONFIG_ESP32S3_SPIRAM),y)
CHIP_CSRCS += esp32s3_spiram.c
CHIP_CSRCS += esp32s3_psram.c
endif
ifeq ($(CONFIG_ESP32S3_TOUCH),y)
CHIP_CSRCS += esp32s3_touch.c
endif

View file

@ -0,0 +1,418 @@
/****************************************************************************
* arch/xtensa/src/esp32s3/esp32s3_touch.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <assert.h>
#include <debug.h>
#include <stdint.h>
#include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/kmalloc.h>
#include <nuttx/spinlock.h>
#include <arch/irq.h>
#include "xtensa.h"
#include "esp32s3_gpio.h"
#include "esp32s3_irq.h"
#include "esp32s3_touch.h"
#include "esp32s3_touch_lowerhalf.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define TOUCH_GET_IO_NUM(channel) (touch_channel_to_gpio[channel])
/****************************************************************************
* Private Types
****************************************************************************/
struct touch_config_volt_s
{
enum touch_high_volt_e refh;
enum touch_low_volt_e refl;
enum touch_volt_atten_e atten;
};
struct touch_config_meas_mode_s
{
enum touch_cnt_slope_e slope;
enum touch_tie_opt_e tie_opt;
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static void touch_config(enum touch_pad_e tp);
static void touch_init(struct touch_config_s *config);
static void touch_set_meas_mode(enum touch_pad_e tp,
struct touch_config_meas_mode_s *meas);
static void touch_set_voltage(struct touch_config_volt_s *volt);
static void touch_io_init(enum touch_pad_e tp);
/****************************************************************************
* Private Data
****************************************************************************/
static mutex_t *touch_mux = NULL;
static spinlock_t lock;
static uint32_t touch_pad_logic_threshold[TOUCH_SENSOR_PINS];
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: touch_init
*
* Description:
* Initialize the touch pad driver.
*
* Input Parameters:
* config - The touch configuration structure.
*
* Returned Value:
* None.
*
****************************************************************************/
static void touch_init(struct touch_config_s *config)
{
if (touch_mux != NULL)
{
iinfo("Touch pad driver already initialized.\n");
return;
}
touch_mux = (mutex_t *) kmm_zalloc(sizeof(mutex_t));
if (touch_mux == NULL)
{
ierr("Failed to initialize touch pad driver.\n");
PANIC();
}
nxmutex_init(touch_mux);
irqstate_t flags = spin_lock_irqsave(&lock);
touch_lh_stop_fsm();
touch_lh_intr_disable(TOUCH_INTR_MASK_ALL);
touch_lh_intr_clear(TOUCH_INTR_MASK_ALL);
touch_lh_clear_channel_mask(TOUCH_BIT_MASK_ALL);
touch_lh_clear_trigger_status_mask();
touch_lh_set_meas_time(TOUCH_MEASURE_CYCLE_DEFAULT);
touch_lh_set_sleep_time(TOUCH_SLEEP_CYCLE_DEFAULT);
/* Configure the touch-sensor power domain into self-bias since
* bandgap-bias level is different under sleep-mode compared to
* running-mode. Self-bias is always on after chip startup.
*/
touch_lh_sleep_low_power(true);
touch_lh_set_voltage_high(TOUCH_HIGH_VOLTAGE_THRESHOLD);
touch_lh_set_voltage_low(TOUCH_LOW_VOLTAGE_THRESHOLD);
touch_lh_set_voltage_attenuation(TOUCH_ATTEN_VOLTAGE_THRESHOLD);
touch_lh_set_idle_channel_connect(TOUCH_IDLE_CH_CONNECT_DEFAULT);
/* Clear touch channels to initialize the channel value (benchmark,
* raw_data).
* Note: Should call it after enable clock gate.
*/
touch_lh_clkgate(true);
touch_lh_reset_benchmark(TOUCH_PAD_ALL);
touch_lh_sleep_reset_benchmark();
#ifdef CONFIG_ESP32S3_TOUCH_FILTER
touch_lh_filter_set_filter_mode(config->filter_mode);
touch_lh_filter_set_debounce(config->filter_debounce_cnt);
touch_lh_filter_set_noise_thres(config->filter_noise_thr);
touch_lh_filter_set_jitter_step(config->filter_jitter_step);
touch_lh_filter_set_smooth_mode(config->filter_smh_lvl);
touch_lh_filter_enable();
#endif
#ifdef CONFIG_ESP32S3_TOUCH_DENOISE
touch_lh_set_slope(TOUCH_DENOISE_CHANNEL, TOUCH_SLOPE_DEFAULT);
touch_lh_set_tie_option(TOUCH_DENOISE_CHANNEL, TOUCH_TIE_OPT_DEFAULT);
touch_lh_denoise_set_cap_level(config->denoise_cap_level);
touch_lh_denoise_set_grade(config->denoise_grade);
touch_lh_denoise_enable();
#endif
spin_unlock_irqrestore(&lock, flags);
}
/****************************************************************************
* Name: touch_config
*
* Description:
* Configure a touch pad channel.
*
* Input Parameters:
* tp - The touch pad channel.
*
* Returned Value:
* None.
*
****************************************************************************/
static void touch_config(enum touch_pad_e tp)
{
DEBUGASSERT(tp < TOUCH_SENSOR_PINS);
if (touch_mux == NULL)
{
ierr("ERROR: Touch pads not initialized.\n");
return;
}
touch_io_init(tp);
irqstate_t flags = spin_lock_irqsave(&lock);
touch_lh_set_slope(tp, TOUCH_SLOPE_DEFAULT);
touch_lh_set_tie_option(tp, TOUCH_TIE_OPT_DEFAULT);
touch_lh_set_channel_mask(BIT(tp));
spin_unlock_irqrestore(&lock, flags);
}
/****************************************************************************
* Name: touch_set_voltage
*
* Description:
* Set the touch pads voltage configuration.
*
* Input Parameters:
* volt - The new configuration struct.
*
* Returned Value:
* None.
*
****************************************************************************/
static void touch_set_voltage(struct touch_config_volt_s *volt)
{
irqstate_t flags = spin_lock_irqsave(&lock);
touch_lh_set_voltage_high(volt->refh);
touch_lh_set_voltage_low(volt->refl);
touch_lh_set_voltage_attenuation(volt->atten);
spin_unlock_irqrestore(&lock, flags);
}
/****************************************************************************
* Name: touch_set_meas_mode
*
* Description:
* Set the measurement mode for a given touch pad.
*
* Input Parameters:
* tp - The touch pad channel;
* meas - The new configuration struct.
*
* Returned Value:
* None.
*
****************************************************************************/
static void touch_set_meas_mode(enum touch_pad_e tp,
struct touch_config_meas_mode_s *meas)
{
DEBUGASSERT(tp < TOUCH_SENSOR_PINS);
irqstate_t flags = spin_lock_irqsave(&lock);
touch_lh_set_slope(tp, meas->slope);
touch_lh_set_tie_option(tp, meas->tie_opt);
spin_unlock_irqrestore(&lock, flags);
}
/****************************************************************************
* Name: touch_io_init
*
* Description:
* Initialize GPIOs for a given touch pad.
*
* Input Parameters:
* tp - The touch pad channel.
*
* Returned Value:
* None.
*
****************************************************************************/
static void touch_io_init(enum touch_pad_e tp)
{
DEBUGASSERT(tp < TOUCH_SENSOR_PINS);
esp32s3_configrtcio(tp, RTC_FUNCTION_RTCIO);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: esp32s3_configtouch
*
* Description:
* Configure a touch pad channel.
*
* Input Parameters:
* tp - The touch pad channel;
* config - The touch pad configuration structure.
*
* Returned Value:
* OK.
*
****************************************************************************/
int esp32s3_configtouch(enum touch_pad_e tp, struct touch_config_s config)
{
struct touch_config_volt_s volt_config =
{
.refh = config.refh,
.refl = config.refl,
.atten = config.atten
};
struct touch_config_meas_mode_s meas_config =
{
.slope = config.slope,
.tie_opt = config.tie_opt
};
touch_init(&config);
touch_config(tp);
touch_set_meas_mode(tp, &meas_config);
touch_lh_set_fsm_mode(config.fsm_mode);
touch_set_voltage(&volt_config);
touch_lh_start_fsm();
return OK;
}
/****************************************************************************
* Name: esp32s3_touchread
*
* Description:
* Read a touch pad channel.
*
* Input Parameters:
* tp - The touch pad channel.
*
* Returned Value:
* 0 if touch pad pressed, 1 if released.
*
****************************************************************************/
bool esp32s3_touchread(enum touch_pad_e tp)
{
irqstate_t flags = spin_lock_irqsave(&lock);
#ifdef CONFIG_ESP32S3_TOUCH_FILTER
uint32_t value = touch_lh_filter_read_smooth(tp);
#else
uint32_t value = touch_lh_read_raw_data(tp);
#endif
spin_unlock_irqrestore(&lock, flags);
iinfo("Touch pad %d value: %u\n", tp, value);
return (value > touch_pad_logic_threshold[tp]);
}
/****************************************************************************
* Name: esp32s3_touchbenchmark
*
* Description:
* Read the touch pad channel benchmark.
* After initialization, the benchmark value is the maximum during the
* first measurement period.
*
* Input Parameters:
* tp - The touch pad channel.
*
* Returned Value:
* The benchmark value.
*
****************************************************************************/
uint32_t esp32s3_touchbenchmark(enum touch_pad_e tp)
{
if (tp >= TOUCH_SENSOR_PINS)
{
ierr("Invalid touch pad!\n");
return 0;
}
irqstate_t flags = spin_lock_irqsave(&lock);
uint32_t value = touch_lh_read_benchmark(tp);
spin_unlock_irqrestore(&lock, flags);
iinfo("Touch pad %d benchmark value: %u\n", tp, value);
return value;
}
/****************************************************************************
* Name: esp32s3_touchsetthreshold
*
* Description:
* Set the touch pad channel threshold.
*
* Input Parameters:
* tp - The touch pad channel;
* threshold - The threshold value.
*
* Returned Value:
* None.
*
****************************************************************************/
void esp32s3_touchsetthreshold(enum touch_pad_e tp, uint32_t threshold)
{
irqstate_t flags = spin_lock_irqsave(&lock);
touch_lh_set_threshold(tp, threshold);
touch_pad_logic_threshold[tp] = threshold;
spin_unlock_irqrestore(&lock, flags);
iinfo("Touch pad %d threshold set to: %u\n", tp, threshold);
}

View file

@ -0,0 +1,196 @@
/****************************************************************************
* arch/xtensa/src/esp32s3/esp32s3_touch.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_TOUCH_H
#define __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_TOUCH_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include "esp32s3_touch_lowerhalf.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define TOUCH_SLOPE_DEFAULT (TOUCH_SLOPE_7)
#define TOUCH_TIE_OPT_DEFAULT (TOUCH_TIE_OPT_LOW)
#define TOUCH_HIGH_VOLTAGE_THRESHOLD (TOUCH_HVOLT_2V7)
#define TOUCH_LOW_VOLTAGE_THRESHOLD (TOUCH_LVOLT_0V5)
#define TOUCH_ATTEN_VOLTAGE_THRESHOLD (TOUCH_HVOLT_ATTEN_0V5)
#define TOUCH_IDLE_CH_CONNECT_DEFAULT (TOUCH_CONN_GND)
#define TOUCH_THRESHOLD_MAX (0x1fffff)
#define TOUCH_SLEEP_CYCLE_DEFAULT (0xf)
#define TOUCH_MEASURE_CYCLE_DEFAULT (500)
#define TOUCH_DEBOUNCE_CNT_MAX (7)
#define TOUCH_NOISE_THR_MAX (3)
#define TOUCH_JITTER_STEP_MAX (15)
#define TOUCH_PROXIMITY_CHANNEL_NUM (3)
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
struct touch_config_s
{
enum touch_high_volt_e refh;
enum touch_low_volt_e refl;
enum touch_volt_atten_e atten;
enum touch_cnt_slope_e slope;
enum touch_tie_opt_e tie_opt;
enum touch_fsm_mode_e fsm_mode;
#ifdef CONFIG_ESP32S3_TOUCH_FILTER
enum touch_filter_mode_e filter_mode;
uint32_t filter_debounce_cnt;
uint32_t filter_noise_thr;
uint32_t filter_jitter_step;
enum touch_smooth_mode_e filter_smh_lvl;
#endif
#ifdef CONFIG_ESP32S3_TOUCH_DENOISE
enum touch_denoise_grade_e denoise_grade;
enum touch_denoise_cap_e denoise_cap_level;
#endif
};
/****************************************************************************
* Public Data
****************************************************************************/
/* Store GPIO number corresponding to the Touch Sensor channel number.
* Note: T0 is an internal channel that does not have a corresponding
* external GPIO.
*/
static const int touch_channel_to_gpio[] =
{
-1,
TOUCH_PAD_NUM1_GPIO_NUM,
TOUCH_PAD_NUM2_GPIO_NUM,
TOUCH_PAD_NUM3_GPIO_NUM,
TOUCH_PAD_NUM4_GPIO_NUM,
TOUCH_PAD_NUM5_GPIO_NUM,
TOUCH_PAD_NUM6_GPIO_NUM,
TOUCH_PAD_NUM7_GPIO_NUM,
TOUCH_PAD_NUM8_GPIO_NUM,
TOUCH_PAD_NUM9_GPIO_NUM,
TOUCH_PAD_NUM10_GPIO_NUM,
TOUCH_PAD_NUM11_GPIO_NUM,
TOUCH_PAD_NUM12_GPIO_NUM,
TOUCH_PAD_NUM13_GPIO_NUM,
TOUCH_PAD_NUM14_GPIO_NUM
};
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Inline Functions
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32s3_configtouch
*
* Description:
* Configure a touch pad channel.
*
* Input Parameters:
* tp - The touch pad channel;
* config - The touch pad configuration structure.
*
* Returned Value:
* OK.
*
****************************************************************************/
int esp32s3_configtouch(enum touch_pad_e tp, struct touch_config_s config);
/****************************************************************************
* Name: esp32_touchread
*
* Description:
* Read a touch pad channel.
*
* Input Parameters:
* tp - The touch pad channel.
*
* Returned Value:
* 0 if touch pad pressed, 1 if released.
*
****************************************************************************/
bool esp32s3_touchread(enum touch_pad_e tp);
/****************************************************************************
* Name: esp32s3_touchbenchmark
*
* Description:
* Read the touch pad channel benchmark.
*
* Input Parameters:
* tp - The touch pad channel.
*
* Returned Value:
* The benchmark value.
*
****************************************************************************/
uint32_t esp32s3_touchbenchmark(enum touch_pad_e tp);
/****************************************************************************
* Name: esp32s3_touchsetthreshold
*
* Description:
* Set the touch pad channel threshold.
*
* Input Parameters:
* tp - The touch pad channel;
* threshold - The threshold value.
*
* Returned Value:
* None.
*
****************************************************************************/
void esp32s3_touchsetthreshold(enum touch_pad_e tp, uint32_t threshold);
#ifdef __cplusplus
}
#endif
#undef EXTERN
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_TOUCH_H */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,251 @@
/****************************************************************************
* arch/xtensa/src/esp32s3/hardware/esp32s3_touch.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_XTENSA_SRC_ESP32S3_HARDWARE_ESP32S3_TOUCH_H
#define __ARCH_XTENSA_SRC_ESP32S3_HARDWARE_ESP32S3_TOUCH_H
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Pre-preprocessor Definitions
****************************************************************************/
#define TOUCH_SENSOR_PINS 15
#define TOUCH_MEASURE_WAIT_MAX (0xff)
/* The water rejection function is fixed to TOUCH_PAD_NUM14. */
#define TOUCH_SHIELD_CHANNEL (14)
/* T0 is an internal channel that does not have a corresponding external
* GPIO. T0 will work simultaneously with the measured channel Tn. Finally,
* the actual measured value of Tn is the value after subtracting lower bits
* of T0.
*/
#define TOUCH_DENOISE_CHANNEL (0)
/* Touch channel to GPIO */
/* Note: T0 is an internal channel that does not have a corresponding
* external GPIO.
*/
#define TOUCH_PAD_NUM1_GPIO_NUM 1
#define TOUCH_PAD_NUM2_GPIO_NUM 2
#define TOUCH_PAD_NUM3_GPIO_NUM 3
#define TOUCH_PAD_NUM4_GPIO_NUM 4
#define TOUCH_PAD_NUM5_GPIO_NUM 5
#define TOUCH_PAD_NUM6_GPIO_NUM 6
#define TOUCH_PAD_NUM7_GPIO_NUM 7
#define TOUCH_PAD_NUM8_GPIO_NUM 8
#define TOUCH_PAD_NUM9_GPIO_NUM 9
#define TOUCH_PAD_NUM10_GPIO_NUM 10
#define TOUCH_PAD_NUM11_GPIO_NUM 11
#define TOUCH_PAD_NUM12_GPIO_NUM 12
#define TOUCH_PAD_NUM13_GPIO_NUM 13
#define TOUCH_PAD_NUM14_GPIO_NUM 14
#define TOUCH_BIT_MASK_ALL ((1 << TOUCH_SENSOR_PINS) - 1)
#define TOUCH_INTR_MASK_ALL (TOUCH_INTR_MASK_TIMEOUT | \
TOUCH_INTR_MASK_SCAN_DONE | \
TOUCH_INTR_MASK_INACTIVE | \
TOUCH_INTR_MASK_ACTIVE | \
TOUCH_INTR_MASK_DONE | \
TOUCH_INTR_MASK_PROXI_MEAS_DONE)
/****************************************************************************
* Public Types
****************************************************************************/
/* Touch pad channel */
enum touch_pad_e
{
TOUCH_PAD_NUM0, /* Touch pad channel 0 is GPIO0 (NC) */
TOUCH_PAD_NUM1, /* Touch pad channel 1 is GPIO1 */
TOUCH_PAD_NUM2, /* Touch pad channel 2 is GPIO2 */
TOUCH_PAD_NUM3, /* Touch pad channel 3 is GPIO3 */
TOUCH_PAD_NUM4, /* Touch pad channel 4 is GPIO4 */
TOUCH_PAD_NUM5, /* Touch pad channel 5 is GPIO5 */
TOUCH_PAD_NUM6, /* Touch pad channel 6 is GPIO6 */
TOUCH_PAD_NUM7, /* Touch pad channel 7 is GPIO7 */
TOUCH_PAD_NUM8, /* Touch pad channel 8 is GPIO8 */
TOUCH_PAD_NUM9, /* Touch pad channel 9 is GPIO9 */
TOUCH_PAD_NUM10, /* Touch pad channel 10 is GPIO10 */
TOUCH_PAD_NUM11, /* Touch pad channel 11 is GPIO11 */
TOUCH_PAD_NUM12, /* Touch pad channel 12 is GPIO12 */
TOUCH_PAD_NUM13, /* Touch pad channel 13 is GPIO13 */
TOUCH_PAD_NUM14, /* Touch pad channel 14 is GPIO14 */
TOUCH_PAD_ALL /* Used only by specific functions */
};
/* Touch sensor high reference voltage */
enum touch_high_volt_e
{
TOUCH_HVOLT_2V4, /* 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 sensor low reference voltage */
enum touch_low_volt_e
{
TOUCH_LVOLT_0V5, /* 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 sensor high reference voltage attenuation */
enum touch_volt_atten_e
{
TOUCH_HVOLT_ATTEN_1V5, /* 1.5V attenuation */
TOUCH_HVOLT_ATTEN_1V, /* 1.0V attenuation */
TOUCH_HVOLT_ATTEN_0V5, /* 0.5V attenuation */
TOUCH_HVOLT_ATTEN_0V /* 0V attenuation */
};
/* Touch sensor charge/discharge speed */
enum touch_cnt_slope_e
{
TOUCH_SLOPE_0, /* Touch sensor charge/discharge speed, always zero */
TOUCH_SLOPE_1, /* Touch sensor charge/discharge speed, slowest */
TOUCH_SLOPE_2, /* Touch sensor charge/discharge speed */
TOUCH_SLOPE_3, /* Touch sensor charge/discharge speed */
TOUCH_SLOPE_4, /* Touch sensor charge/discharge speed */
TOUCH_SLOPE_5, /* Touch sensor charge/discharge speed */
TOUCH_SLOPE_6, /* Touch sensor charge/discharge speed */
TOUCH_SLOPE_7 /* Touch sensor charge/discharge speed, fast */
};
/* Touch sensor initial charge level */
enum touch_tie_opt_e
{
TOUCH_TIE_OPT_LOW, /* Initial level of charging voltage, low level */
TOUCH_TIE_OPT_HIGH /* Initial level of charging voltage, high level */
};
/* Touch sensor FSM mode */
enum touch_fsm_mode_e
{
TOUCH_FSM_MODE_TIMER, /* To start touch FSM by timer */
TOUCH_FSM_MODE_SW /* To start touch FSM by software trigger */
};
enum touch_intr_mask_e
{
TOUCH_INTR_MASK_DONE = BIT(0), /* Measurement done for one of the enabled channels. */
TOUCH_INTR_MASK_ACTIVE = BIT(1), /* Active for one of the enabled channels. */
TOUCH_INTR_MASK_INACTIVE = BIT(2), /* Inactive for one of the enabled channels. */
TOUCH_INTR_MASK_SCAN_DONE = BIT(3), /* Measurement done for all the enabled channels. */
TOUCH_INTR_MASK_TIMEOUT = BIT(4), /* Timeout for one of the enabled channels. */
TOUCH_INTR_MASK_PROXI_MEAS_DONE = BIT(5) /* For proximity sensor, when the number of measurements reaches the set count of measurements, an interrupt will be generated. */
};
enum touch_denoise_grade_e
{
TOUCH_DENOISE_BIT12, /* Denoise range is 12bit */
TOUCH_DENOISE_BIT10, /* Denoise range is 10bit */
TOUCH_DENOISE_BIT8, /* Denoise range is 8bit */
TOUCH_DENOISE_BIT4 /* Denoise range is 4bit */
};
enum touch_denoise_cap_e
{
TOUCH_DENOISE_CAP_L0, /* Denoise channel internal reference capacitance is 5pf */
TOUCH_DENOISE_CAP_L1, /* Denoise channel internal reference capacitance is 6.4pf */
TOUCH_DENOISE_CAP_L2, /* Denoise channel internal reference capacitance is 7.8pf */
TOUCH_DENOISE_CAP_L3, /* Denoise channel internal reference capacitance is 9.2pf */
TOUCH_DENOISE_CAP_L4, /* Denoise channel internal reference capacitance is 10.6pf */
TOUCH_DENOISE_CAP_L5, /* Denoise channel internal reference capacitance is 12.0pf */
TOUCH_DENOISE_CAP_L6, /* Denoise channel internal reference capacitance is 13.4pf */
TOUCH_DENOISE_CAP_L7 /* Denoise channel internal reference capacitance is 14.8pf */
};
/* Touch channel idle state configuration */
enum touch_conn_type_e
{
TOUCH_CONN_HIGHZ, /* Idle status of touch channel is high resistance state */
TOUCH_CONN_GND /* Idle status of touch channel is ground connection */
};
/* Touch channel IIR filter coefficient configuration.
*
* On ESP32-S3, there is an error in the IIR calculation. The magnitude of
* the error is twice the filter coefficient. So please select a smaller
* filter coefficient on the basis of meeting the filtering requirements.
* Recommended filter coefficient selection `IIR_16`.
*/
enum touch_filter_mode_e
{
TOUCH_FILTER_IIR_4, /* The filter mode is first-order IIR filter. The coefficient is 4. */
TOUCH_FILTER_IIR_8, /* The filter mode is first-order IIR filter. The coefficient is 8. */
TOUCH_FILTER_IIR_16, /* The filter mode is first-order IIR filter. The coefficient is 16 (Typical value). */
TOUCH_FILTER_IIR_32, /* The filter mode is first-order IIR filter. The coefficient is 32. */
TOUCH_FILTER_IIR_64, /* The filter mode is first-order IIR filter. The coefficient is 64. */
TOUCH_FILTER_IIR_128, /* The filter mode is first-order IIR filter. The coefficient is 128. */
TOUCH_FILTER_IIR_256, /* The filter mode is first-order IIR filter. The coefficient is 256. */
TOUCH_FILTER_JITTER /* The filter mode is jitter filter */
};
/* Level of filter applied on the original data against large noise
* interference.
*
* On ESP32-S3, there is an error in the IIR calculation. The magnitude of
* the error is twice the filter coefficient. So please select a smaller
* filter coefficient on the basis of meeting the filtering requirements.
* Recommended filter coefficient selection `IIR_2`.
*/
enum touch_smooth_mode_e
{
TOUCH_SMOOTH_OFF, /* No filtering of raw data. */
TOUCH_SMOOTH_IIR_2, /* Filter the raw data. The coefficient is 2 (Typical value). */
TOUCH_SMOOTH_IIR_4, /* Filter the raw data. The coefficient is 4. */
TOUCH_SMOOTH_IIR_8 /* Filter the raw data. The coefficient is 8. */
};
/* Touch sensor shield channel drive capability level */
enum touch_shield_driver_e
{
TOUCH_SHIELD_DRV_L0, /* The max equivalent capacitance in shield channel is 40pf */
TOUCH_SHIELD_DRV_L1, /* The max equivalent capacitance in shield channel is 80pf */
TOUCH_SHIELD_DRV_L2, /* The max equivalent capacitance in shield channel is 120pf */
TOUCH_SHIELD_DRV_L3, /* The max equivalent capacitance in shield channel is 160pf */
TOUCH_SHIELD_DRV_L4, /* The max equivalent capacitance in shield channel is 200pf */
TOUCH_SHIELD_DRV_L5, /* The max equivalent capacitance in shield channel is 240pf */
TOUCH_SHIELD_DRV_L6, /* The max equivalent capacitance in shield channel is 280pf */
TOUCH_SHIELD_DRV_L7 /* The max equivalent capacitance in shield channel is 320pf */
};
#endif /* __ARCH_XTENSA_SRC_ESP32S3_HARDWARE_ESP32S3_TOUCH_H */