more drivers are now cross platform

This commit is contained in:
soypat
2025-07-02 22:03:58 -03:00
committed by deadprogram
parent 7d3404f060
commit cd37668592
20 changed files with 481 additions and 325 deletions
+14 -13
View File
@@ -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)
}