From 4af04c846ff55fc71fbcc16dab9d465cd9a8b25c Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sat, 12 Aug 2023 11:19:13 +0200 Subject: [PATCH] tests/drivers/ft5x06: introduce FT5X06_POLLING_MODE To be able to test the FT5x06 device driver in polling mode, variable `FT5X06_POLLING_MODE` is introduced. It is set to 0 by default and can be overriden by 1 to use the polling mode. The polling period can be controlled by the `FT5X06_POLLING_PERIOD` variable. --- tests/drivers/ft5x06/Makefile | 10 ++++++++++ tests/drivers/ft5x06/README.md | 31 +++++++++++++++++++++++++++++++ tests/drivers/ft5x06/main.c | 23 ++++++++++++++++++++++- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/drivers/ft5x06/README.md diff --git a/tests/drivers/ft5x06/Makefile b/tests/drivers/ft5x06/Makefile index 5e473b6023..c5c46a0ef5 100644 --- a/tests/drivers/ft5x06/Makefile +++ b/tests/drivers/ft5x06/Makefile @@ -1,6 +1,16 @@ BOARD ?= stm32f746g-disco include ../Makefile.drivers_common +FT5X06_POLLING_MODE ?= 0 +FT5X06_POLLING_PERIOD ?= 50 + +CFLAGS += -DFT5X06_POLLING_MODE=$(FT5X06_POLLING_MODE) +CFLAGS += -DFT5X06_POLLING_PERIOD=$(FT5X06_POLLING_PERIOD) + USEMODULE += ft5x06 +ifneq (0,$(FT5X06_POLLING_MODE)) + USEMODULE += ztimer_msec +endif + include $(RIOTBASE)/Makefile.include diff --git a/tests/drivers/ft5x06/README.md b/tests/drivers/ft5x06/README.md new file mode 100644 index 0000000000..b87730f688 --- /dev/null +++ b/tests/drivers/ft5x06/README.md @@ -0,0 +1,31 @@ +# About + +This is a manual test application for the FT5x06 touch device driver. + +# Usage + +The test application initializes the FT5x06 touch device and then waits +for touch events by using interrupts by default. When touch events occur, +the application generates output like the following: +``` ++------------Initializing------------+ +Initialization successful +1 touch detected +Touch 1 - X: 203, Y:156 +Touch 1 - X: 204, Y:157 +Touch 1 - X: 204, Y:157 +Touch 1 - X: 206, Y:158 +Touch 1 - X: 210, Y:159 +Touch 1 - X: 210, Y:159 +Touch 1 - X: 218, Y:160 +Released! +``` + +To use the touch device in polling mode, the environment variable +`FT5X06_POLLING_MODE` must be set to 1. The polling period in milliseconds +is defined by the environment variable `FT5X06_POLLING_PERIOD`. It is +50 ms by default. It can be changed by setting the environment variable +`FT5X06_POLLING_PERIOD` in the make command, for example: +``` +FT5X06_POLLING_MODE=1 FT5X06_POLLING_PERIOD=100 BOARD=... make -C tests/drivers/touch_dev flash term +``` diff --git a/tests/drivers/ft5x06/main.c b/tests/drivers/ft5x06/main.c index 342c27a31e..8d0cfdfaae 100644 --- a/tests/drivers/ft5x06/main.c +++ b/tests/drivers/ft5x06/main.c @@ -25,22 +25,39 @@ #include "ft5x06.h" #include "ft5x06_params.h" +#if IS_ACTIVE(FT5X06_POLLING_MODE) +#include "ztimer.h" +#endif + +#ifndef FT5X06_POLLING_PERIOD +#define FT5X06_POLLING_PERIOD 50 +#endif + +#if !IS_ACTIVE(FT5X06_POLLING_MODE) static void _touch_event_cb(void *arg) { mutex_unlock(arg); } +#endif static ft5x06_touch_position_t positions[FT5X06_TOUCHES_COUNT_MAX]; int main(void) { +#if !IS_ACTIVE(FT5X06_POLLING_MODE) mutex_t lock = MUTEX_INIT_LOCKED; +#endif + ft5x06_t dev; puts("FT5x06 test application\n"); printf("+------------Initializing------------+\n"); +#if IS_ACTIVE(FT5X06_POLLING_MODE) + int ret = ft5x06_init(&dev, &ft5x06_params[0], NULL, NULL); +#else int ret = ft5x06_init(&dev, &ft5x06_params[0], _touch_event_cb, &lock); +#endif if (ret != 0) { puts("[Error] Initialization failed"); return 1; @@ -53,9 +70,13 @@ int main(void) uint8_t last_touch_count = current_touch_count; while (1) { - +#if IS_ACTIVE(FT5X06_POLLING_MODE) + /* polling is used */ + ztimer_sleep(ZTIMER_MSEC, FT5X06_POLLING_PERIOD); +#else /* wait for touch event */ mutex_lock(&lock); +#endif ft5x06_read_touch_count(&dev, ¤t_touch_count);