@@ -5,12 +5,13 @@ package st7735 // import "tinygo.org/x/drivers/st7735"
55
66import (
77 "image/color"
8- "machine"
98 "time"
109
1110 "errors"
1211
1312 "tinygo.org/x/drivers"
13+ "tinygo.org/x/drivers/internal/legacy"
14+ "tinygo.org/x/drivers/internal/pin"
1415 "tinygo.org/x/drivers/pixel"
1516)
1617
@@ -39,10 +40,10 @@ type Device = DeviceOf[pixel.RGB565BE]
3940// formats.
4041type DeviceOf [T Color ] struct {
4142 bus drivers.SPI
42- dcPin machine. Pin
43- resetPin machine. Pin
44- csPin machine. Pin
45- blPin machine. Pin
43+ dcPin pin. OutputFunc
44+ resetPin pin. OutputFunc
45+ csPin pin. OutputFunc
46+ blPin pin. OutputFunc
4647 width int16
4748 height int16
4849 columnOffset int16
@@ -65,23 +66,25 @@ type Config struct {
6566}
6667
6768// New creates a new ST7735 connection. The SPI wire must already be configured.
68- func New (bus drivers.SPI , resetPin , dcPin , csPin , blPin machine. Pin ) Device {
69+ func New (bus drivers.SPI , resetPin , dcPin , csPin , blPin pin. Output ) Device {
6970 return NewOf [pixel.RGB565BE ](bus , resetPin , dcPin , csPin , blPin )
7071}
7172
7273// NewOf creates a new ST7735 connection with a particular pixel format. The SPI
7374// wire must already be configured.
74- func NewOf [T Color ](bus drivers.SPI , resetPin , dcPin , csPin , blPin machine.Pin ) DeviceOf [T ] {
75- dcPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
76- resetPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
77- csPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
78- blPin .Configure (machine.PinConfig {Mode : machine .PinOutput })
75+ func NewOf [T Color ](bus drivers.SPI , resetPin , dcPin , csPin , blPin pin.Output ) DeviceOf [T ] {
76+ // IMPORTANT: pin configuration should really be done outside of this driver,
77+ // but for backwards compatibility with existing code, we do it here.
78+ legacy .ConfigurePinOut (dcPin )
79+ legacy .ConfigurePinOut (resetPin )
80+ legacy .ConfigurePinOut (csPin )
81+ legacy .ConfigurePinOut (blPin )
7982 return DeviceOf [T ]{
8083 bus : bus ,
81- dcPin : dcPin ,
82- resetPin : resetPin ,
83- csPin : csPin ,
84- blPin : blPin ,
84+ dcPin : dcPin . Set ,
85+ resetPin : resetPin . Set ,
86+ csPin : csPin . Set ,
87+ blPin : blPin . Set ,
8588 }
8689}
8790
@@ -423,7 +426,7 @@ func (d *DeviceOf[T]) Data(data uint8) {
423426
424427// Tx sends data to the display
425428func (d * DeviceOf [T ]) Tx (data []byte , isCommand bool ) {
426- d .dcPin . Set (! isCommand )
429+ d .dcPin (! isCommand )
427430 d .bus .Tx (data , nil )
428431}
429432
0 commit comments