revision: modify proposed pin HAL.

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2025-09-16 20:33:50 +02:00
parent f55c0b1853
commit dcf53ac04a
38 changed files with 554 additions and 554 deletions
+29 -31
View File
@@ -5,11 +5,9 @@ package ssd1289
import (
"image/color"
"machine"
"time"
"tinygo.org/x/drivers"
"tinygo.org/x/drivers/internal/legacy"
"tinygo.org/x/drivers/internal/pin"
)
type Bus interface {
@@ -17,17 +15,17 @@ type Bus interface {
}
type Device struct {
rs drivers.PinOutput
wr drivers.PinOutput
cs drivers.PinOutput
rst drivers.PinOutput
rs pin.OutputFunc
wr pin.OutputFunc
cs pin.OutputFunc
rst pin.OutputFunc
bus Bus
}
const width = int16(240)
const height = int16(320)
func New(rs machine.Pin, wr machine.Pin, cs machine.Pin, rst machine.Pin, bus Bus) Device {
func New(rs pin.Output, wr pin.Output, cs pin.Output, rst pin.Output, bus Bus) Device {
d := Device{
rs: rs.Set,
wr: wr.Set,
@@ -35,25 +33,25 @@ func New(rs machine.Pin, wr machine.Pin, cs machine.Pin, rst machine.Pin, bus Bu
rst: rst.Set,
bus: bus,
}
legacy.ConfigurePinOut(rs)
legacy.ConfigurePinOut(wr)
legacy.ConfigurePinOut(cs)
legacy.ConfigurePinOut(rst)
pin.ConfigureOutput(rs)
pin.ConfigureOutput(wr)
pin.ConfigureOutput(cs)
pin.ConfigureOutput(rst)
cs.Set(true)
rst.Set(true)
wr.Set(true)
d.cs.High()
d.rst.High()
d.wr.High()
return d
}
func (d *Device) lcdWriteCom(cmd Command) {
d.rs(false)
d.rs.Low()
d.lcdWriteBusInt(uint16(cmd))
}
func (d *Device) lcdWriteDataInt(data uint16) {
d.rs(true)
d.rs.High()
d.lcdWriteBusInt(data)
}
@@ -63,8 +61,8 @@ func (d *Device) lcdWriteComData(cmd Command, data uint16) {
}
func (d *Device) tx() {
d.wr(false)
d.wr(true)
d.wr.Low()
d.wr.High()
}
func (d *Device) lcdWriteBusInt(data uint16) {
@@ -73,13 +71,13 @@ func (d *Device) lcdWriteBusInt(data uint16) {
}
func (d *Device) Configure() {
d.rst(true)
d.rst.High()
time.Sleep(time.Millisecond * 5)
d.rst(false)
d.rst.Low()
time.Sleep(time.Millisecond * 15)
d.rst(true)
d.rst.High()
time.Sleep(time.Millisecond * 15)
d.cs(false)
d.cs.Low()
//Power supply setting
d.lcdWriteComData(POWERCONTROL1, 0xA8A4)
@@ -139,7 +137,7 @@ func (d *Device) Configure() {
//MUX 319 --> Number of lines in display
d.lcdWriteComData(DRIVEROUTPUTCONTROL, 0x233F)
d.cs(true)
d.cs.High()
}
@@ -169,25 +167,25 @@ func (d *Device) SetPixel(x, y int16, c color.RGBA) {
encoded := encodeColor(c)
d.cs(false)
d.cs.Low()
d.setXY(uint16(x), uint16(y), uint16(x), uint16(y))
d.rs(true)
d.rs.High()
d.lcdWriteBusInt(encoded)
d.cs(true)
d.cs.High()
}
func (d *Device) FillRect(x, y, w, h int16, c color.RGBA) {
encoded := encodeColor(c)
d.cs(false)
d.cs.Low()
d.setXY(uint16(x), uint16(y), uint16(x+(w-1)), uint16(y+(h-1)))
d.rs(true)
d.rs.High()
d.bus.Set(encoded)
for i := int64(0); i < int64(w)*int64(h); i++ {
d.tx()
}
d.cs(true)
d.rs(false)
d.cs.High()
d.rs.Low()
}