2021-05-06 01:43:46 +00:00
|
|
|
use crate::pac::rng::{regs, Rng};
|
2021-04-26 18:11:46 +00:00
|
|
|
use crate::peripherals;
|
|
|
|
use embassy::util::Unborrow;
|
|
|
|
use embassy_extras::unborrow;
|
|
|
|
|
|
|
|
pub struct Random<T: Instance> {
|
|
|
|
inner: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Instance> Random<T> {
|
2021-05-06 01:43:46 +00:00
|
|
|
pub fn new(inner: impl Unborrow<Target = T>) -> Self {
|
2021-04-26 18:11:46 +00:00
|
|
|
unborrow!(inner);
|
2021-05-06 01:43:46 +00:00
|
|
|
Self { inner }
|
2021-04-26 18:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
use core::future::Future;
|
|
|
|
use core::marker::PhantomData;
|
2021-05-06 01:43:46 +00:00
|
|
|
use embassy::traits::rng::Rng as RngTrait;
|
2021-04-26 18:11:46 +00:00
|
|
|
|
2021-05-06 01:43:46 +00:00
|
|
|
impl<T: Instance> RngTrait for Random<T> {
|
2021-04-26 18:11:46 +00:00
|
|
|
type Error = ();
|
2021-05-06 01:43:46 +00:00
|
|
|
#[rustfmt::skip]
|
|
|
|
type RngFuture<'a> where Self: 'a = impl Future<Output = Result<(), Self::Error>>;
|
2021-04-26 18:11:46 +00:00
|
|
|
|
|
|
|
fn fill<'a>(&'a mut self, dest: &'a mut [u8]) -> Self::RngFuture<'a> {
|
2021-05-06 01:43:46 +00:00
|
|
|
async move { Ok(()) }
|
2021-04-26 18:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) mod sealed {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
pub trait Instance {
|
|
|
|
fn regs(&self) -> Rng;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Instance: sealed::Instance {}
|
|
|
|
|
|
|
|
macro_rules! impl_rng {
|
2021-05-06 01:43:46 +00:00
|
|
|
($inst:ident) => {
|
|
|
|
impl crate::rng::sealed::Instance for peripherals::$inst {
|
|
|
|
fn regs(&self) -> crate::pac::rng::Rng {
|
|
|
|
crate::pac::$inst
|
2021-04-26 18:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-06 01:43:46 +00:00
|
|
|
impl crate::rng::Instance for peripherals::$inst {}
|
|
|
|
};
|
|
|
|
}
|