finish rewrites!

This commit is contained in:
soypat
2025-07-08 21:11:46 -03:00
committed by deadprogram
parent cd37668592
commit 67b669f192
16 changed files with 283 additions and 727 deletions
+24 -24
View File
@@ -8,10 +8,10 @@ package uc8151 // import "tinygo.org/x/drivers/uc8151"
import (
"errors"
"image/color"
"machine"
"time"
"tinygo.org/x/drivers"
"tinygo.org/x/drivers/internal/legacy"
"tinygo.org/x/drivers/pixel"
)
@@ -31,10 +31,10 @@ type Config struct {
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
width int16
height int16
buffer []uint8
@@ -49,17 +49,17 @@ type Device struct {
type Speed uint8
// New returns a new uc8151 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})
func New(bus drivers.SPI, csPin, dcPin, rstPin legacy.PinOutput, busyPin legacy.PinInput) Device {
legacy.ConfigurePinOut(csPin)
legacy.ConfigurePinOut(dcPin)
legacy.ConfigurePinOut(rstPin)
legacy.ConfigurePinInput(busyPin)
return Device{
bus: bus,
cs: csPin,
dc: dcPin,
rst: rstPin,
busy: busyPin,
cs: csPin.Set,
dc: dcPin.Set,
rst: rstPin.Set,
busy: busyPin.Get,
}
}
@@ -133,9 +133,9 @@ func (d *Device) Configure(cfg Config) {
// Reset resets the device
func (d *Device) Reset() {
d.rst.Low()
d.rst(false)
time.Sleep(10 * time.Millisecond)
d.rst.High()
d.rst(true)
time.Sleep(10 * time.Millisecond)
d.WaitUntilIdle()
}
@@ -152,18 +152,18 @@ func (d *Device) PowerOn() {
// SendCommand sends a command to the display
func (d *Device) SendCommand(command uint8) {
d.dc.Low()
d.cs.Low()
d.dc(false)
d.cs(false)
d.bus.Transfer(command)
d.cs.High()
d.cs(true)
}
// SendData sends a data byte to the display
func (d *Device) SendData(data ...uint8) {
d.dc.High()
d.cs.Low()
d.dc(true)
d.cs(false)
d.bus.Tx(data, nil)
d.cs.High()
d.cs(true)
}
// SetPixel modifies the internal buffer in a single pixel.
@@ -313,14 +313,14 @@ func (d *Device) ClearDisplay() {
// WaitUntilIdle waits until the display is ready
func (d *Device) WaitUntilIdle() {
for !d.busy.Get() {
for !d.busy() {
time.Sleep(10 * time.Millisecond)
}
}
// IsBusy returns the busy status of the display
func (d *Device) IsBusy() bool {
return d.busy.Get()
return d.busy()
}
// ClearBuffer sets the buffer to 0xFF (white)