mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-16 21:03:23 +00:00
st7789: add Bus interface to accomodate both SPI and parallel connections to display
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -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)
|
||||||
|
}
|
||||||
+3
-3
@@ -46,7 +46,7 @@ type Device = DeviceOf[pixel.RGB565BE]
|
|||||||
// DeviceOf is a generic version of Device. It supports multiple different pixel
|
// DeviceOf is a generic version of Device. It supports multiple different pixel
|
||||||
// formats.
|
// formats.
|
||||||
type DeviceOf[T Color] struct {
|
type DeviceOf[T Color] struct {
|
||||||
bus drivers.SPI
|
bus Bus
|
||||||
dcPin pin.OutputFunc
|
dcPin pin.OutputFunc
|
||||||
resetPin pin.OutputFunc
|
resetPin pin.OutputFunc
|
||||||
csPin 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.
|
// 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)
|
return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOf creates a new ST7789 connection with a particular pixel format. The SPI
|
// NewOf creates a new ST7789 connection with a particular pixel format. The SPI
|
||||||
// wire must already be configured.
|
// 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
|
// IMPORTANT: pin configuration should really be done outside of this
|
||||||
// driver, but for backwards compatibility with existing code, we do it
|
// driver, but for backwards compatibility with existing code, we do it
|
||||||
// here.
|
// here.
|
||||||
|
|||||||
Reference in New Issue
Block a user