base-files: support per-color intensities for multicolor LEDs

The led init script already knows how to drive a multicolor LED: it reads
multi_index and writes one intensity per color to multi_intensity, taken
from color_<name> options of the led section. Nothing fills those options
in, though - generate_led only passes name, sysfs, trigger and default on
to uci, so the intensities stay at zero and the LED remains dark whatever
trigger is set. No board has been able to use it so far.

Pass any color_* key of a board.json led object through to the led
section, and add ucidef_set_led_colors() to set them from board.d:

  ucidef_set_led_default "led1" "LED1" "nbg7815:led1" "1"
  ucidef_set_led_colors "led1" red 255 green 255 blue 255

The colors are not restricted to RGB - the keys are matched against
whatever the LED reports in multi_index.

Signed-off-by: André Valentin <avalentin@marcant.net>
This commit is contained in:
André Valentin authored and Robert Marko committed 2026-10-11 21:28:57 +02:00
1 parent cd649934dc
commit eaffd8be91
2 files changed
+31

No files matched your search

@@ -395,6 +395,7 @@ generate_rssimon() {
generate_led() {
local key="$1"
local cfg="led_$key"
local led_keys led_key led_value
json_select led
json_select "$key"
@@ -409,6 +410,19 @@ generate_led() {
set system.$cfg.default='$default'
EOF
# A multicolor LED carries one intensity per entry of its multi_index,
# which the led init script applies through multi_intensity.
json_get_keys led_keys
for led_key in $led_keys; do
case "$led_key" in
color_*) ;;
*) continue ;;
esac
json_get_var led_value "$led_key"
uci -q set "system.$cfg.$led_key=$led_value"
done
case "$type" in
brightness)
local brightness
@@ -439,6 +439,23 @@ _ucidef_set_led_common() {
json_add_string sysfs "$sysfs"
}
ucidef_set_led_colors() {
local cfg="$1"
shift
json_select_object led
json_select_object "$cfg"
while [ "$#" -gt 1 ]; do
json_add_string "color_$1" "$2"
shift 2
done
json_select ..
json_select ..
}
ucidef_set_led_default() {
local default="$4"