Struct bxcan::Can[][src]

pub struct Can<I: Instance> { /* fields omitted */ }
Expand description

Interface to a CAN peripheral.

Implementations

impl<I> Can<I> where
    I: Instance
[src]

pub fn new(instance: I) -> Self[src]

Creates a CAN interface, taking ownership of the raw peripheral.

pub fn instance(&mut self) -> &mut I[src]

Returns a reference to the peripheral instance.

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

pub fn free(self) -> I[src]

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.

pub fn configure<F>(&mut self, f: F) where
    F: FnOnce(&mut CanConfig<'_, I>), 
[src]

Configure bit timings and silent/loop-back mode.

Acutal configuration happens on the CanConfig that is passed to the closure. It must be done this way because those configuration bits can only be set if the CAN controller is in a special init mode. Puts the peripheral in sleep mode afterwards. Can::enable() must be called to exit sleep mode and start reception and transmission.

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

Configure bit timings and silent/loop-back mode.

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

Configures the automatic wake-up feature.

pub fn enable(&mut self) -> Result<(), Infallible>[src]

Start reception and transmission.

Waits for 11 consecutive recessive bits to sync to the CAN bus.

pub fn sleep(&mut self)[src]

Puts the peripheral in a sleep mode to save power.

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

pub fn wakeup(&mut self)[src]

Wakes up from sleep mode.

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

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

Starts listening for a CAN interrupt.

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

Starts listening for a set of CAN interrupts.

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

Stops listening for a CAN interrupt.

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

Stops listening for a set of CAN interrupts.

pub fn clear_sleep_interrupt(&mut self)[src]

Clears the pending flag of Interrupt::Sleep.

pub fn clear_wakeup_interrupt(&mut self)[src]

Clears the pending flag of Interrupt::Wakeup.

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

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.

pub fn clear_tx_interrupt(&mut self)[src]

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.

pub fn transmit(&mut self, frame: &Frame) -> Result<Option<Frame>, Infallible>[src]

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

Frames are transmitted to the bus based on their priority (identifier). Transmit order is preserved for frames with identical identifiers. If all transmit mailboxes are full, a higher priority frame replaces the lowest priority frame, which is returned as Ok(Some(frame)).

pub fn transmit_and_get_mailbox(
    &mut self,
    frame: &Frame
) -> Result<(Option<Frame>, Mailbox), Infallible>
[src]

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

This function is equivalent to transmit except that it returns the mailbox that was accessed. This can be used to keep track of additional information about each frame, even when frames are placed into transmit mailboxes and later removed before being transmitted.

pub fn is_transmitter_idle(&self) -> bool[src]

Returns true if no frame is pending for transmission.

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

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

If there is no frame in the provided mailbox, this function has no effect and returns false.

If there is a frame in the provided mailbox, this function returns true if the transmission was aborted. This function returns false if the frame was successfully transmitted.

pub fn receive(&mut self) -> Result<Frame, ()>[src]

Returns a received frame if available.

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

pub fn split_by_ref(&mut self) -> (&mut Tx<I>, &mut Rx<I>)[src]

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

pub fn split(self) -> (Tx<I>, Rx<I>)[src]

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

impl<I: FilterOwner> Can<I>[src]

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

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

impl<I> Can for Can<I> where
    I: Instance
[src]

type Frame = Frame

Associated frame type.

type Error = ()

Associated error type.

fn try_transmit(
    &mut self,
    frame: &Self::Frame
) -> Result<Option<Self::Frame>, Self::Error>
[src]

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

fn try_receive(&mut self) -> Result<Self::Frame, Self::Error>[src]

Returns a received frame if available.

Auto Trait Implementations

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.