@@ -5,12 +5,12 @@ package st7735 // import "tinygo.org/x/drivers/st7735"
5
5
6
6
import (
7
7
"image/color"
8
- "machine"
9
8
"time"
10
9
11
10
"errors"
12
11
13
12
"tinygo.org/x/drivers"
13
+ "tinygo.org/x/drivers/internal/legacy"
14
14
"tinygo.org/x/drivers/pixel"
15
15
)
16
16
@@ -39,10 +39,10 @@ type Device = DeviceOf[pixel.RGB565BE]
39
39
// formats.
40
40
type DeviceOf [T Color ] struct {
41
41
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
46
46
width int16
47
47
height int16
48
48
columnOffset int16
@@ -65,23 +65,23 @@ type Config struct {
65
65
}
66
66
67
67
// 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 {
69
69
return NewOf [pixel.RGB565BE ](bus , resetPin , dcPin , csPin , blPin )
70
70
}
71
71
72
72
// NewOf creates a new ST7735 connection with a particular pixel format. The SPI
73
73
// 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 )
79
79
return DeviceOf [T ]{
80
80
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 ,
85
85
}
86
86
}
87
87
@@ -114,11 +114,11 @@ func (d *DeviceOf[T]) Configure(cfg Config) {
114
114
d .batchData = pixel .NewImage [T ](int (d .batchLength ), 1 )
115
115
116
116
// reset the device
117
- d .resetPin . High ( )
117
+ d .resetPin ( true )
118
118
time .Sleep (5 * time .Millisecond )
119
- d .resetPin . Low ( )
119
+ d .resetPin ( false )
120
120
time .Sleep (20 * time .Millisecond )
121
- d .resetPin . High ( )
121
+ d .resetPin ( true )
122
122
time .Sleep (150 * time .Millisecond )
123
123
124
124
// Common initialization
@@ -226,7 +226,7 @@ func (d *DeviceOf[T]) Configure(cfg Config) {
226
226
227
227
d .SetRotation (d .rotation )
228
228
229
- d .blPin . High ( )
229
+ d .blPin ( true )
230
230
}
231
231
232
232
// 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) {
423
423
424
424
// Tx sends data to the display
425
425
func (d * DeviceOf [T ]) Tx (data []byte , isCommand bool ) {
426
- d .dcPin . Set (! isCommand )
426
+ d .dcPin (! isCommand )
427
427
d .bus .Tx (data , nil )
428
428
}
429
429
@@ -438,9 +438,9 @@ func (d *DeviceOf[T]) Size() (w, h int16) {
438
438
// EnableBacklight enables or disables the backlight
439
439
func (d * DeviceOf [T ]) EnableBacklight (enable bool ) {
440
440
if enable {
441
- d .blPin . High ( )
441
+ d .blPin ( true )
442
442
} else {
443
- d .blPin . Low ( )
443
+ d .blPin ( false )
444
444
}
445
445
}
446
446
0 commit comments