@@ -5,12 +5,12 @@ 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"
1414 "tinygo.org/x/drivers/pixel"
1515)
1616
@@ -39,10 +39,10 @@ type Device = DeviceOf[pixel.RGB565BE]
3939// formats.
4040type DeviceOf [T Color ] struct {
4141 bus drivers.SPI
42- dcPin machine. Pin
43- resetPin machine. Pin
44- csPin machine. Pin
45- blPin machine. Pin
42+ dcPin drivers. PinOutput
43+ resetPin drivers. PinOutput
44+ csPin drivers. PinOutput
45+ blPin drivers. PinOutput
4646 width int16
4747 height int16
4848 columnOffset int16
@@ -65,23 +65,23 @@ type Config struct {
6565}
6666
6767// 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 {
68+ func New (bus drivers.SPI , resetPin , dcPin , csPin , blPin legacy. PinOutput ) Device {
6969 return NewOf [pixel.RGB565BE ](bus , resetPin , dcPin , csPin , blPin )
7070}
7171
7272// NewOf creates a new ST7735 connection with a particular pixel format. The SPI
7373// 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 } )
74+ func NewOf [T Color ](bus drivers.SPI , resetPin , dcPin , csPin , blPin legacy. PinOutput ) DeviceOf [T ] {
75+ legacy . ConfigurePinOut ( dcPin )
76+ legacy . ConfigurePinOut ( resetPin )
77+ legacy . ConfigurePinOut ( csPin )
78+ legacy . ConfigurePinOut ( blPin )
7979 return DeviceOf [T ]{
8080 bus : bus ,
81- dcPin : dcPin ,
82- resetPin : resetPin ,
83- csPin : csPin ,
84- blPin : blPin ,
81+ dcPin : dcPin . Set ,
82+ resetPin : resetPin . Set ,
83+ csPin : csPin . Set ,
84+ blPin : blPin . Set ,
8585 }
8686}
8787
@@ -114,11 +114,11 @@ func (d *DeviceOf[T]) Configure(cfg Config) {
114114 d .batchData = pixel .NewImage [T ](int (d .batchLength ), 1 )
115115
116116 // reset the device
117- d .resetPin . High ( )
117+ d .resetPin ( true )
118118 time .Sleep (5 * time .Millisecond )
119- d .resetPin . Low ( )
119+ d .resetPin ( false )
120120 time .Sleep (20 * time .Millisecond )
121- d .resetPin . High ( )
121+ d .resetPin ( true )
122122 time .Sleep (150 * time .Millisecond )
123123
124124 // Common initialization
@@ -226,7 +226,7 @@ func (d *DeviceOf[T]) Configure(cfg Config) {
226226
227227 d .SetRotation (d .rotation )
228228
229- d .blPin . High ( )
229+ d .blPin ( true )
230230}
231231
232232// Display does nothing, there's no buffer as it might be too big for some boards
@@ -423,7 +423,7 @@ func (d *DeviceOf[T]) Data(data uint8) {
423423
424424// Tx sends data to the display
425425func (d * DeviceOf [T ]) Tx (data []byte , isCommand bool ) {
426- d .dcPin . Set (! isCommand )
426+ d .dcPin (! isCommand )
427427 d .bus .Tx (data , nil )
428428}
429429
@@ -438,9 +438,9 @@ func (d *DeviceOf[T]) Size() (w, h int16) {
438438// EnableBacklight enables or disables the backlight
439439func (d * DeviceOf [T ]) EnableBacklight (enable bool ) {
440440 if enable {
441- d .blPin . High ( )
441+ d .blPin ( true )
442442 } else {
443- d .blPin . Low ( )
443+ d .blPin ( false )
444444 }
445445}
446446
0 commit comments