mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
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.
This commit is contained in:
parent
361184833d
commit
4af04c846f
@ -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
|
||||
|
31
tests/drivers/ft5x06/README.md
Normal file
31
tests/drivers/ft5x06/README.md
Normal file
@ -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
|
||||
```
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user