Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ws2812/ws2812_freq_esp32s3.go
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 11 additions & 0 deletions ws2812/ws2812_freq_xtensa.go
Original file line number Diff line number Diff line change
@@ -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()
}
3 changes: 1 addition & 2 deletions ws2812/ws2812_xtensa.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package ws2812

import (
"device"
"machine"
"runtime/interrupt"
"unsafe"
)
Expand All @@ -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/
Expand Down