1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-24 13:48:49 +08:00
hybridgroup.gobot/system/spi_access.go
2023-11-15 20:51:52 +01:00

40 lines
743 B
Go

package system
import (
"gobot.io/x/gobot/v2"
)
type periphioSpiAccess struct {
fs filesystem
}
type gpioSpiAccess struct {
cfg spiGpioConfig
}
func (*periphioSpiAccess) createDevice(
busNum, chipNum, mode, bits int,
maxSpeed int64,
) (gobot.SpiSystemDevicer, error) {
return newSpiPeriphIo(busNum, chipNum, mode, bits, maxSpeed)
}
func (psa *periphioSpiAccess) isSupported() bool {
devices, err := psa.fs.find("/dev", "spidev")
if err != nil || len(devices) == 0 {
return false
}
return true
}
func (gsa *gpioSpiAccess) createDevice(
busNum, chipNum, mode, bits int,
maxSpeed int64,
) (gobot.SpiSystemDevicer, error) {
return newSpiGpio(gsa.cfg, maxSpeed)
}
func (gsa *gpioSpiAccess) isSupported() bool {
return true
}