2022-12-17 18:56:11 +08:00
|
|
|
package spi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/system"
|
2022-12-17 18:56:11 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// make sure that this SpiBusAdaptor fulfills all the required interfaces
|
|
|
|
var _ Connector = (*spiTestAdaptor)(nil)
|
|
|
|
var _ gobot.Connection = (*spiTestAdaptor)(nil)
|
|
|
|
|
|
|
|
type spiTestAdaptor struct {
|
|
|
|
sys *system.Accesser
|
|
|
|
//busNum int
|
|
|
|
spiConnectErr bool
|
|
|
|
spi *system.MockSpiAccess
|
|
|
|
connection Connection
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSpiTestAdaptor() *spiTestAdaptor {
|
|
|
|
sys := system.NewAccesser()
|
|
|
|
spi := sys.UseMockSpi()
|
|
|
|
a := &spiTestAdaptor{
|
|
|
|
sys: sys,
|
|
|
|
spi: spi,
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
// spi.Connector interfaces
|
|
|
|
func (a *spiTestAdaptor) GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (Connection, error) {
|
|
|
|
if a.spiConnectErr {
|
|
|
|
return nil, fmt.Errorf("Invalid SPI connection in helper")
|
|
|
|
}
|
|
|
|
//a.busNum = busNum
|
2023-01-06 02:04:32 +08:00
|
|
|
sysdev, err := a.sys.NewSpiDevice(busNum, chipNum, mode, bits, maxSpeed)
|
|
|
|
a.connection = NewConnection(sysdev)
|
|
|
|
return a.connection, err
|
2022-12-17 18:56:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *spiTestAdaptor) SpiDefaultBusNumber() int { return 0 }
|
|
|
|
func (a *spiTestAdaptor) SpiDefaultChipNumber() int { return 0 }
|
|
|
|
func (a *spiTestAdaptor) SpiDefaultMode() int { return 0 }
|
|
|
|
func (a *spiTestAdaptor) SpiDefaultBitCount() int { return 0 }
|
|
|
|
func (a *spiTestAdaptor) SpiDefaultMaxSpeed() int64 { return 0 }
|
|
|
|
|
|
|
|
// gobot.Connection interfaces
|
|
|
|
func (a *spiTestAdaptor) Connect() error { return nil }
|
|
|
|
func (a *spiTestAdaptor) Finalize() error { return nil }
|
|
|
|
func (a *spiTestAdaptor) Name() string { return "board name" }
|
2023-05-19 20:16:22 +08:00
|
|
|
func (a *spiTestAdaptor) SetName(string) {}
|