Disable interrupts before sending ws2812 data

This commit is contained in:
Daniel Bridges
2021-05-30 12:48:08 -07:00
committed by Ron Evans
parent 5645eb3f91
commit 7b565e8cb0
6 changed files with 21 additions and 0 deletions
+4
View File
@@ -7,6 +7,7 @@ package ws2812
import (
"device/avr"
"machine"
"runtime/interrupt"
)
// Send a single byte using the WS2812 protocol.
@@ -17,6 +18,7 @@ func (d Device) WriteByte(c byte) error {
// Probably this is about pointer registers, which are very limited on AVR.
port, maskSet := d.Pin.PortMaskSet()
_, maskClear := d.Pin.PortMaskClear()
mask := interrupt.Disable()
switch machine.CPUFrequency() {
case 16e6: // 16MHz
@@ -51,8 +53,10 @@ func (d Device) WriteByte(c byte) error {
"maskClear": maskClear,
"portClear": port,
})
interrupt.Restore(mask)
return nil
default:
interrupt.Restore(mask)
return errUnknownClockSpeed
}
}