diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-02-26 01:58:00 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-02-26 01:58:00 +0100 |
| commit | 17cf301d4fdc3bc0b1356ed250bfacca0d67ef3e (patch) | |
| tree | af8f914473df09e19651660a79e19aa06e201419 | |
| parent | 11be9170ec018dcc9284b413c5313ce7bb07159f (diff) | |
Remove rand(), fixes #50
| -rw-r--r-- | embassy-std/Cargo.toml | 3 | ||||
| -rw-r--r-- | embassy-std/src/lib.rs | 9 | ||||
| -rw-r--r-- | embassy/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy/src/rand.rs | 15 |
4 files changed, 1 insertions, 27 deletions
diff --git a/embassy-std/Cargo.toml b/embassy-std/Cargo.toml index 2a8028137..0a59999c0 100644 --- a/embassy-std/Cargo.toml +++ b/embassy-std/Cargo.toml | |||
| @@ -6,5 +6,4 @@ edition = "2018" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy = { version = "0.1.0", path = "../embassy", features = ["std"] } | 8 | embassy = { version = "0.1.0", path = "../embassy", features = ["std"] } |
| 9 | lazy_static = "1.4.0" | 9 | lazy_static = "1.4.0" \ No newline at end of file |
| 10 | rand_core = { version = "0.6.0", features = ["std"] } | ||
diff --git a/embassy-std/src/lib.rs b/embassy-std/src/lib.rs index 29f4de421..688054cb9 100644 --- a/embassy-std/src/lib.rs +++ b/embassy-std/src/lib.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | use embassy::executor::{raw, Spawner}; | 1 | use embassy::executor::{raw, Spawner}; |
| 2 | use embassy::time::TICKS_PER_SECOND; | 2 | use embassy::time::TICKS_PER_SECOND; |
| 3 | use embassy::time::{Alarm, Clock}; | 3 | use embassy::time::{Alarm, Clock}; |
| 4 | use rand_core::{OsRng, RngCore}; | ||
| 5 | use std::marker::PhantomData; | 4 | use std::marker::PhantomData; |
| 6 | use std::mem::MaybeUninit; | 5 | use std::mem::MaybeUninit; |
| 7 | use std::ptr; | 6 | use std::ptr; |
| @@ -19,13 +18,6 @@ impl Clock for StdClock { | |||
| 19 | } | 18 | } |
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | struct StdRand; | ||
| 23 | impl embassy::rand::Rand for StdRand { | ||
| 24 | fn rand(&self, buf: &mut [u8]) { | ||
| 25 | OsRng.fill_bytes(buf); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | static mut ALARM_AT: u64 = u64::MAX; | 21 | static mut ALARM_AT: u64 = u64::MAX; |
| 30 | 22 | ||
| 31 | pub struct StdAlarm; | 23 | pub struct StdAlarm; |
| @@ -101,7 +93,6 @@ impl Executor { | |||
| 101 | unsafe { | 93 | unsafe { |
| 102 | CLOCK_ZERO.as_mut_ptr().write(StdInstant::now()); | 94 | CLOCK_ZERO.as_mut_ptr().write(StdInstant::now()); |
| 103 | embassy::time::set_clock(&StdClock); | 95 | embassy::time::set_clock(&StdClock); |
| 104 | embassy::rand::set_rand(&StdRand); | ||
| 105 | } | 96 | } |
| 106 | 97 | ||
| 107 | Self { | 98 | Self { |
diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index cab61080a..0844df37c 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs | |||
| @@ -13,7 +13,6 @@ pub mod flash; | |||
| 13 | pub mod gpio; | 13 | pub mod gpio; |
| 14 | pub mod interrupt; | 14 | pub mod interrupt; |
| 15 | pub mod io; | 15 | pub mod io; |
| 16 | pub mod rand; | ||
| 17 | pub mod time; | 16 | pub mod time; |
| 18 | pub mod uart; | 17 | pub mod uart; |
| 19 | pub mod util; | 18 | pub mod util; |
diff --git a/embassy/src/rand.rs b/embassy/src/rand.rs deleted file mode 100644 index 7e3788380..000000000 --- a/embassy/src/rand.rs +++ /dev/null | |||
| @@ -1,15 +0,0 @@ | |||
| 1 | use crate::fmt::*; | ||
| 2 | |||
| 3 | pub trait Rand { | ||
| 4 | fn rand(&self, buf: &mut [u8]); | ||
| 5 | } | ||
| 6 | |||
| 7 | static mut RAND: Option<&'static dyn Rand> = None; | ||
| 8 | |||
| 9 | pub unsafe fn set_rand(rand: &'static dyn Rand) { | ||
| 10 | RAND = Some(rand); | ||
| 11 | } | ||
| 12 | |||
| 13 | pub fn rand(buf: &mut [u8]) { | ||
| 14 | unsafe { unwrap!(RAND, "No rand set").rand(buf) } | ||
| 15 | } | ||
