1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

tests/driver_stmpe811: add test application

This commit is contained in:
Alexandre Abadie 2019-04-28 17:54:50 +02:00
parent 1bc842707a
commit e694708bbb
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
3 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,8 @@
BOARD ?= stm32f429i-disc1
include ../Makefile.tests_common
USEMODULE += xtimer
USEMODULE += stmpe811
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,33 @@
## About
This is the test application for the STMPE811 touchscreen controller.
## Usage
The application works out of the box on a STM32F429I-DISC1 board:
```
make -C tests/driver_stmpe811 flash term
```
## Expected output
The application initializes the STMPE811 and displays "Pressed!" when a touch
event is detected.
Current touch positions are printed in terminal while holding the screen
pressed.
"Released" is displayed when the screen is released.
```
2020-02-10 10:20:17,647 # Pressed!
2020-02-10 10:20:17,653 # X: 167, Y:81
2020-02-10 10:20:17,659 # X: 165, Y:75
2020-02-10 10:20:17,671 # X: 165, Y:69
2020-02-10 10:20:17,689 # X: 166, Y:68
2020-02-10 10:20:17,701 # X: 167, Y:68
2020-02-10 10:20:17,713 # X: 169, Y:69
2020-02-10 10:20:17,725 # X: 170, Y:69
2020-02-10 10:20:17,737 # X: 170, Y:70
2020-02-10 10:20:17,755 # X: 173, Y:69
2020-02-10 10:20:17,761 # Released!
```

View File

@ -0,0 +1,73 @@
/*
* Copyright (C) 2019 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 STMPE811 touchscreen controller
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*
* @}
*/
#include <stdio.h>
#include "xtimer.h"
#include "stmpe811.h"
#include "stmpe811_params.h"
static void _touch_event_cb(void *arg)
{
(void)arg;
puts("Pressed!");
}
int main(void)
{
stmpe811_t dev;
puts("STMPE811 test application\n");
printf("+------------Initializing------------+\n");
int ret = stmpe811_init(&dev, &stmpe811_params[0], _touch_event_cb, NULL);
if (ret != STMPE811_OK) {
puts("[Error] Initialization failed");
return 1;
}
puts("Initialization successful");
stmpe811_touch_state_t current_touch_state;
stmpe811_read_touch_state(&dev, &current_touch_state);
stmpe811_touch_state_t last_touch_state = current_touch_state;
while (1) {
stmpe811_read_touch_state(&dev, &current_touch_state);
if (current_touch_state != last_touch_state) {
if (current_touch_state == STMPE811_TOUCH_STATE_RELEASED) {
puts("Released!");
}
last_touch_state = current_touch_state;
}
/* Display touch position if pressed */
if (current_touch_state == STMPE811_TOUCH_STATE_PRESSED) {
stmpe811_touch_position_t position;
stmpe811_read_touch_position(&dev, &position);
printf("X: %i, Y:%i\n", position.x, position.y);
}
xtimer_usleep(10 * US_PER_MS);
}
return 0;
}