mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-09 17: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,6 +15,7 @@ import (
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -82,7 +83,7 @@ var partialRefresh = [159]uint8{
|
||||
}
|
||||
|
||||
// New returns a new epd1in54 driver. Pass in a fully configured SPI bus.
|
||||
func New(bus *machine.SPI, csPin, dcPin, rstPin legacy.PinOutput, busyPin legacy.PinInput) Device {
|
||||
func New(bus *machine.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
return Device{
|
||||
buffer: make([]uint8, (uint32(Width)*uint32(Height))/8),
|
||||
bus: bus,
|
||||
@@ -240,11 +241,11 @@ func (d *Device) setLUT(lut [159]uint8) {
|
||||
|
||||
// Reset resets the display.
|
||||
func (d *Device) Reset() {
|
||||
d.rst(true)
|
||||
d.rst.High()
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
d.rst(false)
|
||||
d.rst.Low()
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
d.rst(true)
|
||||
d.rst.High()
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
}
|
||||
|
||||
@@ -261,13 +262,13 @@ func (d *Device) SendData(data uint8) {
|
||||
// sendDataCommand sends image data or a command to the screen
|
||||
func (d *Device) sendDataCommand(isCommand bool, data uint8) {
|
||||
if isCommand {
|
||||
d.dc(false)
|
||||
d.dc.Low()
|
||||
} else {
|
||||
d.dc(true)
|
||||
d.dc.High()
|
||||
}
|
||||
d.cs(false)
|
||||
d.cs.Low()
|
||||
d.bus.Transfer(data)
|
||||
d.cs(true)
|
||||
d.cs.High()
|
||||
}
|
||||
|
||||
// SetPixel modifies the internal buffer in a single pixel.
|
||||
@@ -429,5 +430,5 @@ func (d *Device) Sleep() {
|
||||
d.SendData(0x01)
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
d.rst(false)
|
||||
d.rst.Low()
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -53,7 +54,7 @@ var lutPartialUpdate = [30]uint8{
|
||||
}
|
||||
|
||||
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin legacy.PinOutput, busyPin legacy.PinInput) Device {
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
@@ -91,9 +92,9 @@ func (d *Device) Configure(cfg Config) {
|
||||
d.buffer[i] = 0xFF
|
||||
}
|
||||
|
||||
d.cs(false)
|
||||
d.dc(false)
|
||||
d.rst(false)
|
||||
d.cs.Low()
|
||||
d.dc.Low()
|
||||
d.rst.Low()
|
||||
|
||||
d.Reset()
|
||||
|
||||
@@ -119,9 +120,9 @@ func (d *Device) Configure(cfg Config) {
|
||||
|
||||
// Reset resets the device
|
||||
func (d *Device) Reset() {
|
||||
d.rst(false)
|
||||
d.rst.Low()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
d.rst(true)
|
||||
d.rst.High()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
|
||||
@@ -155,13 +156,13 @@ func (d *Device) SendData(data uint8) {
|
||||
// sendDataCommand sends image data or a command to the screen
|
||||
func (d *Device) sendDataCommand(isCommand bool, data uint8) {
|
||||
if isCommand {
|
||||
d.dc(false)
|
||||
d.dc.Low()
|
||||
} else {
|
||||
d.dc(true)
|
||||
d.dc.High()
|
||||
}
|
||||
d.cs(false)
|
||||
d.cs.Low()
|
||||
d.bus.Transfer(data)
|
||||
d.cs(true)
|
||||
d.cs.High()
|
||||
}
|
||||
|
||||
// SetLUT sets the look up tables for full or partial updates
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -33,7 +34,7 @@ type Device struct {
|
||||
type Color uint8
|
||||
|
||||
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin legacy.PinOutput, busyPin legacy.PinInput) Device {
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
@@ -75,9 +76,9 @@ func (d *Device) Configure(cfg Config) {
|
||||
}
|
||||
}
|
||||
|
||||
d.cs(false)
|
||||
d.dc(false)
|
||||
d.rst(false)
|
||||
d.cs.Low()
|
||||
d.dc.Low()
|
||||
d.rst.Low()
|
||||
|
||||
d.Reset()
|
||||
|
||||
@@ -99,9 +100,9 @@ func (d *Device) Configure(cfg Config) {
|
||||
|
||||
// Reset resets the device
|
||||
func (d *Device) Reset() {
|
||||
d.rst(false)
|
||||
d.rst.Low()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
d.rst(true)
|
||||
d.rst.High()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
|
||||
@@ -126,13 +127,13 @@ func (d *Device) SendData(data uint8) {
|
||||
// sendDataCommand sends image data or a command to the screen
|
||||
func (d *Device) sendDataCommand(isCommand bool, data uint8) {
|
||||
if isCommand {
|
||||
d.dc(false)
|
||||
d.dc.Low()
|
||||
} else {
|
||||
d.dc(true)
|
||||
d.dc.High()
|
||||
}
|
||||
d.cs(false)
|
||||
d.cs.Low()
|
||||
d.bus.Transfer(data)
|
||||
d.cs(true)
|
||||
d.cs.High()
|
||||
}
|
||||
|
||||
// SetPixel modifies the internal buffer in a single pixel.
|
||||
|
||||
@@ -176,11 +176,11 @@ func (d *Device) setCursor(x, y uint16) error {
|
||||
}
|
||||
|
||||
func (d *Device) hwReset() {
|
||||
d.rst(true)
|
||||
d.rst.High()
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
d.rst(false)
|
||||
d.rst.Low()
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
d.rst(true)
|
||||
d.rst.High()
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
}
|
||||
|
||||
@@ -232,26 +232,26 @@ func (d *Device) sendCommandSequence(seq []byte) error {
|
||||
}
|
||||
|
||||
func (d *Device) sendCommandByte(b byte) error {
|
||||
d.dc(false)
|
||||
d.cs(false)
|
||||
d.dc.Low()
|
||||
d.cs.Low()
|
||||
_, err := d.bus.Transfer(b)
|
||||
d.cs(true)
|
||||
d.cs.High()
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *Device) sendDataByte(b byte) error {
|
||||
d.dc(true)
|
||||
d.cs(false)
|
||||
d.dc.High()
|
||||
d.cs.Low()
|
||||
_, err := d.bus.Transfer(b)
|
||||
d.cs(true)
|
||||
d.cs.High()
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *Device) sendData(b []byte) error {
|
||||
d.dc(true)
|
||||
d.cs(false)
|
||||
d.dc.High()
|
||||
d.cs.Low()
|
||||
err := d.bus.Tx(b, nil)
|
||||
d.cs(true)
|
||||
d.cs.High()
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -61,7 +62,7 @@ var lutPartialUpdate = [30]uint8{
|
||||
}
|
||||
|
||||
// New returns a new epd2in9 driver. Pass in a fully configured SPI bus.
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin legacy.PinOutput, busyPin legacy.PinInput) Device {
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
@@ -99,9 +100,9 @@ func (d *Device) Configure(cfg Config) {
|
||||
d.buffer[i] = 0xFF
|
||||
}
|
||||
|
||||
d.cs(false)
|
||||
d.dc(false)
|
||||
d.rst(false)
|
||||
d.cs.Low()
|
||||
d.dc.Low()
|
||||
d.rst.Low()
|
||||
|
||||
d.Reset()
|
||||
|
||||
@@ -127,9 +128,9 @@ func (d *Device) Configure(cfg Config) {
|
||||
|
||||
// Reset resets the device
|
||||
func (d *Device) Reset() {
|
||||
d.rst(false)
|
||||
d.rst.Low()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
d.rst(true)
|
||||
d.rst.High()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
|
||||
@@ -152,13 +153,13 @@ func (d *Device) SendData(data uint8) {
|
||||
// sendDataCommand sends image data or a command to the screen
|
||||
func (d *Device) sendDataCommand(isCommand bool, data uint8) {
|
||||
if isCommand {
|
||||
d.dc(false)
|
||||
d.dc.Low()
|
||||
} else {
|
||||
d.dc(true)
|
||||
d.dc.High()
|
||||
}
|
||||
d.cs(false)
|
||||
d.cs.Low()
|
||||
d.bus.Transfer(data)
|
||||
d.cs(true)
|
||||
d.cs.High()
|
||||
}
|
||||
|
||||
// SetLUT sets the look up tables for full or partial updates
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -40,7 +41,7 @@ type Device struct {
|
||||
type Rotation uint8
|
||||
|
||||
// New returns a new epd4in2 driver. Pass in a fully configured SPI bus.
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin legacy.PinOutput, busyPin legacy.PinInput) Device {
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
@@ -78,9 +79,9 @@ func (d *Device) Configure(cfg Config) {
|
||||
d.buffer[i] = 0xFF
|
||||
}
|
||||
|
||||
d.cs(false)
|
||||
d.dc(false)
|
||||
d.rst(false)
|
||||
d.cs.Low()
|
||||
d.dc.Low()
|
||||
d.rst.Low()
|
||||
|
||||
d.Reset()
|
||||
d.SendCommand(POWER_SETTING)
|
||||
@@ -104,9 +105,9 @@ func (d *Device) Configure(cfg Config) {
|
||||
|
||||
// Reset resets the device
|
||||
func (d *Device) Reset() {
|
||||
d.rst(false)
|
||||
d.rst.Low()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
d.rst(true)
|
||||
d.rst.High()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
|
||||
@@ -145,13 +146,13 @@ func (d *Device) SendData(data uint8) {
|
||||
// sendDataCommand sends image data or a command to the screen
|
||||
func (d *Device) sendDataCommand(isCommand bool, data uint8) {
|
||||
if isCommand {
|
||||
d.dc(false)
|
||||
d.dc.Low()
|
||||
} else {
|
||||
d.dc(true)
|
||||
d.dc.High()
|
||||
}
|
||||
d.cs(false)
|
||||
d.cs.Low()
|
||||
d.bus.Transfer(data)
|
||||
d.cs(true)
|
||||
d.cs.High()
|
||||
}
|
||||
|
||||
// SetLUT sets the look up tables for full or partial updates
|
||||
|
||||
Reference in New Issue
Block a user