mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-05 15:33:42 +00:00
ws2812: rename WS2812 to Device
This is more consistent with the other drivers.
This commit is contained in:
+10
-10
@@ -5,31 +5,31 @@ import (
|
||||
"machine"
|
||||
)
|
||||
|
||||
// WS2812 wraps a pin object for an easy driver interface.
|
||||
type WS2812 struct {
|
||||
// Device wraps a pin object for an easy driver interface.
|
||||
type Device struct {
|
||||
Pin machine.GPIO
|
||||
}
|
||||
|
||||
// New returns a new WS2812 driver. It does not touch the pin object: you have
|
||||
// to configure it as an output pin before calling New.
|
||||
func New(pin machine.GPIO) WS2812 {
|
||||
return WS2812{pin}
|
||||
func New(pin machine.GPIO) Device {
|
||||
return Device{pin}
|
||||
}
|
||||
|
||||
// Write the raw bitstring out using the WS2812 protocol.
|
||||
func (p WS2812) Write(buf []byte) {
|
||||
func (d Device) Write(buf []byte) {
|
||||
for _, c := range buf {
|
||||
p.WriteByte(c)
|
||||
d.WriteByte(c)
|
||||
}
|
||||
}
|
||||
|
||||
// Write the given color slice out using the WS2812 protocol.
|
||||
// Colors are specified in RGB format, and are send out in the common GRB
|
||||
// format.
|
||||
func (p WS2812) WriteColors(buf []uint32) {
|
||||
func (d Device) WriteColors(buf []uint32) {
|
||||
for _, color := range buf {
|
||||
p.WriteByte(byte(color >> 8)) // green
|
||||
p.WriteByte(byte(color >> 16)) // red
|
||||
p.WriteByte(byte(color >> 0)) // blue
|
||||
d.WriteByte(byte(color >> 8)) // green
|
||||
d.WriteByte(byte(color >> 16)) // red
|
||||
d.WriteByte(byte(color >> 0)) // blue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
)
|
||||
|
||||
// Send a single byte using the WS2812 protocol.
|
||||
func (p WS2812) WriteByte(c byte) {
|
||||
func (d Device) WriteByte(c byte) {
|
||||
// For the Cortex-M0 at 16MHz
|
||||
portSet, maskSet := p.Pin.PortMaskSet()
|
||||
portClear, maskClear := p.Pin.PortMaskClear()
|
||||
portSet, maskSet := d.Pin.PortMaskSet()
|
||||
portClear, maskClear := d.Pin.PortMaskClear()
|
||||
|
||||
value := uint32(c) << 24
|
||||
arm.AsmFull(`
|
||||
|
||||
Reference in New Issue
Block a user