aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-02-26 01:58:00 +0100
committerDario Nieuwenhuis <[email protected]>2021-02-26 01:58:00 +0100
commit17cf301d4fdc3bc0b1356ed250bfacca0d67ef3e (patch)
treeaf8f914473df09e19651660a79e19aa06e201419
parent11be9170ec018dcc9284b413c5313ce7bb07159f (diff)
Remove rand(), fixes #50
-rw-r--r--embassy-std/Cargo.toml3
-rw-r--r--embassy-std/src/lib.rs9
-rw-r--r--embassy/src/lib.rs1
-rw-r--r--embassy/src/rand.rs15
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]
8embassy = { version = "0.1.0", path = "../embassy", features = ["std"] } 8embassy = { version = "0.1.0", path = "../embassy", features = ["std"] }
9lazy_static = "1.4.0" 9lazy_static = "1.4.0" \ No newline at end of file
10rand_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 @@
1use embassy::executor::{raw, Spawner}; 1use embassy::executor::{raw, Spawner};
2use embassy::time::TICKS_PER_SECOND; 2use embassy::time::TICKS_PER_SECOND;
3use embassy::time::{Alarm, Clock}; 3use embassy::time::{Alarm, Clock};
4use rand_core::{OsRng, RngCore};
5use std::marker::PhantomData; 4use std::marker::PhantomData;
6use std::mem::MaybeUninit; 5use std::mem::MaybeUninit;
7use std::ptr; 6use std::ptr;
@@ -19,13 +18,6 @@ impl Clock for StdClock {
19 } 18 }
20} 19}
21 20
22struct StdRand;
23impl embassy::rand::Rand for StdRand {
24 fn rand(&self, buf: &mut [u8]) {
25 OsRng.fill_bytes(buf);
26 }
27}
28
29static mut ALARM_AT: u64 = u64::MAX; 21static mut ALARM_AT: u64 = u64::MAX;
30 22
31pub struct StdAlarm; 23pub 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;
13pub mod gpio; 13pub mod gpio;
14pub mod interrupt; 14pub mod interrupt;
15pub mod io; 15pub mod io;
16pub mod rand;
17pub mod time; 16pub mod time;
18pub mod uart; 17pub mod uart;
19pub mod util; 18pub 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 @@
1use crate::fmt::*;
2
3pub trait Rand {
4 fn rand(&self, buf: &mut [u8]);
5}
6
7static mut RAND: Option<&'static dyn Rand> = None;
8
9pub unsafe fn set_rand(rand: &'static dyn Rand) {
10 RAND = Some(rand);
11}
12
13pub fn rand(buf: &mut [u8]) {
14 unsafe { unwrap!(RAND, "No rand set").rand(buf) }
15}