ws2812: use PIO on RP2040/RP2350 transparently via build tags#851
ws2812: use PIO on RP2040/RP2350 transparently via build tags#851deadprogram merged 1 commit intotinygo-org:devfrom
Conversation
7a3e45a to
be8b579
Compare
be8b579 to
8da19a9
Compare
|
I was not expecting you to add a new type to implement this, @gandarez Seems to me that you could wrap the existing |
8da19a9 to
ddf7d54
Compare
|
@deadprogram is it ok? |
|
Sorry, but that was not what I had in mind @gandarez I do not see any reason to add a new
Hopefully that explains a bit better what I had in mind here. |
90a5a91 to
4b3ba69
Compare
|
@deadprogram I believe this is what you're looking for 544cd43. Do you have any other device to try it out? I also added brightness control in this commit 4b3ba69 |
I think that is a lot more like it.
That might be better to add in a separate PR, no? |
4b3ba69 to
90315ad
Compare
Integrate PIO support directly into the existing Device. NewWS2812() now uses PIO for hardware-timed control on RP2040/RP2350 and falls back to bit-banging on other platforms. No changes to the exported API surface.
90315ad to
dbc032a
Compare
|
@deadprogram PR is ready |
|
Confirmed that it still works on |
Summary
NewWS2812()now uses PIO (viatinygo-org/pio) for hardware-timed control instead of bit-bangingMotivation
The existing
ws2812driver uses CPU-timed bit-banging assembly tuned for Cortex-M0+. The RP2350's Cortex-M33 has a write buffer and different pipeline that breaks the nanosecond-level GPIO timing. The Arduino Adafruit_NeoPixel library works on the same hardware because it uses PIO.Implementation
ws2812_rp2_pio.go(rp2040 || rp2350):newWS2812Device()claims a PIO0 state machine and setswriteColorFuncto a PIO-based closure. Falls back to bit-bang on failure.ws2812_init_other.go(!rp2040 && !rp2350):newWS2812Device()returns the standard bit-bang device.NewWS2812()now delegates tonewWS2812Device().Test plan
tinygo flash -target=pico2 ./examples/ws2812/— verify LEDs work on RP2350 via PIOtinygo build -target=circuitplay-express ./examples/ws2812/— verify bit-bang fallback compilestinygo build -target=arduino ./examples/ws2812/— verify AVR still workstinygo build -target=m5stamp-c3 ./examples/ws2812/— verify Xtensa/RISC-V still works