Struct esp32_hal::twai::Twai

source ·
pub struct Twai<'d, T> { /* 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<'d, T> Twai<'d, T>
where T: Instance,

source

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

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

source

pub fn receive_error_count(&self) -> u8

source

pub fn transmit_error_count(&self) -> u8

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.

Trait Implementations§

source§

impl<T> Can for Twai<'_, T>
where T: Instance,

source§

fn transmit( &mut self, frame: &<Twai<'_, T> as Can>::Frame ) -> Result<Option<<Twai<'_, T> as Can>::Frame>, Error<<Twai<'_, T> as Can>::Error>>

Transmit a frame.

Because of how the TWAI registers are set up, we have to do some assembly of bytes. Note that these registers serve a filter configuration role when the device is in configuration mode so patching the svd files to improve this may be non-trivial.

ESP32C3 Reference Manual

NOTE: TODO: This may not work if using the self reception/self test functionality. See notes 1 and 2 in the “Frame Identifier” section of the reference manual.

source§

fn receive( &mut self ) -> Result<<Twai<'_, T> as Can>::Frame, Error<<Twai<'_, T> as Can>::Error>>

Return a received frame if there are any available.

§

type Frame = EspTwaiFrame

Associated frame type.
§

type Error = EspTwaiError

Associated error type.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

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.