mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge #19882
19882: tests/drivers/touch_dev: allow to test a touch device in polling mode r=aabadie a=gschorcht ### Contribution description To be able to test the touch device in polling mode, variable `TOUCH_DEV_POLLING` 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 `TOUCH_DEV_POLLING_PERIOD` variable. To use it for `ft5x06` and `stmpe811` drivers, the polling mode has to be fixed for these touch device drivers (PR #19880 respective PR #19881). ### Testing procedure Use any board with touch device driver that uses the generic touch device API, for example (PR #19881 is required) ``` TOUCH_DEV_POLLING_MODE=1 TOUCH_DEV_POLLING_PERIOD=100 \ BOARD=stm32f429i-disc1 make -C tests/drivers/touch_dev flash term ``` or (PR #19880 is required) ``` TOUCH_DEV_POLLING_MODE=1 TOUCH_DEV_POLLING_PERIOD=100 \ BOARD=stm32f746g-disco make -C tests/drivers/touch_dev flash term ``` ### Issues/PRs references Depends partially on PR #19880 Depends partially on PR #19881 Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
This commit is contained in:
commit
20cdf176bb
@ -7,4 +7,10 @@ USEMODULE += touch_dev
|
||||
USEMODULE += ztimer
|
||||
USEMODULE += ztimer_msec
|
||||
|
||||
TOUCH_DEV_POLLING_MODE ?= 0
|
||||
TOUCH_DEV_POLLING_PERIOD ?= 50
|
||||
|
||||
CFLAGS += -DTOUCH_DEV_POLLING_MODE=$(TOUCH_DEV_POLLING_MODE)
|
||||
CFLAGS += -DTOUCH_DEV_POLLING_PERIOD=$(TOUCH_DEV_POLLING_PERIOD)
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
34
tests/drivers/touch_dev/README.md
Normal file
34
tests/drivers/touch_dev/README.md
Normal file
@ -0,0 +1,34 @@
|
||||
# About
|
||||
|
||||
This is a manual test application for touch device drivers using the generic
|
||||
touch device API. Which touch device driver is used is determined by the board
|
||||
definition.
|
||||
|
||||
# Usage
|
||||
|
||||
This test application initializes the touch device and then waits
|
||||
for touch events by using interrupts by default. When touch events occur,
|
||||
the application generates output like the following:
|
||||
```
|
||||
Event: pressed!
|
||||
X: 157, Y:152
|
||||
X: 158, Y:152
|
||||
X: 158, Y:152
|
||||
X: 158, Y:152
|
||||
X: 158, Y:152
|
||||
X: 158, Y:152
|
||||
X: 158, Y:152
|
||||
X: 158, Y:152
|
||||
X: 158, Y:152
|
||||
X: 158, Y:152
|
||||
Event: released!
|
||||
```
|
||||
|
||||
To use the touch device in polling mode, the environment variable
|
||||
`TOUCH_DEV_POLLING_MODE` must be set to 1. The polling period in milliseconds
|
||||
is defined by the environment variable `TOUCH_DEV_POLLING_PERIOD`. It is
|
||||
50 ms by default. It can be changed by setting the environment variable
|
||||
`TOUCH_DEV_POLLING_PERIOD` in the make command, for example:
|
||||
```
|
||||
TOUCH_DEV_POLLING_MODE=1 TOUCH_DEV_POLLING_PERIOD=100 BOARD=... make -C tests/drivers/touch_dev flash term
|
||||
```
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Inria
|
||||
* 2023 Gunar Schorcht
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
@ -14,6 +15,7 @@
|
||||
* @brief Generic touch device test application
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
@ -21,6 +23,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "mutex.h"
|
||||
#include "ztimer.h"
|
||||
|
||||
#include "touch_dev.h"
|
||||
@ -30,11 +33,16 @@
|
||||
#include "test_utils/expect.h"
|
||||
#endif
|
||||
|
||||
#ifndef TOUCH_DEV_POLLING_PERIOD
|
||||
#define TOUCH_DEV_POLLING_PERIOD 50
|
||||
#endif
|
||||
|
||||
#if !IS_ACTIVE(TOUCH_DEV_POLLING_MODE)
|
||||
static void _touch_event_cb(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
printf("Event: ");
|
||||
mutex_unlock(arg);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@ -45,7 +53,11 @@ int main(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
touch_dev_set_touch_event_callback(touch_dev->dev, _touch_event_cb, NULL);
|
||||
#if !IS_ACTIVE(TOUCH_DEV_POLLING_MODE)
|
||||
mutex_t lock = MUTEX_INIT_LOCKED;
|
||||
|
||||
touch_dev_set_touch_event_callback(touch_dev->dev, _touch_event_cb, &lock);
|
||||
#endif
|
||||
|
||||
#if IS_USED(MODULE_STMPE811)
|
||||
uint16_t xmax = touch_dev_width(touch_dev->dev);
|
||||
@ -59,15 +71,21 @@ int main(void)
|
||||
uint8_t last_touches = touch_dev_touches(touch_dev->dev, NULL, 1);
|
||||
|
||||
while (1) {
|
||||
#if IS_ACTIVE(TOUCH_DEV_POLLING_MODE)
|
||||
ztimer_sleep(ZTIMER_MSEC, TOUCH_DEV_POLLING_PERIOD);
|
||||
#else
|
||||
/* wait for event */
|
||||
mutex_lock(&lock);
|
||||
#endif
|
||||
touch_t touches[1];
|
||||
uint8_t current_touches = touch_dev_touches(touch_dev->dev, touches, 1);
|
||||
|
||||
if (current_touches != last_touches) {
|
||||
if (current_touches == 0) {
|
||||
puts("released!");
|
||||
puts("Event: released!");
|
||||
}
|
||||
if (current_touches > 0) {
|
||||
puts("pressed!");
|
||||
puts("Event: pressed!");
|
||||
}
|
||||
last_touches = current_touches;
|
||||
}
|
||||
@ -76,8 +94,6 @@ int main(void)
|
||||
if (current_touches == 1) {
|
||||
printf("X: %i, Y:%i\n", touches[0].x, touches[0].y);
|
||||
}
|
||||
|
||||
ztimer_sleep(ZTIMER_MSEC, 10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user