mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-13 11:23:40 +00:00
microbitmatrix: fix for dev branch / volatile package/API (#63)
* microbitmatrix: fix for dev branch / volatile package/API
This commit is contained in:
committed by
Ron Evans
parent
848385d625
commit
2c0bde0dad
@@ -4,7 +4,6 @@
|
|||||||
package microbitmatrix
|
package microbitmatrix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"device/nrf"
|
|
||||||
"image/color"
|
"image/color"
|
||||||
"machine"
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
@@ -46,6 +45,7 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
|
pin [12]*machine.GPIO
|
||||||
buffer [3][9]bool
|
buffer [3][9]bool
|
||||||
rotation uint8
|
rotation uint8
|
||||||
}
|
}
|
||||||
@@ -59,11 +59,10 @@ func New() Device {
|
|||||||
func (d *Device) Configure(cfg Config) {
|
func (d *Device) Configure(cfg Config) {
|
||||||
d.SetRotation(cfg.Rotation)
|
d.SetRotation(cfg.Rotation)
|
||||||
|
|
||||||
set := 0
|
for i := uint8(machine.LED_COL_1); i <= machine.LED_ROW_3; i++ {
|
||||||
for i := machine.LED_COL_1; i <= machine.LED_ROW_3; i++ {
|
d.pin[i-machine.LED_COL_1] = &machine.GPIO{i}
|
||||||
set |= 1 << uint8(i)
|
d.pin[i-machine.LED_COL_1].Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
||||||
}
|
}
|
||||||
nrf.GPIO.DIRSET = nrf.RegValue(set)
|
|
||||||
d.ClearDisplay()
|
d.ClearDisplay()
|
||||||
d.DisableAll()
|
d.DisableAll()
|
||||||
}
|
}
|
||||||
@@ -97,19 +96,14 @@ func (d *Device) GetPixel(x int16, y int16) bool {
|
|||||||
func (d *Device) Display() error {
|
func (d *Device) Display() error {
|
||||||
for row := 0; row < 3; row++ {
|
for row := 0; row < 3; row++ {
|
||||||
d.DisableAll()
|
d.DisableAll()
|
||||||
set := 0
|
d.pin[9+row].High()
|
||||||
set |= 1 << uint8(machine.LED_ROW_1+row)
|
|
||||||
nrf.GPIO.OUTSET = nrf.RegValue(set)
|
|
||||||
|
|
||||||
set = 0
|
|
||||||
for col := 0; col < 9; col++ {
|
for col := 0; col < 9; col++ {
|
||||||
|
|
||||||
if d.buffer[row][col] {
|
if d.buffer[row][col] {
|
||||||
set |= 1 << uint8(machine.LED_COL_1+col)
|
d.pin[col].Low()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
nrf.GPIO.OUTCLR = nrf.RegValue(set)
|
|
||||||
time.Sleep(time.Millisecond * 2)
|
time.Sleep(time.Millisecond * 2)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -126,29 +120,22 @@ func (d *Device) ClearDisplay() {
|
|||||||
|
|
||||||
// DisableAll disables all the LEDs without modifying the buffer
|
// DisableAll disables all the LEDs without modifying the buffer
|
||||||
func (d *Device) DisableAll() {
|
func (d *Device) DisableAll() {
|
||||||
set := 0
|
|
||||||
for i := machine.LED_COL_1; i <= machine.LED_COL_9; i++ {
|
for i := machine.LED_COL_1; i <= machine.LED_COL_9; i++ {
|
||||||
set |= 1 << uint8(i)
|
d.pin[i-machine.LED_COL_1].High()
|
||||||
|
}
|
||||||
|
for i := machine.LED_ROW_1; i <= machine.LED_ROW_3; i++ {
|
||||||
|
d.pin[i-machine.LED_COL_1].Low()
|
||||||
}
|
}
|
||||||
nrf.GPIO.OUTSET = nrf.RegValue(set)
|
|
||||||
nrf.GPIO.OUTCLR = (1 << machine.LED_ROW_1) | (1 << machine.LED_ROW_2) | (1 << machine.LED_ROW_3)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnableAll enables all the LEDs without modifying the buffer
|
// EnableAll enables all the LEDs without modifying the buffer
|
||||||
func EnableAll() error {
|
func (d *Device) EnableAll() {
|
||||||
set := 0
|
|
||||||
for i := machine.LED_ROW_1; i <= machine.LED_ROW_3; i++ {
|
|
||||||
set |= 1 << uint8(i)
|
|
||||||
}
|
|
||||||
nrf.GPIO.OUTSET = nrf.RegValue(set)
|
|
||||||
|
|
||||||
set = 0
|
|
||||||
for i := machine.LED_COL_1; i <= machine.LED_COL_9; i++ {
|
for i := machine.LED_COL_1; i <= machine.LED_COL_9; i++ {
|
||||||
set |= 1 << uint8(i)
|
d.pin[i-machine.LED_COL_1].Low()
|
||||||
|
}
|
||||||
|
for i := machine.LED_ROW_1; i <= machine.LED_ROW_3; i++ {
|
||||||
|
d.pin[i-machine.LED_COL_1].High()
|
||||||
}
|
}
|
||||||
nrf.GPIO.OUTCLR = nrf.RegValue(set)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size returns the current size of the display.
|
// Size returns the current size of the display.
|
||||||
|
|||||||
Reference in New Issue
Block a user