Skip to main content

SpidevBus

Struct SpidevBus 

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§

§

impl SpidevBus

pub fn open<P>(path: P) -> Result<SpidevBus, 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>§

pub fn inner(&self) -> &File

Get a reference to the underlying File object

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

Write the provided configuration to this device

pub fn query_configuration(&self) -> Result<SpidevOptions, Error>

Read the current configuration from this device

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

Perform a single transfer

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§

§

impl Deref for SpidevBus

§

type Target = Spidev

The resulting type after dereferencing.
§

fn deref(&self) -> &<SpidevBus as Deref>::Target

Dereferences the value.
§

impl DerefMut for SpidevBus

§

fn deref_mut(&mut self) -> &mut <SpidevBus as Deref>::Target

Mutably dereferences the value.
§

impl ErrorType for SpidevBus

§

type Error = SPIError

Error type.
§

impl SpiBus for SpidevBus

§

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

Read words from the slave. Read more
§

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

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

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

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

fn transfer_in_place( &mut self, words: &mut [u8], ) -> Result<(), <SpidevBus as ErrorType>::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
§

fn flush(&mut self) -> Result<(), <SpidevBus as ErrorType>::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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

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>,

Source§

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.