Skip to content

Commit

Permalink
Gate the embedded-io trait impls behind a feature (#964)
Browse files Browse the repository at this point in the history
* Gate the `embedded-io` trait impls behind a feature

* Update `CHANGELOG.md`
  • Loading branch information
jessebraham authored Nov 20, 2023
1 parent 04f63b7 commit 8754217
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Only allow a single version of `esp-hal-common` to be present in an application (#934)
- C3, C6 and H2 can now use the `zero-rtc-bss` feature to enable `esp-hal-common/rv-zero-rtc-bss` (#867)
- Reuse `ieee802154_clock_enable/disable()` functions for BLE and rename `ble_ieee802154_clock_enable()` (#953)
- The `embedded-io` trait implementations are now gated behind the `embedded-io` feature (#964)

### Fixed

Expand Down
19 changes: 14 additions & 5 deletions esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ embedded-dma = "0.2.0"
embedded-hal = { version = "0.2.7", features = ["unproven"] }
embedded-hal-1 = { version = "=1.0.0-rc.1", optional = true, package = "embedded-hal" }
embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true }
embedded-io = "0.6.1"
embedded-io = { version = "0.6.1", optional = true }
esp-synopsys-usb-otg = { version = "0.3.2", optional = true, features = ["fs", "esp32sx"] }
fugit = "0.3.7"
log = { version = "0.4.20", optional = true }
Expand Down Expand Up @@ -117,16 +117,25 @@ log = ["dep:log"]

# Trait implementation features:
# - Implement the `[email protected]` traits (and friends)
# - Implement the `embedded-io` traits where able
# - Implement the `ufmt_write::Write` trait where able
eh1 = ["embedded-hal-1", "embedded-hal-nb", "embedded-can"]
ufmt = ["ufmt-write"]
eh1 = ["embedded-hal-1", "embedded-hal-nb", "embedded-can"]
embedded-io = ["dep:embedded-io"]
ufmt = ["ufmt-write"]

# Support for asynchronous operation, implementing traits from
# `embedded-hal-async` and `embedded-io-async`
async = ["embedded-hal-async", "eh1", "embassy-sync", "embassy-futures", "embedded-io-async"]
async = [
"embedded-hal-async",
"eh1",
"embassy-sync",
"embassy-futures",
"embedded-io",
"embedded-io-async",
]

# Embassy support
embassy = ["embassy-time","procmacros/embassy"]
embassy = ["embassy-time", "procmacros/embassy"]

embassy-executor-interrupt = ["embassy", "embassy-executor"]
embassy-executor-thread = ["embassy", "embassy-executor"]
Expand Down
8 changes: 8 additions & 0 deletions esp-hal-common/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl embedded_hal_nb::serial::Error for Error {
}
}

#[cfg(feature = "embedded-io")]
impl embedded_io::Error for Error {
fn kind(&self) -> embedded_io::ErrorKind {
embedded_io::ErrorKind::Other
Expand Down Expand Up @@ -1157,18 +1158,22 @@ where
}
}

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

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

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

#[cfg(feature = "embedded-io")]
impl<T> embedded_io::Read for Uart<'_, T>
where
T: Instance,
Expand All @@ -1178,6 +1183,7 @@ where
}
}

#[cfg(feature = "embedded-io")]
impl<T> embedded_io::Read for UartRx<'_, T>
where
T: Instance,
Expand Down Expand Up @@ -1208,6 +1214,7 @@ where
}
}

#[cfg(feature = "embedded-io")]
impl<T> embedded_io::Write for Uart<'_, T>
where
T: Instance,
Expand All @@ -1221,6 +1228,7 @@ where
}
}

#[cfg(feature = "embedded-io")]
impl<T> embedded_io::Write for UartTx<'_, T>
where
T: Instance,
Expand Down
3 changes: 3 additions & 0 deletions esp-hal-common/src/usb_serial_jtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,12 @@ impl embedded_hal_nb::serial::Write for UsbSerialJtag<'_> {
}
}

#[cfg(feature = "embedded-io")]
impl embedded_io::ErrorType for UsbSerialJtag<'_> {
type Error = Error;
}

#[cfg(feature = "embedded-io")]
impl embedded_io::Read for UsbSerialJtag<'_> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
let mut count = 0;
Expand Down Expand Up @@ -327,6 +329,7 @@ impl embedded_io::Read for UsbSerialJtag<'_> {
}
}

#[cfg(feature = "embedded-io")]
impl embedded_io::Write for UsbSerialJtag<'_> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.write_bytes(buf)?;
Expand Down

0 comments on commit 8754217

Please sign in to comment.