1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 22:43:50 +01:00

tests/driver_stmpe811: don't poll for touch events

Now that the interrupt of the driver works properly, we don't have to
rely on polling.

Instead, wake the thread by touch interrupt.
This commit is contained in:
Benjamin Valentin 2020-07-15 23:09:25 +02:00 committed by Alexandre Abadie
parent cbae0186ca
commit f857b7116b
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
2 changed files with 12 additions and 7 deletions

View File

@ -2,7 +2,6 @@ BOARD ?= stm32f429i-disc1
include ../Makefile.tests_common
USEMODULE += xtimer
USEMODULE += stmpe811
include $(RIOTBASE)/Makefile.include

View File

@ -20,25 +20,25 @@
#include <stdio.h>
#include "xtimer.h"
#include "mutex.h"
#include "stmpe811.h"
#include "stmpe811_params.h"
static void _touch_event_cb(void *arg)
{
(void)arg;
puts("Pressed!");
mutex_unlock(arg);
}
int main(void)
{
mutex_t lock = MUTEX_INIT_LOCKED;
stmpe811_t dev;
puts("STMPE811 test application\n");
printf("+------------Initializing------------+\n");
int ret = stmpe811_init(&dev, &stmpe811_params[0], _touch_event_cb, NULL);
int ret = stmpe811_init(&dev, &stmpe811_params[0], _touch_event_cb, &lock);
if (ret != STMPE811_OK) {
puts("[Error] Initialization failed");
return 1;
@ -51,8 +51,16 @@ int main(void)
stmpe811_touch_state_t last_touch_state = current_touch_state;
while (1) {
/* wait for touch event */
mutex_lock(&lock);
stmpe811_read_touch_state(&dev, &current_touch_state);
if (current_touch_state != last_touch_state) {
if (current_touch_state == STMPE811_TOUCH_STATE_PRESSED) {
puts("Pressed!");
}
if (current_touch_state == STMPE811_TOUCH_STATE_RELEASED) {
puts("Released!");
}
@ -65,8 +73,6 @@ int main(void)
stmpe811_read_touch_position(&dev, &position);
printf("X: %i, Y:%i\n", position.x, position.y);
}
xtimer_usleep(10 * US_PER_MS);
}
return 0;