Struct embassy_stm32::can::Can

source ·
pub struct Can<'d, T: Instance> { /* private fields */ }
Expand description

CAN driver

Implementations§

source§

impl<'d, T: Instance> Can<'d, T>

source

pub fn new( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, tx: impl Peripheral<P = impl TxPin<T>> + 'd, _irqs: impl Binding<T::TXInterrupt, TxInterruptHandler<T>> + Binding<T::RX0Interrupt, Rx0InterruptHandler<T>> + Binding<T::RX1Interrupt, Rx1InterruptHandler<T>> + Binding<T::SCEInterrupt, SceInterruptHandler<T>> + 'd ) -> Self

Creates a new Bxcan instance, keeping the peripheral in sleep mode. You must call [Can::enable_non_blocking] to use the peripheral.

source

pub fn set_bitrate(&mut self, bitrate: u32)

Set CAN bit rate.

source

pub async fn enable(&mut self)

Enables the peripheral and synchronizes with the bus.

This will wait for 11 consecutive recessive bits (bus idle state). Contrary to enable method from bxcan library, this will not freeze the executor while waiting.

source

pub async fn write(&mut self, frame: &Frame) -> TransmitStatus

Queues the message to be sent.

If the TX queue is full, this will wait until there is space, therefore exerting backpressure.

source

pub fn try_write( &mut self, frame: &Frame ) -> Result<TransmitStatus, TryWriteError>

Attempts to transmit a frame without blocking.

Returns [Err(TryWriteError::Full)] if all transmit mailboxes are full.

source

pub async fn flush(&self, mb: Mailbox)

Waits for a specific transmit mailbox to become empty

source

pub async fn flush_any(&self)

Waits until any of the transmit mailboxes become empty

source

pub async fn flush_all(&self)

Waits until all of the transmit mailboxes become empty

source

pub async fn read(&mut self) -> Result<Envelope, BusError>

Read a CAN frame.

If no CAN frame is in the RX buffer, this will wait until there is one.

Returns a tuple of the time the message was received and the message frame

source

pub fn try_read(&mut self) -> Result<Envelope, TryReadError>

Attempts to read a CAN frame without blocking.

Returns [Err(TryReadError::Empty)] if there are no frames in the rx queue.

source

pub async fn wait_not_empty(&mut self)

Waits while receive queue is empty.

source

pub fn split<'c>(&'c mut self) -> (CanTx<'c, 'd, T>, CanRx<'c, 'd, T>)

Split the CAN driver into transmit and receive halves.

Useful for doing separate transmit/receive tasks.

Methods from Deref<Target = Can<BxcanInstance<'d, T>>>§

source

pub fn instance(&mut self) -> &mut I

Returns a reference to the peripheral instance.

This allows accessing HAL-specific data stored in the instance type.

source

pub fn modify_config(&mut self) -> CanConfig<'_, I>

Configure bit timings and silent/loop-back mode.

Calling this method will enter initialization mode.

source

pub fn set_automatic_wakeup(&mut self, enabled: bool)

Configures the automatic wake-up feature.

This is turned off by default.

When turned on, an incoming frame will cause the peripheral to wake up from sleep and receive the frame. If enabled, Interrupt::Wakeup will also be triggered by the incoming frame.

source

pub fn enable_non_blocking(&mut self) -> Result<(), Error<Infallible>>

Leaves initialization mode and enables the peripheral (non-blocking version).

Usually, it is recommended to call CanConfig::enable instead. This method is only needed if you want non-blocking initialization.

If this returns WouldBlock, the peripheral will enable itself in the background. The peripheral is enabled and ready to use when this method returns successfully.

source

pub fn sleep(&mut self)

Puts the peripheral in a sleep mode to save power.

While in sleep mode, an incoming CAN frame will trigger Interrupt::Wakeup if enabled.

source

pub fn wakeup(&mut self)

Wakes up from sleep mode.

Note that this will not trigger Interrupt::Wakeup, only reception of an incoming CAN frame will cause that interrupt.

source

pub fn enable_interrupt(&mut self, interrupt: Interrupt)

Starts listening for a CAN interrupt.

source

pub fn enable_interrupts(&mut self, interrupts: Interrupts)

Starts listening for a set of CAN interrupts.

source

pub fn disable_interrupt(&mut self, interrupt: Interrupt)

Stops listening for a CAN interrupt.

source

pub fn disable_interrupts(&mut self, interrupts: Interrupts)

Stops listening for a set of CAN interrupts.

source

pub fn clear_sleep_interrupt(&self)

Clears the pending flag of Interrupt::Sleep.

source

pub fn clear_wakeup_interrupt(&self)

Clears the pending flag of Interrupt::Wakeup.

source

pub fn clear_request_completed_flag(&mut self) -> Option<Mailbox>

Clears the “Request Completed” (RQCP) flag of a transmit mailbox.

Returns the Mailbox whose flag was cleared. If no mailbox has the flag set, returns None.

Once this function returns None, a pending Interrupt::TransmitMailboxEmpty is considered acknowledged.

source

pub fn clear_tx_interrupt(&mut self)

Clears a pending TX interrupt (Interrupt::TransmitMailboxEmpty).

This does not return the mailboxes that have finished tranmission. If you need that information, call Can::clear_request_completed_flag instead.

source

pub fn transmit( &mut self, frame: &Frame ) -> Result<TransmitStatus, Error<Infallible>>

Puts a CAN frame in a free transmit mailbox for transmission on the bus.

Frames are transmitted to the bus based on their priority (see FramePriority). Transmit order is preserved for frames with identical priority.

If all transmit mailboxes are full, and frame has a higher priority than the lowest-priority message in the transmit mailboxes, transmission of the enqueued frame is cancelled and frame is enqueued instead. The frame that was replaced is returned as TransmitStatus::dequeued_frame.

source

pub fn is_transmitter_idle(&self) -> bool

Returns true if no frame is pending for transmission.

source

pub fn abort(&mut self, mailbox: Mailbox) -> bool

Attempts to abort the sending of a frame that is pending in a mailbox.

If there is no frame in the provided mailbox, or its transmission succeeds before it can be aborted, this function has no effect and returns false.

If there is a frame in the provided mailbox, and it is canceled successfully, this function returns true.

source

pub fn receive(&mut self) -> Result<Frame, Error<OverrunError>>

Returns a received frame if available.

This will first check FIFO 0 for a message or error. If none are available, FIFO 1 is checked.

Returns Err when a frame was lost due to buffer overrun.

source

pub fn rx0(&mut self) -> &mut Rx0<I>

Returns a reference to the RX FIFO 0.

source

pub fn rx1(&mut self) -> &mut Rx1<I>

Returns a reference to the RX FIFO 1.

source

pub fn split_by_ref(&mut self) -> (&mut Tx<I>, &mut Rx0<I>, &mut Rx1<I>)

Splits this Can instance into transmitting and receiving halves, by reference.

source

pub fn modify_filters(&mut self) -> MasterFilters<'_, I>

Accesses the filter banks owned by this CAN peripheral.

To modify filters of a slave peripheral, modify_filters has to be called on the master peripheral instead.

Trait Implementations§

source§

impl<'d, T: Instance> AsMut<Can<BxcanInstance<'d, T>>> for Can<'d, T>

source§

fn as_mut(&mut self) -> &mut Can<BxcanInstance<'d, T>>

Get mutable access to the lower-level driver from the bxcan crate.

source§

impl<'d, T: Instance> Deref for Can<'d, T>

§

type Target = Can<BxcanInstance<'d, T>>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'d, T: Instance> DerefMut for Can<'d, T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'d, T: Instance> Drop for Can<'d, T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'d, T> Freeze for Can<'d, T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<'d, T> !UnwindSafe for Can<'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.