mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-13 11:23:40 +00:00
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>
This commit is contained in:
@@ -5,6 +5,7 @@ package ws2812
|
|||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
"machine"
|
"machine"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
pio "github.com/tinygo-org/pio/rp2-pio"
|
pio "github.com/tinygo-org/pio/rp2-pio"
|
||||||
"github.com/tinygo-org/pio/rp2-pio/piolib"
|
"github.com/tinygo-org/pio/rp2-pio/piolib"
|
||||||
@@ -27,6 +28,9 @@ func newWS2812Device(pin machine.Pin) Device {
|
|||||||
writeColorFunc: func(_ Device, buf []color.RGBA, brightness uint8) error {
|
writeColorFunc: func(_ Device, buf []color.RGBA, brightness uint8) error {
|
||||||
for _, c := range buf {
|
for _, c := range buf {
|
||||||
r, g, b := applyBrightness(c, brightness)
|
r, g, b := applyBrightness(c, brightness)
|
||||||
|
for ws.IsQueueFull() {
|
||||||
|
runtime.Gosched()
|
||||||
|
}
|
||||||
ws.PutRGB(r, g, b)
|
ws.PutRGB(r, g, b)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user