Skip to content

Commit

Permalink
Merge pull request #4 from nerwalt/update-deps-remove-nightly
Browse files Browse the repository at this point in the history
Updating dependencies and removing nightly feature
  • Loading branch information
lulf authored Nov 18, 2024
2 parents 884acff + 369f07b commit 5d709db
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 30 deletions.
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -16,15 +16,15 @@ 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 }
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 }
Expand All @@ -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 = []
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -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"]
50 changes: 46 additions & 4 deletions src/fmt.rs
Original file line number Diff line number Diff line change
@@ -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)*) => {
{
Expand All @@ -15,6 +18,7 @@ macro_rules! assert {
};
}

#[collapse_debuginfo(yes)]
macro_rules! assert_eq {
($($x:tt)*) => {
{
Expand All @@ -26,6 +30,7 @@ macro_rules! assert_eq {
};
}

#[collapse_debuginfo(yes)]
macro_rules! assert_ne {
($($x:tt)*) => {
{
Expand All @@ -37,6 +42,7 @@ macro_rules! assert_ne {
};
}

#[collapse_debuginfo(yes)]
macro_rules! debug_assert {
($($x:tt)*) => {
{
Expand All @@ -48,6 +54,7 @@ macro_rules! debug_assert {
};
}

#[collapse_debuginfo(yes)]
macro_rules! debug_assert_eq {
($($x:tt)*) => {
{
Expand All @@ -59,6 +66,7 @@ macro_rules! debug_assert_eq {
};
}

#[collapse_debuginfo(yes)]
macro_rules! debug_assert_ne {
($($x:tt)*) => {
{
Expand All @@ -70,6 +78,7 @@ macro_rules! debug_assert_ne {
};
}

#[collapse_debuginfo(yes)]
macro_rules! todo {
($($x:tt)*) => {
{
Expand All @@ -81,6 +90,7 @@ macro_rules! todo {
};
}

#[collapse_debuginfo(yes)]
macro_rules! unreachable {
($($x:tt)*) => {
{
Expand All @@ -92,6 +102,7 @@ macro_rules! unreachable {
};
}

#[collapse_debuginfo(yes)]
macro_rules! panic {
($($x:tt)*) => {
{
Expand All @@ -103,6 +114,7 @@ macro_rules! panic {
};
}

#[collapse_debuginfo(yes)]
macro_rules! trace {
($s:literal $(, $x:expr)* $(,)?) => {
{
Expand All @@ -116,6 +128,7 @@ macro_rules! trace {
};
}

#[collapse_debuginfo(yes)]
macro_rules! debug {
($s:literal $(, $x:expr)* $(,)?) => {
{
Expand All @@ -129,6 +142,7 @@ macro_rules! debug {
};
}

#[collapse_debuginfo(yes)]
macro_rules! info {
($s:literal $(, $x:expr)* $(,)?) => {
{
Expand All @@ -142,6 +156,7 @@ macro_rules! info {
};
}

#[collapse_debuginfo(yes)]
macro_rules! warn {
($s:literal $(, $x:expr)* $(,)?) => {
{
Expand All @@ -155,6 +170,7 @@ macro_rules! warn {
};
}

#[collapse_debuginfo(yes)]
macro_rules! error {
($s:literal $(, $x:expr)* $(,)?) => {
{
Expand All @@ -169,13 +185,15 @@ macro_rules! error {
}

#[cfg(feature = "defmt")]
#[collapse_debuginfo(yes)]
macro_rules! unwrap {
($($x:tt)*) => {
::defmt::unwrap!($($x)*)
};
}

#[cfg(not(feature = "defmt"))]
#[collapse_debuginfo(yes)]
macro_rules! unwrap {
($arg:expr) => {
match $crate::fmt::Try::into_result($arg) {
Expand All @@ -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;

Expand Down Expand Up @@ -226,3 +241,30 @@ impl<T, E> Try for Result<T, E> {
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)
}
}
9 changes: 0 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]

Expand All @@ -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::*;
2 changes: 2 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(async_fn_in_trait)]

use {
crate::protocol::{Command, Status},
core::fmt::Debug,
Expand Down
12 changes: 8 additions & 4 deletions src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -85,7 +85,7 @@ where
}
}

async fn check<F: FirmwareDevice, D: DelayUs>(
async fn check<F: FirmwareDevice, D: DelayNs>(
&mut self,
device: &mut F,
delay: &mut D,
Expand Down Expand Up @@ -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<F: FirmwareDevice, D: DelayUs>(
pub async fn run<F: FirmwareDevice, D: DelayNs>(
&mut self,
device: &mut F,
delay: &mut D,
Expand All @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/serial.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 5d709db

Please sign in to comment.