refactor: add display.Pin interface and use it everywhere that is easy to do so

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2025-03-16 17:35:09 +01:00
committed by Yurii Soldak
parent d02d21ecea
commit 38c606d813
28 changed files with 164 additions and 236 deletions
+7 -15
View File
@@ -12,6 +12,8 @@ import (
"image/color"
"machine"
"time"
"tinygo.org/x/drivers"
)
type Config struct {
@@ -23,10 +25,10 @@ type Config struct {
type Device struct {
bus *machine.SPI
cs machine.Pin
dc machine.Pin
rst machine.Pin
busy machine.Pin
cs drivers.Pin
dc drivers.Pin
rst drivers.Pin
busy drivers.Pin
buffer []uint8
rotation Rotation
@@ -79,7 +81,7 @@ var partialRefresh = [159]uint8{
}
// New returns a new epd1in54 driver. Pass in a fully configured SPI bus.
func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
return Device{
buffer: make([]uint8, (uint32(Width)*uint32(Height))/8),
bus: bus,
@@ -91,11 +93,6 @@ func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
}
func (d *Device) LDirInit(cfg Config) {
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
d.bus.Configure(machine.SPIConfig{
Frequency: 2000000,
Mode: 0,
@@ -150,11 +147,6 @@ func (d *Device) LDirInit(cfg Config) {
}
func (d *Device) HDirInit(cfg Config) {
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
d.bus.Configure(machine.SPIConfig{
Frequency: 2000000,
Mode: 0,
+7 -11
View File
@@ -6,7 +6,6 @@ package epd2in13 // import "tinygo.org/x/drivers/waveshare-epd/epd2in13"
import (
"errors"
"image/color"
"machine"
"time"
"tinygo.org/x/drivers"
@@ -21,10 +20,10 @@ type Config struct {
type Device struct {
bus drivers.SPI
cs machine.Pin
dc machine.Pin
rst machine.Pin
busy machine.Pin
cs drivers.Pin
dc drivers.Pin
rst drivers.Pin
busy drivers.Pin
logicalWidth int16
width int16
height int16
@@ -52,12 +51,9 @@ var lutPartialUpdate = [30]uint8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus and pins.
// Busy pin should input, the rest should be output.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
return Device{
bus: bus,
cs: csPin,
+7 -11
View File
@@ -6,7 +6,6 @@ package epd2in13x // import "tinygo.org/x/drivers/waveshare-epd/epd2in13x"
import (
"errors"
"image/color"
"machine"
"time"
"tinygo.org/x/drivers"
@@ -20,10 +19,10 @@ type Config struct {
type Device struct {
bus drivers.SPI
cs machine.Pin
dc machine.Pin
rst machine.Pin
busy machine.Pin
cs drivers.Pin
dc drivers.Pin
rst drivers.Pin
busy drivers.Pin
width int16
height int16
buffer [][]uint8
@@ -32,12 +31,9 @@ type Device struct {
type Color uint8
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus and pins.
// Busy pin should input, the rest should be output.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
return Device{
bus: bus,
cs: csPin,
+10 -15
View File
@@ -5,7 +5,6 @@ package epd2in66b
import (
"image/color"
"machine"
"time"
"tinygo.org/x/drivers"
@@ -19,18 +18,18 @@ const (
const Baudrate = 4_000_000 // 4 MHz
type Config struct {
ResetPin machine.Pin
DataPin machine.Pin
ChipSelectPin machine.Pin
BusyPin machine.Pin
ResetPin drivers.Pin
DataPin drivers.Pin
ChipSelectPin drivers.Pin
BusyPin drivers.Pin
}
type Device struct {
bus drivers.SPI
cs machine.Pin
dc machine.Pin
rst machine.Pin
busy machine.Pin
cs drivers.Pin
dc drivers.Pin
rst drivers.Pin
busy drivers.Pin
blackBuffer []byte
redBuffer []byte
@@ -50,18 +49,14 @@ func New(bus drivers.SPI) Device {
}
}
// Configure configures the device and its pins.
// Configure configures the device. Note that pins should already
// be configured. Busy pin should be input, the rest should be output.
func (d *Device) Configure(c Config) error {
d.cs = c.ChipSelectPin
d.dc = c.DataPin
d.rst = c.ResetPin
d.busy = c.BusyPin
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
return nil
}
+7 -11
View File
@@ -13,7 +13,6 @@ package epd2in9 // import "tinygo.org/x/drivers/waveshare-epd/epd2in9"
import (
"image/color"
"machine"
"time"
"tinygo.org/x/drivers"
@@ -28,10 +27,10 @@ type Config struct {
type Device struct {
bus drivers.SPI
cs machine.Pin
dc machine.Pin
rst machine.Pin
busy machine.Pin
cs drivers.Pin
dc drivers.Pin
rst drivers.Pin
busy drivers.Pin
logicalWidth int16
width int16
height int16
@@ -60,12 +59,9 @@ var lutPartialUpdate = [30]uint8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}
// New returns a new epd2in9 driver. Pass in a fully configured SPI bus.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
// New returns a new epd2in9 driver. Pass in a fully configured SPI bus and pins.
// Busy pin should input, the rest should be output.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
return Device{
bus: bus,
cs: csPin,
+7 -11
View File
@@ -10,7 +10,6 @@ package epd4in2
import (
"image/color"
"machine"
"time"
"tinygo.org/x/drivers"
@@ -25,10 +24,10 @@ type Config struct {
type Device struct {
bus drivers.SPI
cs machine.Pin
dc machine.Pin
rst machine.Pin
busy machine.Pin
cs drivers.Pin
dc drivers.Pin
rst drivers.Pin
busy drivers.Pin
logicalWidth int16
width int16
height int16
@@ -39,12 +38,9 @@ type Device struct {
type Rotation uint8
// New returns a new epd4in2 driver. Pass in a fully configured SPI bus.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
// New returns a new epd4in2 driver. Pass in a fully configured SPI bus and pins.
// Busy pin should input, the rest should be output.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
return Device{
bus: bus,
cs: csPin,