From 497f57d0be7988a1dcdc3548e6ed4961e78f672d Mon Sep 17 00:00:00 2001 From: Tomek Date: Sat, 15 Aug 2026 14:17:29 +0200 Subject: [PATCH] ws2812: fix build on ESP32-S3 The ESP32-S3 machine package supports runtime CPU frequency scaling and exposes machine.GetCPUFrequency() instead of the constant-style machine.CPUFrequency(), so the xtensa WS2812 driver failed to build for esp32s3 targets with: ws2812/ws2812_xtensa.go:17:17: undefined: machine.CPUFrequency Route the frequency lookup through a small build-tagged cpuFrequency() helper: xtensa chips with the constant-style API keep using machine.CPUFrequency(), while the ESP32-S3 uses GetCPUFrequency(). Co-Authored-By: Claude Fable 5 --- ws2812/ws2812_freq_esp32s3.go | 13 +++++++++++++ ws2812/ws2812_freq_xtensa.go | 11 +++++++++++ ws2812/ws2812_xtensa.go | 3 +-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 ws2812/ws2812_freq_esp32s3.go create mode 100644 ws2812/ws2812_freq_xtensa.go diff --git a/ws2812/ws2812_freq_esp32s3.go b/ws2812/ws2812_freq_esp32s3.go new file mode 100644 index 000000000..b3c6ea724 --- /dev/null +++ b/ws2812/ws2812_freq_esp32s3.go @@ -0,0 +1,13 @@ +//go:build esp32s3 + +package ws2812 + +import "machine" + +// cpuFrequency returns the current CPU frequency in Hz on the ESP32-S3, which +// supports runtime frequency scaling and exposes GetCPUFrequency() instead of +// the constant-style CPUFrequency(). +func cpuFrequency() uint32 { + f, _ := machine.GetCPUFrequency() + return f +} diff --git a/ws2812/ws2812_freq_xtensa.go b/ws2812/ws2812_freq_xtensa.go new file mode 100644 index 000000000..5d906600e --- /dev/null +++ b/ws2812/ws2812_freq_xtensa.go @@ -0,0 +1,11 @@ +//go:build xtensa && !esp32s3 + +package ws2812 + +import "machine" + +// cpuFrequency returns the current CPU frequency in Hz on Xtensa targets that +// expose the constant-style machine.CPUFrequency() (e.g. the original ESP32). +func cpuFrequency() uint32 { + return machine.CPUFrequency() +} diff --git a/ws2812/ws2812_xtensa.go b/ws2812/ws2812_xtensa.go index a1af02348..a0c89e504 100644 --- a/ws2812/ws2812_xtensa.go +++ b/ws2812/ws2812_xtensa.go @@ -4,7 +4,6 @@ package ws2812 import ( "device" - "machine" "runtime/interrupt" "unsafe" ) @@ -14,7 +13,7 @@ func (d Device) WriteByte(c byte) error { portClear, maskClear := d.Pin.PortMaskClear() mask := interrupt.Disable() - switch machine.CPUFrequency() { + switch cpuFrequency() { case 160e6: // 160MHz // See: // https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/