stm32: more docs.
This commit is contained in:
@ -13,13 +13,19 @@ use crate::{interrupt, pac, peripherals, Peripheral};
|
||||
|
||||
static RNG_WAKER: AtomicWaker = AtomicWaker::new();
|
||||
|
||||
/// RNG error
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub enum Error {
|
||||
/// Seed error.
|
||||
SeedError,
|
||||
/// Clock error. Double-check the RCC configuration,
|
||||
/// see the Reference Manual for details on restrictions
|
||||
/// on RNG clocks.
|
||||
ClockError,
|
||||
}
|
||||
|
||||
/// RNG interrupt handler.
|
||||
pub struct InterruptHandler<T: Instance> {
|
||||
_phantom: PhantomData<T>,
|
||||
}
|
||||
@ -34,11 +40,13 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
|
||||
}
|
||||
}
|
||||
|
||||
/// RNG driver.
|
||||
pub struct Rng<'d, T: Instance> {
|
||||
_inner: PeripheralRef<'d, T>,
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> Rng<'d, T> {
|
||||
/// Create a new RNG driver.
|
||||
pub fn new(
|
||||
inner: impl Peripheral<P = T> + 'd,
|
||||
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
|
||||
@ -54,6 +62,7 @@ impl<'d, T: Instance> Rng<'d, T> {
|
||||
random
|
||||
}
|
||||
|
||||
/// Reset the RNG.
|
||||
#[cfg(rng_v1)]
|
||||
pub fn reset(&mut self) {
|
||||
T::regs().cr().write(|reg| {
|
||||
@ -106,7 +115,8 @@ impl<'d, T: Instance> Rng<'d, T> {
|
||||
while T::regs().cr().read().condrst() {}
|
||||
}
|
||||
|
||||
pub fn recover_seed_error(&mut self) -> () {
|
||||
/// Try to recover from a seed error.
|
||||
pub fn recover_seed_error(&mut self) {
|
||||
self.reset();
|
||||
// reset should also clear the SEIS flag
|
||||
if T::regs().sr().read().seis() {
|
||||
@ -117,6 +127,7 @@ impl<'d, T: Instance> Rng<'d, T> {
|
||||
while T::regs().sr().read().secs() {}
|
||||
}
|
||||
|
||||
/// Fill the given slice with random values.
|
||||
pub async fn async_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
|
||||
for chunk in dest.chunks_mut(4) {
|
||||
let mut bits = T::regs().sr().read();
|
||||
@ -217,7 +228,9 @@ pub(crate) mod sealed {
|
||||
}
|
||||
}
|
||||
|
||||
/// RNG instance trait.
|
||||
pub trait Instance: sealed::Instance + Peripheral<P = Self> + crate::rcc::RccPeripheral + 'static + Send {
|
||||
/// Interrupt for this RNG instance.
|
||||
type Interrupt: interrupt::typelevel::Interrupt;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user