2022-09-20 19:23:56 +02:00
|
|
|
#![cfg_attr(not(any(feature = "std", feature = "wasm", test)), no_std)]
|
2023-11-29 17:23:48 +01:00
|
|
|
#![cfg_attr(nightly, feature(async_fn_in_trait, impl_trait_projections))]
|
|
|
|
#![cfg_attr(nightly, allow(stable_features, unknown_lints))]
|
|
|
|
#![allow(async_fn_in_trait)]
|
2022-08-23 13:57:45 +02:00
|
|
|
#![doc = include_str!("../README.md")]
|
2022-08-17 23:40:16 +02:00
|
|
|
#![allow(clippy::new_without_default)]
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
|
|
|
|
// This mod MUST go first, so that the others see its macros.
|
|
|
|
pub(crate) mod fmt;
|
2021-08-26 00:20:52 +02:00
|
|
|
|
2021-07-12 03:10:01 +02:00
|
|
|
mod delay;
|
2021-08-03 22:08:13 +02:00
|
|
|
pub mod driver;
|
2020-10-19 21:15:24 +02:00
|
|
|
mod duration;
|
|
|
|
mod instant;
|
2022-09-06 20:39:23 +02:00
|
|
|
pub mod queue;
|
2022-09-02 00:58:31 +02:00
|
|
|
mod tick;
|
2021-07-12 03:10:01 +02:00
|
|
|
mod timer;
|
2020-10-19 21:15:24 +02:00
|
|
|
|
2023-10-29 19:49:52 +01:00
|
|
|
#[cfg(feature = "mock-driver")]
|
|
|
|
mod driver_mock;
|
|
|
|
|
|
|
|
#[cfg(feature = "mock-driver")]
|
|
|
|
pub use driver_mock::MockDriver;
|
|
|
|
|
2021-08-25 20:34:25 +02:00
|
|
|
#[cfg(feature = "std")]
|
|
|
|
mod driver_std;
|
2021-09-13 14:35:40 +02:00
|
|
|
#[cfg(feature = "wasm")]
|
|
|
|
mod driver_wasm;
|
2022-09-26 12:46:15 +02:00
|
|
|
#[cfg(feature = "generic-queue")]
|
|
|
|
mod queue_generic;
|
2021-09-13 14:35:40 +02:00
|
|
|
|
2021-07-12 03:10:01 +02:00
|
|
|
pub use delay::{block_for, Delay};
|
2020-10-19 21:15:24 +02:00
|
|
|
pub use duration::Duration;
|
|
|
|
pub use instant::Instant;
|
2021-07-12 03:10:01 +02:00
|
|
|
pub use timer::{with_timeout, Ticker, TimeoutError, Timer};
|
2020-10-19 21:15:24 +02:00
|
|
|
|
2021-08-24 22:46:07 +02:00
|
|
|
/// Ticks per second of the global timebase.
|
|
|
|
///
|
2022-08-17 23:40:16 +02:00
|
|
|
/// This value is specified by the `tick-*` Cargo features, which
|
2021-08-24 22:46:07 +02:00
|
|
|
/// should be set by the time driver. Some drivers support a fixed tick rate, others
|
|
|
|
/// allow you to choose a tick rate with Cargo features of their own. You should not
|
2022-08-17 23:40:16 +02:00
|
|
|
/// set the `tick-*` features for embassy yourself as an end user.
|
2022-09-02 00:58:31 +02:00
|
|
|
pub const TICK_HZ: u64 = tick::TICK_HZ;
|
2022-02-12 03:19:46 +01:00
|
|
|
|
|
|
|
const fn gcd(a: u64, b: u64) -> u64 {
|
|
|
|
if b == 0 {
|
|
|
|
a
|
|
|
|
} else {
|
|
|
|
gcd(b, a % b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-02 00:58:31 +02:00
|
|
|
pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000);
|
|
|
|
pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000);
|
2023-11-29 16:37:07 +01:00
|
|
|
pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000);
|
2022-08-17 23:40:16 +02:00
|
|
|
|
|
|
|
#[cfg(feature = "defmt-timestamp-uptime")]
|
|
|
|
defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() }
|