Skip to content

Commit 3681452

Browse files
committed
finish rewrites!
1 parent 8f0fbaa commit 3681452

File tree

16 files changed

+283
-727
lines changed

16 files changed

+283
-727
lines changed

easystepper/easystepper.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build baremetal
2-
31
// Package easystepper provides a simple driver to rotate a 4-wire stepper motor.
42
package easystepper // import "tinygo.org/x/drivers/easystepper"
53

internal/legacy/pinhal.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ func ConfigurePinInputPullup(pi PinInput) {
6363
configurePinInputPullup(pi)
6464
}
6565

66+
// PinIsNoPin returns true if the argument is a machine.Pin type and is the machine.NoPin predeclared type.
67+
//
68+
// Deprecated: Drivers do not require pin knowledge from now on.
69+
func PinIsNoPin(pin any) bool {
70+
return pinIsNoPin(pin)
71+
}
72+
6673
var (
6774
ErrConfigBeforeInstantiated = errors.New("device must be instantiated with New before calling Configure method")
6875
)

internal/legacy/pinhal_baremetal.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ func configurePinInputPullup(p PinInput) {
2020
configurePin(p, machine.PinInputPullup)
2121
}
2222

23+
func pinIsNoPin(a any) bool {
24+
p, ok := a.(machine.Pin)
25+
return ok && p == machine.NoPin
26+
}
27+
2328
func configurePin(p any, mode machine.PinMode) {
2429
machinePin, ok := p.(machine.Pin)
2530
if ok {

internal/legacy/pinhal_os.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ func configurePinOut(p PinOutput) {}
66
func configurePinInput(p PinInput) {}
77
func configurePinInputPulldown(p PinInput) {}
88
func configurePinInputPullup(p PinInput) {}
9+
func pinIsNoPin(a any) bool { return false }

st7735/st7735.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ package st7735 // import "tinygo.org/x/drivers/st7735"
55

66
import (
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.
4040
type 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
425425
func (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
439439
func (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

Comments
 (0)