diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a10cecd..f958b3b0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [?.??.?] - ????-??-?? +* MSRV 1.75; remove the nightly feature flag from all async trait implementations +* Update public dependencies `e-hal` to 1.0.0-rc3 and `embassy-sync` to 0.5 and private dependency `heapless` to 0.8 * Allow `cargo check --all-features` to work correctly (there used to be a build error when both the `esp-idf-sys` and the `riscv-ulp-hal` features were enabled) * #351 - Remove the `OutputPin` requirement from SPI SDI pin * #350 - Not checking for ESP_FAIL in AsyncCanDriver::transmit diff --git a/Cargo.toml b/Cargo.toml index de36c132e..2b9b6d73f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" links = "esp_idf_hal" build = "build.rs" documentation = "https://esp-rs.github.io/esp-idf-hal/" -rust-version = "1.71" +rust-version = "1.75" [patch.crates-io] esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" } @@ -22,7 +22,7 @@ esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" } default = ["std", "binstart"] std = ["alloc", "esp-idf-sys/std"] alloc = [] -nightly = ["embedded-hal-async", "embedded-io-async"] +nightly = [] esp-idf-sys = ["dep:esp-idf-sys", "atomic-waker"] riscv-ulp-hal = [] wake-from-isr = [] # Only enable if you plan to use the `edge-executor` crate @@ -39,20 +39,20 @@ libstart = ["esp-idf-sys/libstart"] [dependencies] nb = "1.0.0" embedded-can = "0.4.1" -embedded-hal = "=1.0.0-rc.1" +embedded-hal = "=1.0.0-rc.3" embedded-hal-0-2 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"] } -embedded-hal-nb = "=1.0.0-rc.1" -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true } +embedded-hal-nb = "=1.0.0-rc.3" +embedded-hal-async = "=1.0.0-rc.3" embedded-io = "0.6" -embedded-io-async = { version = "0.6", optional = true } -esp-idf-sys = { version = "0.33.5", optional = true, default-features = false, features = ["native"] } +embedded-io-async = "0.6" +esp-idf-sys = { version = "0.33.7", optional = true, default-features = false } critical-section = { version = "1.1.1", optional = true } -heapless = "0.7" +heapless = "0.8" num_enum = { version = "0.7", default-features = false } enumset = { version = "1", default-features = false } log = { version = "0.4", default-features = false } atomic-waker = { version = "1.1.1", optional = true, default-features = false } -embassy-sync = { version = "0.3" } +embassy-sync = { version = "0.5" } [build-dependencies] embuild = "0.31.3" diff --git a/clippy.toml b/clippy.toml index 5829221cf..493dbc02a 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -future-size-threshold = 50 +future-size-threshold = 900 diff --git a/src/adc.rs b/src/adc.rs index a098618dc..6d14921b0 100644 --- a/src/adc.rs +++ b/src/adc.rs @@ -1344,7 +1344,6 @@ pub mod continuous { } } - #[cfg(feature = "nightly")] #[cfg(not(esp_idf_adc_continuous_isr_iram_safe))] impl<'d> embedded_io_async::Read for AdcDriver<'d> { async fn read(&mut self, buf: &mut [u8]) -> Result { diff --git a/src/delay.rs b/src/delay.rs index de8406291..452b56a4a 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -99,9 +99,14 @@ extern "C" { } impl Ets { + #[deprecated = "Use delay_ns instead"] pub fn delay_us(us: u32) { + Self::delay_ns(us) + } + + pub fn delay_ns(ns: u32) { unsafe { - ets_delay_us(us); + ets_delay_us(ns); } } @@ -114,19 +119,19 @@ impl Ets { impl embedded_hal_0_2::blocking::delay::DelayUs for Ets { fn delay_us(&mut self, us: u32) { - Ets::delay_us(us); + Ets::delay_ns(us); } } impl embedded_hal_0_2::blocking::delay::DelayUs for Ets { fn delay_us(&mut self, us: u16) { - Ets::delay_us(us as _); + Ets::delay_ns(us as _); } } impl embedded_hal_0_2::blocking::delay::DelayUs for Ets { fn delay_us(&mut self, us: u8) { - Ets::delay_us(us as _); + Ets::delay_ns(us as _); } } @@ -148,9 +153,9 @@ impl embedded_hal_0_2::blocking::delay::DelayMs for Ets { } } -impl embedded_hal::delay::DelayUs for Ets { - fn delay_us(&mut self, us: u32) { - Ets::delay_us(us) +impl embedded_hal::delay::DelayNs for Ets { + fn delay_ns(&mut self, ns: u32) { + Ets::delay_ns(ns) } fn delay_ms(&mut self, ms: u32) { @@ -166,8 +171,13 @@ impl embedded_hal::delay::DelayUs for Ets { pub struct FreeRtos; impl FreeRtos { + #[deprecated = "Use delay_ns instead"] pub fn delay_us(us: u32) { - let ms = us / 1000; + Self::delay_ns(us) + } + + pub fn delay_ns(ns: u32) { + let ms = ns / 1000; Self::delay_ms(ms); } @@ -184,19 +194,19 @@ impl FreeRtos { impl embedded_hal_0_2::blocking::delay::DelayUs for FreeRtos { fn delay_us(&mut self, us: u32) { - FreeRtos::delay_us(us); + FreeRtos::delay_ns(us); } } impl embedded_hal_0_2::blocking::delay::DelayUs for FreeRtos { fn delay_us(&mut self, us: u16) { - FreeRtos::delay_us(us as _); + FreeRtos::delay_ns(us as _); } } impl embedded_hal_0_2::blocking::delay::DelayUs for FreeRtos { fn delay_us(&mut self, us: u8) { - FreeRtos::delay_us(us as _); + FreeRtos::delay_ns(us as _); } } @@ -218,9 +228,9 @@ impl embedded_hal_0_2::blocking::delay::DelayMs for FreeRtos { } } -impl embedded_hal::delay::DelayUs for FreeRtos { - fn delay_us(&mut self, us: u32) { - FreeRtos::delay_us(us) +impl embedded_hal::delay::DelayNs for FreeRtos { + fn delay_ns(&mut self, ns: u32) { + FreeRtos::delay_ns(ns) } fn delay_ms(&mut self, ms: u32) { @@ -243,11 +253,16 @@ impl Delay { Self(threshold) } + #[deprecated = "Use delay_ns instead"] pub fn delay_us(&self, us: u32) { - if us < self.0 { - Ets::delay_us(us); + self.delay_ns(us) + } + + pub fn delay_ns(&self, ns: u32) { + if ns < self.0 { + Ets::delay_ns(ns); } else { - FreeRtos::delay_us(us); + FreeRtos::delay_ns(ns); } } @@ -260,9 +275,9 @@ impl Delay { } } -impl embedded_hal::delay::DelayUs for Delay { - fn delay_us(&mut self, us: u32) { - Delay::delay_us(self, us) +impl embedded_hal::delay::DelayNs for Delay { + fn delay_ns(&mut self, us: u32) { + Delay::delay_ns(self, us) } fn delay_ms(&mut self, ms: u32) { @@ -272,13 +287,13 @@ impl embedded_hal::delay::DelayUs for Delay { impl embedded_hal_0_2::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u16) { - Delay::delay_us(self, us as _); + Delay::delay_ns(self, us as _); } } impl embedded_hal_0_2::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u32) { - Delay::delay_us(self, us); + Delay::delay_ns(self, us); } } diff --git a/src/gpio.rs b/src/gpio.rs index 94dc84411..34dc0d977 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -1420,11 +1420,24 @@ impl<'d, T: Pin, MODE> embedded_hal::digital::InputPin for PinDriver<'d, T, MODE where MODE: InputMode, { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(PinDriver::is_high(self)) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { + Ok(PinDriver::is_low(self)) + } +} + +impl<'d, T: Pin, MODE> embedded_hal::digital::InputPin for &PinDriver<'d, T, MODE> +where + MODE: InputMode, +{ + fn is_high(&mut self) -> Result { + Ok(PinDriver::is_high(self)) + } + + fn is_low(&mut self) -> Result { Ok(PinDriver::is_low(self)) } } @@ -1461,15 +1474,29 @@ impl<'d, T: Pin, MODE> embedded_hal::digital::StatefulOutputPin for PinDriver<'d where MODE: OutputMode, { - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Ok(self.get_output_level().into()) } - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Ok(!bool::from(self.get_output_level())) } } +// TODO: Will become possible once the `PinDriver::setXXX`` methods become non-`&mut`, which they really are, internally +// impl<'d, T: Pin, MODE> embedded_hal::digital::StatefulOutputPin for &PinDriver<'d, T, MODE> +// where +// MODE: OutputMode, +// { +// fn is_set_high(&mut self) -> Result { +// Ok(self.get_output_level().into()) +// } + +// fn is_set_low(&mut self) -> Result { +// Ok(!bool::from(self.get_output_level())) +// } +// } + impl<'d, T: Pin, MODE> embedded_hal_0_2::digital::v2::StatefulOutputPin for PinDriver<'d, T, MODE> where MODE: OutputMode, @@ -1504,10 +1531,7 @@ where } } -#[cfg(all( - not(all(feature = "riscv-ulp-hal", not(feature = "esp-idf-sys"))), - feature = "nightly" -))] +#[cfg(not(all(feature = "riscv-ulp-hal", not(feature = "esp-idf-sys"))))] impl embedded_hal_async::digital::Wait for PinDriver<'_, T, MODE> { async fn wait_for_high(&mut self) -> Result<(), GpioError> { self.wait_for_high().await?; diff --git a/src/i2s.rs b/src/i2s.rs index 8aa14ade3..7af58fea2 100644 --- a/src/i2s.rs +++ b/src/i2s.rs @@ -1236,7 +1236,6 @@ where } } -#[cfg(feature = "nightly")] #[cfg(not(esp_idf_version_major = "4"))] impl<'d, Dir> embedded_io_async::Read for I2sDriver<'d, Dir> where @@ -1247,7 +1246,6 @@ where } } -#[cfg(feature = "nightly")] #[cfg(not(esp_idf_version_major = "4"))] impl<'d, Dir> embedded_io_async::Write for I2sDriver<'d, Dir> where diff --git a/src/io.rs b/src/io.rs index 5bcdc46cd..2091dd13c 100644 --- a/src/io.rs +++ b/src/io.rs @@ -30,7 +30,6 @@ impl Display for EspIOError { #[cfg(feature = "std")] impl std::error::Error for EspIOError {} -#[cfg(feature = "nightly")] pub mod asynch { pub use embedded_io_async::*; } diff --git a/src/ledc.rs b/src/ledc.rs index 812a58dc6..bb6a136b6 100644 --- a/src/ledc.rs +++ b/src/ledc.rs @@ -331,7 +331,7 @@ fn to_pwm_err(err: EspError) -> PwmError { } impl<'d> embedded_hal::pwm::SetDutyCycle for LedcDriver<'d> { - fn get_max_duty_cycle(&self) -> u16 { + fn max_duty_cycle(&self) -> u16 { let duty = self.get_max_duty(); let duty_cap: u16 = if duty > u16::MAX as u32 { u16::MAX @@ -354,7 +354,7 @@ impl<'d> embedded_hal::pwm::SetDutyCycle for LedcDriver<'d> { } fn set_duty_cycle_fraction(&mut self, num: u16, denom: u16) -> Result<(), PwmError> { - let duty = num as u32 * self.get_max_duty_cycle() as u32 / denom as u32; + let duty = num as u32 * self.max_duty_cycle() as u32 / denom as u32; self.set_duty_cycle(duty as u16) } diff --git a/src/lib.rs b/src/lib.rs index 6cc45a5d2..6c26971cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -#![allow(stable_features)] -#![allow(unknown_lints)] +#![allow(async_fn_in_trait)] #![allow(clippy::unused_unit)] // enumset #![warn(clippy::large_futures)] -#![cfg_attr(feature = "nightly", feature(async_fn_in_trait))] -#![cfg_attr(feature = "nightly", allow(async_fn_in_trait))] -#![cfg_attr(feature = "nightly", feature(impl_trait_projections))] #![cfg_attr(feature = "nightly", feature(doc_cfg))] #![cfg_attr(target_arch = "xtensa", feature(asm_experimental_arch))] diff --git a/src/spi.rs b/src/spi.rs index 8d7ed0be9..71c89e691 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -673,7 +673,6 @@ where } } -#[cfg(feature = "nightly")] #[cfg(not(esp_idf_spi_master_isr_in_iram))] impl<'d, T> embedded_hal_async::spi::SpiBus for SpiBusDriver<'d, T> where @@ -904,7 +903,7 @@ where while spi_operations.peek().is_some() { if let Some(SpiOperation::Delay(delay)) = spi_operations.peek() { - delay_impl.delay_us(*delay); + delay_impl.delay_ns(*delay); spi_operations.next(); } else { let transactions = core::iter::from_fn(|| { @@ -965,7 +964,7 @@ where while spi_operations.peek().is_some() { if let Some(SpiOperation::Delay(delay)) = spi_operations.peek() { - delay_impl.delay_us(*delay); + delay_impl.delay_ns(*delay); spi_operations.next(); } else { let transactions = core::iter::from_fn(|| { @@ -1091,7 +1090,7 @@ where spi_transfer_in_place_transactions(words, chunk_size) .map(SpiOperation::Transaction), ), - Operation::DelayUs(delay) => { + Operation::DelayNs(delay) => { OperationsIter::Delay(core::iter::once(SpiOperation::Delay(delay))) } }) @@ -1241,7 +1240,6 @@ where } } -#[cfg(feature = "nightly")] #[cfg(not(esp_idf_spi_master_isr_in_iram))] impl<'d, T> embedded_hal_async::spi::SpiDevice for SpiDeviceDriver<'d, T> where @@ -1473,7 +1471,6 @@ where } } -#[cfg(feature = "nightly")] #[cfg(not(esp_idf_spi_master_isr_in_iram))] impl<'d, DEVICE, DRIVER> embedded_hal_async::spi::SpiDevice for SpiSoftCsDeviceDriver<'d, DEVICE, DRIVER> @@ -1573,7 +1570,7 @@ where // TODO: Need to wait asnchronously if in async mode if let Some(delay) = pre_delay { - Ets::delay_us(*delay); + Ets::delay_ns(*delay); } } @@ -1586,7 +1583,7 @@ where // TODO: Need to wait asnchronously if in async mode if let Some(delay) = post_delay { - Ets::delay_us(*delay); + Ets::delay_ns(*delay); } } @@ -1898,7 +1895,7 @@ fn copy_operation<'b>(operation: &'b mut Operation<'_, u8>) -> Operation<'b, u8> Operation::Write(write) => Operation::Write(write), Operation::Transfer(read, write) => Operation::Transfer(read, write), Operation::TransferInPlace(write) => Operation::TransferInPlace(write), - Operation::DelayUs(delay) => Operation::DelayUs(*delay), + Operation::DelayNs(delay) => Operation::DelayNs(*delay), } } diff --git a/src/task.rs b/src/task.rs index 865105afb..fe3086698 100644 --- a/src/task.rs +++ b/src/task.rs @@ -803,8 +803,8 @@ pub mod embassy_sync { #[cfg(all(feature = "alloc", target_has_atomic = "ptr"))] pub mod notification { + use core::marker::PhantomData; use core::num::NonZeroU32; - use core::ptr; use core::sync::atomic::{AtomicPtr, Ordering}; extern crate alloc; @@ -821,13 +821,13 @@ pub mod notification { #[cfg(not(esp_idf_version_major = "4"))] type Task = esp_idf_sys::tskTaskControlBlock; - pub struct Notification(Arc, *const ()); + pub struct Notification(Arc, PhantomData<*const ()>); impl Notification { pub fn new() -> Self { Self( Arc::new(Notifier(AtomicPtr::new(task::current().unwrap()))), - ptr::null(), + PhantomData, ) } diff --git a/src/timer.rs b/src/timer.rs index 4eb8ec901..36d58f940 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -466,10 +466,9 @@ impl<'d> Drop for TimerDriver<'d> { unsafe impl<'d> Send for TimerDriver<'d> {} -#[cfg(feature = "nightly")] -impl<'d> embedded_hal_async::delay::DelayUs for TimerDriver<'d> { - async fn delay_us(&mut self, us: u32) { - let counter = core::cmp::max((self.tick_hz() * us as u64) / 1000000, 1); +impl<'d> embedded_hal_async::delay::DelayNs for TimerDriver<'d> { + async fn delay_ns(&mut self, ns: u32) { + let counter = core::cmp::max((self.tick_hz() * ns as u64) / 1000000, 1); self.delay(counter).await.unwrap(); } diff --git a/src/uart.rs b/src/uart.rs index 0b5d8988c..d51e34c23 100644 --- a/src/uart.rs +++ b/src/uart.rs @@ -1493,7 +1493,6 @@ where type Error = EspIOError; } -#[cfg(feature = "nightly")] impl<'d, T> embedded_io_async::Read for AsyncUartDriver<'d, T> where T: BorrowMut>, @@ -1503,7 +1502,6 @@ where } } -#[cfg(feature = "nightly")] impl<'d, T> embedded_io_async::Write for AsyncUartDriver<'d, T> where T: BorrowMut>, @@ -1613,7 +1611,6 @@ where type Error = EspIOError; } -#[cfg(feature = "nightly")] impl<'d, T> embedded_io_async::Read for AsyncUartRxDriver<'d, T> where T: BorrowMut>, @@ -1732,7 +1729,6 @@ where type Error = EspIOError; } -#[cfg(feature = "nightly")] impl<'d, T> embedded_io_async::Write for AsyncUartTxDriver<'d, T> where T: BorrowMut>,