mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-11 18:33:43 +00:00
more drivers are now cross platform
This commit is contained in:
+14
-13
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
)
|
||||
|
||||
type Model uint8
|
||||
@@ -19,9 +20,9 @@ type Rotation uint8
|
||||
// Device wraps an SPI connection.
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
dcPin machine.Pin
|
||||
resetPin machine.Pin
|
||||
csPin machine.Pin
|
||||
dcPin drivers.PinOutput
|
||||
resetPin drivers.PinOutput
|
||||
csPin drivers.PinOutput
|
||||
width int16
|
||||
height int16
|
||||
batchLength int16
|
||||
@@ -37,14 +38,14 @@ type Config struct {
|
||||
|
||||
// New creates a new SSD1331 connection. The SPI wire must already be configured.
|
||||
func New(bus drivers.SPI, resetPin, dcPin, csPin machine.Pin) Device {
|
||||
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(resetPin)
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
return Device{
|
||||
bus: bus,
|
||||
dcPin: dcPin,
|
||||
resetPin: resetPin,
|
||||
csPin: csPin,
|
||||
dcPin: dcPin.Set,
|
||||
resetPin: resetPin.Set,
|
||||
csPin: csPin.Set,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,11 +70,11 @@ func (d *Device) Configure(cfg Config) {
|
||||
d.batchData = make([]uint8, d.batchLength*2)
|
||||
|
||||
// reset the device
|
||||
d.resetPin.High()
|
||||
d.resetPin(true)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.resetPin.Low()
|
||||
d.resetPin(false)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.resetPin.High()
|
||||
d.resetPin(true)
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
// Initialization
|
||||
@@ -251,7 +252,7 @@ func (d *Device) Data(data uint8) {
|
||||
|
||||
// Tx sends data to the display
|
||||
func (d *Device) Tx(data []byte, isCommand bool) {
|
||||
d.dcPin.Set(!isCommand)
|
||||
d.dcPin(!isCommand)
|
||||
d.bus.Tx(data, nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user