Pin HAL to break dependency of drivers from TinyGo's machine package

This commit is contained in:
Yurii Soldak
2025-09-21 04:38:21 +02:00
parent 3fa08112db
commit c6d83b783f
15 changed files with 328 additions and 88 deletions
+30
View File
@@ -0,0 +1,30 @@
package rpio // import "tinygo.org/x/drivers/rpio"
import go_rpio "github.com/stianeikeland/go-rpio/v4"
type SPI struct {
}
func NewSPI() (s *SPI) {
if err := go_rpio.SpiBegin(go_rpio.Spi0); err != nil {
panic(err)
}
go_rpio.SpiSpeed(25_000_000) // 25 MHz
go_rpio.SpiChipSelect(0)
return &SPI{}
}
func (s *SPI) Tx(w, r []byte) error {
data := make([]byte, len(w))
copy(data, w)
go_rpio.SpiExchange(data)
copy(r, data)
return nil
}
func (s *SPI) Transfer(b byte) (byte, error) {
w := []byte{b}
r := make([]byte, len(w))
err := s.Tx(w, r)
return r[0], err
}