From 96a321796b201083e6dc8b2a2fe68d8e9cbb8458 Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Fri, 30 Aug 2024 09:09:15 -0700 Subject: [PATCH] Eliminate esp-hal's `embedded-hal` feature --- esp-hal/Cargo.toml | 16 ++++++---------- esp-hal/src/delay.rs | 1 - esp-hal/src/gpio/dummy_pin.rs | 3 --- esp-hal/src/gpio/mod.rs | 2 -- esp-hal/src/i2c.rs | 5 ----- esp-hal/src/ledc/channel.rs | 1 - esp-hal/src/mcpwm/operator.rs | 2 -- esp-hal/src/spi/master.rs | 7 ++----- esp-hal/src/spi/mod.rs | 1 - esp-hal/src/timer/mod.rs | 1 - esp-hal/src/twai/mod.rs | 11 ----------- esp-hal/src/uart.rs | 8 -------- esp-hal/src/usb_serial_jtag.rs | 7 ------- examples/Cargo.toml | 5 +---- hil-test/Cargo.toml | 2 +- 15 files changed, 10 insertions(+), 62 deletions(-) diff --git a/esp-hal/Cargo.toml b/esp-hal/Cargo.toml index ed5be4a2e58..6eb19062af8 100644 --- a/esp-hal/Cargo.toml +++ b/esp-hal/Cargo.toml @@ -11,7 +11,7 @@ links = "esp-hal" [package.metadata.docs.rs] default-target = "riscv32imac-unknown-none-elf" -features = ["embedded-hal", "esp32c6"] +features = ["esp32c6"] rustdoc-args = ["--cfg", "docsrs"] [dependencies] @@ -28,11 +28,11 @@ embassy-futures = { version = "0.1.1", optional = true } embassy-sync = { version = "0.6.0", optional = true } embassy-usb-driver = { version = "0.1.0", optional = true } embassy-usb-synopsys-otg = { version = "0.1.0", optional = true } -embedded-can = { version = "0.4.1", optional = true } +embedded-can = "0.4.1" embedded-hal-02 = { version = "0.2.7", features = ["unproven"], package = "embedded-hal" } -embedded-hal = { version = "1.0.0", optional = true } +embedded-hal = "1.0.0" embedded-hal-async = { version = "1.0.0", optional = true } -embedded-hal-nb = { version = "1.0.0", optional = true } +embedded-hal-nb = "1.0.0" embedded-io = { version = "0.6.1", optional = true } embedded-io-async = { version = "0.6.1", optional = true } enumset = "1.1.5" @@ -76,7 +76,7 @@ esp-metadata = { version = "0.3.0", path = "../esp-metadata" } serde = { version = "1.0.209", features = ["derive"] } [features] -default = ["embedded-hal"] +default = [] riscv = ["dep:riscv", "critical-section/restore-state-u8"] xtensa = ["dep:xtensa-lx", "critical-section/restore-state-u32"] @@ -128,7 +128,6 @@ flip-link = ["esp-riscv-rt/fix-sp"] ## `embedded-hal-async` and `embedded-io-async`. ## Also enables `embassy-usb` support for ESP32-S2 and ESP32-S3. async = [ - "embedded-hal", "embedded-hal-async", "embedded-io", "embedded-io-async", @@ -142,7 +141,7 @@ defmt = [ "dep:defmt", "embassy-futures?/defmt", "embassy-sync?/defmt", - "embedded-hal?/defmt-03", + "embedded-hal/defmt-03", "embedded-io/defmt-03", "embedded-io-async?/defmt-03", "esp32?/defmt", @@ -153,9 +152,6 @@ defmt = [ "esp32s2?/defmt", "esp32s3?/defmt", ] -## Implement the traits defined in the `1.0.0` releases of `embedded-hal` and -## `embedded-hal-nb` for the relevant peripherals. -embedded-hal = ["dep:embedded-hal", "dep:embedded-hal-nb", "dep:embedded-can"] ## Implement the traits defined in `embedded-io` for certain peripherals. embedded-io = ["dep:embedded-io"] diff --git a/esp-hal/src/delay.rs b/esp-hal/src/delay.rs index 102c6921bf4..4ce5d0d6421 100644 --- a/esp-hal/src/delay.rs +++ b/esp-hal/src/delay.rs @@ -63,7 +63,6 @@ where } } -#[cfg(feature = "embedded-hal")] impl embedded_hal::delay::DelayNs for Delay { fn delay_ns(&mut self, ns: u32) { self.delay_nanos(ns); diff --git a/esp-hal/src/gpio/dummy_pin.rs b/esp-hal/src/gpio/dummy_pin.rs index 7bb0ee8c232..614132075f7 100644 --- a/esp-hal/src/gpio/dummy_pin.rs +++ b/esp-hal/src/gpio/dummy_pin.rs @@ -154,12 +154,10 @@ impl embedded_hal_02::digital::v2::StatefulOutputPin for DummyPin { } } -#[cfg(feature = "embedded-hal")] impl embedded_hal::digital::ErrorType for DummyPin { type Error = core::convert::Infallible; } -#[cfg(feature = "embedded-hal")] impl embedded_hal::digital::OutputPin for DummyPin { fn set_low(&mut self) -> Result<(), Self::Error> { self.set_output_high(true, private::Internal); @@ -172,7 +170,6 @@ impl embedded_hal::digital::OutputPin for DummyPin { } } -#[cfg(feature = "embedded-hal")] impl embedded_hal::digital::StatefulOutputPin for DummyPin { fn is_set_high(&mut self) -> Result { Ok(OutputPin::is_set_high(self, private::Internal)) diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index 0806a8223d2..d6a2b49945e 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -3248,7 +3248,6 @@ mod embedded_hal_02_impls { } } -#[cfg(feature = "embedded-hal")] mod embedded_hal_impls { use embedded_hal::digital; @@ -3498,7 +3497,6 @@ mod embedded_hal_impls { } } -#[cfg(feature = "embedded-hal")] #[cfg(feature = "async")] mod embedded_hal_async_impls { use embedded_hal_async::digital::Wait; diff --git a/esp-hal/src/i2c.rs b/esp-hal/src/i2c.rs index 223a2873523..94fc99c6e0c 100644 --- a/esp-hal/src/i2c.rs +++ b/esp-hal/src/i2c.rs @@ -95,7 +95,6 @@ pub enum Error { CommandNrExceeded, } -#[cfg(any(feature = "embedded-hal", feature = "async"))] #[derive(PartialEq)] // This enum is used to keep track of the last operation that was performed // in an embedded-hal(-async) I2C::transaction. It used to determine whether @@ -106,7 +105,6 @@ enum LastOpWas { None, } -#[cfg(feature = "embedded-hal")] impl embedded_hal::i2c::Error for Error { fn kind(&self) -> embedded_hal::i2c::ErrorKind { use embedded_hal::i2c::{ErrorKind, NoAcknowledgeSource}; @@ -241,12 +239,10 @@ where } } -#[cfg(feature = "embedded-hal")] impl embedded_hal::i2c::ErrorType for I2C<'_, T, DM> { type Error = Error; } -#[cfg(feature = "embedded-hal")] impl embedded_hal::i2c::I2c for I2C<'_, T, DM> where T: Instance, @@ -890,7 +886,6 @@ mod asynch { } } - #[cfg(feature = "embedded-hal")] impl<'d, T> embedded_hal_async::i2c::I2c for I2C<'d, T, crate::Async> where T: Instance, diff --git a/esp-hal/src/ledc/channel.rs b/esp-hal/src/ledc/channel.rs index aff67d1e6dc..a838fccc36d 100644 --- a/esp-hal/src/ledc/channel.rs +++ b/esp-hal/src/ledc/channel.rs @@ -294,7 +294,6 @@ where } } -#[cfg(feature = "embedded-hal")] mod ehal1 { use embedded_hal::pwm::{self, ErrorKind, ErrorType, SetDutyCycle}; diff --git a/esp-hal/src/mcpwm/operator.rs b/esp-hal/src/mcpwm/operator.rs index 380aafb8f1c..b21a3e050ef 100644 --- a/esp-hal/src/mcpwm/operator.rs +++ b/esp-hal/src/mcpwm/operator.rs @@ -448,7 +448,6 @@ impl<'d, Pin: OutputPin, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> emb } /// Implement no error type for the PwmPin because the method are infallible -#[cfg(feature = "embedded-hal")] impl<'d, Pin: OutputPin, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> embedded_hal::pwm::ErrorType for PwmPin<'d, Pin, PWM, OP, IS_A> { @@ -456,7 +455,6 @@ impl<'d, Pin: OutputPin, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> } /// Implement the trait SetDutyCycle for PwmPin -#[cfg(feature = "embedded-hal")] impl<'d, Pin: OutputPin, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> embedded_hal::pwm::SetDutyCycle for PwmPin<'d, Pin, PWM, OP, IS_A> { diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs index 0f6c9552302..95b0bd32a48 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -16,9 +16,8 @@ //! //! - Use the [`FullDuplex`](embedded_hal_02::spi::FullDuplex) trait to //! read/write single bytes at a time, -//! - Use the [`SpiBus`](embedded_hal::spi::SpiBus) trait (requires the -//! "embedded-hal" feature) and its associated functions to initiate -//! transactions with simultaneous reads and writes, or +//! - Use the [`SpiBus`](embedded_hal::spi::SpiBus) trait and its associated +//! functions to initiate transactions with simultaneous reads and writes, or //! - Use the `ExclusiveDevice` struct from [`embedded-hal-bus`] or `SpiDevice` //! from [`embassy-embedded-hal`]. //! @@ -2158,7 +2157,6 @@ mod dma { } } - #[cfg(feature = "embedded-hal")] mod ehal1 { use embedded_hal::spi::{ErrorType, SpiBus}; @@ -2205,7 +2203,6 @@ mod dma { } } -#[cfg(feature = "embedded-hal")] mod ehal1 { use embedded_hal::spi::SpiBus; use embedded_hal_nb::spi::FullDuplex; diff --git a/esp-hal/src/spi/mod.rs b/esp-hal/src/spi/mod.rs index 3c73581c159..363bb7c09c3 100644 --- a/esp-hal/src/spi/mod.rs +++ b/esp-hal/src/spi/mod.rs @@ -39,7 +39,6 @@ impl From for Error { } } -#[cfg(feature = "embedded-hal")] impl embedded_hal::spi::Error for Error { fn kind(&self) -> embedded_hal::spi::ErrorKind { embedded_hal::spi::ErrorKind::Other diff --git a/esp-hal/src/timer/mod.rs b/esp-hal/src/timer/mod.rs index 15ea085ba01..90f6c5fd234 100644 --- a/esp-hal/src/timer/mod.rs +++ b/esp-hal/src/timer/mod.rs @@ -232,7 +232,6 @@ where } } -#[cfg(feature = "embedded-hal")] impl<'d, T> embedded_hal::delay::DelayNs for OneShotTimer<'d, T> where T: Timer, diff --git a/esp-hal/src/twai/mod.rs b/esp-hal/src/twai/mod.rs index efa6624dc5d..5ccfaa6869f 100644 --- a/esp-hal/src/twai/mod.rs +++ b/esp-hal/src/twai/mod.rs @@ -221,7 +221,6 @@ impl embedded_hal_02::can::Error for ErrorKind { } } -#[cfg(feature = "embedded-hal")] impl From for embedded_can::ErrorKind { fn from(value: ErrorKind) -> Self { match value { @@ -236,7 +235,6 @@ impl From for embedded_can::ErrorKind { } } -#[cfg(feature = "embedded-hal")] impl embedded_can::Error for ErrorKind { fn kind(&self) -> embedded_can::ErrorKind { (*self).into() @@ -307,14 +305,12 @@ impl From for StandardId { } } -#[cfg(feature = "embedded-hal")] impl From for embedded_can::StandardId { fn from(value: StandardId) -> Self { embedded_can::StandardId::new(value.as_raw()).unwrap() } } -#[cfg(feature = "embedded-hal")] impl From for StandardId { fn from(value: embedded_can::StandardId) -> Self { StandardId::new(value.as_raw()).unwrap() @@ -380,14 +376,12 @@ impl From for ExtendedId { } } -#[cfg(feature = "embedded-hal")] impl From for embedded_can::ExtendedId { fn from(value: ExtendedId) -> Self { embedded_can::ExtendedId::new(value.0).unwrap() } } -#[cfg(feature = "embedded-hal")] impl From for ExtendedId { fn from(value: embedded_can::ExtendedId) -> Self { ExtendedId::new(value.as_raw()).unwrap() @@ -435,7 +429,6 @@ impl From for Id { } } -#[cfg(feature = "embedded-hal")] impl From for embedded_can::Id { fn from(value: Id) -> Self { match value { @@ -445,7 +438,6 @@ impl From for embedded_can::Id { } } -#[cfg(feature = "embedded-hal")] impl From for Id { fn from(value: embedded_can::Id) -> Self { match value { @@ -588,7 +580,6 @@ impl embedded_hal_02::can::Frame for EspTwaiFrame { } } -#[cfg(feature = "embedded-hal")] impl embedded_can::Frame for EspTwaiFrame { fn new(id: impl Into, data: &[u8]) -> Option { let id: embedded_can::Id = id.into(); @@ -1190,7 +1181,6 @@ impl embedded_hal_02::can::Error for EspTwaiError { } } -#[cfg(feature = "embedded-hal")] impl embedded_can::Error for EspTwaiError { fn kind(&self) -> embedded_can::ErrorKind { match self { @@ -1256,7 +1246,6 @@ where } } -#[cfg(feature = "embedded-hal")] impl<'d, T, DM> embedded_can::nb::Can for Twai<'d, T, DM> where T: OperationInstance, diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs index 7fd90de669a..bf4286ce44d 100644 --- a/esp-hal/src/uart.rs +++ b/esp-hal/src/uart.rs @@ -255,7 +255,6 @@ pub enum Error { RxParityError, } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::Error for Error { fn kind(&self) -> embedded_hal_nb::serial::ErrorKind { embedded_hal_nb::serial::ErrorKind::Other @@ -1774,22 +1773,18 @@ where } } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::ErrorType for Uart<'_, T, M> { type Error = Error; } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::ErrorType for UartTx<'_, T, M> { type Error = Error; } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::ErrorType for UartRx<'_, T, M> { type Error = Error; } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::Read for Uart<'_, T, M> where T: Instance, @@ -1800,7 +1795,6 @@ where } } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::Read for UartRx<'_, T, M> where T: Instance, @@ -1811,7 +1805,6 @@ where } } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::Write for Uart<'_, T, M> where T: Instance, @@ -1826,7 +1819,6 @@ where } } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::Write for UartTx<'_, T, M> where T: Instance, diff --git a/esp-hal/src/usb_serial_jtag.rs b/esp-hal/src/usb_serial_jtag.rs index cadf7c415d8..6e5778637ac 100644 --- a/esp-hal/src/usb_serial_jtag.rs +++ b/esp-hal/src/usb_serial_jtag.rs @@ -515,7 +515,6 @@ where } } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::ErrorType for UsbSerialJtag<'_, M> where M: Mode, @@ -523,7 +522,6 @@ where type Error = Error; } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::ErrorType for UsbSerialJtagTx<'_, M> where M: Mode, @@ -531,7 +529,6 @@ where type Error = Error; } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::ErrorType for UsbSerialJtagRx<'_, M> where M: Mode, @@ -539,7 +536,6 @@ where type Error = Error; } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::Read for UsbSerialJtag<'_, M> where M: Mode, @@ -549,7 +545,6 @@ where } } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::Read for UsbSerialJtagRx<'_, M> where M: Mode, @@ -559,7 +554,6 @@ where } } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::Write for UsbSerialJtag<'_, M> where M: Mode, @@ -573,7 +567,6 @@ where } } -#[cfg(feature = "embedded-hal")] impl embedded_hal_nb::serial::Write for UsbSerialJtagTx<'_, M> where M: Mode, diff --git a/examples/Cargo.toml b/examples/Cargo.toml index ca8c5017dc1..975381be207 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -71,10 +71,7 @@ esp-wifi = ["dep:esp-wifi"] async = ["esp-hal/async", "embassy-usb"] -embedded-hal = ["esp-hal/embedded-hal"] - -embassy = ["dep:esp-hal-embassy"] - +embassy = ["dep:esp-hal-embassy"] embassy-generic-timers = ["embassy-time/generic-queue-8"] opsram-2m = ["esp-hal/opsram-2m"] diff --git a/hil-test/Cargo.toml b/hil-test/Cargo.toml index 203891ffc6d..e12d9db3117 100644 --- a/hil-test/Cargo.toml +++ b/hil-test/Cargo.toml @@ -180,7 +180,7 @@ embedded-hal-02 = { version = "0.2.7", package = "embedded-hal", features = [ embedded-hal-async = { version = "1.0.0", optional = true } embedded-hal-nb = { version = "1.0.0", optional = true } esp-backtrace = { path = "../esp-backtrace", default-features = false, features = ["exception-handler", "panic-handler", "defmt", "semihosting"] } -esp-hal = { path = "../esp-hal", features = ["defmt", "digest", "embedded-hal"], optional = true } +esp-hal = { path = "../esp-hal", features = ["defmt", "digest"], optional = true } esp-hal-embassy = { path = "../esp-hal-embassy", optional = true } portable-atomic = "1.6.0" static_cell = { version = "2.1.0", features = ["nightly"] }