RcDevice

Struct RcDevice 

Source
pub struct RcDevice<Bus, Cs, Delay> { /* private fields */ }
Available on crate features std or alloc only.
Expand description

Implementation of SpiDevice around a bus shared with Rc<RefCell<T>>. This is the reference-counting equivalent of RefCellDevice, requiring allocation.

A single SpiBus is shared via RefCell, and its ownership is handled by Rc. Both of these mechanisms only allow sharing within a single thread (or interrupt priority level). For this reason, this does not implement Send.

When this structure is dropped, the reference count of the Bus instance will be decremented, and it will be cleaned up once the reference count reaches zero.

Implementations§

Source§

impl<Bus, Cs, Delay> RcDevice<Bus, Cs, Delay>

Source

pub fn new( bus: Rc<RefCell<Bus>>, cs: Cs, delay: Delay, ) -> Result<Self, Cs::Error>
where Cs: OutputPin,

Available on crate feature alloc only.

Creates a new RcDevice.

This sets the cs pin high, and returns an error if that fails. It is recommended to have already set that pin high the moment it has been configured as an output, to avoid glitches.

This function does not increment the reference count: you will need to call Rc::clone(&bus) if you only have a &Rc<RefCell<Bus>>.

Source§

impl<Bus, Cs> RcDevice<Bus, Cs, NoDelay>

Source

pub fn new_no_delay(bus: Rc<RefCell<Bus>>, cs: Cs) -> Result<Self, Cs::Error>
where Cs: OutputPin,

Available on crate feature alloc only.

Creates a new RcDevice without support for in-transaction delays.

Warning: It’s advised to prefer RcDevice::new, as the contract of SpiDevice requests support for in-transaction delays.

Refer to RefCellDevice::new_no_delay for more information.

Trait Implementations§

Source§

impl<Bus, Cs, Delay> ErrorType for RcDevice<Bus, Cs, Delay>
where Bus: ErrorType, Cs: OutputPin,

Available on crate feature alloc only.
Source§

type Error = DeviceError<<Bus as ErrorType>::Error, <Cs as ErrorType>::Error>

Error type.
Source§

impl<Word, Bus, Cs, Delay> SpiDevice<Word> for RcDevice<Bus, Cs, Delay>
where Word: Copy + 'static, Bus: SpiBus<Word>, Cs: OutputPin, Delay: DelayNs,

Available on crate feature alloc only.
Source§

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

Perform a transaction against the device. Read more
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§

§

impl<Bus, Cs, Delay> Freeze for RcDevice<Bus, Cs, Delay>
where Cs: Freeze, Delay: Freeze,

§

impl<Bus, Cs, Delay> !RefUnwindSafe for RcDevice<Bus, Cs, Delay>

§

impl<Bus, Cs, Delay> !Send for RcDevice<Bus, Cs, Delay>

§

impl<Bus, Cs, Delay> !Sync for RcDevice<Bus, Cs, Delay>

§

impl<Bus, Cs, Delay> Unpin for RcDevice<Bus, Cs, Delay>
where Cs: Unpin, Delay: Unpin,

§

impl<Bus, Cs, Delay> !UnwindSafe for RcDevice<Bus, Cs, Delay>

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

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.