Skip to content

Commit 22f2766

Browse files
committed
st7789: add Bus interface to accomodate both SPI and parallel connections to display
Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 6d3907c commit 22f2766

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

st7789/bus.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package st7789
2+
3+
// Bus is the interface that wraps the basic Tx and Transfer methods
4+
// for communication buses like SPI or Parallel.
5+
type Bus interface {
6+
Tx(w, r []byte) error
7+
Transfer(w byte) (byte, error)
8+
}

st7789/st7789.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Device = DeviceOf[pixel.RGB565BE]
4646
// DeviceOf is a generic version of Device. It supports multiple different pixel
4747
// formats.
4848
type DeviceOf[T Color] struct {
49-
bus drivers.SPI
49+
bus Bus
5050
dcPin pin.OutputFunc
5151
resetPin pin.OutputFunc
5252
csPin pin.OutputFunc
@@ -84,13 +84,13 @@ type Config struct {
8484
}
8585

8686
// New creates a new ST7789 connection. The SPI wire must already be configured.
87-
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin pin.Output) Device {
87+
func New(bus Bus, resetPin, dcPin, csPin, blPin pin.Output) Device {
8888
return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin)
8989
}
9090

9191
// NewOf creates a new ST7789 connection with a particular pixel format. The SPI
9292
// wire must already be configured.
93-
func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin pin.Output) DeviceOf[T] {
93+
func NewOf[T Color](bus Bus, resetPin, dcPin, csPin, blPin pin.Output) DeviceOf[T] {
9494
// IMPORTANT: pin configuration should really be done outside of this
9595
// driver, but for backwards compatibility with existing code, we do it
9696
// here.

0 commit comments

Comments
 (0)