diff options
| author | Dario Nieuwenhuis <[email protected]> | 2020-10-31 16:35:18 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2020-10-31 16:35:18 +0100 |
| commit | 03bd11ce0d4da04a4431cd89106b8797e924c2bc (patch) | |
| tree | 2bdeb5e940d4ec297caa33e7607a0777514d14ab | |
| parent | 878bfd2b7520631ab4b39dbe928dec6fc1a69f00 (diff) | |
Add Rand trait
| -rw-r--r-- | embassy/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy/src/rand.rs | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 3b9aa8145..250ef5673 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs | |||
| @@ -8,3 +8,4 @@ pub mod flash; | |||
| 8 | pub mod io; | 8 | pub mod io; |
| 9 | pub mod time; | 9 | pub mod time; |
| 10 | pub mod util; | 10 | pub mod util; |
| 11 | 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 000000000..bb6cd9d3d --- /dev/null +++ b/embassy/src/rand.rs | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | use crate::util::Dewrap; | ||
| 2 | pub trait Rand { | ||
| 3 | fn rand(&self, buf: &mut [u8]); | ||
| 4 | } | ||
| 5 | |||
| 6 | static mut RAND: Option<&'static dyn Rand> = None; | ||
| 7 | |||
| 8 | pub unsafe fn set_rand(rand: &'static dyn Rand) { | ||
| 9 | RAND = Some(rand); | ||
| 10 | } | ||
| 11 | |||
| 12 | pub fn rand(buf: &mut [u8]) { | ||
| 13 | unsafe { RAND.dexpect(defmt::intern!("No rand set")).rand(buf) } | ||
| 14 | } | ||
