From 369f07b1f4651c63bf772b2a86d6d5e0dc852788 Mon Sep 17 00:00:00 2001 From: Tyson Lawrence Date: Sun, 17 Nov 2024 10:03:49 -0700 Subject: [PATCH] Updating dependencies and removing nightlyt feature --- Cargo.toml | 9 ++++---- README.md | 2 -- rust-toolchain.toml | 2 +- src/fmt.rs | 50 +++++++++++++++++++++++++++++++++++++++++---- src/lib.rs | 9 -------- src/traits.rs | 2 ++ src/updater.rs | 12 +++++++---- tests/serial.rs | 10 ++++----- 8 files changed, 66 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 293c8a8..2adc149 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "embedded-update" -version = "0.12.0" +version = "0.12.1" edition = "2021" resolver = "2" description = "Firmware updates for embedded devices supporting multiple update services" @@ -16,7 +16,7 @@ keywords = ["embedded", "async", "dfu", "no_std", "ota"] exclude = [".github"] [dependencies] -heapless = "0.7" +heapless = "0.8" serde = { version = "1", features = ["derive"], default-features = false } postcard = { version = "1.0", default-features = false, optional = true } embedded-io-async = { version = "0.6", optional = true } @@ -24,7 +24,7 @@ embedded-io = "0.6" defmt = { version = "0.3", optional = true } log = { version = "0.4", optional = true } -embedded-hal-async = {version = "1.0.0-rc.1", optional = true } +embedded-hal-async = { version = "1.0", optional = true } futures = { version = "0.3", default-features = false, optional = true } rand_core = { version = "0.6", default-features = false, optional = true } serde_cbor = { version = "0.11", default-features = false, optional = true } @@ -38,7 +38,6 @@ log = "0.4" rand = "0.8" [features] -default = ["nightly"] -nightly = ["embedded-hal-async", "futures", "postcard", "embedded-io-async"] +default = ["embedded-hal-async", "futures", "postcard", "embedded-io-async"] defmt = ["dep:defmt"] std = [] diff --git a/README.md b/README.md index 57c16ae..1c33671 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,4 @@ Update service and device implementations can be added to `embedded-update` when # Minimum supported Rust version (MSRV) -`embedded-update` requires a feature from `nightly` to compile when using the `nightly` flag. - * async_fn_in_traits diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 7d77370..2212029 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ # Before upgrading check that everything is available on all tier1 targets here: # https://rust-lang.github.io/rustup-components-history [toolchain] -channel = "nightly-2023-10-02" +channel = "1.82" components = ["clippy"] diff --git a/src/fmt.rs b/src/fmt.rs index f8bb0a0..8ca61bc 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -1,9 +1,12 @@ #![macro_use] -#![allow(unused_macros)] +#![allow(unused)] + +use core::fmt::{Debug, Display, LowerHex}; #[cfg(all(feature = "defmt", feature = "log"))] compile_error!("You may not enable both `defmt` and `log` features."); +#[collapse_debuginfo(yes)] macro_rules! assert { ($($x:tt)*) => { { @@ -15,6 +18,7 @@ macro_rules! assert { }; } +#[collapse_debuginfo(yes)] macro_rules! assert_eq { ($($x:tt)*) => { { @@ -26,6 +30,7 @@ macro_rules! assert_eq { }; } +#[collapse_debuginfo(yes)] macro_rules! assert_ne { ($($x:tt)*) => { { @@ -37,6 +42,7 @@ macro_rules! assert_ne { }; } +#[collapse_debuginfo(yes)] macro_rules! debug_assert { ($($x:tt)*) => { { @@ -48,6 +54,7 @@ macro_rules! debug_assert { }; } +#[collapse_debuginfo(yes)] macro_rules! debug_assert_eq { ($($x:tt)*) => { { @@ -59,6 +66,7 @@ macro_rules! debug_assert_eq { }; } +#[collapse_debuginfo(yes)] macro_rules! debug_assert_ne { ($($x:tt)*) => { { @@ -70,6 +78,7 @@ macro_rules! debug_assert_ne { }; } +#[collapse_debuginfo(yes)] macro_rules! todo { ($($x:tt)*) => { { @@ -81,6 +90,7 @@ macro_rules! todo { }; } +#[collapse_debuginfo(yes)] macro_rules! unreachable { ($($x:tt)*) => { { @@ -92,6 +102,7 @@ macro_rules! unreachable { }; } +#[collapse_debuginfo(yes)] macro_rules! panic { ($($x:tt)*) => { { @@ -103,6 +114,7 @@ macro_rules! panic { }; } +#[collapse_debuginfo(yes)] macro_rules! trace { ($s:literal $(, $x:expr)* $(,)?) => { { @@ -116,6 +128,7 @@ macro_rules! trace { }; } +#[collapse_debuginfo(yes)] macro_rules! debug { ($s:literal $(, $x:expr)* $(,)?) => { { @@ -129,6 +142,7 @@ macro_rules! debug { }; } +#[collapse_debuginfo(yes)] macro_rules! info { ($s:literal $(, $x:expr)* $(,)?) => { { @@ -142,6 +156,7 @@ macro_rules! info { }; } +#[collapse_debuginfo(yes)] macro_rules! warn { ($s:literal $(, $x:expr)* $(,)?) => { { @@ -155,6 +170,7 @@ macro_rules! warn { }; } +#[collapse_debuginfo(yes)] macro_rules! error { ($s:literal $(, $x:expr)* $(,)?) => { { @@ -169,6 +185,7 @@ macro_rules! error { } #[cfg(feature = "defmt")] +#[collapse_debuginfo(yes)] macro_rules! unwrap { ($($x:tt)*) => { ::defmt::unwrap!($($x)*) @@ -176,6 +193,7 @@ macro_rules! unwrap { } #[cfg(not(feature = "defmt"))] +#[collapse_debuginfo(yes)] macro_rules! unwrap { ($arg:expr) => { match $crate::fmt::Try::into_result($arg) { @@ -195,9 +213,6 @@ macro_rules! unwrap { } } -#[cfg(feature = "defmt-timestamp-uptime")] -defmt::timestamp! {"{=u64:us}", crate::time::Instant::now().as_micros() } - #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct NoneError; @@ -226,3 +241,30 @@ impl Try for Result { self } } + +pub(crate) struct Bytes<'a>(pub &'a [u8]); + +impl<'a> Debug for Bytes<'a> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{:#02x?}", self.0) + } +} + +impl<'a> Display for Bytes<'a> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{:#02x?}", self.0) + } +} + +impl<'a> LowerHex for Bytes<'a> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{:#02x?}", self.0) + } +} + +#[cfg(feature = "defmt")] +impl<'a> defmt::Format for Bytes<'a> { + fn format(&self, fmt: defmt::Formatter) { + defmt::write!(fmt, "{:02x}", self.0) + } +} diff --git a/src/lib.rs b/src/lib.rs index ef28a78..14b4add 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,4 @@ #![cfg_attr(not(test), no_std)] -#![cfg_attr(feature = "nightly", feature(async_fn_in_trait))] #![doc = include_str!("../README.md")] #![deny(missing_docs)] @@ -8,20 +7,12 @@ mod fmt; mod protocol; pub use protocol::*; -#[cfg(feature = "nightly")] pub mod device; -#[cfg(feature = "nightly")] pub mod service; -#[cfg(feature = "nightly")] mod traits; - -#[cfg(feature = "nightly")] pub use traits::*; -#[cfg(feature = "nightly")] mod updater; - -#[cfg(feature = "nightly")] pub use updater::*; diff --git a/src/traits.rs b/src/traits.rs index 758890a..90fdcf9 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,3 +1,5 @@ +#![allow(async_fn_in_trait)] + use { crate::protocol::{Command, Status}, core::fmt::Debug, diff --git a/src/updater.rs b/src/updater.rs index a2b0224..6b4905f 100644 --- a/src/updater.rs +++ b/src/updater.rs @@ -3,7 +3,7 @@ use { protocol::{Command, Status}, traits::{FirmwareDevice, FirmwareVersion, UpdateService}, }, - embedded_hal_async::delay::DelayUs, + embedded_hal_async::delay::DelayNs, futures::{ future::{select, Either}, pin_mut, @@ -85,7 +85,7 @@ where } } - async fn check( + async fn check( &mut self, device: &mut F, delay: &mut D, @@ -208,7 +208,7 @@ where /// 1) The device is in sync, in which case `DeviceStatus::Synced` is returned. /// 2) The device is updated, in which case `DeviceStatus::Updated` is returned. It is the responsibility /// of called to reset the device in order to run the new firmware. - pub async fn run( + pub async fn run( &mut self, device: &mut F, delay: &mut D, @@ -228,7 +228,11 @@ mod tests { pub struct TokioDelay; - impl embedded_hal_async::delay::DelayUs for TokioDelay { + impl embedded_hal_async::delay::DelayNs for TokioDelay { + async fn delay_ns(&mut self, i: u32) { + tokio::time::sleep(tokio::time::Duration::from_nanos(i as u64)).await; + } + async fn delay_us(&mut self, i: u32) { tokio::time::sleep(tokio::time::Duration::from_micros(i as u64)).await; } diff --git a/tests/serial.rs b/tests/serial.rs index 70961cf..320f0df 100644 --- a/tests/serial.rs +++ b/tests/serial.rs @@ -1,7 +1,3 @@ -#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))] -#![cfg_attr(feature = "nightly", feature(async_fn_in_trait))] -#![cfg_attr(feature = "nightly", allow(incomplete_features))] - use { embedded_update::{device, service, FirmwareUpdater}, tokio::sync::mpsc, @@ -89,7 +85,11 @@ impl embedded_io_async::Write for Link { pub struct Timer; -impl embedded_hal_async::delay::DelayUs for Timer { +impl embedded_hal_async::delay::DelayNs for Timer { + async fn delay_ns(&mut self, i: u32) { + tokio::time::sleep(tokio::time::Duration::from_nanos(i as u64)).await; + } + async fn delay_us(&mut self, i: u32) { tokio::time::sleep(tokio::time::Duration::from_micros(i as u64)).await; }