From a8bd3ab9521fc2c3c4a409c40648068af3d63d97 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 10 Feb 2022 16:06:42 +0100 Subject: [PATCH] Add missing `+ 'd` on unborrows. --- embassy-rp/src/spi.rs | 10 +++++----- embassy-rp/src/uart.rs | 10 +++++----- embassy-stm32/src/crc/v1.rs | 10 +++++++--- embassy-stm32/src/crc/v2v3.rs | 10 +++++++--- embassy-stm32/src/i2c/v1.rs | 4 ++-- embassy-stm32/src/rng.rs | 17 +++++++++++------ embassy-stm32/src/sdmmc/v2.rs | 2 +- embassy-stm32/src/spi/mod.rs | 4 ++-- embassy-stm32/src/usart/mod.rs | 10 +++++----- 9 files changed, 45 insertions(+), 32 deletions(-) diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index 906fa23e..49108218 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs @@ -62,11 +62,11 @@ fn calc_prescs(freq: u32) -> (u8, u8) { impl<'d, T: Instance> Spi<'d, T> { pub fn new( - inner: impl Unborrow, - clk: impl Unborrow>, - mosi: impl Unborrow>, - miso: impl Unborrow>, - cs: impl Unborrow>, + inner: impl Unborrow + 'd, + clk: impl Unborrow> + 'd, + mosi: impl Unborrow> + 'd, + miso: impl Unborrow> + 'd, + cs: impl Unborrow> + 'd, config: Config, ) -> Self { unborrow!(inner, clk, mosi, miso, cs); diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs index 3f5c4907..0d85be86 100644 --- a/embassy-rp/src/uart.rs +++ b/embassy-rp/src/uart.rs @@ -30,11 +30,11 @@ pub struct Uart<'d, T: Instance> { impl<'d, T: Instance> Uart<'d, T> { pub fn new( - inner: impl Unborrow, - tx: impl Unborrow>, - rx: impl Unborrow>, - cts: impl Unborrow>, - rts: impl Unborrow>, + inner: impl Unborrow + 'd, + tx: impl Unborrow> + 'd, + rx: impl Unborrow> + 'd, + cts: impl Unborrow> + 'd, + rts: impl Unborrow> + 'd, config: Config, ) -> Self { unborrow!(inner, tx, rx, cts, rts); diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs index c33eea31..c657192e 100644 --- a/embassy-stm32/src/crc/v1.rs +++ b/embassy-stm32/src/crc/v1.rs @@ -1,16 +1,19 @@ +use core::marker::PhantomData; + use crate::pac::CRC as PAC_CRC; use crate::peripherals::CRC; use crate::rcc::sealed::RccPeripheral; use embassy::util::Unborrow; use embassy_hal_common::unborrow; -pub struct Crc { +pub struct Crc<'d> { _peripheral: CRC, + _phantom: PhantomData<&'d mut CRC>, } -impl Crc { +impl<'d> Crc<'d> { /// Instantiates the CRC32 peripheral and initializes it to default values. - pub fn new(peripheral: impl Unborrow) -> Self { + pub fn new(peripheral: impl Unborrow + 'd) -> Self { // Note: enable and reset come from RccPeripheral. // enable CRC clock in RCC. CRC::enable(); @@ -20,6 +23,7 @@ impl Crc { unborrow!(peripheral); let mut instance = Self { _peripheral: peripheral, + _phantom: PhantomData, }; instance.reset(); instance diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs index 1ca52956..77cd3da1 100644 --- a/embassy-stm32/src/crc/v2v3.rs +++ b/embassy-stm32/src/crc/v2v3.rs @@ -1,3 +1,5 @@ +use core::marker::PhantomData; + use crate::pac::crc::vals; use crate::pac::CRC as PAC_CRC; use crate::peripherals::CRC; @@ -5,8 +7,9 @@ use crate::rcc::sealed::RccPeripheral; use embassy::util::Unborrow; use embassy_hal_common::unborrow; -pub struct Crc { +pub struct Crc<'d> { _peripheral: CRC, + _phantom: PhantomData<&'d mut CRC>, _config: Config, } @@ -64,9 +67,9 @@ pub enum PolySize { Width32, } -impl Crc { +impl<'d> Crc<'d> { /// Instantiates the CRC32 peripheral and initializes it to default values. - pub fn new(peripheral: impl Unborrow, config: Config) -> Self { + pub fn new(peripheral: impl Unborrow + 'd, config: Config) -> Self { // Note: enable and reset come from RccPeripheral. // enable CRC clock in RCC. CRC::enable(); @@ -75,6 +78,7 @@ impl Crc { unborrow!(peripheral); let mut instance = Self { _peripheral: peripheral, + _phantom: PhantomData, _config: config, }; CRC::reset(); diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index aa526898..922c1c7e 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -15,8 +15,8 @@ pub struct I2c<'d, T: Instance> { impl<'d, T: Instance> I2c<'d, T> { pub fn new( _peri: impl Unborrow + 'd, - scl: impl Unborrow>, - sda: impl Unborrow>, + scl: impl Unborrow> + 'd, + sda: impl Unborrow> + 'd, freq: F, ) -> Self where diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index bfacdeef..032fee01 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -1,5 +1,6 @@ #![macro_use] +use core::marker::PhantomData; use core::task::Poll; use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; @@ -18,16 +19,20 @@ pub enum Error { ClockError, } -pub struct Rng { +pub struct Rng<'d, T: Instance> { _inner: T, + _phantom: PhantomData<&'d mut T>, } -impl Rng { - pub fn new(inner: impl Unborrow) -> Self { +impl<'d, T: Instance> Rng<'d, T> { + pub fn new(inner: impl Unborrow + 'd) -> Self { T::enable(); T::reset(); unborrow!(inner); - let mut random = Self { _inner: inner }; + let mut random = Self { + _inner: inner, + _phantom: PhantomData, + }; random.reset(); random } @@ -88,7 +93,7 @@ impl Rng { } } -impl RngCore for Rng { +impl<'d, T: Instance> RngCore for Rng<'d, T> { fn next_u32(&mut self) -> u32 { loop { let bits = unsafe { T::regs().sr().read() }; @@ -119,7 +124,7 @@ impl RngCore for Rng { } } -impl CryptoRng for Rng {} +impl<'d, T: Instance> CryptoRng for Rng<'d, T> {} pub(crate) mod sealed { use super::*; diff --git a/embassy-stm32/src/sdmmc/v2.rs b/embassy-stm32/src/sdmmc/v2.rs index 74382ce6..784a07f5 100644 --- a/embassy-stm32/src/sdmmc/v2.rs +++ b/embassy-stm32/src/sdmmc/v2.rs @@ -189,7 +189,7 @@ impl<'d, T: Instance, P: Pins> Sdmmc<'d, T, P> { pub unsafe fn new( _peripheral: impl Unborrow + 'd, pins: impl Unborrow + 'd, - irq: impl Unborrow, + irq: impl Unborrow + 'd, config: Config, ) -> Self { unborrow!(irq, pins); diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 46921623..c0cd56fc 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -202,8 +202,8 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { sck: Option, mosi: Option, miso: Option, - txdma: impl Unborrow, - rxdma: impl Unborrow, + txdma: impl Unborrow + 'd, + rxdma: impl Unborrow + 'd, freq: F, config: Config, ) -> Self diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index a391379c..5f0281f4 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -81,11 +81,11 @@ pub struct Uart<'d, T: Instance, TxDma = NoDma, RxDma = NoDma> { impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { pub fn new( - inner: impl Unborrow, - rx: impl Unborrow>, - tx: impl Unborrow>, - tx_dma: impl Unborrow, - rx_dma: impl Unborrow, + inner: impl Unborrow + 'd, + rx: impl Unborrow> + 'd, + tx: impl Unborrow> + 'd, + tx_dma: impl Unborrow + 'd, + rx_dma: impl Unborrow + 'd, config: Config, ) -> Self { unborrow!(inner, rx, tx, tx_dma, rx_dma);