mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-05-02 22:17:12 +08:00
spi: remove unneeded code as suggested by @maruel
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
parent
026d3000d5
commit
06d26b4102
@ -1,12 +1,8 @@
|
|||||||
package spi
|
package spi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
xspi "periph.io/x/periph/conn/spi"
|
xspi "periph.io/x/periph/conn/spi"
|
||||||
"periph.io/x/periph/conn/spi/spireg"
|
xsysfs "periph.io/x/periph/host/sysfs"
|
||||||
"periph.io/x/periph/host"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -56,6 +52,8 @@ type Connector interface {
|
|||||||
// Provided by an Adaptor by implementing the SPIConnector interface.
|
// Provided by an Adaptor by implementing the SPIConnector interface.
|
||||||
type Connection Operations
|
type Connection Operations
|
||||||
|
|
||||||
|
// SpiConnection is the implementation of the SPI interface using the periph.io
|
||||||
|
// implementataion for Linux.
|
||||||
type SpiConnection struct {
|
type SpiConnection struct {
|
||||||
Connection
|
Connection
|
||||||
port xspi.PortCloser
|
port xspi.PortCloser
|
||||||
@ -84,35 +82,14 @@ func (c *SpiConnection) Tx(w, r []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSpiConnection is a helper to return a SPI device
|
// GetSpiConnection is a helper to return a SPI device
|
||||||
func GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (spiDevice Device, err error) {
|
func GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (Device, error) {
|
||||||
if _, err := host.Init(); err != nil {
|
p, err := xsysfs.NewSPI(busNum, chipNum)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var spiMode xspi.Mode
|
|
||||||
switch mode {
|
|
||||||
case 0:
|
|
||||||
spiMode = xspi.Mode0
|
|
||||||
case 1:
|
|
||||||
spiMode = xspi.Mode1
|
|
||||||
case 2:
|
|
||||||
spiMode = xspi.Mode2
|
|
||||||
case 3:
|
|
||||||
spiMode = xspi.Mode3
|
|
||||||
default:
|
|
||||||
spiMode = xspi.Mode0
|
|
||||||
}
|
|
||||||
devName := fmt.Sprintf("/dev/spidev%d.%d", busNum, chipNum)
|
|
||||||
p, err := spireg.Open(devName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
c, err := p.Connect(maxSpeed, xspi.Mode(mode), bits)
|
||||||
c, err := p.Connect(maxSpeed, spiMode, bits)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
spiDevice = NewConnection(p, c)
|
return NewConnection(p, c), nil
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user