mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-16 21:03:23 +00:00
ws2812: provide proper file-like interface in Device
* Return len and errors in the Write method, to implement io.Writer. * Return a nil error in WriteByte, for compatibility with bufio.
This commit is contained in:
+2
-1
@@ -17,10 +17,11 @@ func New(pin machine.GPIO) Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write the raw bitstring out using the WS2812 protocol.
|
// Write the raw bitstring out using the WS2812 protocol.
|
||||||
func (d Device) Write(buf []byte) {
|
func (d Device) Write(buf []byte) (n int, err error) {
|
||||||
for _, c := range buf {
|
for _, c := range buf {
|
||||||
d.WriteByte(c)
|
d.WriteByte(c)
|
||||||
}
|
}
|
||||||
|
return len(buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the given color slice out using the WS2812 protocol.
|
// Write the given color slice out using the WS2812 protocol.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Send a single byte using the WS2812 protocol.
|
// Send a single byte using the WS2812 protocol.
|
||||||
func (d Device) WriteByte(c byte) {
|
func (d Device) WriteByte(c byte) error {
|
||||||
// For the AVR at 16MHz
|
// For the AVR at 16MHz
|
||||||
portSet, maskSet := d.Pin.PortMaskSet()
|
portSet, maskSet := d.Pin.PortMaskSet()
|
||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
@@ -38,4 +38,5 @@ func (d Device) WriteByte(c byte) {
|
|||||||
"maskClear": maskClear,
|
"maskClear": maskClear,
|
||||||
"portClear": portClear,
|
"portClear": portClear,
|
||||||
})
|
})
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Send a single byte using the WS2812 protocol.
|
// Send a single byte using the WS2812 protocol.
|
||||||
func (d Device) WriteByte(c byte) {
|
func (d Device) WriteByte(c byte) error {
|
||||||
// For the Cortex-M0 at 16MHz
|
// For the Cortex-M0 at 16MHz
|
||||||
portSet, maskSet := d.Pin.PortMaskSet()
|
portSet, maskSet := d.Pin.PortMaskSet()
|
||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
@@ -40,4 +40,5 @@ func (d Device) WriteByte(c byte) {
|
|||||||
"maskClear": maskClear,
|
"maskClear": maskClear,
|
||||||
"portClear": portClear,
|
"portClear": portClear,
|
||||||
})
|
})
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user