pub struct Rng<'d, M: Mode> { /* private fields */ }Expand description
A wrapper around an nRF RNG peripheral.
It has a non-blocking API, and a blocking api through rand.
Implementations§
Source§impl<'d> Rng<'d, Blocking>
impl<'d> Rng<'d, Blocking>
Sourcepub fn new_blocking<T: Instance>(_rng: Peri<'d, T>) -> Self
pub fn new_blocking<T: Instance>(_rng: Peri<'d, T>) -> Self
Creates a new RNG driver from the RNG peripheral and interrupt.
SAFETY: The future returned from fill_bytes must not have its lifetime end without running its destructor,
e.g. using mem::forget.
The synchronous API is safe.
Source§impl<'d> Rng<'d, Async>
impl<'d> Rng<'d, Async>
Sourcepub fn new<T: Instance>(
_rng: Peri<'d, T>,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd,
) -> Self
pub fn new<T: Instance>( _rng: Peri<'d, T>, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, ) -> Self
Creates a new RNG driver from the RNG peripheral and interrupt.
SAFETY: The future returned from fill_bytes must not have its lifetime end without running its destructor,
e.g. using mem::forget.
The synchronous API is safe.
Sourcepub async fn fill_bytes(&mut self, dest: &mut [u8])
pub async fn fill_bytes(&mut self, dest: &mut [u8])
Fill the buffer with random bytes.
Source§impl<'d, M: Mode> Rng<'d, M>
impl<'d, M: Mode> Rng<'d, M>
Sourcepub fn set_bias_correction(&self, enable: bool)
pub fn set_bias_correction(&self, enable: bool)
Enable or disable the RNG’s bias correction.
Bias correction removes any bias towards a ‘1’ or a ‘0’ in the bits generated. However, this makes the generation of numbers slower.
Defaults to disabled.
Sourcepub fn blocking_fill_bytes(&mut self, dest: &mut [u8])
pub fn blocking_fill_bytes(&mut self, dest: &mut [u8])
Fill the buffer with random bytes, blocking version.
Sourcepub fn blocking_next_u32(&mut self) -> u32
pub fn blocking_next_u32(&mut self) -> u32
Generate a random u32
Sourcepub fn blocking_next_u64(&mut self) -> u64
pub fn blocking_next_u64(&mut self) -> u64
Generate a random u64