-
Notifications
You must be signed in to change notification settings - Fork 0
/
rand.rs
37 lines (27 loc) · 949 Bytes
/
rand.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Uses the random number generator via `getrandom()` as a normal program would.
#![no_std]
#![no_main]
use core::fmt::Write;
#[allow(unused_imports)]
use defmt::{debug, info, warn, error};
use {defmt_rtt as _, panic_probe as _};
use embassy_executor::Spawner;
use embassy_time::{Timer, Duration};
use getrandom::register_custom_getrandom;
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let mut gpio = p.PIN_10;
caprand::setup(&mut gpio).unwrap();
register_custom_getrandom!(caprand::getrandom);
loop {
let mut mystery = [0u8; 10];
getrandom::getrandom(mystery.as_mut_slice()).unwrap();
let mut s = heapless::String::<33>::new();
for m in mystery.iter() {
write!(s, "{:02x} ", *m).unwrap();
}
info!("mystery bytes! {}", s.as_str());
Timer::after(Duration::from_millis(333)).await;
}
}