pub struct Can<'d> { /* private fields */ }
Expand description
CAN driver
Implementations§
source§impl<'d> Can<'d>
impl<'d> Can<'d>
sourcepub fn new<T: Instance>(
_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<T: Instance>( _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 fn modify_config(&mut self) -> CanConfig<'_>
pub fn modify_config(&mut self) -> CanConfig<'_>
Configure bit timings and silent/loop-back mode.
Calling this method will enter initialization mode. You must enable the peripheral
again afterwards with enable
.
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 fn set_automatic_wakeup(&mut self, enabled: bool)
pub fn set_automatic_wakeup(&mut self, enabled: bool)
Enables or disables the peripheral from automatically wakeup when a SOF is detected on the bus while the peripheral is in sleep mode
sourcepub fn wakeup(&mut self)
pub fn wakeup(&mut self)
Manually wake the peripheral from sleep mode.
Waking the peripheral manually does not trigger a wake-up interrupt. This will wait until the peripheral has acknowledged it has awoken from sleep mode
sourcepub fn is_sleeping(&self) -> bool
pub fn is_sleeping(&self) -> bool
Check if the peripheral is currently in sleep mode
sourcepub async fn sleep(&mut self)
pub async fn sleep(&mut self)
Put the peripheral in sleep mode
When the peripherial is in sleep mode, messages can still be queued for transmission and any previously received messages can be read from the receive FIFOs, however no messages will be transmitted and no additional messages will be received.
If the peripheral has automatic wakeup enabled, when a Start-of-Frame is detected the peripheral will automatically wake and receive the incoming message.
sourcepub fn set_tx_fifo_scheduling(&mut self, enabled: bool)
pub fn set_tx_fifo_scheduling(&mut self, enabled: bool)
Enable FIFO scheduling of outgoing frames.
If this is enabled, frames will be transmitted in the order that they are passed to
write()
or try_write()
.
If this is disabled, frames are transmitted in order of priority.
FIFO scheduling is disabled by default.
sourcepub fn tx_fifo_scheduling_enabled(&self) -> bool
pub fn tx_fifo_scheduling_enabled(&self) -> bool
Checks if FIFO scheduling of outgoing frames is enabled.
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 the frame can not be queued for transmission now.
If FIFO scheduling is enabled, any empty mailbox will be used.
Otherwise, the frame will only be accepted if there is no frame with the same priority already queued. This is done to work around a hardware limitation that could lead to out-of-order delivery of frames with the same priority.
sourcepub async fn flush_any(&self)
pub async fn flush_any(&self)
Waits until any of the transmit mailboxes become empty
Note that Self::try_write()
may fail with TryWriteError::Full
,
even after the future returned by this function completes.
This will happen if FIFO scheduling of outgoing frames is not enabled,
and a frame with equal priority is already queued 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 is_transmitter_idle(&self) -> bool
pub fn is_transmitter_idle(&self) -> bool
Returns true
if no frame is pending for transmission.
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.
source§impl<'d> Can<'d>
impl<'d> Can<'d>
sourcepub fn modify_filters(&mut self) -> MasterFilters<'_>
pub fn modify_filters(&mut self) -> MasterFilters<'_>
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.