Documentation ¶
Overview ¶
Package spidev wraps the Linux spidev driver and performs low-level SPI operations.
Index ¶
- type ErrBufferMismatch
- type ErrRxOverflow
- type ErrTxOverflow
- type Mode
- type SPI
- func (s *SPI) BitsPerWord() (uint8, error)
- func (s *SPI) Close() error
- func (s *SPI) Mode() (Mode, error)
- func (s *SPI) SetBitsPerWord(bpw uint8) error
- func (s *SPI) SetMode(m Mode) error
- func (s *SPI) SetSpeedHz(hz uint32) error
- func (s *SPI) SpeedHz() (uint32, error)
- func (s *SPI) Transfer(transfers []Transfer) error
- type Transfer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrBufferMismatch ¶
type ErrBufferMismatch struct {
TxLen, RxLen int
}
ErrBufferMismatch is returned if the rx and tx buffers do not have equal length.
func (ErrBufferMismatch) Error ¶
func (e ErrBufferMismatch) Error() string
Error implements the error interface.
type ErrRxOverflow ¶
type ErrRxOverflow struct {
RxLen, RxMax int
}
ErrRxOverflow is returned if the Transfer buffer is too large.
func (ErrRxOverflow) Error ¶
func (e ErrRxOverflow) Error() string
Error implements the error interface.
type ErrTxOverflow ¶
type ErrTxOverflow struct {
TxLen, TxMax int
}
ErrTxOverflow is returned if the Transfer buffer is too large.
func (ErrTxOverflow) Error ¶
func (e ErrTxOverflow) Error() string
Error implements the error interface.
type Mode ¶
type Mode uint32
Mode is a bitset of the current SPI mode bits.
const ( // CPHA determines clock phase sampling (1=trailing edge). CPHA Mode = 1 << iota // CPOL determines clock polarity (1=idle high). CPOL // CS_HIGH determines chip select polarity (1=idle high). CS_HIGH // LSB_FIRST determines whether least significant bit comes first in a // word (1=LSB first). LSB_FIRST // THREE_WIRE determines whether the bus operates in three wire mode // (1=three wire). THREE_WIRE // LOOP determines whether the device should loop (1=loop enabled). LOOP // NO_CS determines whether to disable chip select (1=no chip select). NO_CS // READY determins ready mode bit. READY // TX_DUAL determines whether to transmit in dual mode. TX_DUAL // TX_QUAD determines whether to transmit in quad mode. TX_QUAD // RX_DUAL determines whether to receive in dual mode. RX_DUAL // RX_QUAD determines whether to receive in quad mode. RX_QUAD )
type SPI ¶
type SPI struct {
// contains filtered or unexported fields
}
SPI wraps the Linux device driver and provides low-level SPI operations.
func Open ¶
Open opens a new SPI device. dev is a filename such as "/dev/spidev0.0". Remember to call Close() once done.
func (*SPI) BitsPerWord ¶
BitsPerWord sets the number of bits per word. Myy understanding is this is only useful if there is a word delay.
func (*SPI) SetBitsPerWord ¶
SetBitsPerWord sets the number of bits per word.
func (*SPI) SetSpeedHz ¶
SetSpeedHz sets the transfer speed.
type Transfer ¶
type Transfer struct { // Tx contains a slice sent over the SPI bus. Tx []byte // Rx contains a slice received from the SPI bus. Rx []byte // SpeedHz sets speed in Hz (optional). SpeedHz uint32 // DelayUSecs is how long to delay before the next transfer (optional). DelayUSecs uint16 // BitsPerWord is the device's wordsize (optional). BitsPerWord uint8 // CSChange controls whether the CS (Chip Select) signal will be // de-asserted at the end of the transfer. CSChange bool // TxNbits controls single, dual or quad mode (optional). TxNBits uint8 // RxNbits controls single, dual or quad mode (optional). RxNBits uint8 // WordDelayUSecs is the delay between words (optional). WordDelayUSecs uint8 }
Transfer is the data and options for a single SPI transfer. Note that a SPI transfer is full-duplex meaning data is shifted out of Tx and shifted into Rx on the same clock cycle.