From f15fbf13b36003c1c04e0c36b5c87fb051f1e558 Mon Sep 17 00:00:00 2001 From: Gilles DOFFE Date: Fri, 23 Feb 2018 22:22:51 +0100 Subject: [PATCH] tests: add periph_qdec test * Test all QDEC devices Signed-off-by: Gilles DOFFE --- tests/periph_qdec/Makefile | 8 +++++ tests/periph_qdec/README.md | 7 ++++ tests/periph_qdec/main.c | 64 +++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 tests/periph_qdec/Makefile create mode 100644 tests/periph_qdec/README.md create mode 100644 tests/periph_qdec/main.c diff --git a/tests/periph_qdec/Makefile b/tests/periph_qdec/Makefile new file mode 100644 index 0000000000..faf60b4f13 --- /dev/null +++ b/tests/periph_qdec/Makefile @@ -0,0 +1,8 @@ +BOARD ?= nucleo-f401 +include ../Makefile.tests_common + +FEATURES_REQUIRED = periph_qdec + +USEMODULE += xtimer + +include $(RIOTBASE)/Makefile.include diff --git a/tests/periph_qdec/README.md b/tests/periph_qdec/README.md new file mode 100644 index 0000000000..fb739c4e8c --- /dev/null +++ b/tests/periph_qdec/README.md @@ -0,0 +1,7 @@ +Expected result +=============== +If everything is running as supposed to, you should see a X4 mode quadrature decoding on each qdec configured. + +Background +========== +Test for the low-level QDEC driver. diff --git a/tests/periph_qdec/main.c b/tests/periph_qdec/main.c new file mode 100644 index 0000000000..54b6fd29eb --- /dev/null +++ b/tests/periph_qdec/main.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2017 Gilles DOFFE + * + * 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 low-level QDEC drivers + * + * This test initializes all declared QDEC devices. + * It displays QDEC counters value each second. + * + * @author Gilles DOFFE + * + * @} + */ + +#include + +#include "periph/qdec.h" +#include "xtimer.h" + +void handler(void *arg) +{ + qdec_t qdec = (qdec_t)arg; + printf("QDEC %u counter overflow : reset counter\n", qdec); + qdec_read_and_reset(QDEC_DEV(qdec)); +} + +int main(void) +{ + uint32_t i = 0; + int32_t value = 0; + puts("Welcome into Quadrature Decoder (QDEC) test program."); + puts("This program will count pulses on all available QDEC channels"); + puts("Written for nucleo-f401, you have to plug signals A and B as follow :"); + puts(" QDEC0 : signal A on PA6 and signal B on PA7"); + puts(" QDEC1 : signal A on PB6 and signal B on PB7"); + puts("Quadrature decoding mode is set to X4 : counting on all edges on both signals"); + + for (i = 0; i < QDEC_NUMOF; i++) { + int32_t error = qdec_init(QDEC_DEV(i), QDEC_X4, handler, (void *)i); + if (error) { + fprintf(stderr,"Not supported mode !\n"); + return error; + } + } + + while (1) { + for (i = 0; i < QDEC_NUMOF; i++) { + value = qdec_read_and_reset(QDEC_DEV(i)); + printf("QDEC %lu = %ld\n", (unsigned long int)i, (long int)value); + } + xtimer_sleep(1); + } + + return 0; +}