Signed-off-by: Tony <tonylu@tony-cloud.com>
DALI ESP-IDF Component
This component provides a DALI (IEC 62386) protocol stack and ESP-IDF HAL implementation that can be used directly in native FreeRTOS/ESP-IDF projects.
Features
- DALI forward and backward frame support.
- Multi-bus support (
DALI_PHY_COUNT, default 16). - Runtime baudrate control (
400..2400, default1200). - ESP-IDF GPTimer + GPIO interrupt driven HAL.
Public Headers
dali.h: high-level DALI helpers.dali_hal.h: HAL API and queue access.dali_define.h: DALI command definitions.
Quick Start
- Add this component to your project.
- Configure TX/RX pins and initialize at least one bus.
- Send a DALI frame.
#include "dali.h"
#include "dali_define.h"
#include "dali_hal.h"
void app_main(void) {
ESP_ERROR_CHECK(dali_hal_set_baudrate(1200));
ESP_ERROR_CHECK(dali_hal_init(0, 4, 5));
Dali_msg_t msg = dali_msg_new(0xFF, DALI_CMD_ON); // broadcast ON command
msg.id = 0;
dali_send(&msg);
}
Kconfig Options
Use menuconfig under DALI Component to configure:
- Bus count and default baudrate.
- Native timing values for development, including timer resolution, half-bit period, TX/RX stop conditions, query response timeout, double-send delay, and TX queue arbitration waits.
- TX/RX active polarity. The native gateway default is TX active low and RX active high.
- Native bus power-down polling and legacy
FF FDbus-abnormal raw-frame reporting intervals. - Native DALI HAL log level for the
dali_halESP-IDF log tag. - Queue sizes.
- Task stack sizes and priorities.
- Optional debug task.
The native bus monitor uses CONFIG_DALI_BUS_POWER_CHECK_INTERVAL_MS to resample RX while
power-down and CONFIG_DALI_BUS_ABNORMAL_REPORT_INTERVAL_MS to publish legacy FF FD
raw frames while down. The report interval defaults to 1000 ms; set it to 0 to disable the
compatibility report.
Native timing defaults target standard 1200 bps DALI: a 416.67 us half-bit period is
generated by the default 3 MHz timer as 1250 ticks. CONFIG_DALI_CUSTOM_HALF_BIT_TIME_X100_US
can override the half-bit period for development; keep it at 0 for baudrate-derived timing.
Query no-response timeout defaults to 25 ms, which covers the 5.5-10.5 ms backward-frame
start window plus the approximately 9.95 ms backward frame duration.
Native TX queue arbitration uses frame length as the frame type signal. Two- to four-byte
forward frames wait up to CONFIG_DALI_FORWARD_MAX_WAIT_MS for a valid send window,
using CONFIG_DALI_FORWARD_ACTIVITY_WAIT_MS after normal bus activity and
CONFIG_DALI_FORWARD_AFTER_BACKWARD_WAIT_MS after a valid backward frame. One-byte
backward frames wait up to CONFIG_DALI_BACKWARD_IDLE_TIMEOUT_MS for idle, then are
sent without echo verification because addressing-phase collisions are valid.
API Note
The global TX response queue symbol was renamed:
- old:
dali_send_replay_queue - new:
dali_send_reply_queue
See MIGRATION.md for compatibility notes.
Examples
examples/dali_basicexamples/dali_multi_bus