File tree Expand file tree Collapse file tree 5 files changed +53
-9
lines changed
Expand file tree Collapse file tree 5 files changed +53
-9
lines changed Original file line number Diff line number Diff line change 11module tinygo.org/x/drivers
22
3-
43go 1.22.1
54
65toolchain go1.23.1
76
8-
97require (
108 github.com/eclipse/paho.mqtt.golang v1.2.0
119 github.com/frankban/quicktest v1.10.2
1210 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
1311 github.com/orsinium-labs/tinymath v1.1.0
1412 github.com/soypat/natiu-mqtt v0.5.1
13+ github.com/tinygo-org/pio v0.3.0
1514 golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d
1615 golang.org/x/net v0.33.0
1716 tinygo.org/x/tinyfont v0.3.0
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ github.com/orsinium-labs/tinymath v1.1.0 h1:KomdsyLHB7vE3f1nRAJF2dyf1m/gnM2HxfTe
1717github.com/orsinium-labs/tinymath v1.1.0 /go.mod h1:WPXX6ei3KSXG7JfA03a+ekCYaY9SWN4I+JRl2p6ck+A =
1818github.com/soypat/natiu-mqtt v0.5.1 h1:rwaDmlvjzD2+3MCOjMZc4QEkDkNwDzbct2TJbpz+TPc =
1919github.com/soypat/natiu-mqtt v0.5.1 /go.mod h1:xEta+cwop9izVCW7xOx2W+ct9PRMqr0gNVkvBPnQTc4 =
20+ github.com/tinygo-org/pio v0.3.0 h1:opEnOtw58KGB4RJD3/n/Rd0/djYGX3DeJiXLI6y/yDI =
21+ github.com/tinygo-org/pio v0.3.0 /go.mod h1:wf6c6lKZp+pQOzKKcpzchmRuhiMc27ABRuo7KVnaMFU =
2022github.com/valyala/fastjson v1.6.3 /go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY =
2123golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d h1:0olWaB5pg3+oychR51GUVCEsGkeCU/2JxjBgIo4f3M0 =
2224golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d /go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c =
Original file line number Diff line number Diff line change 11// Package ws2812 implements a driver for WS2812 and SK6812 RGB LED strips.
2+ //
3+ // On most platforms NewWS2812 uses bit-banging.
4+ // On RP2040/RP2350 it uses PIO for hardware-timed control.
25package ws2812 // import "tinygo.org/x/drivers/ws2812"
36
47//go:generate go run gen-ws2812.go -arch=cortexm 16 48 64 120 125 150 168 200
@@ -24,14 +27,11 @@ func New(pin machine.Pin) Device {
2427 return NewWS2812 (pin )
2528}
2629
27- // New returns a new WS2812(RGB) driver.
28- // It does not touch the pin object: you have
29- // 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 .
3033func NewWS2812 (pin machine.Pin ) Device {
31- return Device {
32- Pin : pin ,
33- writeColorFunc : writeColorsRGB ,
34- }
34+ return newWS2812Device (pin )
3535}
3636
3737// 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