Skip to content

Commit

Permalink
Remove most trait implementation features from esp-hal (#2070)
Browse files Browse the repository at this point in the history
* Eliminate esp-hal's `ufmt` feature

* Eliminate esp-hal's `embedded-hal-02` feature

* Eliminate esp-hal's `embedded-hal` feature

* Eliminate esp-hal's `embedded-io` feature

* Eliminate esp-hal's `async` feature

* Update `CHANGELOG.md`

* Remove `async` from required features for HIL tests

* Update migration guide
  • Loading branch information
jessebraham authored Sep 4, 2024
1 parent 49e14b7 commit b7b916f
Show file tree
Hide file tree
Showing 62 changed files with 78 additions and 297 deletions.
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed

- Removed `NoPinType` in favour of `DummyPin`. (#2068)
- Removed the `async`, `embedded-hal-02`, `embedded-hal`, `embedded-io`, `embedded-io-async`, and `ufmt` features (#2070)

## [0.20.1] - 2024-08-30

Expand Down
58 changes: 18 additions & 40 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 @@ -24,17 +24,17 @@ defmt = { version = "0.3.8", optional = true }
delegate = "0.12.0"
digest = { version = "0.10.7", default-features = false, optional = true }
document-features = "0.2.10"
embassy-futures = { version = "0.1.1", optional = true }
embassy-sync = { version = "0.6.0", optional = true }
embassy-futures = "0.1.1"
embassy-sync = "0.6.0"
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-hal-02 = { version = "0.2.7", optional = true, features = ["unproven"], package = "embedded-hal" }
embedded-hal = { version = "1.0.0", optional = true }
embedded-hal-async = { version = "1.0.0", optional = true }
embedded-hal-nb = { version = "1.0.0", optional = true }
embedded-io = { version = "0.6.1", optional = true }
embedded-io-async = { version = "0.6.1", optional = true }
embedded-can = "0.4.1"
embedded-hal-02 = { version = "0.2.7", features = ["unproven"], package = "embedded-hal" }
embedded-hal = "1.0.0"
embedded-hal-async = "1.0.0"
embedded-hal-nb = "1.0.0"
embedded-io = "0.6.1"
embedded-io-async = "0.6.1"
enumset = "1.1.5"
esp-synopsys-usb-otg = { version = "0.4.2", optional = true, features = ["fs", "esp32sx"] }
fugit = "0.3.7"
Expand All @@ -48,7 +48,7 @@ strum = { version = "0.26.3", default-features = false, featu
void = { version = "1.0.2", default-features = false }
usb-device = { version = "0.3.2", optional = true }
rand_core = "0.6.4"
ufmt-write = { version = "0.1.0", optional = true }
ufmt-write = "0.1.0"
xtensa-lx = { version = "0.9.0", optional = true }

# IMPORTANT:
Expand Down Expand Up @@ -76,14 +76,14 @@ 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"]

bluetooth = []

usb-otg = ["esp-synopsys-usb-otg", "usb-device"]
usb-otg = ["dep:embassy-usb-driver", "dep:embassy-usb-synopsys-otg", "dep:esp-synopsys-usb-otg", "dep:usb-device"]

__esp_hal_embassy = []

Expand Down Expand Up @@ -124,27 +124,14 @@ esp32s3 = ["dep:esp32s3", "xtensa", "procmacros/has-ulp-core", "xtensa-lx/spin",
flip-link = ["esp-riscv-rt/fix-sp"]

#! ### Trait Implementation Feature Flags
## Enable support for asynchronous operation, with interfaces provided by
## `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",
"embassy-sync",
"embassy-futures",
"embassy-usb-driver",
"embassy-usb-synopsys-otg"
]
## Implement `defmt::Format` on certain types.
defmt = [
"dep:defmt",
"embassy-futures?/defmt",
"embassy-sync?/defmt",
"embedded-hal?/defmt-03",
"embassy-futures/defmt",
"embassy-sync/defmt",
"embedded-hal/defmt-03",
"embedded-io/defmt-03",
"embedded-io-async?/defmt-03",
"embedded-io-async/defmt-03",
"esp32?/defmt",
"esp32c2?/defmt",
"esp32c3?/defmt",
Expand All @@ -153,15 +140,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 the `0.2.x` release of `embedded-hal`.
embedded-hal-02 = ["dep:embedded-hal-02"]
## Implement the traits defined in `embedded-io` for certain peripherals.
embedded-io = ["dep:embedded-io"]
## Implement the `ufmt_write::uWrite` trait for certain peripherals.
ufmt = ["dep:ufmt-write"]

#! ### PSRAM Feature Flags
## Use externally connected PSRAM (2MB).
Expand All @@ -184,7 +162,7 @@ opsram-8m = []
opsram-16m = []

# This feature is intended for testing; you probably don't want to enable it:
ci = ["async", "embedded-hal-02", "embedded-io", "ufmt", "defmt", "bluetooth", "place-spi-driver-in-ram"]
ci = ["defmt", "bluetooth", "place-spi-driver-in-ram"]

[lints.clippy]
mixed_attributes_style = "allow"
Expand Down
21 changes: 16 additions & 5 deletions esp-hal/MIGRATING-0.20.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
Migration Guide from 0.20.x to vNext
====================================
# Migration Guide from 0.20.x to vNext

HAL initialsation
-----------------
## Cargo Features

A number of trait implementations which were previously feature-gated are now implemented by default. The following Cargo features have been removed:

- `async`
- `embedded-hal-02`
- `embedded-hal`
- `embedded-io`
- `embedded-io-async`
- `ufmt`

If your project enables any of these features, simply remove them from your Cargo manifest and things should continue to work as expected.

## HAL Initialisation

Instead of manually grabbing peripherals and setting up clocks, you should now call `esp_hal::init`.

Expand All @@ -13,7 +24,7 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c
prelude::*,
- system::SystemControl,
};

#[entry]
fn main() -> ! {
- let peripherals = Peripherals::take();
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/analog/adc/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ impl<'d, ADC1> Adc<'d, ADC1> {
}
}

#[cfg(feature = "embedded-hal-02")]
impl<'d, ADCI, PIN> embedded_hal_02::adc::OneShot<ADCI, u16, super::AdcPin<PIN, ADCI>>
for Adc<'d, ADCI>
where
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/analog/adc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ pub struct AdcPin<PIN, ADCI, CS = ()> {
_phantom: PhantomData<ADCI>,
}

#[cfg(feature = "embedded-hal-02")]
impl<PIN, ADCI, CS> embedded_hal_02::adc::Channel<ADCI> for AdcPin<PIN, ADCI, CS>
where
PIN: embedded_hal_02::adc::Channel<ADCI, ID = u8>,
Expand Down Expand Up @@ -260,7 +259,6 @@ macro_rules! impl_adc_interface {
const CHANNEL: u8 = $channel;
}

#[cfg(feature = "embedded-hal-02")]
impl embedded_hal_02::adc::Channel<crate::peripherals::$adc> for crate::gpio::$pin {
type ID = u8;

Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/analog/adc/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,6 @@ impl super::AdcCalEfuse for crate::peripherals::ADC2 {
}
}

#[cfg(feature = "embedded-hal-02")]
impl<'d, ADCI, PIN, CS> embedded_hal_02::adc::OneShot<ADCI, u16, super::AdcPin<PIN, ADCI, CS>>
for Adc<'d, ADCI>
where
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/analog/adc/xtensa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ impl super::AdcCalEfuse for crate::peripherals::ADC2 {
}
}

#[cfg(feature = "embedded-hal-02")]
impl<'d, ADCI, PIN, CS> embedded_hal_02::adc::OneShot<ADCI, u16, AdcPin<PIN, ADCI, CS>>
for Adc<'d, ADCI>
where
Expand Down
3 changes: 0 additions & 3 deletions esp-hal/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use crate::clock::Clocks;
#[non_exhaustive]
pub struct Delay;

#[cfg(feature = "embedded-hal-02")]
impl<T> embedded_hal_02::blocking::delay::DelayMs<T> for Delay
where
T: Into<u32>,
Expand All @@ -55,7 +54,6 @@ where
}
}

#[cfg(feature = "embedded-hal-02")]
impl<T> embedded_hal_02::blocking::delay::DelayUs<T> for Delay
where
T: Into<u32>,
Expand All @@ -65,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
11 changes: 0 additions & 11 deletions esp-hal/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,23 +420,18 @@ impl<const N: u8> RegisterAccess for Channel<N> {
#[doc(hidden)]
pub struct ChannelTxImpl<const N: u8> {}

#[cfg(feature = "async")]
use embassy_sync::waitqueue::AtomicWaker;

#[cfg(feature = "async")]
#[allow(clippy::declare_interior_mutable_const)]
const INIT: AtomicWaker = AtomicWaker::new();

#[cfg(feature = "async")]
static TX_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [INIT; CHANNEL_COUNT];

#[cfg(feature = "async")]
static RX_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [INIT; CHANNEL_COUNT];

impl<const N: u8> crate::private::Sealed for ChannelTxImpl<N> {}

impl<const N: u8> TxChannel<Channel<N>> for ChannelTxImpl<N> {
#[cfg(feature = "async")]
fn waker() -> &'static AtomicWaker {
&TX_WAKERS[N as usize]
}
Expand All @@ -449,7 +444,6 @@ pub struct ChannelRxImpl<const N: u8> {}
impl<const N: u8> crate::private::Sealed for ChannelRxImpl<N> {}

impl<const N: u8> RxChannel<Channel<N>> for ChannelRxImpl<N> {
#[cfg(feature = "async")]
fn waker() -> &'static AtomicWaker {
&RX_WAKERS[N as usize]
}
Expand Down Expand Up @@ -551,7 +545,6 @@ macro_rules! impl_channel {
///
/// Descriptors should be sized as `(CHUNK_SIZE + 4091) / 4092`. I.e., to
/// transfer buffers of size `1..=4092`, you need 1 descriptor.
#[cfg(feature = "async")]
pub fn configure_for_async<'a>(
self,
burst_mode: bool,
Expand All @@ -578,23 +571,19 @@ macro_rules! impl_channel {

cfg_if::cfg_if! {
if #[cfg(esp32c2)] {
#[cfg(feature = "async")]
const CHANNEL_COUNT: usize = 1;
impl_channel!(0, super::asynch::interrupt::interrupt_handler_ch0, DMA_CH0);
} else if #[cfg(esp32c3)] {
#[cfg(feature = "async")]
const CHANNEL_COUNT: usize = 3;
impl_channel!(0, super::asynch::interrupt::interrupt_handler_ch0, DMA_CH0);
impl_channel!(1, super::asynch::interrupt::interrupt_handler_ch1, DMA_CH1);
impl_channel!(2, super::asynch::interrupt::interrupt_handler_ch2, DMA_CH2);
} else if #[cfg(any(esp32c6, esp32h2))] {
#[cfg(feature = "async")]
const CHANNEL_COUNT: usize = 3;
impl_channel!(0, super::asynch::interrupt::interrupt_handler_ch0, DMA_IN_CH0, DMA_OUT_CH0);
impl_channel!(1, super::asynch::interrupt::interrupt_handler_ch1, DMA_IN_CH1, DMA_OUT_CH1);
impl_channel!(2, super::asynch::interrupt::interrupt_handler_ch2, DMA_IN_CH2, DMA_OUT_CH2);
} else if #[cfg(esp32s3)] {
#[cfg(feature = "async")]
const CHANNEL_COUNT: usize = 5;
impl_channel!(0, super::asynch::interrupt::interrupt_handler_ch0, DMA_IN_CH0, DMA_OUT_CH0);
impl_channel!(1, super::asynch::interrupt::interrupt_handler_ch1, DMA_IN_CH1, DMA_OUT_CH1);
Expand Down
7 changes: 0 additions & 7 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,6 @@ pub trait RxPrivate: crate::private::Sealed {

fn clear_interrupts(&self);

#[cfg(feature = "async")]
fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker;
}

Expand Down Expand Up @@ -1296,7 +1295,6 @@ where
R::is_in_done()
}

#[cfg(feature = "async")]
fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker;
}

Expand Down Expand Up @@ -1494,7 +1492,6 @@ where
CH::Channel::clear_in_interrupts();
}

#[cfg(feature = "async")]
fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker {
CH::Rx::waker()
}
Expand Down Expand Up @@ -1552,7 +1549,6 @@ pub trait TxPrivate: crate::private::Sealed {

fn clear_interrupts(&self);

#[cfg(feature = "async")]
fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker;

fn descriptors_handled(&self) -> bool;
Expand Down Expand Up @@ -1633,7 +1629,6 @@ where
R::last_out_dscr_address()
}

#[cfg(feature = "async")]
fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker;
}

Expand Down Expand Up @@ -1759,7 +1754,6 @@ where
CH::Channel::has_out_descriptor_error()
}

#[cfg(feature = "async")]
fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker {
CH::Tx::waker()
}
Expand Down Expand Up @@ -2762,7 +2756,6 @@ where
}
}

#[cfg(feature = "async")]
pub(crate) mod asynch {
use core::task::Poll;

Expand Down
6 changes: 0 additions & 6 deletions esp-hal/src/dma/pdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ macro_rules! ImplSpiChannel {
impl $crate::private::Sealed for [<Spi $num DmaChannelTxImpl>] {}

impl<'a> TxChannel<[<Spi $num DmaChannel>]> for [<Spi $num DmaChannelTxImpl>] {
#[cfg(feature = "async")]
fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker {
static WAKER: embassy_sync::waitqueue::AtomicWaker = embassy_sync::waitqueue::AtomicWaker::new();
&WAKER
Expand All @@ -370,7 +369,6 @@ macro_rules! ImplSpiChannel {
impl $crate::private::Sealed for [<Spi $num DmaChannelRxImpl>] {}

impl<'a> RxChannel<[<Spi $num DmaChannel>]> for [<Spi $num DmaChannelRxImpl>] {
#[cfg(feature = "async")]
fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker {
static WAKER: embassy_sync::waitqueue::AtomicWaker = embassy_sync::waitqueue::AtomicWaker::new();
&WAKER
Expand Down Expand Up @@ -408,7 +406,6 @@ macro_rules! ImplSpiChannel {
///
/// Descriptors should be sized as `(CHUNK_SIZE + 4091) / 4092`. I.e., to
/// transfer buffers of size `1..=4092`, you need 1 descriptor.
#[cfg(feature = "async")]
pub fn configure_for_async<'a>(
self,
burst_mode: bool,
Expand Down Expand Up @@ -752,7 +749,6 @@ macro_rules! ImplI2sChannel {
impl $crate::private::Sealed for [<I2s $num DmaChannelTxImpl>] {}

impl<'a> TxChannel<[<I2s $num DmaChannel>]> for [<I2s $num DmaChannelTxImpl>] {
#[cfg(feature = "async")]
fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker {
static WAKER: embassy_sync::waitqueue::AtomicWaker = embassy_sync::waitqueue::AtomicWaker::new();
&WAKER
Expand All @@ -765,7 +761,6 @@ macro_rules! ImplI2sChannel {
impl $crate::private::Sealed for [<I2s $num DmaChannelRxImpl>] {}

impl<'a> RxChannel<[<I2s $num DmaChannel>]> for [<I2s $num DmaChannelRxImpl>] {
#[cfg(feature = "async")]
fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker {
static WAKER: embassy_sync::waitqueue::AtomicWaker = embassy_sync::waitqueue::AtomicWaker::new();
&WAKER
Expand Down Expand Up @@ -802,7 +797,6 @@ macro_rules! ImplI2sChannel {
///
/// Descriptors should be sized as `(CHUNK_SIZE + 4091) / 4092`. I.e., to
/// transfer buffers of size `1..=4092`, you need 1 descriptor.
#[cfg(feature = "async")]
pub fn configure_for_async<'a>(
self,
burst_mode: bool,
Expand Down
Loading

0 comments on commit b7b916f

Please sign in to comment.