diff --git a/embassy-hal-common/src/macros.rs b/embassy-hal-common/src/macros.rs index da791313..5e62e048 100644 --- a/embassy-hal-common/src/macros.rs +++ b/embassy-hal-common/src/macros.rs @@ -92,7 +92,7 @@ macro_rules! impl_peripheral { type P = $type; #[inline] - unsafe fn clone_unchecked(&mut self) -> Self::P { + unsafe fn clone_unchecked(&self) -> Self::P { $type { ..*self } } } diff --git a/embassy-hal-common/src/peripheral.rs b/embassy-hal-common/src/peripheral.rs index 4a6b6a60..c7133bac 100644 --- a/embassy-hal-common/src/peripheral.rs +++ b/embassy-hal-common/src/peripheral.rs @@ -39,7 +39,7 @@ impl<'a, T> PeripheralRef<'a, T> { /// You should strongly prefer using `reborrow()` instead. It returns a /// `PeripheralRef` that borrows `self`, which allows the borrow checker /// to enforce this at compile time. - pub unsafe fn clone_unchecked(&mut self) -> PeripheralRef<'a, T> + pub unsafe fn clone_unchecked(&self) -> PeripheralRef<'a, T> where T: Peripheral

, { @@ -146,14 +146,14 @@ pub trait Peripheral: Sized { /// /// You should strongly prefer using `into_ref()` instead. It returns a /// `PeripheralRef`, which allows the borrow checker to enforce this at compile time. - unsafe fn clone_unchecked(&mut self) -> Self::P; + unsafe fn clone_unchecked(&self) -> Self::P; /// Convert a value into a `PeripheralRef`. /// /// When called on an owned `T`, yields a `PeripheralRef<'static, T>`. /// When called on an `&'a mut T`, yields a `PeripheralRef<'a, T>`. #[inline] - fn into_ref<'a>(mut self) -> PeripheralRef<'a, Self::P> + fn into_ref<'a>(self) -> PeripheralRef<'a, Self::P> where Self: 'a, { @@ -161,14 +161,14 @@ pub trait Peripheral: Sized { } } -impl<'b, T: DerefMut> Peripheral for T +impl<'b, T: Deref> Peripheral for T where T::Target: Peripheral, { type P = ::P; #[inline] - unsafe fn clone_unchecked(&mut self) -> Self::P { - self.deref_mut().clone_unchecked() + unsafe fn clone_unchecked(&self) -> Self::P { + self.deref().clone_unchecked() } } diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 75f93f90..c41d8398 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs @@ -342,7 +342,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { r.enable.write(|w| w.enable().enabled()); // Configure byte counter. - let mut timer = Timer::new_counter(timer); + let timer = Timer::new_counter(timer); timer.cc(1).write(rx_buffer.len() as u32 * 2); timer.cc(1).short_compare_clear(); timer.clear(); diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index af952f03..8aff7df1 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -315,7 +315,7 @@ impl<'d, const N: usize> Saadc<'d, N> { Ppi::new_one_to_one(ppi_ch1, Event::from_reg(&r.events_end), Task::from_reg(&r.tasks_start)); start_ppi.enable(); - let mut timer = Timer::new(timer); + let timer = Timer::new(timer); timer.set_frequency(frequency); timer.cc(0).write(sample_counter); timer.cc(0).short_compare_clear(); diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs index a9487a9f..e9d2132c 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs @@ -117,7 +117,7 @@ impl<'d, T: Instance> Timer<'d, T> { let regs = T::regs(); - let mut this = Self { _p: timer }; + let this = Self { _p: timer }; // Stop the timer before doing anything else, // since changing BITMODE while running can cause 'unpredictable behaviour' according to the specification. @@ -213,13 +213,13 @@ impl<'d, T: Instance> Timer<'d, T> { /// /// # Panics /// Panics if `n` >= the number of CC registers this timer has (4 for a normal timer, 6 for an extended timer). - pub fn cc(&mut self, n: usize) -> Cc { + pub fn cc(&self, n: usize) -> Cc<'d, T> { if n >= T::CCS { panic!("Cannot get CC register {} of timer with {} CC registers.", n, T::CCS); } Cc { n, - _p: self._p.reborrow(), + _p: unsafe { self._p.clone_unchecked() }, } } } diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 3934d1b5..e59b2332 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -205,7 +205,7 @@ impl<'d, T: Instance> Uarte<'d, T> { ppi_ch1: impl Peripheral

+ 'd, ppi_ch2: impl Peripheral

+ 'd, ) -> (UarteTx<'d, T>, UarteRxWithIdle<'d, T, U>) { - let mut timer = Timer::new(timer); + let timer = Timer::new(timer); into_ref!(ppi_ch1, ppi_ch2); diff --git a/embassy-nrf/src/usb/mod.rs b/embassy-nrf/src/usb/mod.rs index 56de511d..c1f3f48c 100644 --- a/embassy-nrf/src/usb/mod.rs +++ b/embassy-nrf/src/usb/mod.rs @@ -153,7 +153,7 @@ impl<'d, T: Instance, V: VbusDetect + 'd> driver::Driver<'d> for Driver<'d, T, V })) } - fn start(mut self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) { + fn start(self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) { ( Bus { _p: unsafe { self._p.clone_unchecked() }, diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index b01e8ba4..73bd29fc 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -180,7 +180,7 @@ fn main() { #[cfg(flash)] impl<'d> FlashLayout<'d> { - pub(crate) fn new(mut p: embassy_hal_common::PeripheralRef<'d, crate::peripherals::FLASH>) -> Self { + pub(crate) fn new(p: embassy_hal_common::PeripheralRef<'d, crate::peripherals::FLASH>) -> Self { Self { #(#inits),* } diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs index 8235d6f0..1189e447 100644 --- a/embassy-stm32/src/flash/common.rs +++ b/embassy-stm32/src/flash/common.rs @@ -33,8 +33,7 @@ impl<'d> Flash<'d> { } pub(crate) fn release(self) -> PeripheralRef<'d, crate::peripherals::FLASH> { - let mut flash = self; - unsafe { flash.inner.clone_unchecked() } + unsafe { self.inner.clone_unchecked() } } } diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs index 2ce9df69..60ac62c1 100644 --- a/embassy-stm32/src/flash/f4.rs +++ b/embassy-stm32/src/flash/f4.rs @@ -67,7 +67,7 @@ mod alt_regions { // SAFETY: We never expose the cloned peripheral references, and their instance is not public. // Also, all flash region operations are protected with a cs. - let mut p = self.release(); + let p = self.release(); AltFlashLayout { bank1_region1: Bank1Region1(&BANK1_REGION1, unsafe { p.clone_unchecked() }), bank1_region2: Bank1Region2(&BANK1_REGION2, unsafe { p.clone_unchecked() }), diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 3024f1ff..4895684e 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -29,7 +29,7 @@ impl<'d, T: Pin> Flex<'d, T> { } #[inline] - pub fn degrade(mut self) -> Flex<'d, AnyPin> { + pub fn degrade(self) -> Flex<'d, AnyPin> { // Safety: We are about to drop the other copy of this pin, so // this clone is safe. let pin = unsafe { self.pin.clone_unchecked() };