Skip to content

Commit dc6edbb

Browse files
committed
ws2812: fix PIO TX FIFO overflow on rp2040/rp2350 dropping LEDs
PutRGB calls TxPut which is non-blocking and silently discards data when the TX FIFO is full. Wait for FIFO space before each PutRGB using runtime.Gosched() to yield cooperatively, matching the pattern used by piolib.WriteRaw. Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 1d695a2 commit dc6edbb

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

ws2812/ws2812_rp2_pio.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package ws2812
55
import (
66
"image/color"
77
"machine"
8+
"runtime"
89

910
pio "github.com/tinygo-org/pio/rp2-pio"
1011
"github.com/tinygo-org/pio/rp2-pio/piolib"
@@ -27,6 +28,9 @@ func newWS2812Device(pin machine.Pin) Device {
2728
writeColorFunc: func(_ Device, buf []color.RGBA, brightness uint8) error {
2829
for _, c := range buf {
2930
r, g, b := applyBrightness(c, brightness)
31+
for ws.IsQueueFull() {
32+
runtime.Gosched()
33+
}
3034
ws.PutRGB(r, g, b)
3135
}
3236
return nil

0 commit comments

Comments
 (0)