From 26182d87cffc36fd66fa8003ba066a37bd74c7d2 Mon Sep 17 00:00:00 2001 From: ZephCore T096 Date: Thu, 27 Aug 2026 20:36:31 +0200 Subject: [PATCH] wt2: shared PWM brightness for the status LED (heartbeat/TX/flashes) Ports the T096 "Option 1" design (single LED, get/set leds on|off persisted + get/set leds.brightness 0-100 RAM-only) to the Wireless Tracker V2, which has the same single-LED-multi-purpose situation (status_led doubles as heartbeat/message-flash/shutdown-flash/TX indicator, same as T096's P0.28). Adds a new ledc0 PWM channel on GPIO18 (same physical pin as the existing plain-GPIO status_led) with heartbeat-pwm-led/lora-tx-pwm-led aliases -- the shared C++ logic (helpers/ui/ui_common.c, adapters/board/ZephyrBoard.cpp, helpers/led_gate.c/h, helpers/CommonCLI.cpp) already existed from the T096 commits and needed no changes, being board-agnostic behind DT_NODE_EXISTS checks. CONFIG_PWM=y deliberately NOT in the board defconfig: WT2 builds via --sysbuild (mcuboot + app as two images sharing that defconfig), and mcuboot's minimal kernel config has no k_sem_give()/k_sem_take(), which the ESP32 PWM LED driver needs -- CONFIG_PWM=y there links the app image fine but fails mcuboot's link. New boards/common/esp32s3_pwm_led.conf scopes it to the app image only via EXTRA_CONF_FILE, alongside the existing esp32s3_usb.conf. --- zephcore/boards/common/esp32s3_pwm_led.conf | 15 +++++++++ .../heltec_wireless_tracker_v2-pinctrl.dtsi | 7 ++++ .../heltec_wireless_tracker_v2_procpu.dts | 32 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 zephcore/boards/common/esp32s3_pwm_led.conf diff --git a/zephcore/boards/common/esp32s3_pwm_led.conf b/zephcore/boards/common/esp32s3_pwm_led.conf new file mode 100644 index 0000000..97f8f3c --- /dev/null +++ b/zephcore/boards/common/esp32s3_pwm_led.conf @@ -0,0 +1,15 @@ +# Enable PWM on ESP32-S3 sysbuild targets (shared heartbeat/TX LED brightness, +# see the heartbeat-pwm-led / lora-tx-pwm-led devicetree aliases consumed by +# helpers/ui/ui_common.c and adapters/board/ZephyrBoard.cpp). +# +# Deliberately NOT in the board *_defconfig: that file is shared by every +# sysbuild image for the board, including mcuboot, whose minimal kernel +# config has no k_sem_give()/k_sem_take() -- CONFIG_PWM=y there links fine for +# the app image but fails mcuboot's link with "undefined reference to +# z_impl_k_sem_give/take" (drivers/pwm/pwm_led_esp32.c uses a semaphore). +# EXTRA_CONF_FILE scopes this to the app ("zephcore") image only. +# +# Build with: +# -DEXTRA_CONF_FILE="boards/common/esp32s3_usb.conf;boards/common/esp32s3_pwm_led.conf" + +CONFIG_PWM=y diff --git a/zephcore/boards/esp32/heltec_wireless_tracker_v2/heltec_wireless_tracker_v2-pinctrl.dtsi b/zephcore/boards/esp32/heltec_wireless_tracker_v2/heltec_wireless_tracker_v2-pinctrl.dtsi index 15c912d..04c3cd3 100644 --- a/zephcore/boards/esp32/heltec_wireless_tracker_v2/heltec_wireless_tracker_v2-pinctrl.dtsi +++ b/zephcore/boards/esp32/heltec_wireless_tracker_v2/heltec_wireless_tracker_v2-pinctrl.dtsi @@ -72,4 +72,11 @@ output-low; }; }; + + ledc0_default: ledc0_default { + group1 { + pinmux = ; + output-enable; + }; + }; }; diff --git a/zephcore/boards/esp32/heltec_wireless_tracker_v2/heltec_wireless_tracker_v2_procpu.dts b/zephcore/boards/esp32/heltec_wireless_tracker_v2/heltec_wireless_tracker_v2_procpu.dts index ef959e5..36bb17a 100644 --- a/zephcore/boards/esp32/heltec_wireless_tracker_v2/heltec_wireless_tracker_v2_procpu.dts +++ b/zephcore/boards/esp32/heltec_wireless_tracker_v2/heltec_wireless_tracker_v2_procpu.dts @@ -30,6 +30,7 @@ #include #include #include +#include #include "heltec_wireless_tracker_v2-pinctrl.dtsi" / { @@ -39,6 +40,8 @@ aliases { led0 = &status_led; lora-tx-led = &status_led; + heartbeat-pwm-led = &pwm_status_led; + lora-tx-pwm-led = &pwm_status_led; uart-0 = &uart0; uart-2 = &uart2; i2c-0 = &i2c0; @@ -69,6 +72,22 @@ }; }; + /* Same GPIO18 net as status_led above, driven through the LEDC PWM + * peripheral instead of a raw GPIO write. Single LED doubling as + * heartbeat, message/shutdown flash and LoRa TX indicator (same + * "Option 1" shared-brightness pattern as T096, see helpers/ui/ui_common.c + * and adapters/board/ZephyrBoard.cpp: heartbeat-pwm-led/lora-tx-pwm-led + * aliases give every one of those events a single 0-100 brightness knob, + * RAM-only, on top of the existing persisted on/off gate. */ + pwm_leds { + compatible = "pwm-leds"; + + pwm_status_led: pwm_led_gpio18 { + label = "Status PWM LED"; + pwms = <&ledc0 0 PWM_MSEC(10) PWM_POLARITY_NORMAL>; + }; + }; + buttons: buttons { compatible = "gpio-keys"; @@ -231,6 +250,19 @@ status = "okay"; }; +&ledc0 { + pinctrl-0 = <&ledc0_default>; + pinctrl-names = "default"; + status = "okay"; + #address-cells = <1>; + #size-cells = <0>; + + channel0@0 { + reg = <0x0>; + timer = <0>; + }; +}; + &i2c0 { status = "okay"; clock-frequency = ;