File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -93,7 +93,6 @@ tinygo build -size short -o ./build/test.bin -target=m5stamp-c3 ./examp
9393tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/is31fl3731/main.go
9494tinygo build -size short -o ./build/test.hex -target=arduino ./examples/ws2812
9595tinygo build -size short -o ./build/test.hex -target=digispark ./examples/ws2812
96- tinygo build -size short -o ./build/test.bin -target=pico2 ./examples/ws2812-strip
9796tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bme280/main.go
9897tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/microphone/main.go
9998tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/buzzer/main.go
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11// Package ws2812 implements a driver for WS2812 and SK6812 RGB LED strips.
22//
3- // For low-level control, use Device with NewWS2812 or NewSK6812.
4- // For a higher-level API with pixel buffering and brightness control,
5- // use Strip with NewStrip. On RP2040/RP2350, Strip uses PIO for
6- // hardware-timed control; on other platforms it falls back to bit-banging.
3+ // On RP2040/RP2350, NewWS2812 uses PIO for hardware-timed control.
4+ // On other platforms it uses bit-banging.
75package ws2812 // import "tinygo.org/x/drivers/ws2812"
86
97//go:generate go run gen-ws2812.go -arch=cortexm 16 48 64 120 125 150 168 200
@@ -29,14 +27,11 @@ func New(pin machine.Pin) Device {
2927 return NewWS2812 (pin )
3028}
3129
32- // New returns a new WS2812(RGB) driver.
33- // It does not touch the pin object: you have
34- // to configure it as an output pin before calling New .
30+ // NewWS2812 returns a new WS2812(RGB) driver.
31+ // On RP2040/RP2350, it uses PIO for hardware-timed control.
32+ // On other platforms, you must configure the pin as output before calling this .
3533func NewWS2812 (pin machine.Pin ) Device {
36- return Device {
37- Pin : pin ,
38- writeColorFunc : writeColorsRGB ,
39- }
34+ return newWS2812Device (pin )
4035}
4136
4237// New returns a new SK6812(RGBA) driver.
Original file line number Diff line number Diff line change 1+ //go:build !rp2040 && !rp2350
2+
3+ package ws2812
4+
5+ import "machine"
6+
7+ // newWS2812Device creates a WS2812 device using the bit-bang driver.
8+ func newWS2812Device (pin machine.Pin ) Device {
9+ return Device {Pin : pin , writeColorFunc : writeColorsRGB }
10+ }
Original file line number Diff line number Diff line change 1+ //go:build rp2040 || rp2350
2+
3+ package ws2812
4+
5+ import (
6+ "image/color"
7+ "machine"
8+
9+ pio "github.com/tinygo-org/pio/rp2-pio"
10+ "github.com/tinygo-org/pio/rp2-pio/piolib"
11+ )
12+
13+ // newWS2812Device creates a WS2812 device using PIO for hardware-timed control.
14+ // If PIO initialization fails, it falls back to the bit-bang driver.
15+ func newWS2812Device (pin machine.Pin ) Device {
16+ sm , err := pio .PIO0 .ClaimStateMachine ()
17+ if err != nil {
18+ return Device {Pin : pin , writeColorFunc : writeColorsRGB }
19+ }
20+ ws , err := piolib .NewWS2812B (sm , pin )
21+ if err != nil {
22+ return Device {Pin : pin , writeColorFunc : writeColorsRGB }
23+ }
24+ return Device {
25+ Pin : pin ,
26+ writeColorFunc : func (_ Device , buf []color.RGBA ) error {
27+ for _ , c := range buf {
28+ ws .PutRGB (c .R , c .G , c .B )
29+ }
30+ return nil
31+ },
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments