pub struct Can<I: Instance> { /* private fields */ }
Expand description
Interface to a bxCAN peripheral.
Implementations§
source§impl<I> Can<I>where
I: Instance,
impl<I> Can<I>where
I: Instance,
sourcepub fn builder(instance: I) -> CanBuilder<I>
pub fn builder(instance: I) -> CanBuilder<I>
Creates a CanBuilder
for constructing a CAN interface.
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 free(self) -> I
pub fn free(self) -> I
Disables the CAN interface and returns back the raw peripheral it was created from.
The peripheral is disabled by setting RESET
in CAN_MCR
, which causes the peripheral to
enter sleep mode.
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<(), Infallible>
pub fn enable_non_blocking(&mut self) -> Result<(), 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, Infallible>
pub fn transmit(&mut self, frame: &Frame) -> Result<TransmitStatus, 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, OverrunError>
pub fn receive(&mut self) -> Result<Frame, 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.
source§impl<I: FilterOwner> Can<I>
impl<I: FilterOwner> Can<I>
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.