From 263071d0169318ab24e0f6caac87a13d1c906769 Mon Sep 17 00:00:00 2001 From: Torin Cooper-Bennun Date: Fri, 19 Apr 2024 14:41:49 +0100 Subject: [PATCH] stm32: can: fd: Properties: rm &mut refs; make !Sync; rename getters --- embassy-stm32/src/can/fdcan.rs | 47 +++++++++++----------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/embassy-stm32/src/can/fdcan.rs b/embassy-stm32/src/can/fdcan.rs index cec94e78a..0916f6ac6 100644 --- a/embassy-stm32/src/can/fdcan.rs +++ b/embassy-stm32/src/can/fdcan.rs @@ -209,11 +209,6 @@ impl<'d, T: Instance> CanConfigurator<'d, T> { &self.properties } - /// Get mutable driver properties - pub fn properties_mut(&mut self) -> &mut Properties { - &mut self.properties - } - /// Get configuration pub fn config(&self) -> crate::can::fd::config::FdCanConfig { return self.config; @@ -299,11 +294,6 @@ impl<'d, T: Instance> Can<'d, T> { &self.properties } - /// Get mutable driver properties - pub fn properties_mut(&mut self) -> &mut Properties { - &mut self.properties - } - /// Flush one of the TX mailboxes. pub async fn flush(&self, idx: usize) { poll_fn(|cx| { @@ -437,11 +427,6 @@ impl<'c, 'd, T: Instance, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> &self.properties } - /// Get mutable driver properties - pub fn properties_mut(&mut self) -> &mut Properties { - &mut self.properties - } - fn setup(self) -> Self { // We don't want interrupts being processed while we change modes. critical_section::with(|_| unsafe { @@ -565,11 +550,6 @@ impl<'c, 'd, T: Instance, const TX_BUF_SIZE: usize, const RX_BUF_SIZE: usize> &self.properties } - /// Get mutable driver properties - pub fn properties_mut(&mut self) -> &mut Properties { - &mut self.properties - } - fn setup(self) -> Self { // We don't want interrupts being processed while we change modes. critical_section::with(|_| unsafe { @@ -830,7 +810,8 @@ impl TxMode { /// Common driver properties, including filters and error counters pub struct Properties { - instance: PhantomData, + // phantom pointer to ensure !Sync + instance: PhantomData<*const T>, } impl Properties { @@ -840,44 +821,46 @@ impl Properties { } } - /// Set an Standard Address CAN filter into slot 'id' + /// Set a standard address CAN filter in the specified slot in FDCAN memory. #[inline] - pub fn set_standard_filter(&mut self, slot: StandardFilterSlot, filter: StandardFilter) { + pub fn set_standard_filter(&self, slot: StandardFilterSlot, filter: StandardFilter) { T::registers().msg_ram_mut().filters.flssa[slot as usize].activate(filter); } - /// Set an array of Standard Address CAN filters and overwrite the current set - pub fn set_standard_filters(&mut self, filters: &[StandardFilter; STANDARD_FILTER_MAX as usize]) { + /// Set the full array of standard address CAN filters in FDCAN memory. + /// Overwrites all standard address filters in memory. + pub fn set_standard_filters(&self, filters: &[StandardFilter; STANDARD_FILTER_MAX as usize]) { for (i, f) in filters.iter().enumerate() { T::registers().msg_ram_mut().filters.flssa[i].activate(*f); } } - /// Set an Extended Address CAN filter into slot 'id' + /// Set an extended address CAN filter in the specified slot in FDCAN memory. #[inline] - pub fn set_extended_filter(&mut self, slot: ExtendedFilterSlot, filter: ExtendedFilter) { + pub fn set_extended_filter(&self, slot: ExtendedFilterSlot, filter: ExtendedFilter) { T::registers().msg_ram_mut().filters.flesa[slot as usize].activate(filter); } - /// Set an array of Extended Address CAN filters and overwrite the current set - pub fn set_extended_filters(&mut self, filters: &[ExtendedFilter; EXTENDED_FILTER_MAX as usize]) { + /// Set the full array of extended address CAN filters in FDCAN memory. + /// Overwrites all extended address filters in memory. + pub fn set_extended_filters(&self, filters: &[ExtendedFilter; EXTENDED_FILTER_MAX as usize]) { for (i, f) in filters.iter().enumerate() { T::registers().msg_ram_mut().filters.flesa[i].activate(*f); } } /// Get the CAN RX error counter - pub fn get_rx_error_count(&self) -> u8 { + pub fn rx_error_count(&self) -> u8 { T::registers().regs.ecr().read().rec() } /// Get the CAN TX error counter - pub fn get_tx_error_count(&self) -> u8 { + pub fn tx_error_count(&self) -> u8 { T::registers().regs.ecr().read().tec() } /// Get the current Bus-Off state - pub fn get_bus_off(&self) -> bool { + pub fn bus_off(&self) -> bool { T::registers().regs.psr().read().bo() } }