From 03bf0fae0174f28094b257301aa1b2c49339b6c6 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Sat, 18 Jan 2020 15:05:14 +0100 Subject: [PATCH] tests/cst816s: Add basic touch screen test --- tests/driver_cst816s/Makefile | 6 ++++ tests/driver_cst816s/main.c | 67 +++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/driver_cst816s/Makefile create mode 100644 tests/driver_cst816s/main.c diff --git a/tests/driver_cst816s/Makefile b/tests/driver_cst816s/Makefile new file mode 100644 index 0000000000..119614342d --- /dev/null +++ b/tests/driver_cst816s/Makefile @@ -0,0 +1,6 @@ +include ../Makefile.tests_common + +USEMODULE += cst816s +USEMODULE += core_thread_flags + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_cst816s/main.c b/tests/driver_cst816s/main.c new file mode 100644 index 0000000000..30090e4b58 --- /dev/null +++ b/tests/driver_cst816s/main.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2020 Koen Zandberg + * + * 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 + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Test application for the CST816S touch screen driver + * + * @author Koen Zandberg + * + * @} + */ + +#include +#include + +#include "cst816s_params.h" +#include "cst816s.h" +#include "thread.h" +#include "thread_flags.h" + +#define CST816S_THREAD_FLAG (1 << 8) +#define CST816S_NUM_TOUCHES 5 + +static void _cb(void *arg) +{ + kernel_pid_t *pid = arg; + thread_flags_set((thread_t *)sched_threads[*pid], CST816S_THREAD_FLAG); +} + +static void _dump_cst816s(cst816s_t *dev) +{ + puts("Reading data:"); + cst816s_touch_data_t touches; + if (cst816s_read(dev, &touches) == 0) { + printf("Touch at %03u, %03u with gesture type \"%s\"\n", touches.x, + touches.y, cst816s_gesture_str[touches.gesture]); + } + else { + puts("Device not responding"); + } +} + +int main(void) +{ + cst816s_t dev; + + kernel_pid_t pid = thread_getpid(); + + puts("CST816S test application\n"); + cst816s_init(&dev, &cst816s_params[0], _cb, &pid); + + while (1) { + thread_flags_t flags = thread_flags_wait_any(CST816S_THREAD_FLAG); + if (flags & CST816S_THREAD_FLAG) { + _dump_cst816s(&dev); + } + } + return 0; +}