pub struct SpidevDevice(pub Spidev);
Expand description

Spidev wrapper providing the embedded-hal SpiDevice trait.

Use this struct when you want a single spidev device, using a Linux-managed CS (chip-select) pin, which is already defined in your device tree. Linux will handle sharing the bus between different SPI devices, even between different processes.

You get an object that implements SpiDevice, which is what most drivers require, but does not implement SpiBus. In some rare cases, you may require SpiBus instead; for that refer to SpidevBus below. You may also want to use SpiBus if you want to handle all the CS pins yourself using GPIO.

This struct wraps a spidev::Spidev struct, so it can be constructed directly and the inner struct accessed if needed, for example to (re)configure the SPI settings.

Note that delay operations on this device are capped to 65535 microseconds.

Tuple Fields§

§0: Spidev

Implementations§

source§

impl SpidevDevice

source

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

See spidev::Spidev::open for details.

The provided path is for the specific device you wish to access. Access to the bus is shared with other devices via the Linux kernel.

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 SpidevDevice

§

type Target = Spidev

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl DerefMut for SpidevDevice

source§

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

Mutably dereferences the value.
source§

impl ErrorType for SpidevDevice

§

type Error = SPIError

Error type.
source§

impl SpiDevice for SpidevDevice

source§

fn transaction( &mut self, operations: &mut [SpiOperation<'_, u8>] ) -> Result<(), Self::Error>

Perform a transaction against the device. Read more

Delay operations are capped to 65535 microseconds.

source§

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

Do a read within a transaction. Read more
source§

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

Do a write within a transaction. Read more
source§

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

Do a transfer within a transaction. Read more
source§

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

Do an in-place transfer within a transaction. 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.