Struct linux_embedded_hal::SpidevBus
source · 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:
- 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. - No other
spidev
device on the same bus may be used as long as thisSpidevBus
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
impl SpidevBus
sourcepub fn open<P>(path: P) -> Result<Self, SPIError>
pub fn open<P>(path: P) -> Result<Self, SPIError>
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>§
sourcepub fn configure(&mut self, options: &SpidevOptions) -> Result<(), Error>
pub fn configure(&mut self, options: &SpidevOptions) -> Result<(), Error>
Write the provided configuration to this device
sourcepub fn transfer(
&self,
transfer: &mut spi_ioc_transfer<'_, '_>
) -> Result<(), Error>
pub fn transfer( &self, transfer: &mut spi_ioc_transfer<'_, '_> ) -> Result<(), Error>
Perform a single transfer
sourcepub fn transfer_multiple(
&self,
transfers: &mut [spi_ioc_transfer<'_, '_>]
) -> Result<(), Error>
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 SpiBus for SpidevBus
impl SpiBus for SpidevBus
source§fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error>
fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error>
words
from the slave. Read moresource§fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>
fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>
words
to the slave, ignoring all the incoming words. Read moresource§fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error>
fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error>
write
is written to the slave on MOSI and
words received on MISO are stored in read
. Read more