From e681478943aa9acbccb4e22488be00fbd5a16b42 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sun, 12 Nov 2023 15:38:07 +0000 Subject: [PATCH 1/3] Add a short explanation on how to use RingOscillator as a random number source --- rp2040-hal/Cargo.toml | 1 + rp2040-hal/src/rosc.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index c2f80b812..ba279d275 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -50,6 +50,7 @@ rp2040-boot2 = "0.3.0" hd44780-driver = "0.4.0" pio-proc = "0.2.0" dht-sensor = "0.2.1" +rand = { version = "0.8.5", default-features = false } [features] # Minimal startup / runtime for Cortex-M microcontrollers diff --git a/rp2040-hal/src/rosc.rs b/rp2040-hal/src/rosc.rs index 0ad85f299..7f4760cf8 100644 --- a/rp2040-hal/src/rosc.rs +++ b/rp2040-hal/src/rosc.rs @@ -1,5 +1,16 @@ //! Ring Oscillator (ROSC) -// See [Chapter 2 Section 17](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details +//! See [Chapter 2 Section 17](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details +//! +//! In addition to its obvious role as a clock source, [`RingOscillator`] can also be used as a random number source +//! for the [`rand`] crate: +//! +//! ```no_run +//! # let mut pac = rp2040_pac::Peripherals::take().unwrap(); +//! use rp2040_hal::rosc::RingOscillator; +//! use rand::Rng; +//! let mut rnd = RingOscillator::new(pac.ROSC).initialize(); +//! let random_value: u32 = rnd.gen(); +//! ``` use fugit::HertzU32; From a3fcf144f85b9260954b8a94376365aed2a3ad28 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Tue, 21 Nov 2023 18:54:23 +0100 Subject: [PATCH 2/3] Improve formatting Co-authored-by: 9names <60134748+9names@users.noreply.github.com> --- rp2040-hal/src/rosc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rp2040-hal/src/rosc.rs b/rp2040-hal/src/rosc.rs index 7f4760cf8..28a142866 100644 --- a/rp2040-hal/src/rosc.rs +++ b/rp2040-hal/src/rosc.rs @@ -1,4 +1,5 @@ //! Ring Oscillator (ROSC) +//! //! See [Chapter 2 Section 17](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details //! //! In addition to its obvious role as a clock source, [`RingOscillator`] can also be used as a random number source From df9d35b6b28786cd4e71b3b772bdbe60a10aea6f Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Tue, 21 Nov 2023 18:54:54 +0100 Subject: [PATCH 3/3] Fix dangling link Co-authored-by: 9names <60134748+9names@users.noreply.github.com> --- rp2040-hal/src/rosc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rp2040-hal/src/rosc.rs b/rp2040-hal/src/rosc.rs index 28a142866..93a0ab17b 100644 --- a/rp2040-hal/src/rosc.rs +++ b/rp2040-hal/src/rosc.rs @@ -12,7 +12,7 @@ //! let mut rnd = RingOscillator::new(pac.ROSC).initialize(); //! let random_value: u32 = rnd.gen(); //! ``` - +//! [`rand`]: https://docs.rs/rand use fugit::HertzU32; use crate::{pac::ROSC, typelevel::Sealed};