tests/driver_ft5x06: add test application for touch panel

This commit is contained in:
Alexandre Abadie 2021-12-27 11:25:33 +01:00
parent 11f73ea5c9
commit 444170ed04
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
4 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,7 @@
BOARD ?= stm32f746g-disco
include ../Makefile.tests_common
DRIVER ?= ft5336
USEMODULE += $(DRIVER)
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,3 @@
BOARD_INSUFFICIENT_MEMORY := \
nucleo-l011k4 \
#

View File

@ -0,0 +1,3 @@
# this file enables modules defined in Kconfig. Do not use this file for
# application configuration. This is only needed during migration.
CONFIG_MODULE_FT5336=y

View File

@ -0,0 +1,89 @@
/*
* Copyright (C) 2021 Inria
*
* 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 ft5x06 touch driver
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*
* @}
*/
#include <stdio.h>
#include "mutex.h"
#include "ft5x06.h"
#include "ft5x06_params.h"
static void _touch_event_cb(void *arg)
{
mutex_unlock(arg);
}
static ft5x06_touch_position_t positions[FT5X06_TOUCHES_COUNT_MAX];
int main(void)
{
mutex_t lock = MUTEX_INIT_LOCKED;
ft5x06_t dev;
puts("FT5x06 test application\n");
printf("+------------Initializing------------+\n");
int ret = ft5x06_init(&dev, &ft5x06_params[0], _touch_event_cb, &lock);
if (ret != 0) {
puts("[Error] Initialization failed");
return 1;
}
puts("Initialization successful");
uint8_t current_touch_count = 0;
ft5x06_read_touch_count(&dev, &current_touch_count);
uint8_t last_touch_count = current_touch_count;
while (1) {
/* wait for touch event */
mutex_lock(&lock);
ft5x06_read_touch_count(&dev, &current_touch_count);
if (current_touch_count != last_touch_count) {
if (current_touch_count) {
printf("%d touch detected\n", current_touch_count);
}
if (!current_touch_count) {
puts("Released!");
}
last_touch_count = current_touch_count;
}
ft5x06_touch_gesture_t gesture;
ft5x06_read_touch_gesture(&dev, &gesture);
if (gesture != FT5X06_TOUCH_NO_GESTURE) {
printf("Gesture detected: %d\n", gesture);
}
/* Display touch positions if there are some */
if (current_touch_count > 0) {
ft5x06_read_touch_positions(&dev, positions, current_touch_count);
for (uint8_t touch = 0; touch < current_touch_count; touch++) {
printf("Touch %d - X: %i, Y:%i\n",
touch + 1, positions[touch].x, positions[touch].y);
}
}
}
return 0;
}