finish rewrites!

This commit is contained in:
soypat
2025-07-08 21:11:46 -03:00
parent 8f0fbaa945
commit 3681452097
16 changed files with 283 additions and 727 deletions
+17 -40
View File
@@ -5,7 +5,6 @@ package epd2in66b
import (
"image/color"
"machine"
"time"
"tinygo.org/x/drivers"
@@ -18,19 +17,12 @@ const (
const Baudrate = 4_000_000 // 4 MHz
type Config struct {
ResetPin machine.Pin
DataPin machine.Pin
ChipSelectPin machine.Pin
BusyPin machine.Pin
}
type Device struct {
bus drivers.SPI
cs machine.Pin
dc machine.Pin
rst machine.Pin
busy machine.Pin
cs drivers.PinOutput
dc drivers.PinOutput
rst drivers.PinOutput
busy drivers.PinInput
blackBuffer []byte
redBuffer []byte
@@ -50,21 +42,6 @@ func New(bus drivers.SPI) Device {
}
}
// Configure configures the device and its pins.
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
}
func (d *Device) Size() (x, y int16) {
return displayWidth, displayHeight
}
@@ -199,11 +176,11 @@ func (d *Device) setCursor(x, y uint16) error {
}
func (d *Device) hwReset() {
d.rst.High()
d.rst(true)
time.Sleep(50 * time.Millisecond)
d.rst.Low()
d.rst(false)
time.Sleep(2 * time.Millisecond)
d.rst.High()
d.rst(true)
time.Sleep(50 * time.Millisecond)
}
@@ -229,7 +206,7 @@ func (d *Device) WaitUntilIdle() {
// give it some time to get busy
time.Sleep(50 * time.Millisecond)
for d.busy.Get() { // high = busy
for d.busy() { // high = busy
time.Sleep(10 * time.Millisecond)
}
@@ -255,26 +232,26 @@ func (d *Device) sendCommandSequence(seq []byte) error {
}
func (d *Device) sendCommandByte(b byte) error {
d.dc.Low()
d.cs.Low()
d.dc(false)
d.cs(false)
_, err := d.bus.Transfer(b)
d.cs.High()
d.cs(true)
return err
}
func (d *Device) sendDataByte(b byte) error {
d.dc.High()
d.cs.Low()
d.dc(true)
d.cs(false)
_, err := d.bus.Transfer(b)
d.cs.High()
d.cs(true)
return err
}
func (d *Device) sendData(b []byte) error {
d.dc.High()
d.cs.Low()
d.dc(true)
d.cs(false)
err := d.bus.Tx(b, nil)
d.cs.High()
d.cs(true)
return err
}