mirror of
https://github.com/kidoman/embd
synced 2025-07-03 11:57:38 +02:00
spi: use a initializer if required by any host
This commit is contained in:
parent
faa686f01c
commit
42033238e2
4 changed files with 38 additions and 15 deletions
|
@ -53,24 +53,36 @@ type spiBus struct {
|
|||
|
||||
spiTransferData spiIocTransfer
|
||||
initialized bool
|
||||
|
||||
shouldInitialize bool
|
||||
initializer func() error
|
||||
}
|
||||
|
||||
func spiIocMessageN(n uint32) uint32 {
|
||||
return (spiIocMessage0 + (n * spiIocIncrementor))
|
||||
}
|
||||
|
||||
func NewSPIBus(spiDevMinor, mode, channel byte, speed, bpw, delay int) embd.SPIBus {
|
||||
func NewSPIBus(spiDevMinor, mode, channel byte, speed, bpw, delay int, shouldInitialize bool, i func() error) embd.SPIBus {
|
||||
return &spiBus{
|
||||
spiDevMinor: spiDevMinor,
|
||||
mode: mode,
|
||||
channel: channel,
|
||||
speed: speed,
|
||||
bpw: bpw,
|
||||
delayms: delay,
|
||||
spiDevMinor: spiDevMinor,
|
||||
mode: mode,
|
||||
channel: channel,
|
||||
speed: speed,
|
||||
bpw: bpw,
|
||||
delayms: delay,
|
||||
shouldInitialize: shouldInitialize,
|
||||
initializer: i,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *spiBus) init() error {
|
||||
if b.shouldInitialize {
|
||||
if err := b.initializer(); err != nil {
|
||||
return err
|
||||
}
|
||||
b.shouldInitialize = false
|
||||
}
|
||||
|
||||
if b.initialized {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue