Skip to main content

arm_generic_timer/
embedded_hal.rs

1// SPDX-FileCopyrightText: Copyright The arm-generic-timer Contributors.
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Implementation of `embedded-hal` traits for timers.
5
6use core::time::Duration;
7
8use crate::{Timer, TimerInterface};
9use embedded_hal::delay::DelayNs;
10
11impl<T: TimerInterface> DelayNs for Timer<T> {
12    fn delay_ns(&mut self, ns: u32) {
13        self.wait(Duration::from_nanos(ns.into()));
14    }
15
16    fn delay_ms(&mut self, ms: u32) {
17        self.wait(Duration::from_millis(ms.into()));
18    }
19
20    fn delay_us(&mut self, us: u32) {
21        self.wait(Duration::from_micros(us.into()));
22    }
23}