pub struct Twai<'d, Dm: DriverMode> { /* private fields */ }
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>
impl Twai<'_, Async>
Sourcepub async fn transmit_async(
&mut self,
frame: &EspTwaiFrame,
) -> Result<(), EspTwaiError>
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.
Sourcepub async fn receive_async(&mut self) -> Result<EspTwaiFrame, EspTwaiError>
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,
impl<'d, Dm> Twai<'d, Dm>where
Dm: DriverMode,
Sourcepub fn stop(self) -> TwaiConfiguration<'d, Dm>
pub fn stop(self) -> TwaiConfiguration<'d, Dm>
Stop the peripheral, putting it into reset mode and enabling reconfiguration.
Sourcepub fn receive_error_count(&self) -> u8
pub fn receive_error_count(&self) -> u8
Returns the value of the receive error counter.
Sourcepub fn transmit_error_count(&self) -> u8
pub fn transmit_error_count(&self) -> u8
Returns the value of the transmit error counter.
Sourcepub fn is_bus_off(&self) -> bool
pub fn is_bus_off(&self) -> bool
Check if the controller is in a bus off state.
Sourcepub fn num_available_messages(&self) -> u8
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.
Sourcepub fn clear_receive_fifo(&self)
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.
Sourcepub fn transmit(&mut self, frame: &EspTwaiFrame) -> Result<(), EspTwaiError>
pub fn transmit(&mut self, frame: &EspTwaiFrame) -> Result<(), EspTwaiError>
Sends the specified EspTwaiFrame
over the TWAI bus.
Sourcepub fn receive(&mut self) -> Result<EspTwaiFrame, EspTwaiError>
pub fn receive(&mut self) -> Result<EspTwaiFrame, EspTwaiError>
Receives a TWAI frame from the TWAI bus.
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.
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>
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>
fn receive(&mut self) -> Result<Self::Frame, Self::Error>
Return a received frame if there are any available.