Skip to main content

Twai

Struct Twai 

Source
pub struct Twai<'d, Dm: DriverMode> { /* private fields */ }
Expand description

An active TWAI peripheral in Normal Mode.

In this mode, the TWAI controller can transmit and receive messages including error signals (such as error and overload frames).

Implementations§

Source§

impl Twai<'_, Async>

Source

pub async fn transmit_async( &mut self, frame: &EspTwaiFrame, ) -> Result<(), EspTwaiError>

Transmits an EspTwaiFrame asynchronously over the TWAI bus.

The transmission is aborted if the future is dropped. The technical reference manual does not specifiy if aborting the transmission also stops it, in case it is activly transmitting. Therefor it could be the case that even though the future is dropped, the frame was sent anyways.

If the bus cannot carry the frame (e.g. no other node acknowledges it), the transmission is aborted once the peripheral enters the error-passive or bus-off state and the future resolves to EspTwaiError::TransmissionAborted or EspTwaiError::BusOff, respectively.

Source

pub async fn receive_async(&mut self) -> Result<EspTwaiFrame, EspTwaiError>

Receives an EspTwaiFrame asynchronously over the TWAI bus.

Source§

impl<'d, Dm> Twai<'d, Dm>
where Dm: DriverMode,

Source

pub fn stop(self) -> TwaiConfiguration<'d, Dm>

Stop the peripheral, putting it into reset mode and enabling reconfiguration.

Source

pub fn receive_error_count(&self) -> u8

Returns the value of the receive error counter.

Source

pub fn transmit_error_count(&self) -> u8

Returns the value of the transmit error counter.

Source

pub fn is_bus_off(&self) -> bool

Check if the controller is in a bus off state.

Source

pub fn initiate_recovery(&mut self)

Available on crate feature unstable only.

Initiates recovery from the bus-off state.

The peripheral recovers once it has observed 128 occurrences of 11 consecutive recessive (idle) bits on the bus. Use Self::is_bus_off to poll whether recovery has completed.

Does nothing if the peripheral is not in the bus-off state.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn num_available_messages(&self) -> u8

Get the number of messages that the peripheral has available in the receive FIFO.

Note that this may not be the number of valid messages in the receive FIFO due to fifo overflow/overrun.

Source

pub fn clear_receive_fifo(&self)

Clear the receive FIFO, discarding any valid, partial, or invalid packets.

This is typically used to clear an overrun receive FIFO.

TODO: Not sure if this needs to be guarded against Bus Off or other error states.

Source

pub fn transmit(&mut self, frame: &EspTwaiFrame) -> Result<(), EspTwaiError>

Sends the specified EspTwaiFrame over the TWAI bus.

Source

pub fn receive(&mut self) -> Result<EspTwaiFrame, EspTwaiError>

Receives a TWAI frame from the TWAI bus.

Source

pub fn split(self) -> (TwaiRx<'d, Dm>, TwaiTx<'d, Dm>)

Consumes this Twai instance and splits it into transmitting and receiving halves.

Trait Implementations§

Source§

impl<Dm> Can for Twai<'_, Dm>
where Dm: DriverMode,

Available on crate feature unstable only.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

fn transmit( &mut self, frame: &Self::Frame, ) -> Result<Option<Self::Frame>, Self::Error>

Transmit a frame.

Source§

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

Return a received frame if there are any available.

Source§

type Frame = EspTwaiFrame

Associated frame type.
Source§

type Error = EspTwaiError

Associated error type.

Auto Trait Implementations§

§

impl<'d, Dm> !UnwindSafe for Twai<'d, Dm>

§

impl<'d, Dm> Freeze for Twai<'d, Dm>
where TwaiTx<'d, Dm>: Freeze, TwaiRx<'d, Dm>: Freeze, PhantomData<Dm>: Freeze,

§

impl<'d, Dm> RefUnwindSafe for Twai<'d, Dm>
where TwaiTx<'d, Dm>: RefUnwindSafe, TwaiRx<'d, Dm>: RefUnwindSafe, PhantomData<Dm>: RefUnwindSafe,

§

impl<'d, Dm> Send for Twai<'d, Dm>
where TwaiTx<'d, Dm>: Send, TwaiRx<'d, Dm>: Send, PhantomData<Dm>: Send,

§

impl<'d, Dm> Sync for Twai<'d, Dm>
where TwaiTx<'d, Dm>: Sync, TwaiRx<'d, Dm>: Sync, PhantomData<Dm>: Sync,

§

impl<'d, Dm> Unpin for Twai<'d, Dm>
where TwaiTx<'d, Dm>: Unpin, TwaiRx<'d, Dm>: Unpin, PhantomData<Dm>: Unpin,

§

impl<'d, Dm> UnsafeUnpin for Twai<'d, Dm>
where TwaiTx<'d, Dm>: UnsafeUnpin, TwaiRx<'d, Dm>: UnsafeUnpin, PhantomData<Dm>: UnsafeUnpin,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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.
§

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

Performs the conversion.