2022-12-17 18:56:11 +08:00
|
|
|
package system
|
|
|
|
|
2023-01-06 02:04:32 +08:00
|
|
|
import (
|
|
|
|
"gobot.io/x/gobot"
|
|
|
|
)
|
2022-12-17 18:56:11 +08:00
|
|
|
|
2023-01-06 02:04:32 +08:00
|
|
|
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)
|
|
|
|
}
|
2022-12-17 18:56:11 +08:00
|
|
|
|
2023-01-06 02:04:32 +08:00
|
|
|
func (gsa *gpioSpiAccess) isSupported() bool {
|
|
|
|
return true
|
2022-12-17 18:56:11 +08:00
|
|
|
}
|