diff --git a/tests/driver_my9221/Makefile b/tests/driver_my9221/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..0f1bce3a58124993a2e86425dc1f7f4e50af6311 --- /dev/null +++ b/tests/driver_my9221/Makefile @@ -0,0 +1,22 @@ +APPLICATION = driver_my9221 +include ../Makefile.tests_common + +USEMODULE += my9221 + +# set default device parameters in case they are undefined +# the following params are for board pba-d-01-kw2x and pins PA01 and PA02 +TEST_MY9221_CLK ?= GPIO_PIN\(0,1\) +TEST_MY9221_DAT ?= GPIO_PIN\(0,2\) +TEST_MY9221_DIR ?= MY9221_DIR_FWD +TEST_MY9221_NUM ?= 10 + +# export parameters +CFLAGS += -DTEST_MY9221_CLK=$(TEST_MY9221_CLK) +CFLAGS += -DTEST_MY9221_DAT=$(TEST_MY9221_DAT) +CFLAGS += -DTEST_MY9221_DIR=$(TEST_MY9221_DIR) +CFLAGS += -DTEST_MY9221_NUM=$(TEST_MY9221_NUM) + +test: + tests/01-run.py + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_my9221/README.md b/tests/driver_my9221/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e5b4eb57e0bbfdd6e4f4392e3d2b31b503e8abf9 --- /dev/null +++ b/tests/driver_my9221/README.md @@ -0,0 +1,16 @@ +# About + +This is a test application for the MY9221 LED controller driver, which is found +on the Seeed Studio Grove LED bar module [1]. + +# Details + +For this test application you can use e.g. the Groove LED bar which has 10 LEDs. +The default settings in the Makefile are suited for the Grove ledbar, adapt them +as needed for any other device or number of LEDs. + +The test application runs several test sequence, first toggling all LEDs +one by one, and secondly setting all LEDs to 33%, 66%, and 100% brightness. +Finally all LEDs are turned of again. + +[1]: https://www.seeedstudio.com/Grove-LED-Bar-v2.0-p-2474.html diff --git a/tests/driver_my9221/main.c b/tests/driver_my9221/main.c new file mode 100644 index 0000000000000000000000000000000000000000..96223591b1442b50c609425400eeabf1adaf39eb --- /dev/null +++ b/tests/driver_my9221/main.c @@ -0,0 +1,86 @@ +/* + * 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 application for the MY9221 LED controller + * + * @author Sebastian Meiling <s@mlng.net> + * + * @} + */ + +#include <stdio.h> + +#include "log.h" +#include "xtimer.h" +#include "my9221.h" + +#define TEST_STEP (5U) +#define TEST_WAIT (42*US_PER_MS) + +static my9221_params_t params = { + .leds = TEST_MY9221_NUM, + .dir = TEST_MY9221_DIR, + .clk = TEST_MY9221_CLK, + .dat = TEST_MY9221_DAT, +}; + +int main(void) +{ + my9221_t dev; + /* init display */ + puts("[START]"); + if (my9221_init(&dev, ¶ms) != 0) { + puts("[FAILED]"); + return 1; + } + /* run some tests */ + LOG_INFO("- light up all LEDs one by one.\n"); + for (unsigned i=0; i < dev.params.leds; ++i) { + my9221_set_led(&dev, i, MY9221_LED_ON); + xtimer_usleep(TEST_WAIT); + my9221_set_led(&dev, i, MY9221_LED_OFF); + } + xtimer_usleep(TEST_WAIT); + for (unsigned i=dev.params.leds; i > 0 ; --i) { + my9221_set_led(&dev, i, MY9221_LED_ON); + xtimer_usleep(TEST_WAIT); + my9221_set_led(&dev, i, MY9221_LED_OFF); + } + xtimer_usleep(TEST_WAIT); + LOG_INFO("- light up all LEDs to 33%%.\n"); + for (unsigned i=0; i < dev.params.leds; ++i) { + my9221_set_led(&dev, i, MY9221_LED_ON/3); + xtimer_usleep(TEST_WAIT); + } + xtimer_usleep(TEST_WAIT); + LOG_INFO("- light up all LEDs to 66%%.\n"); + for (unsigned i=0; i < dev.params.leds; ++i) { + my9221_set_led(&dev, i, (MY9221_LED_ON/3)*2); + xtimer_usleep(TEST_WAIT); + } + xtimer_usleep(TEST_WAIT); + LOG_INFO("- light up all LEDs to 100%%.\n"); + for (unsigned i=0; i < dev.params.leds; ++i) { + my9221_set_led(&dev, i, MY9221_LED_ON); + xtimer_usleep(TEST_WAIT); + } + xtimer_usleep(TEST_WAIT); + LOG_INFO("- turn off all LEDs\n"); + for (unsigned i=dev.params.leds; i > 0 ; --i) { + my9221_toggle_led(&dev, i-1); + xtimer_usleep(TEST_WAIT); + } + puts("[SUCCESS]"); + + return 0; +} diff --git a/tests/driver_my9221/tests/01-run.py b/tests/driver_my9221/tests/01-run.py new file mode 100755 index 0000000000000000000000000000000000000000..5801a4475cb6dc201675d6d719433585b7bd2974 --- /dev/null +++ b/tests/driver_my9221/tests/01-run.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de> +# 2017 Sebastian Meiling <s@mlng.net> +# +# 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. + +import os +import sys + +sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner')) +import testrunner + +def testfunc(child): + child.expect_exact("[SUCCESS]", timeout=60) + +if __name__ == "__main__": + sys.exit(testrunner.run(testfunc))