Skip to content

Commit

Permalink
Put the embedded-hal alpha trait implementations behind a feature (#88
Browse files Browse the repository at this point in the history
)

* Remove unused dependencies from HAL packages

* Put the `embedded-hal` alpha trait implementations behind a feature
  • Loading branch information
jessebraham authored Jun 27, 2022
1 parent fbd4286 commit 3d48190
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 16 deletions.
5 changes: 4 additions & 1 deletion esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
[dependencies]
cfg-if = "1.0"
embedded-hal = { version = "0.2", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.8" }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.8", optional = true }
fugit = "0.3"
nb = "1.0"
paste = "1.0"
Expand Down Expand Up @@ -62,3 +62,6 @@ ufmt = ["ufmt-write"]

# To use the external `smart_led` crate
smartled = ["smart-leds-trait"]

# Implement the `embedded-hal==1.0.0-alpha.x` traits
eh1 = ["embedded-hal-1"]
5 changes: 2 additions & 3 deletions esp-hal-common/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//!
//! [embedded-hal]: https://docs.rs/embedded-hal/latest/embedded_hal/

use core::convert::Infallible;

pub use self::delay::Delay;

impl<T> embedded_hal::blocking::delay::DelayMs<T> for Delay
Expand All @@ -28,8 +26,9 @@ where
}
}

#[cfg(feature = "eh1")]
impl embedded_hal_1::delay::blocking::DelayUs for Delay {
type Error = Infallible;
type Error = core::convert::Infallible;

fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> {
self.delay(us);
Expand Down
6 changes: 6 additions & 0 deletions esp-hal-common/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,12 @@ macro_rules! impl_input {
}
}

#[cfg(feature = "eh1")]
impl<MODE> embedded_hal_1::digital::ErrorType for $pxi<Input<MODE>> {
type Error = Infallible;
}

#[cfg(feature = "eh1")]
impl<MODE> embedded_hal_1::digital::blocking::InputPin for $pxi<Input<MODE>> {
fn is_high(&self) -> Result<bool, Self::Error> {
Ok(self.read_input() & (1 << $bit) != 0)
Expand Down Expand Up @@ -764,10 +766,12 @@ macro_rules! impl_output {
}
}

#[cfg(feature = "eh1")]
impl<MODE> embedded_hal_1::digital::ErrorType for $pxi<Output<MODE>> {
type Error = Infallible;
}

#[cfg(feature = "eh1")]
impl<MODE> embedded_hal_1::digital::blocking::OutputPin for $pxi<Output<MODE>> {
fn set_low(&mut self) -> Result<(), Self::Error> {
self.write_output_clear(1 << $bit);
Expand All @@ -780,6 +784,7 @@ macro_rules! impl_output {
}
}

#[cfg(feature = "eh1")]
impl<MODE> embedded_hal_1::digital::blocking::StatefulOutputPin for $pxi<Output<MODE>> {
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(self.read_output() & (1 << $bit) != 0)
Expand All @@ -790,6 +795,7 @@ macro_rules! impl_output {
}
}

#[cfg(feature = "eh1")]
impl<MODE> embedded_hal_1::digital::blocking::ToggleableOutputPin for $pxi<Output<MODE>> {
fn toggle(&mut self) -> Result<(), Self::Error> {
use embedded_hal_1::digital::blocking::{StatefulOutputPin as _, OutputPin as _};
Expand Down
3 changes: 3 additions & 0 deletions esp-hal-common/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum Error {
CommandNrExceeded,
}

#[cfg(feature = "eh1")]
impl embedded_hal_1::i2c::Error for Error {
fn kind(&self) -> embedded_hal_1::i2c::ErrorKind {
use embedded_hal_1::i2c::ErrorKind;
Expand Down Expand Up @@ -202,10 +203,12 @@ where
}
}

#[cfg(feature = "eh1")]
impl<T> embedded_hal_1::i2c::ErrorType for I2C<T> {
type Error = Error;
}

#[cfg(feature = "eh1")]
impl<T> embedded_hal_1::i2c::blocking::I2c for I2C<T>
where
T: Instance,
Expand Down
1 change: 1 addition & 0 deletions esp-hal-common/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub use nb;
pub use crate::system::SystemExt;

/// All traits required for using the 1.0.0-alpha.x release of embedded-hal
#[cfg(feature = "eh1")]
pub mod eh1 {
pub use embedded_hal_1::{
delay::blocking::DelayUs as _embedded_hal_delay_blocking_DelayUs,
Expand Down
4 changes: 4 additions & 0 deletions esp-hal-common/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const UART_FIFO_SIZE: u16 = 128;
#[derive(Debug)]
pub enum Error {}

#[cfg(feature = "eh1")]
impl embedded_hal_1::serial::Error for Error {
fn kind(&self) -> embedded_hal_1::serial::ErrorKind {
embedded_hal_1::serial::ErrorKind::Other
Expand Down Expand Up @@ -245,10 +246,12 @@ where
}
}

#[cfg(feature = "eh1")]
impl<T> embedded_hal_1::serial::ErrorType for Serial<T> {
type Error = Error;
}

#[cfg(feature = "eh1")]
impl<T> embedded_hal_1::serial::nb::Read for Serial<T>
where
T: Instance,
Expand All @@ -258,6 +261,7 @@ where
}
}

#[cfg(feature = "eh1")]
impl<T> embedded_hal_1::serial::nb::Write for Serial<T>
where
T: Instance,
Expand Down
2 changes: 2 additions & 0 deletions esp-hal-common/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ where
}
}

#[cfg(feature = "eh1")]
impl<T> embedded_hal_1::spi::ErrorType for Spi<T> {
type Error = Infallible;
}

#[cfg(feature = "eh1")]
impl<T> embedded_hal_1::spi::nb::FullDuplex for Spi<T>
where
T: Instance,
Expand Down
4 changes: 1 addition & 3 deletions esp32-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ categories = [
bare-metal = "1.0"
embedded-hal = { version = "0.2", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.8" }
fugit = "0.3"
nb = "1.0"
void = { version = "1.0", default-features = false }
xtensa-lx = { version = "0.7", features = ["esp32"] }
xtensa-lx-rt = { version = "0.12", features = ["esp32"], optional = true }

Expand All @@ -46,5 +43,6 @@ smart-leds = "0.3"
[features]
default = ["rt"]
bluetooth = []
eh1 = ["esp-hal-common/eh1"]
rt = ["xtensa-lx-rt/esp32"]
ufmt = ["esp-hal-common/ufmt"]
4 changes: 1 addition & 3 deletions esp32c3-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ categories = [
bare-metal = "1.0"
embedded-hal = { version = "0.2", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.8" }
fugit = "0.3"
nb = "1.0"
r0 = "1.0"
riscv = "0.8"
riscv-rt = { version = "0.8", optional = true }
void = { version = "1.0", default-features = false }

[dependencies.esp-hal-common]
path = "../esp-hal-common"
Expand All @@ -47,5 +44,6 @@ smart-leds = "0.3"
[features]
default = ["rt"]
direct-boot = []
eh1 = ["esp-hal-common/eh1"]
rt = ["riscv-rt"]
ufmt = ["esp-hal-common/ufmt"]
4 changes: 1 addition & 3 deletions esp32s2-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ categories = [
bare-metal = "1.0"
embedded-hal = { version = "0.2", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.8" }
fugit = "0.3"
nb = "1.0"
void = { version = "1.0", default-features = false }
xtensa-lx = { version = "0.7", features = ["esp32s2"] }
xtensa-lx-rt = { version = "0.12", features = ["esp32s2"], optional = true }

Expand All @@ -45,5 +42,6 @@ smart-leds = "0.3"

[features]
default = ["rt"]
eh1 = ["esp-hal-common/eh1"]
rt = ["xtensa-lx-rt/esp32s2"]
ufmt = ["esp-hal-common/ufmt"]
4 changes: 1 addition & 3 deletions esp32s3-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ categories = [
bare-metal = "1.0"
embedded-hal = { version = "0.2", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.8" }
fugit = "0.3"
nb = "1.0"
void = { version = "1.0", default-features = false }
xtensa-lx = { version = "0.7", features = ["esp32s3"] }
xtensa-lx-rt = { version = "0.12", features = ["esp32s3"], optional = true }

Expand All @@ -45,5 +42,6 @@ smart-leds = "0.3"

[features]
default = ["rt"]
eh1 = ["esp-hal-common/eh1"]
rt = ["xtensa-lx-rt/esp32s3"]
ufmt = ["esp-hal-common/ufmt"]

0 comments on commit 3d48190

Please sign in to comment.