@@ -20,17 +20,18 @@ var (
2020
2121// Device wraps an SPI connection.
2222type Device struct {
23- bus drivers.SPI
24- dcPin pin.OutputStruct
25- resetPin pin.OutputStruct
26- csPin pin.OutputStruct
27- enPin pin.OutputStruct
28- rwPin pin.OutputStruct
29- width int16
30- height int16
31- rowOffset int16
32- columnOffset int16
33- 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 ()
3435}
3536
3637// Config is the configuration for the display
@@ -45,11 +46,18 @@ type Config struct {
4546func New (bus drivers.SPI , resetPin , dcPin , csPin , enPin , rwPin pin.Output ) Device {
4647 return Device {
4748 bus : bus ,
48- dcPin : pin.OutputStruct {Output : dcPin },
49- resetPin : pin.OutputStruct {Output : resetPin },
50- csPin : pin.OutputStruct {Output : csPin },
51- enPin : pin.OutputStruct {Output : enPin },
52- rwPin : pin.OutputStruct {Output : 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+ },
5361 }
5462}
5563
@@ -74,11 +82,7 @@ func (d *Device) Configure(cfg Config) {
7482 }
7583
7684 // configure GPIO pins (on baremetal targets only, for backwards compatibility)
77- legacy .ConfigurePinOut (d .dcPin )
78- legacy .ConfigurePinOut (d .resetPin )
79- legacy .ConfigurePinOut (d .csPin )
80- legacy .ConfigurePinOut (d .enPin )
81- legacy .ConfigurePinOut (d .rwPin )
85+ d .configurePins ()
8286
8387 // reset the device
8488 d .resetPin .High ()
@@ -279,7 +283,7 @@ func (d *Device) Data(data uint8) {
279283
280284// Tx sends data to the display
281285func (d * Device ) Tx (data []byte , isCommand bool ) {
282- d .dcPin . Set (! isCommand )
286+ d .dcPin (! isCommand )
283287 d .csPin .Low ()
284288 d .bus .Tx (data , nil )
285289 d .csPin .High ()
0 commit comments