mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-12 10:53:43 +00:00
bring #753 changes over to new pin HAL
This commit is contained in:
@@ -12,6 +12,9 @@ import (
|
||||
"image/color"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -22,14 +25,14 @@ type Config struct {
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
bus *machine.SPI
|
||||
cs machine.Pin
|
||||
dc machine.Pin
|
||||
rst machine.Pin
|
||||
busy machine.Pin
|
||||
|
||||
buffer []uint8
|
||||
rotation Rotation
|
||||
bus *machine.SPI
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy pin.InputFunc
|
||||
configurePins func()
|
||||
buffer []uint8
|
||||
rotation Rotation
|
||||
}
|
||||
|
||||
type Rotation uint8
|
||||
@@ -79,22 +82,28 @@ 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, busyPin machine.Pin) 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,
|
||||
cs: csPin,
|
||||
dc: dcPin,
|
||||
rst: rstPin,
|
||||
busy: busyPin,
|
||||
cs: csPin.Set,
|
||||
dc: dcPin.Set,
|
||||
rst: rstPin.Set,
|
||||
isBusy: busyPin.Get,
|
||||
configurePins: func() {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
legacy.ConfigurePinInput(busyPin)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Device) LDirInit(cfg Config) {
|
||||
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
if d.configurePins == nil {
|
||||
panic(legacy.ErrConfigBeforeInstantiated)
|
||||
}
|
||||
d.configurePins()
|
||||
|
||||
d.bus.Configure(machine.SPIConfig{
|
||||
Frequency: 2000000,
|
||||
@@ -150,10 +159,10 @@ func (d *Device) LDirInit(cfg Config) {
|
||||
}
|
||||
|
||||
func (d *Device) HDirInit(cfg Config) {
|
||||
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
if d.configurePins == nil {
|
||||
panic(legacy.ErrConfigBeforeInstantiated)
|
||||
}
|
||||
d.configurePins()
|
||||
|
||||
d.bus.Configure(machine.SPIConfig{
|
||||
Frequency: 2000000,
|
||||
@@ -369,7 +378,7 @@ func (d *Device) Clear() {
|
||||
|
||||
// WaitUntilIdle waits until the display is ready
|
||||
func (d *Device) WaitUntilIdle() {
|
||||
for d.busy.Get() {
|
||||
for d.isBusy() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
@@ -377,7 +386,7 @@ func (d *Device) WaitUntilIdle() {
|
||||
|
||||
// IsBusy returns the busy status of the display
|
||||
func (d *Device) IsBusy() bool {
|
||||
return d.busy.Get()
|
||||
return d.isBusy()
|
||||
}
|
||||
|
||||
// ClearBuffer sets the buffer to 0xFF (white)
|
||||
|
||||
@@ -6,10 +6,11 @@ package epd2in13 // import "tinygo.org/x/drivers/waveshare-epd/epd2in13"
|
||||
import (
|
||||
"errors"
|
||||
"image/color"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -21,10 +22,10 @@ type Config struct {
|
||||
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
cs machine.Pin
|
||||
dc machine.Pin
|
||||
rst machine.Pin
|
||||
busy machine.Pin
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy pin.InputFunc
|
||||
logicalWidth int16
|
||||
width int16
|
||||
height int16
|
||||
@@ -53,17 +54,17 @@ 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, busyPin machine.Pin) Device {
|
||||
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
legacy.ConfigurePinInput(busyPin)
|
||||
return Device{
|
||||
bus: bus,
|
||||
cs: csPin,
|
||||
dc: dcPin,
|
||||
rst: rstPin,
|
||||
busy: busyPin,
|
||||
bus: bus,
|
||||
cs: csPin.Set,
|
||||
dc: dcPin.Set,
|
||||
rst: rstPin.Set,
|
||||
isBusy: busyPin.Get,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,14 +299,14 @@ func (d *Device) setMemoryPointer(x int16, y int16) {
|
||||
|
||||
// WaitUntilIdle waits until the display is ready
|
||||
func (d *Device) WaitUntilIdle() {
|
||||
for d.busy.Get() {
|
||||
for d.isBusy() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// IsBusy returns the busy status of the display
|
||||
func (d *Device) IsBusy() bool {
|
||||
return d.busy.Get()
|
||||
return d.isBusy()
|
||||
}
|
||||
|
||||
// ClearBuffer sets the buffer to 0xFF (white)
|
||||
|
||||
@@ -6,10 +6,11 @@ package epd2in13x // import "tinygo.org/x/drivers/waveshare-epd/epd2in13x"
|
||||
import (
|
||||
"errors"
|
||||
"image/color"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -20,10 +21,10 @@ type Config struct {
|
||||
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
cs machine.Pin
|
||||
dc machine.Pin
|
||||
rst machine.Pin
|
||||
busy machine.Pin
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy pin.InputFunc
|
||||
width int16
|
||||
height int16
|
||||
buffer [][]uint8
|
||||
@@ -33,17 +34,17 @@ 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, busyPin machine.Pin) Device {
|
||||
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
legacy.ConfigurePinInput(busyPin)
|
||||
return Device{
|
||||
bus: bus,
|
||||
cs: csPin,
|
||||
dc: dcPin,
|
||||
rst: rstPin,
|
||||
busy: busyPin,
|
||||
bus: bus,
|
||||
cs: csPin.Set,
|
||||
dc: dcPin.Set,
|
||||
rst: rstPin.Set,
|
||||
isBusy: busyPin.Get,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,14 +278,14 @@ func (d *Device) ClearDisplay() {
|
||||
|
||||
// WaitUntilIdle waits until the display is ready
|
||||
func (d *Device) WaitUntilIdle() {
|
||||
for !d.busy.Get() {
|
||||
for !d.isBusy() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// IsBusy returns the busy status of the display
|
||||
func (d *Device) IsBusy() bool {
|
||||
return d.busy.Get()
|
||||
return d.isBusy()
|
||||
}
|
||||
|
||||
// ClearBuffer sets the buffer to 0xFF (white)
|
||||
|
||||
@@ -5,10 +5,10 @@ package epd2in66b
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -18,20 +18,12 @@ const (
|
||||
|
||||
const Baudrate = 4_000_000 // 4 MHz
|
||||
|
||||
type Config struct {
|
||||
ResetPin machine.Pin
|
||||
DataPin machine.Pin
|
||||
ChipSelectPin machine.Pin
|
||||
BusyPin machine.Pin
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
cs machine.Pin
|
||||
dc machine.Pin
|
||||
rst machine.Pin
|
||||
busy machine.Pin
|
||||
|
||||
bus drivers.SPI
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy pin.InputFunc
|
||||
blackBuffer []byte
|
||||
redBuffer []byte
|
||||
}
|
||||
@@ -50,21 +42,6 @@ func New(bus drivers.SPI) Device {
|
||||
}
|
||||
}
|
||||
|
||||
// Configure configures the device and its pins.
|
||||
func (d *Device) Configure(c Config) error {
|
||||
d.cs = c.ChipSelectPin
|
||||
d.dc = c.DataPin
|
||||
d.rst = c.ResetPin
|
||||
d.busy = c.BusyPin
|
||||
|
||||
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Device) Size() (x, y int16) {
|
||||
return displayWidth, displayHeight
|
||||
}
|
||||
@@ -229,7 +206,7 @@ func (d *Device) WaitUntilIdle() {
|
||||
// give it some time to get busy
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
for d.busy.Get() { // high = busy
|
||||
for d.isBusy() { // high = busy
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,11 @@ package epd2in9 // import "tinygo.org/x/drivers/waveshare-epd/epd2in9"
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -28,10 +29,10 @@ type Config struct {
|
||||
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
cs machine.Pin
|
||||
dc machine.Pin
|
||||
rst machine.Pin
|
||||
busy machine.Pin
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy pin.InputFunc
|
||||
logicalWidth int16
|
||||
width int16
|
||||
height int16
|
||||
@@ -61,17 +62,17 @@ 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, busyPin machine.Pin) Device {
|
||||
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
legacy.ConfigurePinInput(busyPin)
|
||||
return Device{
|
||||
bus: bus,
|
||||
cs: csPin,
|
||||
dc: dcPin,
|
||||
rst: rstPin,
|
||||
busy: busyPin,
|
||||
bus: bus,
|
||||
cs: csPin.Set,
|
||||
dc: dcPin.Set,
|
||||
rst: rstPin.Set,
|
||||
isBusy: busyPin.Get,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,14 +246,14 @@ func (d *Device) setMemoryPointer(x int16, y int16) {
|
||||
|
||||
// WaitUntilIdle waits until the display is ready
|
||||
func (d *Device) WaitUntilIdle() {
|
||||
for d.busy.Get() {
|
||||
for d.isBusy() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// IsBusy returns the busy status of the display
|
||||
func (d *Device) IsBusy() bool {
|
||||
return d.busy.Get()
|
||||
return d.isBusy()
|
||||
}
|
||||
|
||||
// ClearBuffer sets the buffer to 0xFF (white)
|
||||
|
||||
@@ -10,10 +10,11 @@ package epd4in2
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -25,10 +26,10 @@ type Config struct {
|
||||
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
cs machine.Pin
|
||||
dc machine.Pin
|
||||
rst machine.Pin
|
||||
busy machine.Pin
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy pin.InputFunc
|
||||
logicalWidth int16
|
||||
width int16
|
||||
height int16
|
||||
@@ -40,17 +41,17 @@ 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, busyPin machine.Pin) Device {
|
||||
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
legacy.ConfigurePinInput(busyPin)
|
||||
return Device{
|
||||
bus: bus,
|
||||
cs: csPin,
|
||||
dc: dcPin,
|
||||
rst: rstPin,
|
||||
busy: busyPin,
|
||||
bus: bus,
|
||||
cs: csPin.Set,
|
||||
dc: dcPin.Set,
|
||||
rst: rstPin.Set,
|
||||
isBusy: busyPin.Get,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,14 +312,14 @@ func (d *Device) ClearDisplay() {
|
||||
|
||||
// WaitUntilIdle waits until the display is ready
|
||||
func (d *Device) WaitUntilIdle() {
|
||||
for d.busy.Get() {
|
||||
for d.isBusy() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// IsBusy returns the busy status of the display
|
||||
func (d *Device) IsBusy() bool {
|
||||
return d.busy.Get()
|
||||
return d.isBusy()
|
||||
}
|
||||
|
||||
// ClearBuffer sets the buffer to 0xFF (white)
|
||||
|
||||
Reference in New Issue
Block a user