diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 3b9aa814..250ef567 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs @@ -8,3 +8,4 @@ pub mod flash; pub mod io; pub mod time; pub mod util; +pub mod rand; \ No newline at end of file diff --git a/embassy/src/rand.rs b/embassy/src/rand.rs new file mode 100644 index 00000000..bb6cd9d3 --- /dev/null +++ b/embassy/src/rand.rs @@ -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) } +}