Skip to content

Commit

Permalink
Eliminate esp-hal's async feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed Sep 3, 2024
1 parent ae37ae1 commit 1fe0423
Show file tree
Hide file tree
Showing 45 changed files with 42 additions and 134 deletions.
29 changes: 9 additions & 20 deletions esp-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "0.4.1"
embedded-hal-02 = { version = "0.2.7", features = ["unproven"], package = "embedded-hal" }
embedded-hal = "1.0.0"
embedded-hal-async = { version = "1.0.0", optional = true }
embedded-hal-async = "1.0.0"
embedded-hal-nb = "1.0.0"
embedded-io = "0.6.1"
embedded-io-async = { version = "0.6.1", optional = true }
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 Down Expand Up @@ -83,7 +83,7 @@ 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,25 +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-async",
"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",
"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 Down Expand Up @@ -173,7 +162,7 @@ opsram-8m = []
opsram-16m = []

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

[lints.clippy]
mixed_attributes_style = "allow"
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
3 changes: 0 additions & 3 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,6 @@ extern "C" fn gpio_interrupt_handler() {
user_handler.call();
}

#[cfg(feature = "async")]
asynch::handle_gpio_interrupt();
}

Expand Down Expand Up @@ -2786,7 +2785,6 @@ pub(crate) mod internal {
}
}

#[cfg(feature = "async")]
mod asynch {
use core::task::{Context, Poll};

Expand Down Expand Up @@ -3497,7 +3495,6 @@ mod embedded_hal_impls {
}
}

#[cfg(feature = "async")]
mod embedded_hal_async_impls {
use embedded_hal_async::digital::Wait;

Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ where
}
}

#[cfg(feature = "async")]
impl<'d, T> I2C<'d, T, crate::Async>
where
T: Instance,
Expand Down Expand Up @@ -457,7 +456,6 @@ where
}
}

#[cfg(feature = "async")]
mod asynch {
#[cfg(not(esp32))]
use core::{
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,6 @@ mod private {
}

/// Async functionality
#[cfg(feature = "async")]
pub mod asynch {
use super::{Error, I2sRx, I2sTx, RegisterAccess};
use crate::{
Expand Down
4 changes: 1 addition & 3 deletions esp-hal/src/lcd_cam/lcd/i8080.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ use core::{fmt::Formatter, marker::PhantomData, mem::size_of};

use fugit::HertzU32;

#[cfg(feature = "async")]
use crate::lcd_cam::asynch::LcdDoneFuture;
use crate::{
clock::Clocks,
dma::{
Expand All @@ -81,6 +79,7 @@ use crate::{
},
gpio::{OutputPin, OutputSignal},
lcd_cam::{
asynch::LcdDoneFuture,
lcd::{i8080::private::TxPins, ClockMode, DelayMode, Phase, Polarity},
private::calculate_clkm,
BitOrder,
Expand Down Expand Up @@ -378,7 +377,6 @@ where
}
}

#[cfg(feature = "async")]
impl<'d, CH: DmaChannel, P: TxPins> I8080<'d, CH, P, crate::Async>
where
P::Word: Into<u16>,
Expand Down
4 changes: 0 additions & 4 deletions esp-hal/src/lcd_cam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ impl<'d> InterruptConfigurable for LcdCam<'d, crate::Blocking> {
}
}

#[cfg(feature = "async")]
impl<'d> LcdCam<'d, crate::Async> {
/// Creates a new `LcdCam` instance for asynchronous operation.
pub fn new_async(lcd_cam: impl Peripheral<P = LCD_CAM> + 'd) -> Self {
Expand Down Expand Up @@ -118,7 +117,6 @@ pub enum ByteOrder {
}

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

Expand Down Expand Up @@ -173,13 +171,11 @@ pub mod asynch {
}

mod private {
#[cfg(feature = "async")]
pub(crate) struct Instance;

// NOTE: the LCD_CAM interrupt registers are shared between LCD and Camera and
// this is only implemented for the LCD side, when the Camera is implemented a
// CriticalSection will be needed to protect these shared registers.
#[cfg(feature = "async")]
impl Instance {
pub(crate) fn listen_lcd_done() {
let lcd_cam = unsafe { crate::peripherals::LCD_CAM::steal() };
Expand Down
3 changes: 1 addition & 2 deletions esp-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@
//! ## Feature Flags
#![doc = document_features::document_features!(feature_label = r#"<span class="stab portability"><code>{feature}</code></span>"#)]
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")]
#![allow(asm_sub_register)]
#![cfg_attr(feature = "async", allow(stable_features, async_fn_in_trait))]
#![allow(asm_sub_register, async_fn_in_trait, stable_features)]
#![cfg_attr(xtensa, feature(asm_experimental_arch))]
#![deny(missing_docs, rust_2018_idioms)]
#![no_std]
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/otg_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ unsafe impl<'d> UsbPeripheral for Usb<'d> {
}
}
/// Async functionality
#[cfg(feature = "async")]
pub mod asynch {
use embassy_usb_driver::{
EndpointAddress,
Expand Down
Loading

0 comments on commit 1fe0423

Please sign in to comment.