CanBus

Struct CanBus 

Source
pub struct CanBus<I>
where Can<I>: Instance,
{ /* private fields */ }
Expand description

Wrapper around a bxcan CAN instance built from a HAL CAN peripheral.

Implementations§

Source§

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

Source

pub fn new(hal_can: Can<I>, btr: u32, loopback: bool, silent: bool) -> Self

Create and enable a bxcan instance from a HAL CAN peripheral.

  • hal_can – the HAL CAN wrapper
  • btr – value for the CAN_BTR register (bit timing). Get this from the reference manual or the bxcan timing tables.
  • loopback – enable internal loopback
  • silent – enable silent mode
Source

pub fn inner(&mut self) -> &mut Can<Can<I>>

Access the underlying bxcan instance for advanced configuration.

Source

pub fn free(self) -> Can<I>

Consume the wrapper and get back the underlying HAL CAN instance.

Source

pub fn transmit_frame( &mut self, frame: &Frame, ) -> Result<TransmitStatus, Infallible>

Transmit a pre-built CAN frame.

Returns the bxcan TransmitStatus. The error type is Infallible.

Source

pub fn transmit_data( &mut self, id: StandardId, data: &[u8], ) -> Option<Result<TransmitStatus, Infallible>>

Transmit a data frame with a standard 11-bit ID.

data must be at most 8 bytes, otherwise this returns None.

Source

pub fn receive(&mut self) -> Result<Frame, OverrunError>

Blocking receive of a frame.

This will block inside bxcan until a frame is available or an overrun is detected.

Source§

impl<I> CanBus<I>
where Can<I>: Instance + FilterOwner,

Extra helpers for CAN instances that own filters (e.g., CAN1 on STM32F7).

Source

pub fn configure_accept_all_filters_for_dual_can<I2>( &mut self, _can2: &mut Can<I2>, )
where Can<I2>: Instance,

Configure CAN1 and CAN2 filters so that both accept all frames on FIFO0.

This must be called on CAN1 (the filter owner).

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<I> UnwindSafe for CanBus<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>,

Source§

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

Source§

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.