Add missing + 'd on unborrows.

This commit is contained in:
Dario Nieuwenhuis 2022-02-10 16:06:42 +01:00
parent 550da471be
commit a8bd3ab952
9 changed files with 45 additions and 32 deletions

View file

@ -62,11 +62,11 @@ fn calc_prescs(freq: u32) -> (u8, u8) {
impl<'d, T: Instance> Spi<'d, T> {
pub fn new(
inner: impl Unborrow<Target = T>,
clk: impl Unborrow<Target = impl ClkPin<T>>,
mosi: impl Unborrow<Target = impl MosiPin<T>>,
miso: impl Unborrow<Target = impl MisoPin<T>>,
cs: impl Unborrow<Target = impl CsPin<T>>,
inner: impl Unborrow<Target = T> + 'd,
clk: impl Unborrow<Target = impl ClkPin<T>> + 'd,
mosi: impl Unborrow<Target = impl MosiPin<T>> + 'd,
miso: impl Unborrow<Target = impl MisoPin<T>> + 'd,
cs: impl Unborrow<Target = impl CsPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(inner, clk, mosi, miso, cs);

View file

@ -30,11 +30,11 @@ pub struct Uart<'d, T: Instance> {
impl<'d, T: Instance> Uart<'d, T> {
pub fn new(
inner: impl Unborrow<Target = T>,
tx: impl Unborrow<Target = impl TxPin<T>>,
rx: impl Unborrow<Target = impl RxPin<T>>,
cts: impl Unborrow<Target = impl CtsPin<T>>,
rts: impl Unborrow<Target = impl RtsPin<T>>,
inner: impl Unborrow<Target = T> + 'd,
tx: impl Unborrow<Target = impl TxPin<T>> + 'd,
rx: impl Unborrow<Target = impl RxPin<T>> + 'd,
cts: impl Unborrow<Target = impl CtsPin<T>> + 'd,
rts: impl Unborrow<Target = impl RtsPin<T>> + 'd,
config: Config,
) -> Self {
unborrow!(inner, tx, rx, cts, rts);

View file

@ -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<Target = CRC>) -> Self {
pub fn new(peripheral: impl Unborrow<Target = CRC> + '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

View file

@ -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<Target = CRC>, config: Config) -> Self {
pub fn new(peripheral: impl Unborrow<Target = CRC> + '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();

View file

@ -15,8 +15,8 @@ pub struct I2c<'d, T: Instance> {
impl<'d, T: Instance> I2c<'d, T> {
pub fn new<F>(
_peri: impl Unborrow<Target = T> + 'd,
scl: impl Unborrow<Target = impl SclPin<T>>,
sda: impl Unborrow<Target = impl SdaPin<T>>,
scl: impl Unborrow<Target = impl SclPin<T>> + 'd,
sda: impl Unborrow<Target = impl SdaPin<T>> + 'd,
freq: F,
) -> Self
where

View file

@ -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<T: Instance> {
pub struct Rng<'d, T: Instance> {
_inner: T,
_phantom: PhantomData<&'d mut T>,
}
impl<T: Instance> Rng<T> {
pub fn new(inner: impl Unborrow<Target = T>) -> Self {
impl<'d, T: Instance> Rng<'d, T> {
pub fn new(inner: impl Unborrow<Target = T> + '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<T: Instance> Rng<T> {
}
}
impl<T: Instance> RngCore for Rng<T> {
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<T: Instance> RngCore for Rng<T> {
}
}
impl<T: Instance> CryptoRng for Rng<T> {}
impl<'d, T: Instance> CryptoRng for Rng<'d, T> {}
pub(crate) mod sealed {
use super::*;

View file

@ -189,7 +189,7 @@ impl<'d, T: Instance, P: Pins<T>> Sdmmc<'d, T, P> {
pub unsafe fn new(
_peripheral: impl Unborrow<Target = T> + 'd,
pins: impl Unborrow<Target = P> + 'd,
irq: impl Unborrow<Target = T::Interrupt>,
irq: impl Unborrow<Target = T::Interrupt> + 'd,
config: Config,
) -> Self {
unborrow!(irq, pins);

View file

@ -202,8 +202,8 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
sck: Option<AnyPin>,
mosi: Option<AnyPin>,
miso: Option<AnyPin>,
txdma: impl Unborrow<Target = Tx>,
rxdma: impl Unborrow<Target = Rx>,
txdma: impl Unborrow<Target = Tx> + 'd,
rxdma: impl Unborrow<Target = Rx> + 'd,
freq: F,
config: Config,
) -> Self

View file

@ -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<Target = T>,
rx: impl Unborrow<Target = impl RxPin<T>>,
tx: impl Unborrow<Target = impl TxPin<T>>,
tx_dma: impl Unborrow<Target = TxDma>,
rx_dma: impl Unborrow<Target = RxDma>,
inner: impl Unborrow<Target = T> + 'd,
rx: impl Unborrow<Target = impl RxPin<T>> + 'd,
tx: impl Unborrow<Target = impl TxPin<T>> + 'd,
tx_dma: impl Unborrow<Target = TxDma> + 'd,
rx_dma: impl Unborrow<Target = RxDma> + 'd,
config: Config,
) -> Self {
unborrow!(inner, rx, tx, tx_dma, rx_dma);