Add Rand trait
This commit is contained in:
parent
878bfd2b75
commit
03bd11ce0d
2 changed files with 15 additions and 0 deletions
|
@ -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
14
embassy/src/rand.rs
Normal 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) }
|
||||
}
|
Loading…
Reference in a new issue