mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2026-01-01 01:41:18 +01:00
drivers/tm1637: tests for the tm1637 7-segment display
This commit is contained in:
parent
cccce720e3
commit
c27420418f
11
tests/drivers/tm1637/Makefile
Normal file
11
tests/drivers/tm1637/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
include ../Makefile.drivers_common
|
||||
|
||||
USEMODULE += tm1637
|
||||
|
||||
USEMODULE += ztimer_sec
|
||||
USEMODULE += embunit
|
||||
|
||||
CFLAGS += "-DTM1637_PARAM_CLK=GPIO_PIN(0, 0)"
|
||||
CFLAGS += "-DTM1637_PARAM_DIO=GPIO_PIN(0, 1)"
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
3
tests/drivers/tm1637/Makefile.ci
Normal file
3
tests/drivers/tm1637/Makefile.ci
Normal file
@ -0,0 +1,3 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
atmega8 \
|
||||
#
|
||||
18
tests/drivers/tm1637/README.md
Normal file
18
tests/drivers/tm1637/README.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Test Application for the TM1637 4 digit 7-segment display.
|
||||
|
||||
## About
|
||||
|
||||
This is a simple test application for the TM1637 driver.
|
||||
|
||||
## Details
|
||||
|
||||
This test application will initialize the TM1637 driver with the configuration
|
||||
as specified in the default `tm1637_params.h` file. The 4 pins of the display need to
|
||||
be connected in this way:
|
||||
- The clk pin connects to GPIO 0
|
||||
- The dio pin connects to GPIO 1
|
||||
- The VCC pin connects to either 5V or 3.3V
|
||||
- The GND pin connects to GND
|
||||
|
||||
## Expected result
|
||||
The displays switches between different configurations, all digits and all brightness levels.
|
||||
109
tests/drivers/tm1637/main.c
Normal file
109
tests/drivers/tm1637/main.c
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Nico Behrens <nifrabe@outlook.de>
|
||||
*
|
||||
* 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 TM1637 4-digit 7-segment display driver
|
||||
*
|
||||
* @author Nico Behrens <nifrabe@outlook.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "tm1637.h"
|
||||
#include "tm1637_params.h"
|
||||
|
||||
#include "periph/gpio.h"
|
||||
#include "ztimer.h"
|
||||
#include "embUnit.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* @brief device descriptor of the display
|
||||
*/
|
||||
static tm1637_t dev;
|
||||
|
||||
static void test_setup(void)
|
||||
{
|
||||
tm1637_init(&dev, &tm1637_params[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Display a number with different settings
|
||||
*/
|
||||
static void test_number(void)
|
||||
{
|
||||
int number = -42;
|
||||
TEST_ASSERT_EQUAL_INT(0, tm1637_write_number(&dev, number, TM1637_PW_14_16, false, false));
|
||||
ztimer_sleep(ZTIMER_SEC, 1);
|
||||
TEST_ASSERT_EQUAL_INT(0, tm1637_write_number(&dev, number, TM1637_PW_14_16, false, true));
|
||||
ztimer_sleep(ZTIMER_SEC, 1);
|
||||
TEST_ASSERT_EQUAL_INT(0, tm1637_write_number(&dev, number, TM1637_PW_14_16, true, false));
|
||||
ztimer_sleep(ZTIMER_SEC, 1);
|
||||
TEST_ASSERT_EQUAL_INT(0, tm1637_write_number(&dev, number, TM1637_PW_14_16, true, true));
|
||||
ztimer_sleep(ZTIMER_SEC, 1);
|
||||
TEST_ASSERT_EQUAL_INT(0, tm1637_clear(&dev));
|
||||
ztimer_sleep(ZTIMER_SEC, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shows all digits on the display
|
||||
*/
|
||||
static void test_all_digits(void)
|
||||
{
|
||||
for (int i = 0; i < 10; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, tm1637_write_number(&dev, i, TM1637_PW_14_16, false, false));
|
||||
ztimer_sleep(ZTIMER_SEC, 1);
|
||||
}
|
||||
TEST_ASSERT_EQUAL_INT(0, tm1637_clear(&dev));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test all brightness levels
|
||||
*/
|
||||
static void test_brightness(void)
|
||||
{
|
||||
int number = 8888;
|
||||
/* the brightness goes from 0 to 7 */
|
||||
for (int i = 0; i <= 7; i++) {
|
||||
TEST_ASSERT_EQUAL_INT(0, tm1637_write_number(&dev, number, i, false, false));
|
||||
ztimer_sleep(ZTIMER_SEC, 1);
|
||||
}
|
||||
TEST_ASSERT_EQUAL_INT(0, tm1637_clear(&dev));
|
||||
ztimer_sleep(ZTIMER_SEC, 1);
|
||||
}
|
||||
|
||||
static Test *tests_tm1637_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures){
|
||||
new_TestFixture(test_number),
|
||||
new_TestFixture(test_all_digits),
|
||||
new_TestFixture(test_brightness),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(tm1637_tests, test_setup, NULL, fixtures);
|
||||
|
||||
return (Test *)&tm1637_tests;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("Starting TM1637 driver test application");
|
||||
|
||||
TESTS_START();
|
||||
TESTS_RUN(tests_tm1637_tests());
|
||||
TESTS_END();
|
||||
|
||||
puts("Ending TM1637 driver test application");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user