add Kconfig option for touch check

This commit is contained in:
Christopher Liebman 2020-12-24 13:46:04 -08:00
parent b7ca802bcd
commit 0fc057b22c
3 changed files with 52 additions and 41 deletions

View file

@ -180,6 +180,10 @@ menu "LVGL Touch controller"
prompt "Invert Y coordinate value."
default y
config LV_TOUCH_CHECK
bool
prompt "Check touch pressure to validate LV_TOUCH_PIN_IRQ"
default n
endmenu
menu "Touchpanel (FT6X06) Pin Assignments"

View file

@ -33,6 +33,7 @@
**********************/
static void xpt2046_corr(int16_t * x, int16_t * y);
static void xpt2046_avg(int16_t * x, int16_t * y);
static int16_t xpt2046_cmd(uint8_t cmd);
/**********************
* STATIC VARIABLES
@ -68,14 +69,6 @@ void xpt2046_init(void)
assert(ret == ESP_OK);
}
static int16_t readVal(uint8_t cmd)
{
uint8_t data[2];
tp_spi_read_reg(cmd, data, 2);
int16_t val = (data[0] << 8) | data[1];
return val;
}
/**
* Get the current position and state of the touchpad
* @param data store the read data here
@ -85,29 +78,32 @@ bool xpt2046_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
{
static int16_t last_x = 0;
static int16_t last_y = 0;
bool valid = true;
bool valid = false;
int16_t x = 0;
int16_t y = 0;
int16_t z = 0;
int16_t x = last_x;
int16_t y = last_y;
uint8_t irq = gpio_get_level(XPT2046_IRQ);
// only compute Z if we think its pressed (irq)
if (irq == 0)
if (irq == 0) {
#if XPT2046_TOUCH_CHECK != 0
int16_t z1 = xpt2046_cmd(CMD_Z1_READ) >> 3;
int16_t z2 = xpt2046_cmd(CMD_Z2_READ) >> 3;
// this is not what the confusing datasheet says but it seems to
// be enough to detect real touches on the panel
int16_t z = z1 + 4096 - z2;
// seems the irq can be noisy so we only accept this as a touch if
// there is some pressure (z) detected
if (z >= Z_MIN)
{
int16_t z1 = readVal(CMD_Z1_READ) >> 3;
int16_t z2 = readVal(CMD_Z2_READ) >> 3;
#endif
valid = true;
z = z1 + 4096;
z -= z2;
}
if (irq == 0 && z >= Z_MIN) {
x = readVal(CMD_X_READ);
y = readVal(CMD_Y_READ);
ESP_LOGI(TAG, "P(%d,%d,%d)", x, y, z);
x = xpt2046_cmd(CMD_X_READ);
y = xpt2046_cmd(CMD_Y_READ);
ESP_LOGI(TAG, "P(%d,%d)", x, y);
/*Normalize Data back to 12-bits*/
x = x >> 4;
@ -120,11 +116,14 @@ bool xpt2046_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
last_y = y;
ESP_LOGI(TAG, "x = %d, y = %d", x, y);
} else {
x = last_x;
y = last_y;
#if XPT2046_TOUCH_CHECK != 0
}
#endif
}
if (!valid)
{
avg_last = 0;
valid = false;
}
data->point.x = x;
@ -137,6 +136,14 @@ bool xpt2046_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
/**********************
* STATIC FUNCTIONS
**********************/
static int16_t xpt2046_cmd(uint8_t cmd)
{
uint8_t data[2];
tp_spi_read_reg(cmd, data, 2);
int16_t val = (data[0] << 8) | data[1];
return val;
}
static void xpt2046_corr(int16_t * x, int16_t * y)
{
#if XPT2046_XY_SWAP != 0

View file

@ -35,7 +35,7 @@ extern "C" {
#define XPT2046_X_INV CONFIG_LV_TOUCH_INVERT_X
#define XPT2046_Y_INV CONFIG_LV_TOUCH_INVERT_Y
#define XPT2046_XY_SWAP CONFIG_LV_TOUCH_XY_SWAP
#define XPT2046_TOUCH_CHECK CONFIG_LV_TOUCH_CHECK
/**********************
* TYPEDEFS
**********************/