@@ -8,10 +8,11 @@ package uc8151 // import "tinygo.org/x/drivers/uc8151"
88import (
99 "errors"
1010 "image/color"
11- "machine"
1211 "time"
1312
1413 "tinygo.org/x/drivers"
14+ "tinygo.org/x/drivers/internal/legacy"
15+ "tinygo.org/x/drivers/internal/pin"
1516 "tinygo.org/x/drivers/pixel"
1617)
1718
@@ -31,10 +32,10 @@ type Config struct {
3132
3233type Device struct {
3334 bus drivers.SPI
34- cs machine. Pin
35- dc machine. Pin
36- rst machine. Pin
37- busy machine. Pin
35+ cs drivers. PinOutput
36+ dc drivers. PinOutput
37+ rst drivers. PinOutput
38+ isBusy drivers. PinInput
3839 width int16
3940 height int16
4041 buffer []uint8
@@ -49,17 +50,22 @@ type Device struct {
4950type Speed uint8
5051
5152// New returns a new uc8151 driver. Pass in a fully configured SPI bus.
52- func New (bus drivers.SPI , csPin , dcPin , rstPin , busyPin machine.Pin ) Device {
53- csPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
54- dcPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
55- rstPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
56- busyPin .Configure (machine.PinConfig {Mode : machine .PinInput })
53+ // Pins passed in must be configured beforehand.
54+ func New (bus drivers.SPI , csPin , dcPin , rstPin pin.Output , busyPin pin.Input ) Device {
55+ // For backwards compatibility.
56+ // This driver used to configure pins,
57+ // so leave in to not break users.
58+ // May be removed in future so try not to depend on it!
59+ legacy .ConfigurePinOut (csPin )
60+ legacy .ConfigurePinOut (dcPin )
61+ legacy .ConfigurePinOut (rstPin )
62+ legacy .ConfigurePinInput (busyPin )
5763 return Device {
58- bus : bus ,
59- cs : csPin ,
60- dc : dcPin ,
61- rst : rstPin ,
62- busy : busyPin ,
64+ bus : bus ,
65+ cs : csPin . Set ,
66+ dc : dcPin . Set ,
67+ rst : rstPin . Set ,
68+ isBusy : busyPin . Get ,
6369 }
6470}
6571
@@ -313,14 +319,14 @@ func (d *Device) ClearDisplay() {
313319
314320// WaitUntilIdle waits until the display is ready
315321func (d * Device ) WaitUntilIdle () {
316- for ! d .busy . Get () {
322+ for ! d .isBusy () {
317323 time .Sleep (10 * time .Millisecond )
318324 }
319325}
320326
321327// IsBusy returns the busy status of the display
322328func (d * Device ) IsBusy () bool {
323- return d .busy . Get ()
329+ return d .isBusy ()
324330}
325331
326332// ClearBuffer sets the buffer to 0xFF (white)
0 commit comments