diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index 9eedcb17d..af527cd53 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -1,15 +1,16 @@ #![macro_use] -//use crate::pac::rng::{regs, Rng}; -use crate::pac; -use crate::peripherals; -use crate::interrupt; -use futures::future::poll_fn; -use embassy::util::{Unborrow, AtomicWaker}; -use embassy_extras::unborrow; -use rand_core::{RngCore, CryptoRng}; - +use core::future::Future; +use core::task::Poll; use defmt::*; +use embassy::traits; +use embassy::util::{AtomicWaker, Unborrow}; +use embassy_extras::unborrow; +use futures::future::poll_fn; +use rand_core::{CryptoRng, RngCore}; + +use crate::interrupt; +use crate::pac; static RNG_WAKER: AtomicWaker = AtomicWaker::new(); @@ -27,7 +28,7 @@ pub struct Random { } impl Random { - pub fn new(inner: impl Unborrow) -> Self { + pub fn new(inner: impl Unborrow) -> Self { unborrow!(inner); let mut random = Self { inner }; random.reset(); @@ -55,7 +56,7 @@ impl RngCore for Random { loop { let bits = unsafe { T::regs().sr().read() }; if bits.drdy() { - return unsafe{ T::regs().dr().read() } + return unsafe { T::regs().dr().read() }; } } } @@ -76,18 +77,12 @@ impl RngCore for Random { } fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> { - self.fill_bytes( dest ); + self.fill_bytes(dest); Ok(()) } } -impl CryptoRng for Random { } - -use core::future::Future; -use core::marker::PhantomData; -use embassy::traits; -use core::task::{Poll, Context}; -use core::pin::Pin; +impl CryptoRng for Random {} pub enum Error { SeedError, @@ -96,6 +91,7 @@ pub enum Error { impl traits::rng::Rng for Random { type Error = Error; + #[rustfmt::skip] type RngFuture<'a> where Self: 'a = impl Future>; fn fill_bytes<'a>(&'a mut self, dest: &'a mut [u8]) -> Self::RngFuture<'a> { @@ -127,7 +123,8 @@ impl traits::rng::Rng for Random { } else { Poll::Pending } - } ).await?; + }) + .await?; let random_bytes = unsafe { T::regs().dr().read() }.to_be_bytes(); for (dest, src) in chunk.iter_mut().zip(random_bytes.iter()) { *dest = *src