From 047c45495c91bf7cd9e939ad81d7e8cb4caaf770 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 12 Apr 2024 14:25:21 +0200 Subject: [PATCH] random: Make available as riot_rs::random; rename laze feature to match --- Cargo.lock | 1 + examples/random/Cargo.toml | 9 ++++----- examples/random/laze.yml | 4 ++-- examples/random/src/main.rs | 2 +- laze-project.yml | 11 +++++++++-- src/riot-rs/Cargo.toml | 3 +++ src/riot-rs/src/lib.rs | 3 +++ 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76d5434f5..ab0f17c95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2375,6 +2375,7 @@ dependencies = [ "riot-rs-debug", "riot-rs-embassy", "riot-rs-macros", + "riot-rs-random", "riot-rs-rt", "riot-rs-threads", "static_cell", diff --git a/examples/random/Cargo.toml b/examples/random/Cargo.toml index 7bc791234..42dcecb8b 100644 --- a/examples/random/Cargo.toml +++ b/examples/random/Cargo.toml @@ -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 } diff --git a/examples/random/laze.yml b/examples/random/laze.yml index 667cd8551..597db6ba2 100644 --- a/examples/random/laze.yml +++ b/examples/random/laze.yml @@ -1,5 +1,5 @@ apps: - - name: random + - name: example-random selects: - ?release - - rng + - random diff --git a/examples/random/src/main.rs b/examples/random/src/main.rs index 89333a3f6..f2c272a47 100644 --- a/examples/random/src/main.rs +++ b/examples/random/src/main.rs @@ -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); diff --git a/laze-project.yml b/laze-project.yml index ca53586bd..ec52ed9c8 100644 --- a/laze-project.yml +++ b/laze-project.yml @@ -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()` diff --git a/src/riot-rs/Cargo.toml b/src/riot-rs/Cargo.toml index 976309521..9ee608e67 100644 --- a/src/riot-rs/Cargo.toml +++ b/src/riot-rs/Cargo.toml @@ -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 } @@ -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"] diff --git a/src/riot-rs/src/lib.rs b/src/riot-rs/src/lib.rs index 1ecdf1c3a..d09cbbebd 100644 --- a/src/riot-rs/src/lib.rs +++ b/src/riot-rs/src/lib.rs @@ -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")]