From 51561d4eabce53c99a4080c193a8d116e9c1b4a1 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Sun, 14 Dec 2025 11:19:41 +0100 Subject: [PATCH] st7789: add Bus interface to accomodate both SPI and parallel connections to display Signed-off-by: deadprogram --- st7789/bus.go | 8 ++++++++ st7789/st7789.go | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 st7789/bus.go diff --git a/st7789/bus.go b/st7789/bus.go new file mode 100644 index 0000000..44a2ea8 --- /dev/null +++ b/st7789/bus.go @@ -0,0 +1,8 @@ +package st7789 + +// Bus is the interface that wraps the basic Tx and Transfer methods +// for communication buses like SPI or Parallel. +type Bus interface { + Tx(w, r []byte) error + Transfer(w byte) (byte, error) +} diff --git a/st7789/st7789.go b/st7789/st7789.go index 561a559..838f284 100644 --- a/st7789/st7789.go +++ b/st7789/st7789.go @@ -46,7 +46,7 @@ type Device = DeviceOf[pixel.RGB565BE] // DeviceOf is a generic version of Device. It supports multiple different pixel // formats. type DeviceOf[T Color] struct { - bus drivers.SPI + bus Bus dcPin pin.OutputFunc resetPin pin.OutputFunc csPin pin.OutputFunc @@ -84,13 +84,13 @@ type Config struct { } // New creates a new ST7789 connection. The SPI wire must already be configured. -func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin pin.Output) Device { +func New(bus Bus, resetPin, dcPin, csPin, blPin pin.Output) Device { return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin) } // NewOf creates a new ST7789 connection with a particular pixel format. The SPI // wire must already be configured. -func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin pin.Output) DeviceOf[T] { +func NewOf[T Color](bus Bus, resetPin, dcPin, csPin, blPin pin.Output) DeviceOf[T] { // IMPORTANT: pin configuration should really be done outside of this // driver, but for backwards compatibility with existing code, we do it // here.