Skip to content

Commit

Permalink
Doc comments fix
Browse files Browse the repository at this point in the history
  • Loading branch information
playfulFence committed Jul 1, 2024
1 parent b30c079 commit cf3dbeb
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions esp-hal/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,36 @@ impl rand_core::RngCore for Rng {
/// Due to pulling the entropy source from the ADC, it uses the associated
/// regiters, so to use TRNG we need to "occupy" the ADC peripheral.
///
/// ```rust, ignore
/// ```rust, no_run
#[doc = crate::before_snippet!()]
/// # use esp_hal::rng::Trng;
/// # use esp_hal::peripherals::Peripherals;
/// # use esp_hal::peripherals::ADC1;
/// # use esp_hal::analog::adc::{AdcConfig, Attenuation, Adc};
/// # use esp_hal::gpio::Io;
///
/// let mut peripherals = Peripherals::take();
/// let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
/// let mut buf = [0u8; 16];
///
/// // ADC is not available from now
/// let mut trng = Trng::new(peripherals.RNG, &mut peripherals.ADC1);
/// trng.read(&mut buf);
///
/// println!("TRNG: Random bytes: {:?}", buf);
/// println!("TRNG: Random u32: {}", rng.random());
///
/// let mut true_rand = trng.random();
///
/// let mut rng = trng.downgrade();
///
/// // ADC is available now
/// let analog_pin = io.pins.gpio3;
/// let mut adc1_config = AdcConfig::new();
/// let mut adc1_pin = adc1_config.enable_pin(analog_pin, Attenuation::Attenuation11dB);
/// let mut adc1 = Adc::<ADC1>::new(peripherals.ADC1, adc1_config);
/// let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
///
/// rng.read(&mut buf);
/// println!("Random bytes: {:?}", buf);
/// println!("Random u32: {}", rng.random());
/// true_rand = rng.random();
/// let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
/// println!("ADC reading = {}", pin_value);
/// # }
/// ```

pub struct Trng<'d> {
Expand Down

0 comments on commit cf3dbeb

Please sign in to comment.