pub struct SpidevBus(pub Spidev);
Expand description

Spidev wrapper providing the embedded-hal SpiBus trait.

Use this struct when you require direct access to the underlying SPI bus, for example when you want to use GPIOs as software-controlled CS (chip-select) pins to share the bus with multiple devices, or because a driver requires the entire bus (for example to drive smart LEDs).

Do not use this struct if you’re accessing SPI devices that already appear in your device tree; you will not be able to drive CS pins that are already used by spidev as GPIOs. Instead use SpidevDevice.

This struct must still be created from a spidev::Spidev device, but there are two important notes:

  1. The CS pin associated with this spidev device will be driven whenever any device accesses this bus, so it should be an unconnected or unused pin.
  2. No other spidev device on the same bus may be used as long as this SpidevBus exists, as Linux will not do anything to ensure this bus has exclusive access.

It is recommended to use a dummy spidev device associated with an unused CS pin, and then use regular GPIOs as CS pins if required. If you are planning to share this bus using GPIOs, the embedded-hal-bus crate may be of interest.

If necessary, you can configure the underlying spidev::Spidev instance with the SPI_NO_CS flag set to prevent any CS pin activity.

Tuple Fields§

§0: Spidev

Implementations§

source§

impl SpidevBus

source

pub fn open<P>(path: P) -> Result<Self, SPIError>
where P: AsRef<Path>,

See spidev::Spidev::open for details.

The provided path must be the only device in use on its bus, and note its own CS pin will be asserted for all device access, so the path should be to a dummy device used only to access the underlying bus.

Methods from Deref<Target = Spidev>§

source

pub fn inner(&self) -> &File

Get a reference to the underlying File object

source

pub fn configure(&mut self, options: &SpidevOptions) -> Result<(), Error>

Write the provided configuration to this device

source

pub fn transfer( &self, transfer: &mut spi_ioc_transfer<'_, '_> ) -> Result<(), Error>

Perform a single transfer

source

pub fn transfer_multiple( &self, transfers: &mut [spi_ioc_transfer<'_, '_>] ) -> Result<(), Error>

Perform multiple transfers in a single system call to the kernel

Chaining together multiple requests like this can reduce latency and be used for conveniently and efficient implementing some protocols without extra round trips back to userspace.

Trait Implementations§

source§

impl Deref for SpidevBus

§

type Target = Spidev

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for SpidevBus

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl ErrorType for SpidevBus

§

type Error = SPIError

Error type.
source§

impl SpiBus for SpidevBus

source§

fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error>

Read words from the slave. Read more
source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Write words to the slave, ignoring all the incoming words. Read more
source§

fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error>

Write and read simultaneously. write is written to the slave on MOSI and words received on MISO are stored in read. Read more
source§

fn transfer_in_place(&mut self, words: &mut [u8]) -> Result<(), Self::Error>

Write and read simultaneously. The contents of words are written to the slave, and the received words are stored into the same words buffer, overwriting it. Read more
source§

fn flush(&mut self) -> Result<(), Self::Error>

Wait until all operations have completed and the bus is idle. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.