From 3531770689e1b90d2086aa96ed5738557f82089d Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Mon, 14 Aug 2023 17:41:03 +0200 Subject: [PATCH 1/4] drivers/stmpe811: reset the FIFO queue after read The FIFO queue has to be reset after reading one touch position. Otherwise new touch positions are processed with a delay if the rate of calling the function to read the FIFO is slower than the rate at which the FIFO is filled. The reason for this is that with each call of this function always only the oldest touch position is read value by value from the FIFO. Gestures, for example, can't be implemented with such a behavior --- drivers/stmpe811/stmpe811.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/stmpe811/stmpe811.c b/drivers/stmpe811/stmpe811.c index f8adf0dfc9cd2..fb5aa73f5094d 100644 --- a/drivers/stmpe811/stmpe811.c +++ b/drivers/stmpe811/stmpe811.c @@ -339,6 +339,14 @@ int stmpe811_read_touch_position(stmpe811_t *dev, stmpe811_touch_position_t *pos } #endif + /* Reset the FIFO, otherwise new touch data will be processed with a delay + * if the rate of calling this function to read the FIFO is slower than + * the rate at which the FIFO is filled. The reason for this is that with + * each call of this function only the oldest touch data is read + * value by value from the FIFO. Gestures, for example, can't be + * implemented with such a behavior. */ + _reset_fifo(dev); + /* Release device bus */ _release(dev); From 9aecdaf2f67e19e8348ecd86e1c139b206f9402b Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Mon, 14 Aug 2023 17:26:33 +0200 Subject: [PATCH 2/4] drivers/stmpe811: enable FIFO threshold interrupt For continuous reporting of the touch position the FIFO threshold interrupt is used. This is necessary for example to implement gestures in interrupt mode. To activate the FIFO threshold interrupt and thus continuous reporting, the macro 'STMPE811_FIFO_THRESHOLD_ENABLED' must be set to 1. However, the driver only works reliably with FIFO threshold interrupts if the FIFO threshold value is at least 2. Otherwise the Touch Detect interrupt will not work correctly when a touch is released. Therefore, the FIFO threshold is set to 2 by default when `STMPE811_FIFO_THRESHOLD_ENABLED` is set. This default value can be overwritten by `STMPE811_FIFO_THRESHOLD`. --- drivers/stmpe811/stmpe811.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/stmpe811/stmpe811.c b/drivers/stmpe811/stmpe811.c index fb5aa73f5094d..ed0b0939a1234 100644 --- a/drivers/stmpe811/stmpe811.c +++ b/drivers/stmpe811/stmpe811.c @@ -46,6 +46,23 @@ #define ADDR (dev->params.addr) #endif +#ifndef STMPE811_FIFO_THRESHOLD_ENABLED +#define STMPE811_FIFO_THRESHOLD_ENABLED (0) +#endif + +/* The driver only works reliably with FIFO threshold interrupts if the FIFO + * threshold is at least 2. The reason is that all interrupts are cleared when + * the status is checked in `stmpe811_read_touch_state` but the FIFO Threshold + * interrupt is asserted again immediately since the FIFO is not read so that + * a new interrupt is pending. On the other hand, the Touch Detected interrupt + * does not work reliably for the release event if only the Touch Detected + * interrupt in `stmpe811_read_touch_state` is cleared. The workaround is + * to set the FIFO threshold to at least 2 to introduce a small delay between + * the Touch Detect interrupt on a touch and the first FIFO threshold + * interrupt. */ +#ifndef STMPE811_FIFO_THRESHOLD +#define STMPE811_FIFO_THRESHOLD (STMPE811_FIFO_THRESHOLD_ENABLED ? 2 : 1) +#endif #if IS_USED(MODULE_STMPE811_SPI) /* using SPI mode */ static inline void _acquire(const stmpe811_t *dev) @@ -194,7 +211,7 @@ int stmpe811_init(stmpe811_t *dev, const stmpe811_params_t *params, stmpe811_eve } /* check mode configuration */ - if(_stmpe811_check_mode(dev) != 0) { + if (_stmpe811_check_mode(dev) != 0) { DEBUG("[stmpe811] error: couldn't setup SPI\n"); return -EIO; } @@ -257,7 +274,7 @@ int stmpe811_init(stmpe811_t *dev, const stmpe811_params_t *params, stmpe811_eve ret += _write_reg(dev, STMPE811_TSC_CFG, reg); /* set fifo threshold */ - ret += _write_reg(dev, STMPE811_FIFO_TH, 0x01); + ret += _write_reg(dev, STMPE811_FIFO_TH, STMPE811_FIFO_THRESHOLD); /* reset fifo */ _reset_fifo(dev); @@ -285,7 +302,9 @@ int stmpe811_init(stmpe811_t *dev, const stmpe811_params_t *params, stmpe811_eve gpio_init_int(dev->params.int_pin, GPIO_IN, GPIO_FALLING, cb, arg); /* Enable touchscreen interrupt */ - ret += _write_reg(dev, STMPE811_INT_EN, STMPE811_INT_EN_TOUCH_DET); + ret += _write_reg(dev, STMPE811_INT_EN, + STMPE811_INT_EN_TOUCH_DET | + (STMPE811_FIFO_THRESHOLD_ENABLED ? STMPE811_INT_EN_FIFO_TH : 0)); /* Enable global interrupt */ ret += _write_reg(dev, STMPE811_INT_CTRL, From 0382e10e6fa83e0d1411560110b0f5ab62aff5fb Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Mon, 14 Aug 2023 22:59:26 +0200 Subject: [PATCH 3/4] drivers/stmpe811: use FIFO thresh interrupt for touch_dev by default --- drivers/stmpe811/Makefile.include | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/stmpe811/Makefile.include b/drivers/stmpe811/Makefile.include index 66e6da5c94301..656f2ec0d8dd8 100644 --- a/drivers/stmpe811/Makefile.include +++ b/drivers/stmpe811/Makefile.include @@ -3,3 +3,7 @@ USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_stmpe811) PSEUDOMODULES += stmpe811_i2c PSEUDOMODULES += stmpe811_spi + +ifneq (,$(filter touch_dev,$(USEMODULE))) + CFLAGS += '-DSTMPE811_FIFO_THRESHOLD_ENABLED=1' +endif From f95b225a8f3c5613d1a7cebcbe9610a126fd0568 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sat, 12 Aug 2023 13:54:16 +0200 Subject: [PATCH 4/4] makefiles: fix typo in driver_with_touch_dev.mk --- makefiles/driver_with_touch_dev.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefiles/driver_with_touch_dev.mk b/makefiles/driver_with_touch_dev.mk index 2b6afdd8c1951..cf394855ab4c3 100644 --- a/makefiles/driver_with_touch_dev.mk +++ b/makefiles/driver_with_touch_dev.mk @@ -4,7 +4,7 @@ TOUCH_DEV_INTERFACE ?= $(MODULE)_touch_dev.c # by default include all .c files except _touch_dev.c SRC = $(filter-out $(TOUCH_DEV_INTERFACE),$(wildcard *.c)) -# only include _touch_dev.c if saul module is used +# only include _touch_dev.c if touch_dev module is used ifneq (,$(filter touch_dev,$(USEMODULE))) SRC += $(TOUCH_DEV_INTERFACE) endif