mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-12 02:43:42 +00:00
more drivers are now cross platform
This commit is contained in:
+33
-26
@@ -6,10 +6,10 @@ package ssd1351 // import "tinygo.org/x/drivers/ssd1351"
|
||||
import (
|
||||
"errors"
|
||||
"image/color"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -20,11 +20,12 @@ var (
|
||||
// Device wraps an SPI connection.
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
dcPin machine.Pin
|
||||
resetPin machine.Pin
|
||||
csPin machine.Pin
|
||||
enPin machine.Pin
|
||||
rwPin machine.Pin
|
||||
dcPin drivers.PinOutput
|
||||
resetPin drivers.PinOutput
|
||||
csPin drivers.PinOutput
|
||||
enPin drivers.PinOutput
|
||||
rwPin drivers.PinOutput
|
||||
config func()
|
||||
width int16
|
||||
height int16
|
||||
rowOffset int16
|
||||
@@ -41,19 +42,29 @@ type Config struct {
|
||||
}
|
||||
|
||||
// New creates a new SSD1351 connection. The SPI wire must already be configured.
|
||||
func New(bus drivers.SPI, resetPin, dcPin, csPin, enPin, rwPin machine.Pin) Device {
|
||||
func New(bus drivers.SPI, resetPin, dcPin, csPin, enPin, rwPin legacy.PinOutput) Device {
|
||||
return Device{
|
||||
bus: bus,
|
||||
dcPin: dcPin,
|
||||
resetPin: resetPin,
|
||||
csPin: csPin,
|
||||
enPin: enPin,
|
||||
rwPin: rwPin,
|
||||
dcPin: dcPin.Set,
|
||||
resetPin: resetPin.Set,
|
||||
csPin: csPin.Set,
|
||||
enPin: enPin.Set,
|
||||
rwPin: rwPin.Set,
|
||||
config: func() {
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(resetPin)
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(enPin)
|
||||
legacy.ConfigurePinOut(rwPin)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Configure initializes the display with default configuration
|
||||
func (d *Device) Configure(cfg Config) {
|
||||
if d.config == nil {
|
||||
panic(legacy.ErrConfigBeforeInstantiated)
|
||||
}
|
||||
if cfg.Width == 0 {
|
||||
cfg.Width = 128
|
||||
}
|
||||
@@ -73,23 +84,19 @@ func (d *Device) Configure(cfg Config) {
|
||||
}
|
||||
|
||||
// configure GPIO pins
|
||||
d.dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.enPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.rwPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.config()
|
||||
|
||||
// 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)
|
||||
|
||||
d.rwPin.Low()
|
||||
d.dcPin.Low()
|
||||
d.enPin.High()
|
||||
d.rwPin(false)
|
||||
d.dcPin(false)
|
||||
d.enPin(true)
|
||||
|
||||
// Initialization
|
||||
d.Command(SET_COMMAND_LOCK)
|
||||
@@ -278,10 +285,10 @@ 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.csPin.Low()
|
||||
d.dcPin(!isCommand)
|
||||
d.csPin(false)
|
||||
d.bus.Tx(data, nil)
|
||||
d.csPin.High()
|
||||
d.csPin(true)
|
||||
}
|
||||
|
||||
// Size returns the current size of the display
|
||||
|
||||
Reference in New Issue
Block a user