From 8afe0b702ee2850ecb415b7cddd9758a6431e73f Mon Sep 17 00:00:00 2001 From: Iker Perez del Palomar Sustatxa Date: Wed, 19 May 2021 15:05:57 +0100 Subject: [PATCH] bloodlight_based.c: Create test for led.c * Bloodlight_based.c: Test leds with led.c APIs. * Build bloodlight_based.c by default. Keep both tests zephyr_based (previous main) and bloodlight_based.c so the user can select in CMakeFie which test wants to run. zephyr_based to test leds using zephyrs APIs or bloodlight_based to test them using bloodlight's APIs. Signed-off-by: Iker Perez del Palomar Sustatxa --- boards/arm/bloodlight_rev2/Kconfig.defconfig | 7 +++- tests/led/CMakeLists.txt | 2 +- tests/led/bloodlight_based.c | 41 ++++++++++++++++++++ tests/led/{main.c => zephyr_based.c} | 0 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 tests/led/bloodlight_based.c rename tests/led/{main.c => zephyr_based.c} (100%) diff --git a/boards/arm/bloodlight_rev2/Kconfig.defconfig b/boards/arm/bloodlight_rev2/Kconfig.defconfig index d55a4bb..1cdffbc 100644 --- a/boards/arm/bloodlight_rev2/Kconfig.defconfig +++ b/boards/arm/bloodlight_rev2/Kconfig.defconfig @@ -20,9 +20,14 @@ config USB_DEVICE_VID depends on USB help USB device vendor ID. MUST be configured by vendor. + config USB_DEVICE_PID hex "USB Product ID" default 0x0100 depends on USB help - USB device product ID. MUST be configured by vendor. \ No newline at end of file + USB device product ID. MUST be configured by vendor. + +config PRINTK + bool "Send printk() to console" + default y \ No newline at end of file diff --git a/tests/led/CMakeLists.txt b/tests/led/CMakeLists.txt index 06ebc6f..7a3459e 100644 --- a/tests/led/CMakeLists.txt +++ b/tests/led/CMakeLists.txt @@ -15,6 +15,6 @@ zephyr_include_directories(${CMAKE_SOURCE_DIR}/../..) project(led_test) target_sources(app PRIVATE - main.c + bloodlight_based.c ../../src/led.c ) diff --git a/tests/led/bloodlight_based.c b/tests/led/bloodlight_based.c new file mode 100644 index 0000000..da8d3f4 --- /dev/null +++ b/tests/led/bloodlight_based.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "../../src/led.h" +#include "../../src/led.c" + +void main (void) { + const struct device *dev = device_get_binding( + CONFIG_UART_CONSOLE_ON_DEV_NAME); + uint32_t dtr = 0; + + if (usb_enable(NULL)) { + return; + } + + /* Poll if the DTR flag was set, optional */ + while (!dtr) { + uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr); + } + + if (strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME) != + strlen("CDC_ACM_0") || + strncmp(CONFIG_UART_CONSOLE_ON_DEV_NAME, "CDC_ACM_0", + strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME))) { + printk("Error: Console device name is not USB ACM\n"); + + return; + } + + printk("Before led init\n"); + bl_led_init(); + printk("After led init\n"); + bl_led_status_set(true); + bl_led_set(0xffff); + +}; \ No newline at end of file diff --git a/tests/led/main.c b/tests/led/zephyr_based.c similarity index 100% rename from tests/led/main.c rename to tests/led/zephyr_based.c