mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-09 09:23:39 +00:00
0d692cfd0a
* Return len and errors in the Write method, to implement io.Writer. * Return a nil error in WriteByte, for compatibility with bufio.
45 lines
810 B
Go
45 lines
810 B
Go
// +build nrf51
|
|
|
|
package ws2812
|
|
|
|
// This file implements the WS2812 protocol for 16MHz Cortex-M0
|
|
// microcontrollers.
|
|
|
|
import (
|
|
"device/arm"
|
|
)
|
|
|
|
// Send a single byte using the WS2812 protocol.
|
|
func (d Device) WriteByte(c byte) error {
|
|
// For the Cortex-M0 at 16MHz
|
|
portSet, maskSet := d.Pin.PortMaskSet()
|
|
portClear, maskClear := d.Pin.PortMaskClear()
|
|
|
|
value := uint32(c) << 24
|
|
arm.AsmFull(`
|
|
send_bit:
|
|
str {maskSet}, {portSet}
|
|
lsls {value}, #1
|
|
bcs.n skip_store
|
|
str {maskClear}, {portClear}
|
|
skip_store:
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
str {maskClear}, {portClear}
|
|
subs {i}, #1
|
|
bne.n send_bit
|
|
`, map[string]interface{}{
|
|
"value": value,
|
|
"i": 8,
|
|
"maskSet": maskSet,
|
|
"portSet": portSet,
|
|
"maskClear": maskClear,
|
|
"portClear": portClear,
|
|
})
|
|
return nil
|
|
}
|