mirror of
https://github.com/kidoman/embd
synced 2024-12-22 12:50:19 +01:00
spi: got rid of shouldInitialize arg in spibus (redundant).
This commit is contained in:
parent
f80e6f624d
commit
454eca42d0
@ -180,7 +180,7 @@ func init() {
|
||||
return embd.NewLEDDriver(ledMap, generic.NewLED)
|
||||
},
|
||||
SPIDriver: func() embd.SPIDriver {
|
||||
return embd.NewSPIDriver(spiDeviceMinor, generic.NewSPIBus, true, spiInitializer)
|
||||
return embd.NewSPIDriver(spiDeviceMinor, generic.NewSPIBus, spiInitializer)
|
||||
},
|
||||
}
|
||||
})
|
||||
|
@ -54,24 +54,22 @@ type spiBus struct {
|
||||
spiTransferData spiIOCTransfer
|
||||
initialized bool
|
||||
|
||||
shouldInitialize bool
|
||||
initializer func() error
|
||||
initializer func() error
|
||||
}
|
||||
|
||||
func spiIOCMessageN(n uint32) uint32 {
|
||||
return (spiIOCMessage0 + (n * spiIOCIncrementor))
|
||||
}
|
||||
|
||||
func NewSPIBus(spiDevMinor, mode, channel byte, speed, bpw, delay int, shouldInitialize bool, i func() error) embd.SPIBus {
|
||||
func NewSPIBus(spiDevMinor, mode, channel byte, speed, bpw, delay int, i func() error) embd.SPIBus {
|
||||
return &spiBus{
|
||||
spiDevMinor: spiDevMinor,
|
||||
mode: mode,
|
||||
channel: channel,
|
||||
speed: speed,
|
||||
bpw: bpw,
|
||||
delayms: delay,
|
||||
shouldInitialize: shouldInitialize,
|
||||
initializer: i,
|
||||
spiDevMinor: spiDevMinor,
|
||||
mode: mode,
|
||||
channel: channel,
|
||||
speed: speed,
|
||||
bpw: bpw,
|
||||
delayms: delay,
|
||||
initializer: i,
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,11 +78,10 @@ func (b *spiBus) init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if b.shouldInitialize {
|
||||
if b.initializer != nil {
|
||||
if err := b.initializer(); err != nil {
|
||||
return err
|
||||
}
|
||||
b.shouldInitialize = false
|
||||
}
|
||||
|
||||
var err error
|
||||
@ -93,20 +90,17 @@ func (b *spiBus) init() error {
|
||||
}
|
||||
glog.V(3).Infof("spi: sucessfully opened file /dev/spidev%v.%v", b.spiDevMinor, b.channel)
|
||||
|
||||
err = b.setMode()
|
||||
if err != nil {
|
||||
if err = b.setMode(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.spiTransferData = spiIOCTransfer{}
|
||||
|
||||
err = b.setSpeed()
|
||||
if err != nil {
|
||||
if err = b.setSpeed(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = b.setBPW()
|
||||
if err != nil {
|
||||
if err = b.setBPW(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ func init() {
|
||||
return embd.NewLEDDriver(ledMap, generic.NewLED)
|
||||
},
|
||||
SPIDriver: func() embd.SPIDriver {
|
||||
return embd.NewSPIDriver(spiDeviceMinor, generic.NewSPIBus, false, nil)
|
||||
return embd.NewSPIDriver(spiDeviceMinor, generic.NewSPIBus, nil)
|
||||
},
|
||||
}
|
||||
})
|
||||
|
18
spidriver.go
18
spidriver.go
@ -2,12 +2,11 @@ package embd
|
||||
|
||||
import "sync"
|
||||
|
||||
type spiBusFactory func(byte, byte, byte, int, int, int, bool, func() error) SPIBus
|
||||
type spiBusFactory func(byte, byte, byte, int, int, int, func() error) SPIBus
|
||||
|
||||
type spiDriver struct {
|
||||
spiDevMinor byte
|
||||
shouldInitialize bool
|
||||
initializer func() error
|
||||
spiDevMinor byte
|
||||
initializer func() error
|
||||
|
||||
busMap map[byte]SPIBus
|
||||
busMapLock sync.Mutex
|
||||
@ -15,12 +14,11 @@ type spiDriver struct {
|
||||
sbf spiBusFactory
|
||||
}
|
||||
|
||||
func NewSPIDriver(spiDevMinor byte, sbf spiBusFactory, shouldInitialize bool, i func() error) SPIDriver {
|
||||
func NewSPIDriver(spiDevMinor byte, sbf spiBusFactory, i func() error) SPIDriver {
|
||||
return &spiDriver{
|
||||
spiDevMinor: spiDevMinor,
|
||||
sbf: sbf,
|
||||
shouldInitialize: shouldInitialize,
|
||||
initializer: i,
|
||||
spiDevMinor: spiDevMinor,
|
||||
sbf: sbf,
|
||||
initializer: i,
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +26,7 @@ func (s *spiDriver) Bus(mode, channel byte, speed, bpw, delay int) SPIBus {
|
||||
s.busMapLock.Lock()
|
||||
defer s.busMapLock.Unlock()
|
||||
|
||||
b := s.sbf(s.spiDevMinor, mode, channel, speed, bpw, delay, s.shouldInitialize, s.initializer)
|
||||
b := s.sbf(s.spiDevMinor, mode, channel, speed, bpw, delay, s.initializer)
|
||||
s.busMap = make(map[byte]SPIBus)
|
||||
s.busMap[channel] = b
|
||||
return b
|
||||
|
Loading…
x
Reference in New Issue
Block a user