Skip to content

Commit

Permalink
random: Make available as riot_rs::random; rename laze feature to match
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn authored and kaspar030 committed Apr 12, 2024
1 parent 83ca461 commit 047c454
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions examples/random/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
[package]
name = "random"
name = "example-random"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
publish = false

[dependencies]
# not enabling riot-rs/hwrng even though it's currently needed -- laze takes
# care of that.
riot-rs = { path = "../../src/riot-rs", features = ["threading"] }
# Enabling the feature "random" is somewhat redundant with laze.yml's selects:
# random, but helps with interactive tools.
riot-rs = { path = "../../src/riot-rs", features = ["threading", "random"] }
riot-rs-boards = { path = "../../src/riot-rs-boards" }

riot-rs-random = { version = "0.1.0", path = "../../src/riot-rs-random" }
rand = { version = "0.8.5", default-features = false }
4 changes: 2 additions & 2 deletions examples/random/laze.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apps:
- name: random
- name: example-random
selects:
- ?release
- rng
- random
2 changes: 1 addition & 1 deletion examples/random/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use riot_rs::debug::println;
#[riot_rs::thread(autostart)]
fn main() {
use rand::Rng as _;
let mut rng = riot_rs_random::get_rng();
let mut rng = riot_rs::random::get_rng();

let value = rng.gen_range(1..=6);

Expand Down
11 changes: 9 additions & 2 deletions laze-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,18 @@ modules:
FEATURES:
- riot-rs/hwrng

- name: rng
help: A system-wide RNG is available
- name: random
help: A system-wide RNG is available (through the riot_rs::random module).

As the riot_rs::random module will refuse operation at run time if not
properly initialized, this depends on sources of original entropy.
depends:
# could later alternatively depend on mutable config storage
- hwrng
env:
global:
FEATURES:
- riot-rs/random

- name: sw/benchmark
help: provided if a target supports `benchmark()`
Expand Down
3 changes: 3 additions & 0 deletions src/riot-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ riot-rs-buildinfo = { path = "../riot-rs-buildinfo" }
riot-rs-debug = { workspace = true }
riot-rs-embassy = { path = "../riot-rs-embassy" }
riot-rs-macros = { path = "../riot-rs-macros" }
riot-rs-random = { path = "../riot-rs-random", optional = true }
riot-rs-rt = { path = "../riot-rs-rt" }
riot-rs-threads = { path = "../riot-rs-threads", optional = true }
static_cell = { workspace = true }
Expand Down Expand Up @@ -44,6 +45,8 @@ threading = [
## Enables support for timeouts in the internal executor---required to use
## `embassy_time::Timer`.
time = ["riot-rs-embassy/time"]
## Enables the [`riot-rs::random`] module.
random = ["riot-rs-random"]
## Enables seeding the random number generator from hardware.
hwrng = ["riot-rs-embassy/hwrng"]

Expand Down
3 changes: 3 additions & 0 deletions src/riot-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub use riot_rs_debug as debug;
#[doc(inline)]
pub use riot_rs_embassy as embassy;
pub use riot_rs_embassy::{define_peripherals, group_peripherals};
#[cfg(feature = "random")]
#[doc(inline)]
pub use riot_rs_random as random;
#[doc(inline)]
pub use riot_rs_rt as rt;
#[cfg(feature = "threading")]
Expand Down

0 comments on commit 047c454

Please sign in to comment.