mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-11 02:13:42 +00:00
revision: modify proposed pin HAL.
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -26,9 +26,9 @@ type Config struct {
|
||||
|
||||
type Device struct {
|
||||
bus *machine.SPI
|
||||
cs drivers.PinOutput
|
||||
dc drivers.PinOutput
|
||||
rst drivers.PinOutput
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy drivers.PinInput
|
||||
configurePins func()
|
||||
buffer []uint8
|
||||
@@ -82,7 +82,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,
|
||||
@@ -91,17 +91,17 @@ func New(bus *machine.SPI, csPin, dcPin, rstPin legacy.PinOutput, busyPin legacy
|
||||
rst: rstPin.Set,
|
||||
isBusy: busyPin.Get,
|
||||
configurePins: func() {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
legacy.ConfigurePinInput(busyPin)
|
||||
pin.ConfigureOutput(csPin)
|
||||
pin.ConfigureOutput(dcPin)
|
||||
pin.ConfigureOutput(rstPin)
|
||||
pin.ConfigureInput(busyPin)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Device) LDirInit(cfg Config) {
|
||||
if d.configurePins == nil {
|
||||
panic(legacy.ErrConfigBeforeInstantiated)
|
||||
panic(pin.ErrConfigBeforeInstantiated)
|
||||
}
|
||||
d.configurePins()
|
||||
|
||||
@@ -160,7 +160,7 @@ func (d *Device) LDirInit(cfg Config) {
|
||||
|
||||
func (d *Device) HDirInit(cfg Config) {
|
||||
if d.configurePins == nil {
|
||||
panic(legacy.ErrConfigBeforeInstantiated)
|
||||
panic(pin.ErrConfigBeforeInstantiated)
|
||||
}
|
||||
d.configurePins()
|
||||
|
||||
@@ -240,11 +240,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 +261,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 +429,5 @@ func (d *Device) Sleep() {
|
||||
d.SendData(0x01)
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
d.rst(false)
|
||||
d.rst.Low()
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -21,9 +21,9 @@ type Config struct {
|
||||
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
cs drivers.PinOutput
|
||||
dc drivers.PinOutput
|
||||
rst drivers.PinOutput
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy drivers.PinInput
|
||||
logicalWidth int16
|
||||
width int16
|
||||
@@ -53,11 +53,11 @@ 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 {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
legacy.ConfigurePinInput(busyPin)
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
pin.ConfigureOutput(csPin)
|
||||
pin.ConfigureOutput(dcPin)
|
||||
pin.ConfigureOutput(rstPin)
|
||||
pin.ConfigureInput(busyPin)
|
||||
return Device{
|
||||
bus: bus,
|
||||
cs: csPin.Set,
|
||||
@@ -91,9 +91,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 +119,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 +155,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
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -20,9 +20,9 @@ type Config struct {
|
||||
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
cs drivers.PinOutput
|
||||
dc drivers.PinOutput
|
||||
rst drivers.PinOutput
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy drivers.PinInput
|
||||
width int16
|
||||
height int16
|
||||
@@ -33,11 +33,11 @@ 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 {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
legacy.ConfigurePinInput(busyPin)
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
pin.ConfigureOutput(csPin)
|
||||
pin.ConfigureOutput(dcPin)
|
||||
pin.ConfigureOutput(rstPin)
|
||||
pin.ConfigureInput(busyPin)
|
||||
return Device{
|
||||
bus: bus,
|
||||
cs: csPin.Set,
|
||||
@@ -75,9 +75,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 +99,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 +126,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.
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -19,9 +20,9 @@ const Baudrate = 4_000_000 // 4 MHz
|
||||
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
cs drivers.PinOutput
|
||||
dc drivers.PinOutput
|
||||
rst drivers.PinOutput
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy drivers.PinInput
|
||||
|
||||
blackBuffer []byte
|
||||
@@ -176,11 +177,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 +233,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
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -28,9 +28,9 @@ type Config struct {
|
||||
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
cs drivers.PinOutput
|
||||
dc drivers.PinOutput
|
||||
rst drivers.PinOutput
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy drivers.PinInput
|
||||
logicalWidth int16
|
||||
width int16
|
||||
@@ -61,11 +61,11 @@ 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 {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
legacy.ConfigurePinInput(busyPin)
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
pin.ConfigureOutput(csPin)
|
||||
pin.ConfigureOutput(dcPin)
|
||||
pin.ConfigureOutput(rstPin)
|
||||
pin.ConfigureInput(busyPin)
|
||||
return Device{
|
||||
bus: bus,
|
||||
cs: csPin.Set,
|
||||
@@ -99,9 +99,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()
|
||||
|
||||
@@ -122,14 +122,14 @@ func (d *Device) Configure(cfg Config) {
|
||||
d.SendCommand(DATA_ENTRY_MODE_SETTING)
|
||||
d.SendData(0x03) // X increment; Y increment
|
||||
|
||||
d.SetLUT(true)
|
||||
d.SetLUT.High()
|
||||
}
|
||||
|
||||
// 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 +152,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
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/internal/legacy"
|
||||
"tinygo.org/x/drivers/internal/pin"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -25,9 +25,9 @@ type Config struct {
|
||||
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
cs drivers.PinOutput
|
||||
dc drivers.PinOutput
|
||||
rst drivers.PinOutput
|
||||
cs pin.OutputFunc
|
||||
dc pin.OutputFunc
|
||||
rst pin.OutputFunc
|
||||
isBusy drivers.PinInput
|
||||
logicalWidth int16
|
||||
width int16
|
||||
@@ -40,11 +40,11 @@ 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 {
|
||||
legacy.ConfigurePinOut(csPin)
|
||||
legacy.ConfigurePinOut(dcPin)
|
||||
legacy.ConfigurePinOut(rstPin)
|
||||
legacy.ConfigurePinInput(busyPin)
|
||||
func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device {
|
||||
pin.ConfigureOutput(csPin)
|
||||
pin.ConfigureOutput(dcPin)
|
||||
pin.ConfigureOutput(rstPin)
|
||||
pin.ConfigureInput(busyPin)
|
||||
return Device{
|
||||
bus: bus,
|
||||
cs: csPin.Set,
|
||||
@@ -78,9 +78,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 +104,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 +145,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