Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a short explanation on how to use RingOscillator as a random number source #718

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 14 additions & 2 deletions rp2040-hal/src/rosc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
//! 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
//!
jannic marked this conversation as resolved.
Show resolved Hide resolved
//! 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();
//! ```
//! [`rand`]: https://docs.rs/rand
use fugit::HertzU32;

use crate::{pac::ROSC, typelevel::Sealed};
Expand Down
Loading