Skip to content

Commit

Permalink
Add a short explanation on how to use RingOscillator as a random numb…
Browse files Browse the repository at this point in the history
…er source
  • Loading branch information
jannic committed Nov 12, 2023
1 parent 7b04000 commit 0b214dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions rp2040-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion rp2040-hal/src/rosc.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down

0 comments on commit 0b214dc

Please sign in to comment.