1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:32:45 +01:00

tests: add driver_my9221 test application

This commit is contained in:
smlng 2017-06-12 22:29:29 +02:00
parent ecaca83b0b
commit aa554d7cce
4 changed files with 144 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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, &params) != 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;
}

View File

@ -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))