From bf93cd59fb4936fda6bf8eaaee3d2b7415e4f489 Mon Sep 17 00:00:00 2001 From: smlng Date: Tue, 20 Jun 2017 21:15:30 +0200 Subject: [PATCH] tests: add on-board button test --- tests/buttons/Makefile | 6 +++ tests/buttons/README.md | 13 +++++++ tests/buttons/main.c | 81 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 tests/buttons/Makefile create mode 100644 tests/buttons/README.md create mode 100644 tests/buttons/main.c diff --git a/tests/buttons/Makefile b/tests/buttons/Makefile new file mode 100644 index 0000000000..9a5f773077 --- /dev/null +++ b/tests/buttons/Makefile @@ -0,0 +1,6 @@ +APPLICATION = buttons +include ../Makefile.tests_common + +USEMODULE += xtimer + +include $(RIOTBASE)/Makefile.include diff --git a/tests/buttons/README.md b/tests/buttons/README.md new file mode 100644 index 0000000000..0279917439 --- /dev/null +++ b/tests/buttons/README.md @@ -0,0 +1,13 @@ +# On-Board Button Test + +This tests initializes all on-board buttons available, currently up to 4 in +total. Each button is configured as an input with interrupt on button press +or release depending on the configured TEST_FLANK. + +# Expected Result + +When a button is pressed (and/or released) an interrupt fires which results in +a message indicating which button was used. The test naturally qualifies for +manual testing only. Nevertheless, it prints "[SUCCESS]" after all buttons +were initialized successfully or "[FAILED] " on error, so it can be used +for limited automated testing as well. diff --git a/tests/buttons/main.c b/tests/buttons/main.c new file mode 100644 index 0000000000..de18b9528d --- /dev/null +++ b/tests/buttons/main.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2017 HAW Hamburg + * + * 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 for the on-board button macros + * + * @author Sebastian Meiling + * + * @} + */ + +#include +#include + +#include "board.h" +#include "periph/gpio.h" +#include "periph_conf.h" + +#define TEST_FLANK GPIO_FALLING + +#ifdef BTN0_PIN /* assuming that first button is always BTN0 */ +static void cb(void *arg) +{ + printf("Pressed BTN%d\n", (int)arg); +} +#endif + +int main(void) +{ + int cnt = 0; + /* get the number of available buttons and init interrupt handler */ +#ifdef BTN0_PIN + if (gpio_init_int(BTN0_PIN, BTN0_MODE, TEST_FLANK, cb, (void *)cnt) < 0) { + puts("[FAILED] init BTN0!"); + return 1; + } + ++cnt; +#endif +#ifdef BTN1_PIN + if (gpio_init_int(BTN1_PIN, BTN1_MODE, TEST_FLANK, cb, (void *)cnt) < 0) { + puts("[FAILED] init BTN1!"); + return 1; + } + ++cnt; +#endif +#ifdef BTN2_PIN + if (gpio_init_int(BTN2_PIN, BTN2_MODE, TEST_FLANK, cb, (void *)cnt) < 0) { + puts("[FAILED] init BTN2!"); + return 1; + } + ++cnt; +#endif +#ifdef BTN3_PIN + if (gpio_init_int(BTN3_PIN, BTN3_MODE, TEST_FLANK, cb, (void *)cnt) < 0) { + puts("[FAILED] init BTN3!"); + return 1; + } + ++cnt; +#endif + + puts("On-board button test\n"); + /* cppcheck-suppress knownConditionTrueFalse + * rationale: board-dependent ifdefs */ + if (cnt == 0) { + puts("[FAILED] no buttons available!"); + return 2; + } + printf(" -- Available buttons: %i\n\n", cnt); + puts(" -- Try pressing buttons to test.\n"); + puts("[SUCCESS]"); + return 0; +}