mirror of
https://github.com/kidoman/embd
synced 2025-01-08 20:54:27 +01:00
spi: added godoc
This commit is contained in:
parent
dbc97bd15c
commit
c42a345a60
20
spi.go
20
spi.go
@ -1,27 +1,44 @@
|
|||||||
|
// SPI support.
|
||||||
|
|
||||||
package embd
|
package embd
|
||||||
|
|
||||||
const (
|
const (
|
||||||
spiCpha = 0x01
|
spiCpha = 0x01
|
||||||
spiCpol = 0x02
|
spiCpol = 0x02
|
||||||
|
|
||||||
|
// SpiMode0 represents the mode0 operation (CPOL=0 CPHA=0) of spi.
|
||||||
SpiMode0 = (0 | 0)
|
SpiMode0 = (0 | 0)
|
||||||
|
|
||||||
|
// SpiMode0 represents the mode0 operation (CPOL=0 CPHA=1) of spi.
|
||||||
SpiMode1 = (0 | spiCpha)
|
SpiMode1 = (0 | spiCpha)
|
||||||
|
|
||||||
|
// SpiMode0 represents the mode0 operation (CPOL=1 CPHA=0) of spi.
|
||||||
SpiMode2 = (spiCpol | 0)
|
SpiMode2 = (spiCpol | 0)
|
||||||
|
|
||||||
|
// SpiMode0 represents the mode0 operation (CPOL=1 CPHA=1) of spi.
|
||||||
SpiMode3 = (spiCpol | spiCpha)
|
SpiMode3 = (spiCpol | spiCpha)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SPI interface allows interaction with the SPI bus.
|
||||||
type SPIBus interface {
|
type SPIBus interface {
|
||||||
|
// TransferAndRecieveData transmits data in a buffer(slice) and receives into it.
|
||||||
TransferAndRecieveData(dataBuffer []uint8) error
|
TransferAndRecieveData(dataBuffer []uint8) error
|
||||||
|
|
||||||
|
// ReceiveData receives data of length len into a slice.
|
||||||
ReceiveData(len int) ([]uint8, error)
|
ReceiveData(len int) ([]uint8, error)
|
||||||
|
|
||||||
|
// TransferAndReceiveByte transmits a byte data and receives a byte.
|
||||||
TransferAndReceiveByte(data byte) (byte, error)
|
TransferAndReceiveByte(data byte) (byte, error)
|
||||||
|
|
||||||
|
// ReceiveByte receives a byte data.
|
||||||
ReceiveByte() (byte, error)
|
ReceiveByte() (byte, error)
|
||||||
|
|
||||||
|
// Close releases the resources associated with the bus.
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SPIDriver interface interacts with the host descriptors to allow us
|
||||||
|
// control of SPI communication.
|
||||||
type SPIDriver interface {
|
type SPIDriver interface {
|
||||||
Bus(byte, byte, int, int, int) SPIBus
|
Bus(byte, byte, int, int, int) SPIBus
|
||||||
|
|
||||||
@ -31,6 +48,7 @@ type SPIDriver interface {
|
|||||||
var spiDriverInitialized bool
|
var spiDriverInitialized bool
|
||||||
var spiDriverInstance SPIDriver
|
var spiDriverInstance SPIDriver
|
||||||
|
|
||||||
|
// InitSPI initializes the SPI driver.
|
||||||
func InitSPI() error {
|
func InitSPI() error {
|
||||||
if spiDriverInitialized {
|
if spiDriverInitialized {
|
||||||
return nil
|
return nil
|
||||||
@ -51,10 +69,12 @@ func InitSPI() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseSPI releases resources associated with the SPI driver.
|
||||||
func CloseSPI() error {
|
func CloseSPI() error {
|
||||||
return spiDriverInstance.Close()
|
return spiDriverInstance.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSPIBus returns a SPIBus.
|
||||||
func NewSPIBus(mode, channel byte, speed, bpw, delay int) SPIBus {
|
func NewSPIBus(mode, channel byte, speed, bpw, delay int) SPIBus {
|
||||||
if err := InitSPI(); err != nil {
|
if err := InitSPI(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user