mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-11 18:33:43 +00:00
legacy.PinOutput->pin.Output and add High+Low methods on drivers.PinOutput and use them in drivers
This commit is contained in:
committed by
deadprogram
parent
2e007a6de7
commit
8ac285e821
+15
-14
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
"tinygo.org/x/drivers/pixel"
|
||||
)
|
||||
|
||||
@@ -83,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 legacy.PinOutput) Device {
|
||||
func New(bus drivers.SPI, 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 legacy.PinOutput) DeviceOf[T] {
|
||||
func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin pin.Output) DeviceOf[T] {
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(resetPin)
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
@@ -143,11 +144,11 @@ func (d *DeviceOf[T]) Configure(cfg Config) {
|
||||
d.batchLength += d.batchLength & 1
|
||||
|
||||
// Reset the device
|
||||
d.resetPin(true)
|
||||
d.resetPin.High()
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
d.resetPin(false)
|
||||
d.resetPin.Low()
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
d.resetPin(true)
|
||||
d.resetPin.High()
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
// Common initialization
|
||||
@@ -213,7 +214,7 @@ func (d *DeviceOf[T]) Configure(cfg Config) {
|
||||
time.Sleep(10 * time.Millisecond) //
|
||||
|
||||
d.endWrite()
|
||||
d.blPin(true) // Backlight ON
|
||||
d.blPin.High() // Backlight ON
|
||||
}
|
||||
|
||||
// Send a command with data to the display. It does not change the chip select
|
||||
@@ -221,9 +222,9 @@ func (d *DeviceOf[T]) Configure(cfg Config) {
|
||||
// meaning that data can be sent right away.
|
||||
func (d *DeviceOf[T]) sendCommand(command uint8, data []byte) error {
|
||||
d.cmdBuf[0] = command
|
||||
d.dcPin(false)
|
||||
d.dcPin.Low()
|
||||
err := d.bus.Tx(d.cmdBuf[:1], nil)
|
||||
d.dcPin(true)
|
||||
d.dcPin.High()
|
||||
if len(data) != 0 {
|
||||
err = d.bus.Tx(data, nil)
|
||||
}
|
||||
@@ -234,7 +235,7 @@ func (d *DeviceOf[T]) sendCommand(command uint8, data []byte) error {
|
||||
// chip select pin low.
|
||||
func (d *DeviceOf[T]) startWrite() {
|
||||
if d.csPin != nil {
|
||||
d.csPin(false)
|
||||
d.csPin.Low()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +243,7 @@ func (d *DeviceOf[T]) startWrite() {
|
||||
// select pin high.
|
||||
func (d *DeviceOf[T]) endWrite() {
|
||||
if d.csPin != nil {
|
||||
d.csPin(true)
|
||||
d.csPin.High()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,9 +305,9 @@ func (d *DeviceOf[T]) SyncToScanLine(scanline uint16) {
|
||||
func (d *DeviceOf[T]) GetScanLine() uint16 {
|
||||
d.startWrite()
|
||||
data := []uint8{0x00, 0x00}
|
||||
d.dcPin(false)
|
||||
d.dcPin.Low()
|
||||
d.bus.Transfer(GSCAN)
|
||||
d.dcPin(true)
|
||||
d.dcPin.High()
|
||||
for i := range data {
|
||||
data[i], _ = d.bus.Transfer(0xFF)
|
||||
}
|
||||
@@ -545,9 +546,9 @@ func (d *DeviceOf[T]) Size() (w, h int16) {
|
||||
// EnableBacklight enables or disables the backlight
|
||||
func (d *DeviceOf[T]) EnableBacklight(enable bool) {
|
||||
if enable {
|
||||
d.blPin(true)
|
||||
d.blPin.High()
|
||||
} else {
|
||||
d.blPin(false)
|
||||
d.blPin.Low()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user