Skip to content

Commit 2c5607d

Browse files
committed
sample: drivers: dali: add a logger sample
A sample that logs frames on a DALI bus to UART/RTT. Signed-off-by: Markus Becker <markushx@gmail.com>
1 parent ff3284f commit 2c5607d

File tree

6 files changed

+162
-0
lines changed

6 files changed

+162
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.20.0)
2+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
3+
project(dali_app LANGUAGES C)
4+
5+
include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
6+
target_sources(app PRIVATE src/main.c)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. zephyr:code-sample:: dali-logger
2+
:name: Digital Addressable Lighting Interface (DALI) logger
3+
:relevant-api: dali
4+
5+
Log activity on a DALI bus to UART.
6+
7+
Overview
8+
********
9+
10+
This sample utilizes the :ref:`dali <dali_api>` driver API to log DALI frames to UART.
11+
12+
Building and Running
13+
********************
14+
15+
The interface to the DALI bus is defined in the board's devicetree. For details see the dali_ sample.
16+
17+
.. note:: For proper operation a DALI specific physical interface is required.
18+
19+
Building and Running for Nordic nRF52840
20+
============================================
21+
The :zephyr_file:`samples/drivers/dali_logger/boards/nrf52840dk/nrf52840.overlay`
22+
is specifically for the Mikroe-2672 DALI2 click development board
23+
used as physical interface to the DALI bus. This board uses negative
24+
logic for signal transmission (Tx Low <-> DALI Bus Idle).
25+
The sample can be build and executed for the
26+
:zephyr:board:`nrf52840` as follows:
27+
28+
.. zephyr-app-commands::
29+
:zephyr-app: samples/drivers/dali
30+
:board: nrf52840dk/nrf52840
31+
:goals: build flash
32+
:compact:
33+
34+
Sample outout
35+
=============
36+
37+
You should see log on DALI, when there's activity on the bus.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2025 by Markus Becker
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* add DALI 2 Click (MIKROE-2672)
6+
* via Arduino UNO click shield (MIKROE-1581)
7+
* to nRF52840 DK (pca10056)
8+
* DALI 2 Click
9+
* DALI TX 2
10+
* DALI RX 15
11+
* Arduino UNO click shield:
12+
* DALI TX 2 > A3
13+
* DALI RX 15 > D2
14+
* nRF52840 DK:
15+
* DALI TX A3 > P0.29
16+
* DALI RX D2 > P1.03
17+
*/
18+
19+
/ {
20+
dali0: dali {
21+
compatible = "zephyr,dali-pwm";
22+
status = "okay";
23+
counter = <&timer2>;
24+
pwms = <&pwm0 0 PWM_USEC(41) PWM_POLARITY_NORMAL>;
25+
rx-gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>; // D2
26+
tx-flank-shift-us = <(-35)>;
27+
rx-flank-shift-us = <(-59)>;
28+
tx-rx-propagation-max-us = <2400>;
29+
rx-max-latency-us = <80>;
30+
rx-grey-area-us = <800>;
31+
};
32+
};
33+
34+
&pinctrl {
35+
pwm0_default: pwm0_default {
36+
group1 {
37+
psels = <NRF_PSEL(PWM_OUT0, 0, 29)>; // A3
38+
nordic,invert;
39+
};
40+
};
41+
42+
pwm0_sleep: pwm0_sleep {
43+
group1 {
44+
psels = <NRF_PSEL(PWM_OUT0, 0, 29)>; // A3
45+
low-power-enable;
46+
};
47+
};
48+
};
49+
50+
&timer2 {
51+
compatible = "nordic,nrf-timer";
52+
status = "okay";
53+
prescaler = <4>;
54+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CONFIG_DALI=y
2+
3+
CONFIG_LOG=y
4+
CONFIG_LOG_BACKEND_SHOW_COLOR=n
5+
CONFIG_LOG_BACKEND_SHOW_LEVEL=n
6+
CONFIG_LOG_FUNC_NAME_PREFIX_DBG=n
7+
CONFIG_LOG_BACKEND_SHOW_TIMESTAMP=y
8+
CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP=n
9+
10+
CONFIG_DALI_LOW_LEVEL_LOG_LEVEL_OFF=y
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sample:
2+
description: DALI Logger application
3+
name: dali-logger
4+
common:
5+
build_only: true
6+
integration_platforms:
7+
- nrf52840dk/nrf52840
8+
tests:
9+
app.default: {}
10+
app.debug:
11+
extra_overlay_confs:
12+
- debug.conf
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2025 by Markus Becker <markushx@gmail.com>
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/kernel.h>
7+
#include <zephyr/device.h>
8+
#include <zephyr/drivers/dali.h>
9+
10+
#include <zephyr/logging/log.h>
11+
LOG_MODULE_REGISTER(D, LOG_LEVEL_INF);
12+
13+
static uint32_t packet_counter;
14+
15+
void dali_rx_callback(const struct device *dev, struct dali_frame frame, void *user_data)
16+
{
17+
LOG_INF("RX %u %u %x", packet_counter++, frame.event_type, frame.data);
18+
}
19+
20+
#define DALI_NODE DT_NODELABEL(dali0)
21+
22+
int main(void)
23+
{
24+
LOG_INF("DALI Logger");
25+
LOG_INF("Target board: %s", CONFIG_BOARD_TARGET);
26+
27+
/* get the DALI device */
28+
const struct device *dali_dev = DEVICE_DT_GET(DALI_NODE);
29+
30+
if (!device_is_ready(dali_dev)) {
31+
LOG_ERR("failed to get DALI device.");
32+
return 0;
33+
}
34+
35+
dali_receive(dali_dev, dali_rx_callback, NULL);
36+
37+
/* idle and wait for callbacks */
38+
for (;;) {
39+
k_sleep(K_MSEC(60000));
40+
LOG_INF("ALIVE");
41+
}
42+
return 0;
43+
}

0 commit comments

Comments
 (0)