aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamme Dittrich <[email protected]>2025-01-07 09:25:25 +0100
committerTamme Dittrich <[email protected]>2025-01-07 10:11:53 +0100
commit7ac2a4f674030bf82f7892b25a43a5efc01d9e62 (patch)
treeba1f9899c413660d9a576e8a3dfca6e39756c9c9
parent8a9ca88cc46ebfe64ba1ebc0402f0ea44f6030c6 (diff)
Allow split CAN Rx to modify the filters
-rw-r--r--embassy-stm32/src/can/bxcan/mod.rs30
1 files changed, 27 insertions, 3 deletions
diff --git a/embassy-stm32/src/can/bxcan/mod.rs b/embassy-stm32/src/can/bxcan/mod.rs
index 19f1cea29..8165364f5 100644
--- a/embassy-stm32/src/can/bxcan/mod.rs
+++ b/embassy-stm32/src/can/bxcan/mod.rs
@@ -502,6 +502,14 @@ impl<'d, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> BufferedCan<'d, TX_
502 pub fn reader(&self) -> BufferedCanReceiver { 502 pub fn reader(&self) -> BufferedCanReceiver {
503 self.rx.reader() 503 self.rx.reader()
504 } 504 }
505
506 /// Accesses the filter banks owned by this CAN peripheral.
507 ///
508 /// To modify filters of a slave peripheral, `modify_filters` has to be called on the master
509 /// peripheral instead.
510 pub fn modify_filters(&mut self) -> MasterFilters<'_> {
511 self.rx.modify_filters()
512 }
505} 513}
506 514
507/// CAN driver, transmit half. 515/// CAN driver, transmit half.
@@ -733,6 +741,14 @@ impl<'d> CanRx<'d> {
733 ) -> BufferedCanRx<'d, RX_BUF_SIZE> { 741 ) -> BufferedCanRx<'d, RX_BUF_SIZE> {
734 BufferedCanRx::new(self.info, self.state, self, rxb) 742 BufferedCanRx::new(self.info, self.state, self, rxb)
735 } 743 }
744
745 /// Accesses the filter banks owned by this CAN peripheral.
746 ///
747 /// To modify filters of a slave peripheral, `modify_filters` has to be called on the master
748 /// peripheral instead.
749 pub fn modify_filters(&mut self) -> MasterFilters<'_> {
750 unsafe { MasterFilters::new(self.info) }
751 }
736} 752}
737 753
738/// User supplied buffer for RX Buffering 754/// User supplied buffer for RX Buffering
@@ -742,16 +758,16 @@ pub type RxBuf<const BUF_SIZE: usize> = Channel<CriticalSectionRawMutex, Result<
742pub struct BufferedCanRx<'d, const RX_BUF_SIZE: usize> { 758pub struct BufferedCanRx<'d, const RX_BUF_SIZE: usize> {
743 info: &'static Info, 759 info: &'static Info,
744 state: &'static State, 760 state: &'static State,
745 _rx: CanRx<'d>, 761 rx: CanRx<'d>,
746 rx_buf: &'static RxBuf<RX_BUF_SIZE>, 762 rx_buf: &'static RxBuf<RX_BUF_SIZE>,
747} 763}
748 764
749impl<'d, const RX_BUF_SIZE: usize> BufferedCanRx<'d, RX_BUF_SIZE> { 765impl<'d, const RX_BUF_SIZE: usize> BufferedCanRx<'d, RX_BUF_SIZE> {
750 fn new(info: &'static Info, state: &'static State, _rx: CanRx<'d>, rx_buf: &'static RxBuf<RX_BUF_SIZE>) -> Self { 766 fn new(info: &'static Info, state: &'static State, rx: CanRx<'d>, rx_buf: &'static RxBuf<RX_BUF_SIZE>) -> Self {
751 BufferedCanRx { 767 BufferedCanRx {
752 info, 768 info,
753 state, 769 state,
754 _rx, 770 rx,
755 rx_buf, 771 rx_buf,
756 } 772 }
757 .setup() 773 .setup()
@@ -811,6 +827,14 @@ impl<'d, const RX_BUF_SIZE: usize> BufferedCanRx<'d, RX_BUF_SIZE> {
811 pub fn reader(&self) -> BufferedCanReceiver { 827 pub fn reader(&self) -> BufferedCanReceiver {
812 self.rx_buf.receiver().into() 828 self.rx_buf.receiver().into()
813 } 829 }
830
831 /// Accesses the filter banks owned by this CAN peripheral.
832 ///
833 /// To modify filters of a slave peripheral, `modify_filters` has to be called on the master
834 /// peripheral instead.
835 pub fn modify_filters(&mut self) -> MasterFilters<'_> {
836 self.rx.modify_filters()
837 }
814} 838}
815 839
816impl<'d, const RX_BUF_SIZE: usize> Drop for BufferedCanRx<'d, RX_BUF_SIZE> { 840impl<'d, const RX_BUF_SIZE: usize> Drop for BufferedCanRx<'d, RX_BUF_SIZE> {