Skip to content

Commit

Permalink
Eliminate esp-hal's embedded-hal feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed Sep 3, 2024
1 parent 5ba0382 commit 96a3217
Show file tree
Hide file tree
Showing 15 changed files with 10 additions and 62 deletions.
16 changes: 6 additions & 10 deletions esp-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"]

Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions esp-hal/src/gpio/dummy_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<bool, Self::Error> {
Ok(OutputPin::is_set_high(self, private::Internal))
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,6 @@ mod embedded_hal_02_impls {
}
}

#[cfg(feature = "embedded-hal")]
mod embedded_hal_impls {
use embedded_hal::digital;

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions esp-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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};
Expand Down Expand Up @@ -241,12 +239,10 @@ where
}
}

#[cfg(feature = "embedded-hal")]
impl<T, DM: crate::Mode> embedded_hal::i2c::ErrorType for I2C<'_, T, DM> {
type Error = Error;
}

#[cfg(feature = "embedded-hal")]
impl<T, DM: crate::Mode> embedded_hal::i2c::I2c for I2C<'_, T, DM>
where
T: Instance,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/ledc/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ where
}
}

#[cfg(feature = "embedded-hal")]
mod ehal1 {
use embedded_hal::pwm::{self, ErrorKind, ErrorType, SetDutyCycle};

Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/mcpwm/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,13 @@ 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>
{
type Error = core::convert::Infallible;
}

/// 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>
{
Expand Down
7 changes: 2 additions & 5 deletions esp-hal/src/spi/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
//!
Expand Down Expand Up @@ -2158,7 +2157,6 @@ mod dma {
}
}

#[cfg(feature = "embedded-hal")]
mod ehal1 {
use embedded_hal::spi::{ErrorType, SpiBus};

Expand Down Expand Up @@ -2205,7 +2203,6 @@ mod dma {
}
}

#[cfg(feature = "embedded-hal")]
mod ehal1 {
use embedded_hal::spi::SpiBus;
use embedded_hal_nb::spi::FullDuplex;
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/spi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl From<DmaError> 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
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/timer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ where
}
}

#[cfg(feature = "embedded-hal")]
impl<'d, T> embedded_hal::delay::DelayNs for OneShotTimer<'d, T>
where
T: Timer,
Expand Down
11 changes: 0 additions & 11 deletions esp-hal/src/twai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ impl embedded_hal_02::can::Error for ErrorKind {
}
}

#[cfg(feature = "embedded-hal")]
impl From<ErrorKind> for embedded_can::ErrorKind {
fn from(value: ErrorKind) -> Self {
match value {
Expand All @@ -236,7 +235,6 @@ impl From<ErrorKind> for embedded_can::ErrorKind {
}
}

#[cfg(feature = "embedded-hal")]
impl embedded_can::Error for ErrorKind {
fn kind(&self) -> embedded_can::ErrorKind {
(*self).into()
Expand Down Expand Up @@ -307,14 +305,12 @@ impl From<embedded_hal_02::can::StandardId> for StandardId {
}
}

#[cfg(feature = "embedded-hal")]
impl From<StandardId> for embedded_can::StandardId {
fn from(value: StandardId) -> Self {
embedded_can::StandardId::new(value.as_raw()).unwrap()
}
}

#[cfg(feature = "embedded-hal")]
impl From<embedded_can::StandardId> for StandardId {
fn from(value: embedded_can::StandardId) -> Self {
StandardId::new(value.as_raw()).unwrap()
Expand Down Expand Up @@ -380,14 +376,12 @@ impl From<embedded_hal_02::can::ExtendedId> for ExtendedId {
}
}

#[cfg(feature = "embedded-hal")]
impl From<ExtendedId> for embedded_can::ExtendedId {
fn from(value: ExtendedId) -> Self {
embedded_can::ExtendedId::new(value.0).unwrap()
}
}

#[cfg(feature = "embedded-hal")]
impl From<embedded_can::ExtendedId> for ExtendedId {
fn from(value: embedded_can::ExtendedId) -> Self {
ExtendedId::new(value.as_raw()).unwrap()
Expand Down Expand Up @@ -435,7 +429,6 @@ impl From<embedded_hal_02::can::Id> for Id {
}
}

#[cfg(feature = "embedded-hal")]
impl From<Id> for embedded_can::Id {
fn from(value: Id) -> Self {
match value {
Expand All @@ -445,7 +438,6 @@ impl From<Id> for embedded_can::Id {
}
}

#[cfg(feature = "embedded-hal")]
impl From<embedded_can::Id> for Id {
fn from(value: embedded_can::Id) -> Self {
match value {
Expand Down Expand Up @@ -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<embedded_can::Id>, data: &[u8]) -> Option<Self> {
let id: embedded_can::Id = id.into();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions esp-hal/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1774,22 +1773,18 @@ where
}
}

#[cfg(feature = "embedded-hal")]
impl<T, M> embedded_hal_nb::serial::ErrorType for Uart<'_, T, M> {
type Error = Error;
}

#[cfg(feature = "embedded-hal")]
impl<T, M> embedded_hal_nb::serial::ErrorType for UartTx<'_, T, M> {
type Error = Error;
}

#[cfg(feature = "embedded-hal")]
impl<T, M> embedded_hal_nb::serial::ErrorType for UartRx<'_, T, M> {
type Error = Error;
}

#[cfg(feature = "embedded-hal")]
impl<T, M> embedded_hal_nb::serial::Read for Uart<'_, T, M>
where
T: Instance,
Expand All @@ -1800,7 +1795,6 @@ where
}
}

#[cfg(feature = "embedded-hal")]
impl<T, M> embedded_hal_nb::serial::Read for UartRx<'_, T, M>
where
T: Instance,
Expand All @@ -1811,7 +1805,6 @@ where
}
}

#[cfg(feature = "embedded-hal")]
impl<T, M> embedded_hal_nb::serial::Write for Uart<'_, T, M>
where
T: Instance,
Expand All @@ -1826,7 +1819,6 @@ where
}
}

#[cfg(feature = "embedded-hal")]
impl<T, M> embedded_hal_nb::serial::Write for UartTx<'_, T, M>
where
T: Instance,
Expand Down
Loading

0 comments on commit 96a3217

Please sign in to comment.