Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions samples/drivers/dali_logger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(dali_app LANGUAGES C)

include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
target_sources(app PRIVATE src/main.c)
37 changes: 37 additions & 0 deletions samples/drivers/dali_logger/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.. zephyr:code-sample:: dali-logger
:name: Digital Addressable Lighting Interface (DALI) logger
:relevant-api: dali

Log activity on a DALI bus to UART.

Overview
********

This sample utilizes the :ref:`dali <dali_api>` driver API to log DALI frames to UART.

Building and Running
********************

The interface to the DALI bus is defined in the board's devicetree. For details see the dali_ sample.

.. note:: For proper operation a DALI specific physical interface is required.

Building and Running for Nordic nRF52840
============================================
The :zephyr_file:`samples/drivers/dali_logger/boards/nrf52840dk/nrf52840.overlay`
is specifically for the Mikroe-2672 DALI2 click development board
used as physical interface to the DALI bus. This board uses negative
logic for signal transmission (Tx Low <-> DALI Bus Idle).
The sample can be build and executed for the
:zephyr:board:`nrf52840` as follows:

.. zephyr-app-commands::
:zephyr-app: samples/drivers/dali
:board: nrf52840dk/nrf52840
:goals: build flash
:compact:

Sample outout
=============

You should see log on DALI, when there's activity on the bus.
54 changes: 54 additions & 0 deletions samples/drivers/dali_logger/boards/nrf52840dk_nrf52840.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2025 by Markus Becker
* SPDX-License-Identifier: Apache-2.0
*
* add DALI 2 Click (MIKROE-2672)
* via Arduino UNO click shield (MIKROE-1581)
* to nRF52840 DK (pca10056)
* DALI 2 Click
* DALI TX 2
* DALI RX 15
* Arduino UNO click shield:
* DALI TX 2 > A3
* DALI RX 15 > D2
* nRF52840 DK:
* DALI TX A3 > P0.29
* DALI RX D2 > P1.03
*/

/ {
dali0: dali {
compatible = "zephyr,dali-pwm";
status = "okay";
counter = <&timer2>;
pwms = <&pwm0 0 PWM_USEC(41) PWM_POLARITY_NORMAL>;
rx-gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>; // D2
tx-flank-shift-us = <(-35)>;
rx-flank-shift-us = <(-59)>;
tx-rx-propagation-max-us = <2400>;
rx-max-latency-us = <80>;
rx-grey-area-us = <800>;
};
};

&pinctrl {
pwm0_default: pwm0_default {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 0, 29)>; // A3
nordic,invert;
};
};

pwm0_sleep: pwm0_sleep {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 0, 29)>; // A3
low-power-enable;
};
};
};

&timer2 {
compatible = "nordic,nrf-timer";
status = "okay";
prescaler = <4>;
};
10 changes: 10 additions & 0 deletions samples/drivers/dali_logger/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CONFIG_DALI=y

CONFIG_LOG=y
CONFIG_LOG_BACKEND_SHOW_COLOR=n
CONFIG_LOG_BACKEND_SHOW_LEVEL=n
CONFIG_LOG_FUNC_NAME_PREFIX_DBG=n
CONFIG_LOG_BACKEND_SHOW_TIMESTAMP=y
CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP=n

CONFIG_DALI_LOW_LEVEL_LOG_LEVEL_OFF=y
12 changes: 12 additions & 0 deletions samples/drivers/dali_logger/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sample:
description: DALI Logger application
name: dali-logger
common:
build_only: true
integration_platforms:
- nrf52840dk/nrf52840
tests:
app.default: {}
app.debug:
extra_overlay_confs:
- debug.conf
43 changes: 43 additions & 0 deletions samples/drivers/dali_logger/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2025 by Markus Becker <markushx@gmail.com>
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/dali.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(D, LOG_LEVEL_INF);

static uint32_t packet_counter;

void dali_rx_callback(const struct device *dev, struct dali_frame frame, void *user_data)
{
LOG_INF("RX %u %u %x", packet_counter++, frame.event_type, frame.data);
}

#define DALI_NODE DT_NODELABEL(dali0)

int main(void)
{
LOG_INF("DALI Logger");
LOG_INF("Target board: %s", CONFIG_BOARD_TARGET);

/* get the DALI device */
const struct device *dali_dev = DEVICE_DT_GET(DALI_NODE);

if (!device_is_ready(dali_dev)) {
LOG_ERR("failed to get DALI device.");
return 0;
}

dali_receive(dali_dev, dali_rx_callback, NULL);

/* idle and wait for callbacks */
for (;;) {
k_sleep(K_MSEC(60000));
LOG_INF("ALIVE");
}
return 0;
}
Loading