rustfmt rng
This commit is contained in:
parent
6c3299c82f
commit
9492b8555c
@ -1,15 +1,16 @@
|
|||||||
#![macro_use]
|
#![macro_use]
|
||||||
|
|
||||||
//use crate::pac::rng::{regs, Rng};
|
use core::future::Future;
|
||||||
use crate::pac;
|
use core::task::Poll;
|
||||||
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 defmt::*;
|
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();
|
static RNG_WAKER: AtomicWaker = AtomicWaker::new();
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ impl<T: Instance> RngCore for Random<T> {
|
|||||||
loop {
|
loop {
|
||||||
let bits = unsafe { T::regs().sr().read() };
|
let bits = unsafe { T::regs().sr().read() };
|
||||||
if bits.drdy() {
|
if bits.drdy() {
|
||||||
return unsafe{ T::regs().dr().read() }
|
return unsafe { T::regs().dr().read() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,12 +84,6 @@ impl<T: Instance> RngCore for Random<T> {
|
|||||||
|
|
||||||
impl<T: Instance> CryptoRng for Random<T> {}
|
impl<T: Instance> CryptoRng for Random<T> {}
|
||||||
|
|
||||||
use core::future::Future;
|
|
||||||
use core::marker::PhantomData;
|
|
||||||
use embassy::traits;
|
|
||||||
use core::task::{Poll, Context};
|
|
||||||
use core::pin::Pin;
|
|
||||||
|
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
SeedError,
|
SeedError,
|
||||||
ClockError,
|
ClockError,
|
||||||
@ -96,6 +91,7 @@ pub enum Error {
|
|||||||
|
|
||||||
impl<T: Instance> traits::rng::Rng for Random<T> {
|
impl<T: Instance> traits::rng::Rng for Random<T> {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
#[rustfmt::skip]
|
||||||
type RngFuture<'a> where Self: 'a = impl Future<Output=Result<(), Self::Error>>;
|
type RngFuture<'a> where Self: 'a = impl Future<Output=Result<(), Self::Error>>;
|
||||||
|
|
||||||
fn fill_bytes<'a>(&'a mut self, dest: &'a mut [u8]) -> Self::RngFuture<'a> {
|
fn fill_bytes<'a>(&'a mut self, dest: &'a mut [u8]) -> Self::RngFuture<'a> {
|
||||||
@ -127,7 +123,8 @@ impl<T: Instance> traits::rng::Rng for Random<T> {
|
|||||||
} else {
|
} else {
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
}
|
}
|
||||||
} ).await?;
|
})
|
||||||
|
.await?;
|
||||||
let random_bytes = unsafe { T::regs().dr().read() }.to_be_bytes();
|
let random_bytes = unsafe { T::regs().dr().read() }.to_be_bytes();
|
||||||
for (dest, src) in chunk.iter_mut().zip(random_bytes.iter()) {
|
for (dest, src) in chunk.iter_mut().zip(random_bytes.iter()) {
|
||||||
*dest = *src
|
*dest = *src
|
||||||
|
Loading…
Reference in New Issue
Block a user