//! Basic blocking delay //! //! This module provides a basic asm-based blocking delay. //! Borrowed from our good friends at Quartiq: //! https://github.com/quartiq/stabilizer/blob/master/src/hardware/delay.rs //! use stm32f4xx_hal::hal::blocking::delay::{DelayMs, DelayUs}; // use stm32f4xx_hal::block; /// A basic delay implementation. pub struct AsmDelay { frequency_us: u32, frequency_ms: u32, } impl AsmDelay { /// Create a new delay. /// /// # Args /// * `freq` - The CPU core frequency. pub fn new(freq: u32) -> AsmDelay { AsmDelay { frequency_us: (freq / 1_000_000), frequency_ms: (freq / 1_000), } } } impl DelayUs for AsmDelay where U: Into, { fn delay_us(&mut self, us: U) { cortex_m::asm::delay(self.frequency_us * us.into()) } } impl DelayMs for AsmDelay where U: Into, { fn delay_ms(&mut self, ms: U) { cortex_m::asm::delay(self.frequency_ms * ms.into()) } }