spidev

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2022 License: BSD-3-Clause Imports: 7 Imported by: 4

Documentation

Overview

Package spidev wraps the Linux spidev driver and performs low-level SPI operations.

Index

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

func Open(dev string) (*SPI, error)

Open opens a new SPI device. dev is a filename such as "/dev/spidev0.0". Remember to call Close() once done.

func (*SPI) BitsPerWord

func (s *SPI) BitsPerWord() (uint8, error)

BitsPerWord sets the number of bits per word. Myy understanding is this is only useful if there is a word delay.

func (*SPI) Close

func (s *SPI) Close() error

Close closes the SPI device.

func (*SPI) Mode

func (s *SPI) Mode() (Mode, error)

Mode returns the Mode bitset.

func (*SPI) SetBitsPerWord

func (s *SPI) SetBitsPerWord(bpw uint8) error

SetBitsPerWord sets the number of bits per word.

func (*SPI) SetMode

func (s *SPI) SetMode(m Mode) error

SetMode sets the Mode bitset.

func (*SPI) SetSpeedHz

func (s *SPI) SetSpeedHz(hz uint32) error

SetSpeedHz sets the transfer speed.

func (*SPI) SpeedHz

func (s *SPI) SpeedHz() (uint32, error)

SpeedHz gets the transfer speed.

func (*SPI) Transfer

func (s *SPI) Transfer(transfers []Transfer) error

Transfer performs multiple SPI reads and/or writes in a single function. See the Transfer struct for details.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL