@@ -6,10 +6,11 @@ package ssd1351 // import "tinygo.org/x/drivers/ssd1351"
66import (
77 "errors"
88 "image/color"
9- "machine"
109 "time"
1110
1211 "tinygo.org/x/drivers"
12+ "tinygo.org/x/drivers/internal/legacy"
13+ "tinygo.org/x/drivers/internal/pin"
1314)
1415
1516var (
@@ -19,17 +20,18 @@ var (
1920
2021// Device wraps an SPI connection.
2122type Device struct {
22- bus drivers.SPI
23- dcPin machine.Pin
24- resetPin machine.Pin
25- csPin machine.Pin
26- enPin machine.Pin
27- rwPin machine.Pin
28- width int16
29- height int16
30- rowOffset int16
31- columnOffset int16
32- bufferLength int16
23+ bus drivers.SPI
24+ dcPin pin.OutputFunc
25+ resetPin pin.OutputFunc
26+ csPin pin.OutputFunc
27+ enPin pin.OutputFunc
28+ rwPin pin.OutputFunc
29+ width int16
30+ height int16
31+ rowOffset int16
32+ columnOffset int16
33+ bufferLength int16
34+ configurePins func ()
3335}
3436
3537// Config is the configuration for the display
@@ -41,14 +43,21 @@ type Config struct {
4143}
4244
4345// New creates a new SSD1351 connection. The SPI wire must already be configured.
44- func New (bus drivers.SPI , resetPin , dcPin , csPin , enPin , rwPin machine. Pin ) Device {
46+ func New (bus drivers.SPI , resetPin , dcPin , csPin , enPin , rwPin pin. Output ) Device {
4547 return Device {
4648 bus : bus ,
47- dcPin : dcPin ,
48- resetPin : resetPin ,
49- csPin : csPin ,
50- enPin : enPin ,
51- rwPin : rwPin ,
49+ dcPin : dcPin .Set ,
50+ resetPin : resetPin .Set ,
51+ csPin : csPin .Set ,
52+ enPin : enPin .Set ,
53+ rwPin : rwPin .Set ,
54+ configurePins : func () {
55+ legacy .ConfigurePinOut (dcPin )
56+ legacy .ConfigurePinOut (resetPin )
57+ legacy .ConfigurePinOut (csPin )
58+ legacy .ConfigurePinOut (enPin )
59+ legacy .ConfigurePinOut (rwPin )
60+ },
5261 }
5362}
5463
@@ -72,12 +81,8 @@ func (d *Device) Configure(cfg Config) {
7281 d .bufferLength = d .height
7382 }
7483
75- // configure GPIO pins
76- d .dcPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
77- d .resetPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
78- d .csPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
79- d .enPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
80- d .rwPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
84+ // configure GPIO pins (on baremetal targets only, for backwards compatibility)
85+ d .configurePins ()
8186
8287 // reset the device
8388 d .resetPin .High ()
@@ -278,7 +283,7 @@ func (d *Device) Data(data uint8) {
278283
279284// Tx sends data to the display
280285func (d * Device ) Tx (data []byte , isCommand bool ) {
281- d .dcPin . Set (! isCommand )
286+ d .dcPin (! isCommand )
282287 d .csPin .Low ()
283288 d .bus .Tx (data , nil )
284289 d .csPin .High ()
0 commit comments