From c27420418f23536a2ace016a15ca4c744649d2b3 Mon Sep 17 00:00:00 2001 From: KSKNico Date: Tue, 25 Mar 2025 14:03:44 +0100 Subject: [PATCH] drivers/tm1637: tests for the tm1637 7-segment display --- tests/drivers/tm1637/Makefile | 11 ++++ tests/drivers/tm1637/Makefile.ci | 3 + tests/drivers/tm1637/README.md | 18 +++++ tests/drivers/tm1637/main.c | 109 +++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 tests/drivers/tm1637/Makefile create mode 100644 tests/drivers/tm1637/Makefile.ci create mode 100644 tests/drivers/tm1637/README.md create mode 100644 tests/drivers/tm1637/main.c diff --git a/tests/drivers/tm1637/Makefile b/tests/drivers/tm1637/Makefile new file mode 100644 index 0000000000..a3708deb7a --- /dev/null +++ b/tests/drivers/tm1637/Makefile @@ -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 diff --git a/tests/drivers/tm1637/Makefile.ci b/tests/drivers/tm1637/Makefile.ci new file mode 100644 index 0000000000..72db76ccb5 --- /dev/null +++ b/tests/drivers/tm1637/Makefile.ci @@ -0,0 +1,3 @@ +BOARD_INSUFFICIENT_MEMORY := \ + atmega8 \ + # diff --git a/tests/drivers/tm1637/README.md b/tests/drivers/tm1637/README.md new file mode 100644 index 0000000000..5477432f47 --- /dev/null +++ b/tests/drivers/tm1637/README.md @@ -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. \ No newline at end of file diff --git a/tests/drivers/tm1637/main.c b/tests/drivers/tm1637/main.c new file mode 100644 index 0000000000..3c17018f8a --- /dev/null +++ b/tests/drivers/tm1637/main.c @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2024 Nico Behrens + * + * 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 + * + * @} + */ + +#include "tm1637.h" +#include "tm1637_params.h" + +#include "periph/gpio.h" +#include "ztimer.h" +#include "embUnit.h" + +#include + +/** + * @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; +}