aboutsummaryrefslogtreecommitdiff
path: root/embassy-time
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-11-29 17:23:48 +0100
committerDario Nieuwenhuis <[email protected]>2023-11-29 17:26:33 +0100
commitc6989dfbca51787146f50270c671af9db434f577 (patch)
tree5974a8ec41c108d5208e4f68027b918d424a2046 /embassy-time
parent384bad7bfaa1f2415baf2cd3b69ebf36dc0a02d7 (diff)
Remove nightly and unstable-traits features in preparation for 1.75.
Diffstat (limited to 'embassy-time')
-rw-r--r--embassy-time/Cargo.toml17
-rw-r--r--embassy-time/build.rs19
-rw-r--r--embassy-time/src/delay.rs100
-rw-r--r--embassy-time/src/lib.rs5
4 files changed, 67 insertions, 74 deletions
diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml
index 570e0efa7..5cbb44b33 100644
--- a/embassy-time/Cargo.toml
+++ b/embassy-time/Cargo.toml
@@ -22,23 +22,16 @@ links = "embassy-time"
22[package.metadata.embassy_docs] 22[package.metadata.embassy_docs]
23src_base = "https://github.com/embassy-rs/embassy/blob/embassy-time-v$VERSION/embassy-time/src/" 23src_base = "https://github.com/embassy-rs/embassy/blob/embassy-time-v$VERSION/embassy-time/src/"
24src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-time/src/" 24src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-time/src/"
25features = ["nightly", "defmt", "unstable-traits", "std"] 25features = ["defmt", "std"]
26target = "x86_64-unknown-linux-gnu" 26target = "x86_64-unknown-linux-gnu"
27 27
28[package.metadata.docs.rs] 28[package.metadata.docs.rs]
29features = ["nightly", "defmt", "unstable-traits", "std"] 29features = ["defmt", "std"]
30 30
31[features] 31[features]
32std = ["tick-hz-1_000_000", "critical-section/std"] 32std = ["tick-hz-1_000_000", "critical-section/std"]
33wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-hz-1_000_000"] 33wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-hz-1_000_000"]
34 34
35# Enable nightly-only features
36nightly = ["embedded-hal-async"]
37
38# Implement embedded-hal 1.0 alpha and embedded-hal-async traits.
39# Implement embedded-hal-async traits if `nightly` is set as well.
40unstable-traits = ["embedded-hal-1"]
41
42# Display a timestamp of the number of seconds since startup next to defmt log messages 35# Display a timestamp of the number of seconds since startup next to defmt log messages
43# To use this you must have a time driver provided. 36# To use this you must have a time driver provided.
44defmt-timestamp-uptime = ["defmt"] 37defmt-timestamp-uptime = ["defmt"]
@@ -242,8 +235,8 @@ defmt = { version = "0.3", optional = true }
242log = { version = "0.4.14", optional = true } 235log = { version = "0.4.14", optional = true }
243 236
244embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } 237embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" }
245embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} 238embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" }
246embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} 239embedded-hal-async = { version = "=1.0.0-rc.2" }
247 240
248futures-util = { version = "0.3.17", default-features = false } 241futures-util = { version = "0.3.17", default-features = false }
249critical-section = "1.1" 242critical-section = "1.1"
@@ -258,4 +251,4 @@ wasm-timer = { version = "0.2.5", optional = true }
258[dev-dependencies] 251[dev-dependencies]
259serial_test = "0.9" 252serial_test = "0.9"
260critical-section = { version = "1.1", features = ["std"] } 253critical-section = { version = "1.1", features = ["std"] }
261embassy-executor = { version = "0.3.3", path = "../embassy-executor", features = ["nightly"] } 254embassy-executor = { version = "0.3.3", path = "../embassy-executor" }
diff --git a/embassy-time/build.rs b/embassy-time/build.rs
index 5b0095661..78bd27ec7 100644
--- a/embassy-time/build.rs
+++ b/embassy-time/build.rs
@@ -1,3 +1,18 @@
1// empty, needed to be able to use `links` in Cargo.toml. 1use std::env;
2use std::ffi::OsString;
3use std::process::Command;
2 4
3fn main() {} 5fn main() {
6 println!("cargo:rerun-if-changed=build.rs");
7
8 let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc"));
9
10 let output = Command::new(rustc)
11 .arg("--version")
12 .output()
13 .expect("failed to run `rustc --version`");
14
15 if String::from_utf8_lossy(&output.stdout).contains("nightly") {
16 println!("cargo:rustc-cfg=nightly");
17 }
18}
diff --git a/embassy-time/src/delay.rs b/embassy-time/src/delay.rs
index aab56b1f1..7ef5961f0 100644
--- a/embassy-time/src/delay.rs
+++ b/embassy-time/src/delay.rs
@@ -1,4 +1,5 @@
1use super::{Duration, Instant}; 1use super::{Duration, Instant};
2use crate::Timer;
2 3
3/// Blocks for at least `duration`. 4/// Blocks for at least `duration`.
4pub fn block_for(duration: Duration) { 5pub fn block_for(duration: Duration) {
@@ -14,83 +15,66 @@ pub fn block_for(duration: Duration) {
14/// active driver. 15/// active driver.
15pub struct Delay; 16pub struct Delay;
16 17
17#[cfg(feature = "unstable-traits")] 18impl embedded_hal_1::delay::DelayNs for Delay {
18mod eh1 { 19 fn delay_ns(&mut self, ns: u32) {
19 use super::*; 20 block_for(Duration::from_nanos(ns as u64))
20 21 }
21 impl embedded_hal_1::delay::DelayNs for Delay {
22 fn delay_ns(&mut self, ns: u32) {
23 block_for(Duration::from_nanos(ns as u64))
24 }
25 22
26 fn delay_us(&mut self, us: u32) { 23 fn delay_us(&mut self, us: u32) {
27 block_for(Duration::from_micros(us as u64)) 24 block_for(Duration::from_micros(us as u64))
28 } 25 }
29 26
30 fn delay_ms(&mut self, ms: u32) { 27 fn delay_ms(&mut self, ms: u32) {
31 block_for(Duration::from_millis(ms as u64)) 28 block_for(Duration::from_millis(ms as u64))
32 }
33 } 29 }
34} 30}
35 31
36#[cfg(all(feature = "unstable-traits", feature = "nightly"))] 32impl embedded_hal_async::delay::DelayNs for Delay {
37mod eha { 33 async fn delay_ns(&mut self, ns: u32) {
38 use super::*; 34 Timer::after_nanos(ns as _).await
39 use crate::Timer; 35 }
40
41 impl embedded_hal_async::delay::DelayNs for Delay {
42 async fn delay_ns(&mut self, ns: u32) {
43 Timer::after_nanos(ns as _).await
44 }
45 36
46 async fn delay_us(&mut self, us: u32) { 37 async fn delay_us(&mut self, us: u32) {
47 Timer::after_micros(us as _).await 38 Timer::after_micros(us as _).await
48 } 39 }
49 40
50 async fn delay_ms(&mut self, ms: u32) { 41 async fn delay_ms(&mut self, ms: u32) {
51 Timer::after_millis(ms as _).await 42 Timer::after_millis(ms as _).await
52 }
53 } 43 }
54} 44}
55 45
56mod eh02 { 46impl embedded_hal_02::blocking::delay::DelayMs<u8> for Delay {
57 use embedded_hal_02::blocking::delay::{DelayMs, DelayUs}; 47 fn delay_ms(&mut self, ms: u8) {
58 48 block_for(Duration::from_millis(ms as u64))
59 use super::*;
60
61 impl DelayMs<u8> for Delay {
62 fn delay_ms(&mut self, ms: u8) {
63 block_for(Duration::from_millis(ms as u64))
64 }
65 } 49 }
50}
66 51
67 impl DelayMs<u16> for Delay { 52impl embedded_hal_02::blocking::delay::DelayMs<u16> for Delay {
68 fn delay_ms(&mut self, ms: u16) { 53 fn delay_ms(&mut self, ms: u16) {
69 block_for(Duration::from_millis(ms as u64)) 54 block_for(Duration::from_millis(ms as u64))
70 }
71 } 55 }
56}
72 57
73 impl DelayMs<u32> for Delay { 58impl embedded_hal_02::blocking::delay::DelayMs<u32> for Delay {
74 fn delay_ms(&mut self, ms: u32) { 59 fn delay_ms(&mut self, ms: u32) {
75 block_for(Duration::from_millis(ms as u64)) 60 block_for(Duration::from_millis(ms as u64))
76 }
77 } 61 }
62}
78 63
79 impl DelayUs<u8> for Delay { 64impl embedded_hal_02::blocking::delay::DelayUs<u8> for Delay {
80 fn delay_us(&mut self, us: u8) { 65 fn delay_us(&mut self, us: u8) {
81 block_for(Duration::from_micros(us as u64)) 66 block_for(Duration::from_micros(us as u64))
82 }
83 } 67 }
68}
84 69
85 impl DelayUs<u16> for Delay { 70impl embedded_hal_02::blocking::delay::DelayUs<u16> for Delay {
86 fn delay_us(&mut self, us: u16) { 71 fn delay_us(&mut self, us: u16) {
87 block_for(Duration::from_micros(us as u64)) 72 block_for(Duration::from_micros(us as u64))
88 }
89 } 73 }
74}
90 75
91 impl DelayUs<u32> for Delay { 76impl embedded_hal_02::blocking::delay::DelayUs<u32> for Delay {
92 fn delay_us(&mut self, us: u32) { 77 fn delay_us(&mut self, us: u32) {
93 block_for(Duration::from_micros(us as u64)) 78 block_for(Duration::from_micros(us as u64))
94 }
95 } 79 }
96} 80}
diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs
index a0f6e3824..82a7ee0df 100644
--- a/embassy-time/src/lib.rs
+++ b/embassy-time/src/lib.rs
@@ -1,6 +1,7 @@
1#![cfg_attr(not(any(feature = "std", feature = "wasm", test)), no_std)] 1#![cfg_attr(not(any(feature = "std", feature = "wasm", test)), no_std)]
2#![cfg_attr(feature = "nightly", feature(async_fn_in_trait))] 2#![cfg_attr(nightly, feature(async_fn_in_trait, impl_trait_projections))]
3#![cfg_attr(feature = "nightly", allow(stable_features, unknown_lints, async_fn_in_trait))] 3#![cfg_attr(nightly, allow(stable_features, unknown_lints))]
4#![allow(async_fn_in_trait)]
4#![doc = include_str!("../README.md")] 5#![doc = include_str!("../README.md")]
5#![allow(clippy::new_without_default)] 6#![allow(clippy::new_without_default)]
6#![warn(missing_docs)] 7#![warn(missing_docs)]