mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-16 12:53:23 +00:00
ssd1xxx: break dependency from machine package (#812)
* ssd1xxx: break dependency from machine package * fix ssd1289 example * simplify
This commit is contained in:
+11
-20
@@ -1,15 +1,19 @@
|
||||
package ssd1289
|
||||
|
||||
import "machine"
|
||||
import (
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type pinBus struct {
|
||||
pins [16]machine.Pin
|
||||
pins [16]pin.Output
|
||||
}
|
||||
|
||||
func NewPinBus(pins [16]machine.Pin) pinBus {
|
||||
func NewPinBus(pins [16]pin.Output) pinBus {
|
||||
|
||||
// configure GPIO pins (on baremetal targets only, for backwards compatibility)
|
||||
for i := 0; i < 16; i++ {
|
||||
pins[i].Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
legacy.ConfigurePinOut(pins[i])
|
||||
}
|
||||
|
||||
return pinBus{
|
||||
@@ -18,20 +22,7 @@ func NewPinBus(pins [16]machine.Pin) pinBus {
|
||||
}
|
||||
|
||||
func (b pinBus) Set(data uint16) {
|
||||
b.pins[15].Set((data & (1 << 15)) != 0)
|
||||
b.pins[14].Set((data & (1 << 14)) != 0)
|
||||
b.pins[13].Set((data & (1 << 13)) != 0)
|
||||
b.pins[12].Set((data & (1 << 12)) != 0)
|
||||
b.pins[11].Set((data & (1 << 11)) != 0)
|
||||
b.pins[10].Set((data & (1 << 10)) != 0)
|
||||
b.pins[9].Set((data & (1 << 9)) != 0)
|
||||
b.pins[8].Set((data & (1 << 8)) != 0)
|
||||
b.pins[7].Set((data & (1 << 7)) != 0)
|
||||
b.pins[6].Set((data & (1 << 6)) != 0)
|
||||
b.pins[5].Set((data & (1 << 5)) != 0)
|
||||
b.pins[4].Set((data & (1 << 4)) != 0)
|
||||
b.pins[3].Set((data & (1 << 3)) != 0)
|
||||
b.pins[2].Set((data & (1 << 2)) != 0)
|
||||
b.pins[1].Set((data & (1 << 1)) != 0)
|
||||
b.pins[0].Set((data & (1 << 0)) != 0)
|
||||
for i := 15; i >= 0; i-- {
|
||||
b.pins[i].Set((data & (1 << i)) != 0)
|
||||
}
|
||||
}
|
||||
|
||||
+21
-18
@@ -5,8 +5,10 @@ package ssd1289
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Bus interface {
|
||||
@@ -14,33 +16,34 @@ type Bus interface {
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
rs machine.Pin
|
||||
wr machine.Pin
|
||||
cs machine.Pin
|
||||
rst machine.Pin
|
||||
rs pin.OutputFunc
|
||||
wr pin.OutputFunc
|
||||
cs pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
bus Bus
|
||||
}
|
||||
|
||||
const width = int16(240)
|
||||
const height = int16(320)
|
||||
|
||||
func New(rs machine.Pin, wr machine.Pin, cs machine.Pin, rst machine.Pin, bus Bus) Device {
|
||||
d := Device{
|
||||
rs: rs,
|
||||
wr: wr,
|
||||
cs: cs,
|
||||
rst: rst,
|
||||
func New(rs, wr, cs, rst pin.Output, bus Bus) *Device {
|
||||
d := &Device{
|
||||
rs: rs.Set,
|
||||
wr: wr.Set,
|
||||
cs: cs.Set,
|
||||
rst: rst.Set,
|
||||
bus: bus,
|
||||
}
|
||||
|
||||
rs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
wr.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
// configure GPIO pins (only on baremetal targets, for backwards compatibility)
|
||||
legacy.ConfigurePinOut(rs)
|
||||
legacy.ConfigurePinOut(wr)
|
||||
legacy.ConfigurePinOut(cs)
|
||||
legacy.ConfigurePinOut(rst)
|
||||
|
||||
cs.High()
|
||||
rst.High()
|
||||
wr.High()
|
||||
d.cs.High()
|
||||
d.rst.High()
|
||||
d.wr.High()
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user