legacy.PinOutput->pin.Output and add High+Low methods on drivers.PinOutput and use them in drivers

This commit is contained in:
Patricio Whittingslow
2025-09-16 17:53:18 -03:00
committed by deadprogram
parent 2e007a6de7
commit 8ac285e821
30 changed files with 280 additions and 245 deletions
+4 -4
View File
@@ -5,7 +5,7 @@ import (
"errors"
"tinygo.org/x/drivers"
"tinygo.org/x/drivers/internal/legacy"
"tinygo.org/x/drivers/internal/pin"
)
// ErrThermocoupleOpen is returned when the thermocouple input is open.
@@ -20,7 +20,7 @@ type Device struct {
// Create a new Device to read from a MAX6675 thermocouple.
// Pins must be configured before use. Frequency for SPI
// should be 4.3MHz maximum.
func NewDevice(bus drivers.SPI, cs legacy.PinOutput) *Device {
func NewDevice(bus drivers.SPI, cs pin.Output) *Device {
return &Device{
bus: bus,
cs: cs.Set,
@@ -34,11 +34,11 @@ func (d *Device) Read() (float32, error) {
value uint16
)
d.cs(false)
d.cs.Low()
if err := d.bus.Tx([]byte{0, 0}, read); err != nil {
return 0, err
}
d.cs(true)
d.cs.High()
// datasheet: Bit D2 is normally low and goes high if the thermocouple input is open.
if read[1]&0x04 == 0x04 {