Struct bxcan::Can

source ·
pub struct Can<I: Instance> { /* private fields */ }
Expand description

Interface to a bxCAN peripheral.

Implementations§

source§

impl<I> Can<I>
where I: Instance,

source

pub fn builder(instance: I) -> CanBuilder<I>

Creates a CanBuilder for constructing a CAN interface.

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 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.

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<(), 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, 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, 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 split(self) -> (Tx<I>, Rx0<I>, Rx1<I>)

Consumes this Can instance and splits it into transmitting and receiving halves.

source§

impl<I: FilterOwner> Can<I>

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<I> Can for Can<I>
where I: Instance,

§

type Frame = Frame

Associated frame type.
§

type Error = OverrunError

Associated error type.
source§

fn transmit( &mut self, frame: &Self::Frame ) -> Result<Option<Self::Frame>, Self::Error>

Puts a frame in the transmit buffer to be sent on the bus. Read more
source§

fn receive(&mut self) -> Result<Self::Frame, Self::Error>

Returns a received frame if available.

Auto Trait Implementations§

§

impl<I> Freeze for Can<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for Can<I>
where I: RefUnwindSafe,

§

impl<I> Send for Can<I>
where I: Send,

§

impl<I> Sync for Can<I>
where I: Sync,

§

impl<I> Unpin for Can<I>
where I: Unpin,

§

impl<I> UnwindSafe for Can<I>
where I: UnwindSafe,

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.