Struct Twai

Source
pub struct Twai<'d, Dm: DriverMode> { /* private fields */ }
Available on crate feature unstable only.
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.

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

§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> Freeze for Twai<'d, Dm>

§

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

§

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

§

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

§

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

§

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

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.

§

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.