Add Rand trait

This commit is contained in:
Dario Nieuwenhuis 2020-10-31 16:35:18 +01:00
parent 878bfd2b75
commit 03bd11ce0d
2 changed files with 15 additions and 0 deletions

View file

@ -8,3 +8,4 @@ pub mod flash;
pub mod io;
pub mod time;
pub mod util;
pub mod rand;

14
embassy/src/rand.rs Normal file
View file

@ -0,0 +1,14 @@
use crate::util::Dewrap;
pub trait Rand {
fn rand(&self, buf: &mut [u8]);
}
static mut RAND: Option<&'static dyn Rand> = None;
pub unsafe fn set_rand(rand: &'static dyn Rand) {
RAND = Some(rand);
}
pub fn rand(buf: &mut [u8]) {
unsafe { RAND.dexpect(defmt::intern!("No rand set")).rand(buf) }
}