Skip to content

Commit

Permalink
Merge pull request #3733 from tdittr/stm32-can-rx-filters
Browse files Browse the repository at this point in the history
feat: STM32 Allow to modify the receiver filters from `BufferedCan`, `CanRx`, and `BufferedCanRx`
  • Loading branch information
Dirbaio authored Jan 7, 2025
2 parents 49dfad6 + 7ac2a4f commit 4790f8f
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions embassy-stm32/src/can/bxcan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,14 @@ impl<'d, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> BufferedCan<'d, TX_
pub fn reader(&self) -> BufferedCanReceiver {
self.rx.reader()
}

/// 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.
pub fn modify_filters(&mut self) -> MasterFilters<'_> {
self.rx.modify_filters()
}
}

/// CAN driver, transmit half.
Expand Down Expand Up @@ -733,6 +741,14 @@ impl<'d> CanRx<'d> {
) -> BufferedCanRx<'d, RX_BUF_SIZE> {
BufferedCanRx::new(self.info, self.state, self, rxb)
}

/// 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.
pub fn modify_filters(&mut self) -> MasterFilters<'_> {
unsafe { MasterFilters::new(self.info) }
}
}

/// User supplied buffer for RX Buffering
Expand All @@ -742,16 +758,16 @@ pub type RxBuf<const BUF_SIZE: usize> = Channel<CriticalSectionRawMutex, Result<
pub struct BufferedCanRx<'d, const RX_BUF_SIZE: usize> {
info: &'static Info,
state: &'static State,
_rx: CanRx<'d>,
rx: CanRx<'d>,
rx_buf: &'static RxBuf<RX_BUF_SIZE>,
}

impl<'d, const RX_BUF_SIZE: usize> BufferedCanRx<'d, RX_BUF_SIZE> {
fn new(info: &'static Info, state: &'static State, _rx: CanRx<'d>, rx_buf: &'static RxBuf<RX_BUF_SIZE>) -> Self {
fn new(info: &'static Info, state: &'static State, rx: CanRx<'d>, rx_buf: &'static RxBuf<RX_BUF_SIZE>) -> Self {
BufferedCanRx {
info,
state,
_rx,
rx,
rx_buf,
}
.setup()
Expand Down Expand Up @@ -811,6 +827,14 @@ impl<'d, const RX_BUF_SIZE: usize> BufferedCanRx<'d, RX_BUF_SIZE> {
pub fn reader(&self) -> BufferedCanReceiver {
self.rx_buf.receiver().into()
}

/// 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.
pub fn modify_filters(&mut self) -> MasterFilters<'_> {
self.rx.modify_filters()
}
}

impl<'d, const RX_BUF_SIZE: usize> Drop for BufferedCanRx<'d, RX_BUF_SIZE> {
Expand Down

0 comments on commit 4790f8f

Please sign in to comment.