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
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"tinygo.org/x/drivers"
"tinygo.org/x/drivers/internal/legacy"
"tinygo.org/x/drivers/internal/pin"
)
const (
@@ -37,7 +38,7 @@ func New(b drivers.SPI) *Device {
// NewSoftwareSPI returns a new APA102 driver that will use a software based
// implementation of the SPI protocol.
func NewSoftwareSPI(sckPin, sdoPin legacy.PinOutput, delay uint32) *Device {
func NewSoftwareSPI(sckPin, sdoPin pin.Output, delay uint32) *Device {
return New(&bbSPI{SCK: sckPin.Set, SDO: sdoPin.Set, Delay: delay, configurePins: func() {
legacy.ConfigurePinOut(sckPin)
legacy.ConfigurePinOut(sdoPin)
+6 -6
View File
@@ -23,8 +23,8 @@ func (s *bbSPI) Configure() {
panic(legacy.ErrConfigBeforeInstantiated)
}
s.configurePins()
s.SCK(false)
s.SDO(false)
s.SCK.Low()
s.SDO.Low()
if s.Delay == 0 {
s.Delay = 1
}
@@ -53,19 +53,19 @@ func (s *bbSPI) Transfer(b byte) (byte, error) {
for i := uint8(0); i < 8; i++ {
// half clock cycle high to start
s.SCK(true)
s.SCK.High()
s.delay()
// write the value to SDO (MSB first)
if b&(1<<(7-i)) == 0 {
s.SDO(false)
s.SDO.Low()
} else {
s.SDO(true)
s.SDO.High()
}
s.delay()
// half clock cycle low
s.SCK(false)
s.SCK.Low()
s.delay()
// for actual SPI would try to read the SDI value here