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

@ -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();