From c9b9be5b819911aaf809df9b55be7e7efa3a1fba Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 2 Jul 2023 22:07:20 +0200 Subject: [PATCH] hal-common: require DerefMut for peripherals, not just Deref. Otherwise you can create multiple drivers on the same singleton like this: ```rust let mut input = Input::new(&pin, Pull::None); let mut output = Output::new(&pin, Level::Low, Speed::Low); input.is_high(); output.set_high(); input.is_high(); output.set_high(); ``` Thanks @pennae for reporting. --- embassy-hal-common/src/peripheral.rs | 2 +- embassy-stm32/src/dac/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/embassy-hal-common/src/peripheral.rs b/embassy-hal-common/src/peripheral.rs index c7133bac..38b4c452 100644 --- a/embassy-hal-common/src/peripheral.rs +++ b/embassy-hal-common/src/peripheral.rs @@ -161,7 +161,7 @@ pub trait Peripheral: Sized { } } -impl<'b, T: Deref> Peripheral for T +impl<'b, T: DerefMut> Peripheral for T where T::Target: Peripheral, { diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 1dc13949..31a2d886 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs @@ -264,7 +264,7 @@ impl<'d, T: Instance, Tx> DacCh1<'d, T, Tx> { }); let tx_request = self.dma.request(); - let dma_channel = &self.dma; + let dma_channel = &mut self.dma; let tx_options = crate::dma::TransferOptions { circular, @@ -376,7 +376,7 @@ impl<'d, T: Instance, Tx> DacCh2<'d, T, Tx> { }); let tx_request = self.dma.request(); - let dma_channel = &self.dma; + let dma_channel = &mut self.dma; let tx_options = crate::dma::TransferOptions { circular,