From 03bd11ce0d4da04a4431cd89106b8797e924c2bc Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 31 Oct 2020 16:35:18 +0100 Subject: [PATCH] Add Rand trait --- embassy/src/lib.rs | 1 + embassy/src/rand.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 embassy/src/rand.rs 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) } +}