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>
impl<'d, T: Instance> Can<'d, T>
sourcepub 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
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.
sourcepub fn set_bitrate(&mut self, bitrate: u32)
pub fn set_bitrate(&mut self, bitrate: u32)
Set CAN bit rate.
sourcepub async fn enable(&mut self)
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.
sourcepub async fn write(&mut self, frame: &Frame) -> TransmitStatus
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.
sourcepub fn try_write(
&mut self,
frame: &Frame
) -> Result<TransmitStatus, TryWriteError>
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.
sourcepub async fn read(&mut self) -> Result<Envelope, BusError>
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
sourcepub fn try_read(&mut self) -> Result<Envelope, TryReadError>
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.
sourcepub async fn wait_not_empty(&mut self)
pub async fn wait_not_empty(&mut self)
Waits while receive queue is empty.
Methods from Deref<Target = Can<BxcanInstance<'d, T>>>§
sourcepub fn instance(&mut self) -> &mut I
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.
sourcepub fn modify_config(&mut self) -> CanConfig<'_, I>
pub fn modify_config(&mut self) -> CanConfig<'_, I>
Configure bit timings and silent/loop-back mode.
Calling this method will enter initialization mode.
sourcepub fn set_automatic_wakeup(&mut self, enabled: bool)
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.
sourcepub fn enable_non_blocking(&mut self) -> Result<(), Error<Infallible>>
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.
sourcepub fn sleep(&mut self)
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.
sourcepub fn wakeup(&mut self)
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.
sourcepub fn enable_interrupt(&mut self, interrupt: Interrupt)
pub fn enable_interrupt(&mut self, interrupt: Interrupt)
Starts listening for a CAN interrupt.
sourcepub fn enable_interrupts(&mut self, interrupts: Interrupts)
pub fn enable_interrupts(&mut self, interrupts: Interrupts)
Starts listening for a set of CAN interrupts.
sourcepub fn disable_interrupt(&mut self, interrupt: Interrupt)
pub fn disable_interrupt(&mut self, interrupt: Interrupt)
Stops listening for a CAN interrupt.
sourcepub fn disable_interrupts(&mut self, interrupts: Interrupts)
pub fn disable_interrupts(&mut self, interrupts: Interrupts)
Stops listening for a set of CAN interrupts.
sourcepub fn clear_sleep_interrupt(&self)
pub fn clear_sleep_interrupt(&self)
Clears the pending flag of Interrupt::Sleep
.
sourcepub fn clear_wakeup_interrupt(&self)
pub fn clear_wakeup_interrupt(&self)
Clears the pending flag of Interrupt::Wakeup
.
sourcepub fn clear_request_completed_flag(&mut self) -> Option<Mailbox>
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.
sourcepub fn clear_tx_interrupt(&mut self)
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.
sourcepub fn transmit(
&mut self,
frame: &Frame
) -> Result<TransmitStatus, Error<Infallible>>
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
.
sourcepub fn is_transmitter_idle(&self) -> bool
pub fn is_transmitter_idle(&self) -> bool
Returns true
if no frame is pending for transmission.
sourcepub fn abort(&mut self, mailbox: Mailbox) -> bool
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
.
sourcepub fn receive(&mut self) -> Result<Frame, Error<OverrunError>>
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.
sourcepub fn split_by_ref(&mut self) -> (&mut Tx<I>, &mut Rx0<I>, &mut Rx1<I>)
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.
sourcepub fn modify_filters(&mut self) -> MasterFilters<'_, I>
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>
impl<'d, T: Instance> AsMut<Can<BxcanInstance<'d, T>>> for Can<'d, T>
source§fn as_mut(&mut self) -> &mut Can<BxcanInstance<'d, T>>
fn as_mut(&mut self) -> &mut Can<BxcanInstance<'d, T>>
Get mutable access to the lower-level driver from the bxcan
crate.