1
0
Fork 0
mirror of https://github.com/kidoman/embd synced 2025-07-03 03:47:33 +02:00

spi: use a initializer if required by any host

This commit is contained in:
kunalpowar 2014-05-01 22:44:41 +05:30
parent faa686f01c
commit 42033238e2
4 changed files with 38 additions and 15 deletions

View file

@ -2,10 +2,12 @@ package embd
import "sync"
type spiBusFactory func(byte, byte, byte, int, int, int) SPIBus
type spiBusFactory func(byte, byte, byte, int, int, int, bool, func() error) SPIBus
type spiDriver struct {
spiDevMinor byte
spiDevMinor byte
shouldInitialize bool
initializer func() error
busMap map[byte]SPIBus
busMapLock sync.Mutex
@ -13,10 +15,12 @@ type spiDriver struct {
sbf spiBusFactory
}
func NewSPIDriver(spiDevMinor byte, sbf spiBusFactory) SPIDriver {
func NewSPIDriver(spiDevMinor byte, sbf spiBusFactory, shouldInitialize bool, i func() error) SPIDriver {
return &spiDriver{
spiDevMinor: spiDevMinor,
sbf: sbf,
spiDevMinor: spiDevMinor,
sbf: sbf,
shouldInitialize: shouldInitialize,
initializer: i,
}
}
@ -24,7 +28,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)
b := s.sbf(s.spiDevMinor, mode, channel, speed, bpw, delay, s.shouldInitialize, s.initializer)
s.busMap[channel] = b
return b
}