diff --git a/Cargo.toml b/Cargo.toml index 5ee055df4c8..4d9381fb6be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ exclude = [ "esp-backtrace", "esp-build", "esp-hal", + "esp-hal-embassy", "esp-hal-procmacros", "esp-hal-smartled", "esp-ieee802154", diff --git a/esp-hal-embassy/Cargo.toml b/esp-hal-embassy/Cargo.toml new file mode 100644 index 00000000000..714b18c4270 --- /dev/null +++ b/esp-hal-embassy/Cargo.toml @@ -0,0 +1,48 @@ +[package] +name = "esp-hal-embassy" +version = "0.1.0" +edition = "2021" +rust-version = "1.76.0" +description = "Embassy support for esp-hal" +repository = "https://github.com/esp-rs/esp-hal" +license = "MIT OR Apache-2.0" + +[package.metadata.docs.rs] +default-target = "riscv32imac-unknown-none-elf" +features = ["esp32c6", "time-timg0"] + +[dependencies] +critical-section = "1.1.2" +defmt = { version = "0.3.8", optional = true } +document-features = "0.2.8" +embassy-executor = "0.5.0" +embassy-time-driver = "0.1.0" +esp-hal = { version = "0.17.0", path = "../esp-hal" } +portable-atomic = "1.6.0" + +[build-dependencies] +cfg-if = "1.0.0" +esp-build = { version = "0.1.0", path = "../esp-build" } +esp-metadata = { version = "0.1.0", path = "../esp-metadata" } + +[features] +esp32 = ["esp-hal/esp32"] +esp32c2 = ["esp-hal/esp32c2"] +esp32c3 = ["esp-hal/esp32c3"] +esp32c6 = ["esp-hal/esp32c6"] +esp32h2 = ["esp-hal/esp32h2"] +esp32s2 = ["esp-hal/esp32s2"] +esp32s3 = ["esp-hal/esp32s3"] + +## Implement `defmt::Format` on certain types. +defmt = ["dep:defmt", "embassy-executor/defmt", "esp-hal/defmt"] +## Use the executor-integrated `embassy-time` timer queue. +integrated-timers = ["embassy-executor/integrated-timers"] + +#! ### Time Driver Feature Flags +## SYSTIMER (16MHz) +time-systimer-16mhz = ["embassy-time-driver/tick-hz-16_000_000"] +## SYSTIMER (80MHz) +time-systimer-80mhz = ["embassy-time-driver/tick-hz-80_000_000"] +## TIMG0 (1MHz) +time-timg0 = ["embassy-time-driver/tick-hz-1_000_000"] diff --git a/esp-hal-embassy/README.md b/esp-hal-embassy/README.md new file mode 100644 index 00000000000..26456877c92 --- /dev/null +++ b/esp-hal-embassy/README.md @@ -0,0 +1,35 @@ +# esp-hal-embassy + +[![Crates.io](https://img.shields.io/crates/v/esp-hal-embassy?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp-hal-embassy) +[![docs.rs](https://img.shields.io/docsrs/esp-hal-embassy?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp-hal-embassy) +![MSRV](https://img.shields.io/badge/MSRV-1.76-blue?labelColor=1C2C2E&style=flat-square) +![Crates.io](https://img.shields.io/crates/l/esp-hal-embassy?labelColor=1C2C2E&style=flat-square) +[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) + +[Embassy] support for `esp-hal`. + +[embassy]: https://github.com/embassy-rs/embassy + +## [Documentation] + +[documentation]: https://docs.rs/esp-hal-embassy/ + +## Minimum Supported Rust Version (MSRV) + +This crate is guaranteed to compile on stable Rust 1.76 and up. It _might_ +compile with older versions but that may change in any new patch release. + +## License + +Licensed under either of: + +- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in +the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without +any additional terms or conditions. diff --git a/esp-hal-embassy/build.rs b/esp-hal-embassy/build.rs new file mode 100644 index 00000000000..c78fdab0116 --- /dev/null +++ b/esp-hal-embassy/build.rs @@ -0,0 +1,53 @@ +use std::{error::Error, str::FromStr}; + +use esp_build::assert_unique_used_features; +use esp_metadata::{Chip, Config}; + +fn main() -> Result<(), Box> { + // NOTE: update when adding new device support! + // Ensure that exactly one chip has been specified: + assert_unique_used_features!( + "esp32", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32s2", "esp32s3" + ); + + // If the `embassy` feature is enabled, ensure that a time driver implementation + // is available: + cfg_if::cfg_if! { + if #[cfg(feature = "esp32")] { + assert_unique_used_features!("time-timg0"); + } else if #[cfg(feature = "esp32s2")] { + assert_unique_used_features!("time-systimer-80mhz", "time-timg0"); + } else { + assert_unique_used_features!("time-systimer-16mhz", "time-timg0"); + } + } + + // NOTE: update when adding new device support! + // Determine the name of the configured device: + let device_name = if cfg!(feature = "esp32") { + "esp32" + } else if cfg!(feature = "esp32c2") { + "esp32c2" + } else if cfg!(feature = "esp32c3") { + "esp32c3" + } else if cfg!(feature = "esp32c6") { + "esp32c6" + } else if cfg!(feature = "esp32h2") { + "esp32h2" + } else if cfg!(feature = "esp32s2") { + "esp32s2" + } else if cfg!(feature = "esp32s3") { + "esp32s3" + } else { + unreachable!() // We've confirmed exactly one known device was selected + }; + + // Load the configuration file for the configured device: + let chip = Chip::from_str(device_name)?; + let config = Config::for_chip(&chip); + + // Define all necessary configuration symbols for the configured device: + config.define_symbols(); + + Ok(()) +} diff --git a/esp-hal/src/embassy/executor/interrupt.rs b/esp-hal-embassy/src/executor/interrupt.rs similarity index 95% rename from esp-hal/src/embassy/executor/interrupt.rs rename to esp-hal-embassy/src/executor/interrupt.rs index b9485fb1b87..b9859a2d561 100644 --- a/esp-hal/src/embassy/executor/interrupt.rs +++ b/esp-hal-embassy/src/executor/interrupt.rs @@ -1,14 +1,14 @@ //! Interrupt-mode executor. + use core::{cell::UnsafeCell, mem::MaybeUninit}; use embassy_executor::{raw, SendSpawner}; -use portable_atomic::{AtomicUsize, Ordering}; - -use crate::{ +use esp_hal::{ get_core, interrupt::{self, InterruptHandler}, system::SoftwareInterrupt, }; +use portable_atomic::{AtomicUsize, Ordering}; static mut EXECUTORS: [CallbackContext; 4] = [ CallbackContext::new(), @@ -43,7 +43,7 @@ impl CallbackContext { } fn get(&self) -> *mut raw::Executor { - unsafe { (*self.raw_executor.get()) as *mut raw::Executor } + unsafe { *self.raw_executor.get() } } fn set(&self, executor: *mut raw::Executor) { @@ -58,7 +58,7 @@ fn handle_interrupt() { swi.reset(); unsafe { - let executor = EXECUTORS[NUM as usize].get().as_mut().unwrap(); + let executor = unwrap!(EXECUTORS[NUM as usize].get().as_mut()); executor.poll(); } } @@ -151,7 +151,7 @@ impl InterruptExecutor { if self.core.load(Ordering::Acquire) == usize::MAX { panic!("InterruptExecutor::spawner() called on uninitialized executor."); } - let executor = unsafe { (&*self.executor.get()).assume_init_ref() }; + let executor = unsafe { (*self.executor.get()).assume_init_ref() }; executor.spawner().make_send() } } diff --git a/esp-hal/src/embassy/executor/mod.rs b/esp-hal-embassy/src/executor/mod.rs similarity index 89% rename from esp-hal/src/embassy/executor/mod.rs rename to esp-hal-embassy/src/executor/mod.rs index 983a3c8a46d..f82bf3f6c43 100644 --- a/esp-hal/src/embassy/executor/mod.rs +++ b/esp-hal-embassy/src/executor/mod.rs @@ -1,12 +1,11 @@ +pub use self::{interrupt::*, thread::*}; + mod interrupt; mod thread; -pub use interrupt::*; -pub use thread::*; - #[export_name = "__pender"] fn __pender(context: *mut ()) { - use crate::system::SoftwareInterrupt; + use esp_hal::system::SoftwareInterrupt; let context = (context as usize).to_le_bytes(); diff --git a/esp-hal/src/embassy/executor/thread.rs b/esp-hal-embassy/src/executor/thread.rs similarity index 95% rename from esp-hal/src/embassy/executor/thread.rs rename to esp-hal-embassy/src/executor/thread.rs index 78416fe41ec..7ac8807ae20 100644 --- a/esp-hal/src/embassy/executor/thread.rs +++ b/esp-hal-embassy/src/executor/thread.rs @@ -1,14 +1,14 @@ //! Multicore-aware thread-mode embassy executor. + use core::marker::PhantomData; use embassy_executor::{raw, Spawner}; -use portable_atomic::{AtomicBool, Ordering}; +use esp_hal::get_core; #[cfg(multi_core)] -use procmacros::handler; - -use crate::get_core; +use esp_hal::macros::handler; #[cfg(multi_core)] -use crate::peripherals::SYSTEM; +use esp_hal::peripherals::SYSTEM; +use portable_atomic::{AtomicBool, Ordering}; pub(crate) const THREAD_MODE_CONTEXT: u8 = 16; @@ -39,7 +39,7 @@ pub(crate) fn pend_thread_mode(core: usize) { // If we are pending a task on the current core, we're done. Otherwise, we // need to make sure the other core wakes up. #[cfg(multi_core)] - if core != crate::get_core() as usize { + if core != get_core() as usize { // We need to clear the interrupt from software. We don't actually // need it to trigger and run the interrupt handler, we just need to // kick waiti to return. @@ -78,7 +78,7 @@ impl Executor { pub fn new() -> Self { #[cfg(multi_core)] unsafe { - crate::system::SoftwareInterrupt::<3>::steal() + esp_hal::system::SoftwareInterrupt::<3>::steal() .set_interrupt_handler(software3_interrupt) } @@ -179,3 +179,9 @@ impl Executor { // here } } + +impl Default for Executor { + fn default() -> Self { + Self::new() + } +} diff --git a/esp-hal-embassy/src/fmt.rs b/esp-hal-embassy/src/fmt.rs new file mode 100644 index 00000000000..aa009027405 --- /dev/null +++ b/esp-hal-embassy/src/fmt.rs @@ -0,0 +1,226 @@ +#![macro_use] +#![allow(unused_macros)] + +#[cfg(all(feature = "defmt", feature = "log"))] +compile_error!("You may not enable both `defmt` and `log` features."); + +macro_rules! assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert!($($x)*); + } + }; +} + +macro_rules! assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert_eq!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert_eq!($($x)*); + } + }; +} + +macro_rules! assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::assert_ne!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::assert_ne!($($x)*); + } + }; +} + +macro_rules! debug_assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert!($($x)*); + } + }; +} + +macro_rules! debug_assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert_eq!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert_eq!($($x)*); + } + }; +} + +macro_rules! debug_assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::debug_assert_ne!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::debug_assert_ne!($($x)*); + } + }; +} + +macro_rules! todo { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::todo!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::todo!($($x)*); + } + }; +} + +macro_rules! unreachable { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::unreachable!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::unreachable!($($x)*); + } + }; +} + +macro_rules! panic { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + ::core::panic!($($x)*); + #[cfg(feature = "defmt")] + ::defmt::panic!($($x)*); + } + }; +} + +macro_rules! trace { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::trace!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::trace!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! debug { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::debug!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::debug!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! info { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::info!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::info!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! warn { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::warn!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::warn!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +macro_rules! error { + ($s:literal $(, $x:expr)* $(,)?) => { + { + #[cfg(feature = "log")] + ::log::error!($s $(, $x)*); + #[cfg(feature = "defmt")] + ::defmt::error!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); + } + }; +} + +#[cfg(feature = "defmt")] +macro_rules! unwrap { + ($($x:tt)*) => { + ::defmt::unwrap!($($x)*) + }; +} + +#[cfg(not(feature = "defmt"))] +macro_rules! unwrap { + ($arg:expr) => { + match $crate::fmt::Try::into_result($arg) { + ::core::result::Result::Ok(t) => t, + ::core::result::Result::Err(e) => { + ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); + } + } + }; + ($arg:expr, $($msg:expr),+ $(,)? ) => { + match $crate::fmt::Try::into_result($arg) { + ::core::result::Result::Ok(t) => t, + ::core::result::Result::Err(e) => { + ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); + } + } + } +} + +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct NoneError; + +pub trait Try { + type Ok; + type Error; + #[allow(unused)] + fn into_result(self) -> Result; +} + +impl Try for Option { + type Ok = T; + type Error = NoneError; + + #[inline] + fn into_result(self) -> Result { + self.ok_or(NoneError) + } +} + +impl Try for Result { + type Ok = T; + type Error = E; + + #[inline] + fn into_result(self) -> Self { + self + } +} diff --git a/esp-hal-embassy/src/lib.rs b/esp-hal-embassy/src/lib.rs new file mode 100644 index 00000000000..3a1ef10e42d --- /dev/null +++ b/esp-hal-embassy/src/lib.rs @@ -0,0 +1,102 @@ +//! Embassy support for [esp-hal]. +//! +//! [Embassy] is a modern asynchronous framework intended for use with embedded +//! systems. This package provides support for building applications using +//! Embassy with [esp-hal]. +//! +//! [esp-hal]: https://github.com/esp-rs/esp-hal +//! [embassy]: https://github.com/embassy-rs/embassy +//! +//! ## Executors +//! +//! Two types of executors are provided: +//! +//! - [Executor]: A thread-mode executor +//! - [InterruptExecutor]: An interrupt-mode executor +//! +//! [InterruptExecutor] can be used to achieve preemptive multitasking in +//! asynchronous applications, which is typically something reserved for more +//! traditional RTOS. More information can be found in the [Embassy +//! documentation]. +//! +//! [embassy documentation]: https://embassy.dev/book/dev/runtime.html +//! +//! ## Initialization +//! +//! Embassy **must** be initialized by calling the [init] function. This +//! initialization must be performed *prior* to spawning any tasks. +//! +//! ## Feature Flags +#![doc = document_features::document_features!()] +#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] +#![deny(missing_docs)] +#![cfg_attr(xtensa, feature(asm_experimental_arch))] +#![no_std] + +// MUST be the first module +mod fmt; + +use core::cell::Cell; + +use embassy_time_driver::{AlarmHandle, Driver}; +use esp_hal::clock::Clocks; + +pub use self::executor::{Executor, InterruptExecutor}; +use self::time_driver::{EmbassyTimer, TimerType}; + +mod executor; +mod time_driver; + +/// Initialize embassy +pub fn init(clocks: &Clocks, time_driver: TimerType) { + EmbassyTimer::init(clocks, time_driver) +} + +#[allow(clippy::type_complexity)] +pub(crate) struct AlarmState { + pub callback: Cell>, + pub allocated: Cell, +} + +unsafe impl Send for AlarmState {} + +impl AlarmState { + pub const fn new() -> Self { + Self { + callback: Cell::new(None), + allocated: Cell::new(false), + } + } +} + +impl Driver for EmbassyTimer { + fn now(&self) -> u64 { + EmbassyTimer::now() + } + + unsafe fn allocate_alarm(&self) -> Option { + critical_section::with(|cs| { + for (i, alarm) in self.alarms.borrow(cs).iter().enumerate() { + if !alarm.allocated.get() { + // set alarm so it is not overwritten + alarm.allocated.set(true); + self.on_alarm_allocated(i); + return Some(AlarmHandle::new(i as u8)); + } + } + None + }) + } + + fn set_alarm_callback(&self, alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) { + let n = alarm.id() as usize; + critical_section::with(|cs| { + let alarm = &self.alarms.borrow(cs)[n]; + alarm.callback.set(Some((callback, ctx))); + }) + } + + fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool { + self.set_alarm(alarm, timestamp) + } +} diff --git a/esp-hal-embassy/src/time_driver/mod.rs b/esp-hal-embassy/src/time_driver/mod.rs new file mode 100644 index 00000000000..b91741e4220 --- /dev/null +++ b/esp-hal-embassy/src/time_driver/mod.rs @@ -0,0 +1,9 @@ +#[cfg(any(feature = "time-systimer-16mhz", feature = "time-systimer-80mhz"))] +pub use self::systimer::*; +#[cfg(feature = "time-timg0")] +pub use self::timg::*; + +#[cfg(any(feature = "time-systimer-16mhz", feature = "time-systimer-80mhz"))] +mod systimer; +#[cfg(feature = "time-timg0")] +mod timg; diff --git a/esp-hal/src/embassy/time_driver_systimer.rs b/esp-hal-embassy/src/time_driver/systimer.rs similarity index 60% rename from esp-hal/src/embassy/time_driver_systimer.rs rename to esp-hal-embassy/src/time_driver/systimer.rs index f53dc819a0c..b62fd53d672 100644 --- a/esp-hal/src/embassy/time_driver_systimer.rs +++ b/esp-hal-embassy/src/time_driver/systimer.rs @@ -1,35 +1,35 @@ use critical_section::{CriticalSection, Mutex}; -use procmacros::handler; - -use super::AlarmState; -use crate::{ +use embassy_time_driver::AlarmHandle; +use esp_hal::{ clock::Clocks, - peripherals, + interrupt, + peripherals::Interrupt, prelude::*, - timer::{ - systimer::{Alarm, SystemTimer, Target}, - Timer as _, - }, + timer::systimer::{Alarm, SystemTimer, Target}, + Async, }; +use crate::AlarmState; + pub const ALARM_COUNT: usize = 3; -pub type TimerType = SystemTimer<'static, crate::Async>; +pub type TimerType = SystemTimer<'static, Async>; pub struct EmbassyTimer { pub(crate) alarms: Mutex<[AlarmState; ALARM_COUNT]>, - pub(crate) alarm0: Alarm, - pub(crate) alarm1: Alarm, - pub(crate) alarm2: Alarm, + pub(crate) alarm0: Alarm, + pub(crate) alarm1: Alarm, + pub(crate) alarm2: Alarm, } +#[allow(clippy::declare_interior_mutable_const)] const ALARM_STATE_NONE: AlarmState = AlarmState::new(); embassy_time_driver::time_driver_impl!(static DRIVER: EmbassyTimer = EmbassyTimer { alarms: Mutex::new([ALARM_STATE_NONE; ALARM_COUNT]), - alarm0: unsafe { Alarm::<_, crate::Async, 0>::conjure() }, - alarm1: unsafe { Alarm::<_, crate::Async, 1>::conjure() }, - alarm2: unsafe { Alarm::<_, crate::Async, 2>::conjure() }, + alarm0: unsafe { Alarm::<_, Async, 0>::conjure() }, + alarm1: unsafe { Alarm::<_, Async, 1>::conjure() }, + alarm2: unsafe { Alarm::<_, Async, 2>::conjure() }, }); impl EmbassyTimer { @@ -45,7 +45,7 @@ impl EmbassyTimer { } } - pub(super) fn on_alarm_allocated(&self, n: usize) { + pub(crate) fn on_alarm_allocated(&self, n: usize) { match n { 0 => self.alarm0.enable_interrupt(true), 1 => self.alarm1.enable_interrupt(true), @@ -63,30 +63,21 @@ impl EmbassyTimer { pub fn init(_clocks: &Clocks, _systimer: TimerType) { unsafe { - crate::interrupt::bind_interrupt( - peripherals::Interrupt::SYSTIMER_TARGET0, - target0_handler.handler(), - ); - unwrap!(crate::interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET0, + interrupt::bind_interrupt(Interrupt::SYSTIMER_TARGET0, target0_handler.handler()); + unwrap!(interrupt::enable( + Interrupt::SYSTIMER_TARGET0, target0_handler.priority() )); - crate::interrupt::bind_interrupt( - peripherals::Interrupt::SYSTIMER_TARGET1, - target1_handler.handler(), - ); - unwrap!(crate::interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET1, + interrupt::bind_interrupt(Interrupt::SYSTIMER_TARGET1, target1_handler.handler()); + unwrap!(interrupt::enable( + Interrupt::SYSTIMER_TARGET1, target1_handler.priority() )); - crate::interrupt::bind_interrupt( - peripherals::Interrupt::SYSTIMER_TARGET2, - target2_handler.handler(), - ); - unwrap!(crate::interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET2, + interrupt::bind_interrupt(Interrupt::SYSTIMER_TARGET2, target2_handler.handler()); + unwrap!(interrupt::enable( + Interrupt::SYSTIMER_TARGET2, target2_handler.priority() )); } @@ -107,11 +98,7 @@ impl EmbassyTimer { } } - pub(crate) fn set_alarm( - &self, - alarm: embassy_time_driver::AlarmHandle, - timestamp: u64, - ) -> bool { + pub(crate) fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool { critical_section::with(|_cs| { let n = alarm.id() as usize; @@ -139,9 +126,9 @@ impl EmbassyTimer { fn arm(&self, id: usize, timestamp: u64) { match id { - 0 => self.alarm0.load_value(timestamp.micros()).unwrap(), - 1 => self.alarm1.load_value(timestamp.micros()).unwrap(), - 2 => self.alarm2.load_value(timestamp.micros()).unwrap(), + 0 => self.alarm0.set_target(timestamp), + 1 => self.alarm1.set_target(timestamp), + 2 => self.alarm2.set_target(timestamp), _ => {} } } diff --git a/esp-hal/src/embassy/time_driver_timg.rs b/esp-hal-embassy/src/time_driver/timg.rs similarity index 69% rename from esp-hal/src/embassy/time_driver_timg.rs rename to esp-hal-embassy/src/time_driver/timg.rs index 3e5f8a6c104..a046fba03a5 100644 --- a/esp-hal/src/embassy/time_driver_timg.rs +++ b/esp-hal-embassy/src/time_driver/timg.rs @@ -1,27 +1,30 @@ use critical_section::{CriticalSection, Mutex}; -use peripherals::TIMG0; - -use super::AlarmState; +use embassy_time_driver::AlarmHandle; #[cfg(any(esp32, esp32s2, esp32s3))] -use crate::timer::timg::Timer1; -use crate::{ +use esp_hal::timer::timg::Timer1; +use esp_hal::{ clock::Clocks, - peripherals, + interrupt::{self, Priority}, + peripherals::{Interrupt, TIMG0}, prelude::*, timer::timg::{Instance, Timer0, TimerGroup}, + Async, }; +use crate::AlarmState; + #[cfg(not(any(esp32, esp32s2, esp32s3)))] pub const ALARM_COUNT: usize = 1; #[cfg(any(esp32, esp32s2, esp32s3))] pub const ALARM_COUNT: usize = 2; -pub type TimerType = TimerGroup<'static, TIMG0, crate::Async>; +pub type TimerType = TimerGroup<'static, TIMG0, Async>; pub struct EmbassyTimer { pub(crate) alarms: Mutex<[AlarmState; ALARM_COUNT]>, } +#[allow(clippy::declare_interior_mutable_const)] const ALARM_STATE_NONE: AlarmState = AlarmState::new(); embassy_time_driver::time_driver_impl!(static DRIVER: EmbassyTimer = EmbassyTimer { @@ -41,7 +44,7 @@ impl EmbassyTimer { } } - pub(super) fn on_alarm_allocated(&self, _n: usize) {} + pub(crate) fn on_alarm_allocated(&self, _n: usize) {} fn on_interrupt(&self, id: u8, timer: Timer) { critical_section::with(|cs| { @@ -62,48 +65,36 @@ impl EmbassyTimer { } unsafe { - crate::interrupt::bind_interrupt( - crate::peripherals::Interrupt::TG0_T0_LEVEL, - tg0_t0_level.handler(), - ); - crate::interrupt::enable( - crate::peripherals::Interrupt::TG0_T0_LEVEL, - tg0_t0_level.priority(), - ) - .unwrap(); + interrupt::bind_interrupt(Interrupt::TG0_T0_LEVEL, tg0_t0_level.handler()); + unwrap!(interrupt::enable( + Interrupt::TG0_T0_LEVEL, + tg0_t0_level.priority() + )); } #[cfg(any(esp32, esp32s2, esp32s3))] unsafe { - crate::interrupt::bind_interrupt( - crate::peripherals::Interrupt::TG0_T1_LEVEL, - tg0_t1_level.handler(), - ); - crate::interrupt::enable( - crate::peripherals::Interrupt::TG0_T1_LEVEL, - tg0_t1_level.priority(), - ) - .unwrap(); + interrupt::bind_interrupt(Interrupt::TG0_T1_LEVEL, tg0_t1_level.handler()); + unwrap!(interrupt::enable( + Interrupt::TG0_T1_LEVEL, + tg0_t1_level.priority() + )); } - #[handler(priority = crate::interrupt::Priority::max())] + #[handler(priority = Priority::max())] fn tg0_t0_level() { let timer = unsafe { Timer0::::steal() }; DRIVER.on_interrupt(0, timer); } #[cfg(any(esp32, esp32s2, esp32s3))] - #[handler(priority = crate::interrupt::Priority::max())] + #[handler(priority = Priority::max())] fn tg0_t1_level() { let timer = unsafe { Timer1::::steal() }; DRIVER.on_interrupt(1, timer); } } - pub(crate) fn set_alarm( - &self, - _alarm: embassy_time_driver::AlarmHandle, - timestamp: u64, - ) -> bool { + pub(crate) fn set_alarm(&self, _alarm: AlarmHandle, timestamp: u64) -> bool { critical_section::with(|_cs| { // The hardware fires the alarm even if timestamp is lower than the current // time. In this case the interrupt handler will pend a wakeup when we exit the @@ -122,7 +113,10 @@ impl EmbassyTimer { true } - fn arm(tg: &mut Timer, timestamp: u64) { + fn arm(tg: &mut T, timestamp: u64) + where + T: Instance, + { tg.load_alarm_value(timestamp); tg.listen(); tg.set_counter_decrementing(false); diff --git a/esp-hal-procmacros/src/embassy.rs b/esp-hal-procmacros/src/embassy.rs index c6797ed71bd..34c9dcc53e6 100644 --- a/esp-hal-procmacros/src/embassy.rs +++ b/esp-hal-procmacros/src/embassy.rs @@ -22,8 +22,7 @@ pub(crate) mod main { use std::{cell::RefCell, fmt::Display, thread}; use darling::{export::NestedMeta, FromMeta}; - use proc_macro2::{Ident, Span, TokenStream}; - use proc_macro_crate::{crate_name, FoundCrate}; + use proc_macro2::TokenStream; use quote::{quote, ToTokens}; use syn::{ReturnType, Type}; @@ -157,23 +156,10 @@ pub(crate) mod main { } pub fn main() -> TokenStream { - let hal_crate = if cfg!(any(feature = "is-lp-core", feature = "is-ulp-core")) { - crate_name("esp-lp-hal") - } else { - crate_name("esp-hal") - }; - - let executor = if let Ok(FoundCrate::Name(ref name)) = hal_crate { - let ident = Ident::new(&name, Span::call_site().into()); - quote!( #ident::embassy::executor::Executor ) - } else { - quote!(crate::embassy::executor::Executor) - }; - quote! { #[entry] fn main() -> ! { - let mut executor = #executor::new(); + let mut executor = ::esp_hal_embassy::Executor::new(); let executor = unsafe { __make_static(&mut executor) }; executor.run(|spawner| { spawner.must_spawn(__embassy_main(spawner)); diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 236febfdd84..e5111917781 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed the `SystemExt` trait (#1495) - Removed the `GpioExt` trait (#1496) +- Embassy support (and all related features) has been removed, now available in the `esp-hal-embassy` package instead (#1595) ## [0.17.0] - 2024-04-18 diff --git a/esp-hal/Cargo.toml b/esp-hal/Cargo.toml index a597a42cddc..91a8d9ab4d5 100644 --- a/esp-hal/Cargo.toml +++ b/esp-hal/Cargo.toml @@ -22,10 +22,8 @@ critical-section = "1.1.2" defmt = { version = "0.3.6", optional = true } delegate = "0.12.0" document-features = "0.2.8" -embassy-executor = { version = "0.5.0", optional = true } embassy-futures = { version = "0.1.1", optional = true } embassy-sync = { version = "0.5.0", optional = true } -embassy-time-driver = { version = "0.1.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 } @@ -43,7 +41,7 @@ log = { version = "0.4.21", optional = true } nb = "1.1.0" paste = "1.0.14" portable-atomic = { version = "1.6.0", default-features = false } -procmacros = { version = "0.10.0", features = ["enum-dispatch", "interrupt", "ram"], package = "esp-hal-procmacros", path = "../esp-hal-procmacros" } +procmacros = { version = "0.10.0", features = ["embassy", "enum-dispatch", "interrupt", "ram"], package = "esp-hal-procmacros", path = "../esp-hal-procmacros" } riscv = { version = "0.11.1", optional = true } strum = { version = "0.26.2", default-features = false, features = ["derive"] } void = { version = "1.0.2", default-features = false } @@ -145,7 +143,6 @@ async = [ ## Implement `defmt::Format` on certain types. defmt = [ "dep:defmt", - "embassy-executor?/defmt", "embassy-futures?/defmt", "embassy-sync?/defmt", "embedded-hal?/defmt-03", @@ -169,25 +166,6 @@ embedded-io = ["dep:embedded-io"] ## Implement the `ufmt_write::uWrite` trait for certain peripherals. ufmt = ["dep:ufmt-write"] -#! ### Embassy Feature Flags -## Enable support for `embassy`, a modern asynchronous embedded framework. -embassy = ["embassy-time-driver", "procmacros/embassy", "embassy-executor"] -## Uses hardware timers as alarms for the executors. Using this feature -## limits the number of executors to the number of hardware alarms provided -## by the time driver. -embassy-integrated-timers = ["embassy-executor?/integrated-timers"] -## Enable the embassy time driver using the `SYSTIMER` peripheral. The -## `SYSTIMER` peripheral has three alarams available for use. Do **not** -## use when targeting an `esp32s2`. -embassy-time-systick-16mhz = ["embassy-time-driver/tick-hz-16_000_000"] -## Enable the embassy time driver using the `SYSTIMER` peripheral. The -## `SYSTIMER` peripheral has three alarams available for use. Must only -## be used when targeting an `esp32s2`. -embassy-time-systick-80mhz = ["embassy-time-driver/tick-hz-80_000_000"] -## Enable the embassy time driver using the `TIMG0` peripheral. The `TIMG0` -## peripheral has two alarms available for use. -embassy-time-timg0 = ["embassy-time-driver/tick-hz-1_000_000"] - #! ### PSRAM Feature Flags ## Use externally connected PSRAM (2MB). psram-2m = [] @@ -209,15 +187,7 @@ opsram-8m = [] opsram-16m = [] # This feature is intended for testing; you probably don't want to enable it: -ci = [ - "default", - "embedded-hal-02", - "ufmt", - "async", - "embassy", - "embassy-time-timg0", - "embedded-io" -] +ci = ["async", "embedded-hal-02", "embedded-io", "ufmt"] [lints.clippy] mixed_attributes_style = "allow" diff --git a/esp-hal/build.rs b/esp-hal/build.rs index b1ff0e215cb..2ed457c8782 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -26,19 +26,6 @@ fn main() -> Result<(), Box> { "esp32", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32s2", "esp32s3" ); - // If the `embassy` feature is enabled, ensure that a time driver implementation - // is available: - #[cfg(feature = "embassy")] - cfg_if::cfg_if! { - if #[cfg(feature = "esp32")] { - assert_unique_used_features!("embassy-time-timg0"); - } else if #[cfg(feature = "esp32s2")] { - assert_unique_used_features!("embassy-time-systick-80mhz", "embassy-time-timg0"); - } else { - assert_unique_used_features!("embassy-time-systick-16mhz", "embassy-time-timg0"); - } - } - #[cfg(all( feature = "flip-link", not(any(feature = "esp32c6", feature = "esp32h2")) diff --git a/esp-hal/src/embassy/mod.rs b/esp-hal/src/embassy/mod.rs deleted file mode 100644 index b8c481bdc45..00000000000 --- a/esp-hal/src/embassy/mod.rs +++ /dev/null @@ -1,107 +0,0 @@ -//! # Embassy -//! -//! The [embassy](https://github.com/embassy-rs/embassy) project is a toolkit to leverage async Rust -//! in embedded applications. This module adds the required -//! support to use embassy on Espressif chips. -//! -//! ## Initialization -//! -//! Embassy **must** be initialized by calling [`init`], before beginning any -//! async operations. -//! -//! [`init`] installs a [global time driver](https://github.com/embassy-rs/embassy/tree/main/embassy-time#global-time-driver) -//! allowing users to use [embassy-time](https://docs.rs/embassy-time/latest/embassy_time/) APIs in any async context -//! within their application. A time driver must be chosen by enabling the -//! correct feature on esp-hal, see the crate level documentation for more -//! details. -//! -//! ## Executors -//! -//! We offer two executor types, a thread mode [`Executor`](executor::Executor) -//! and [`InterruptExecutor`](executor::InterruptExecutor). -//! An [`InterruptExecutor`](executor::InterruptExecutor) can be used to achieve -//! preemptive multitasking in async applications, which is usually something reserved for more traditional RTOS systems, read more about it in [the embassy documentation](https://embassy.dev/book/dev/runtime.html). - -pub mod executor; - -use core::cell::Cell; - -use embassy_time_driver::{AlarmHandle, Driver}; - -#[cfg_attr( - all( - systimer, - any( - feature = "embassy-time-systick-16mhz", - feature = "embassy-time-systick-80mhz" - ) - ), - path = "time_driver_systimer.rs" -)] -#[cfg_attr( - all(timg0, feature = "embassy-time-timg0"), - path = "time_driver_timg.rs" -)] -mod time_driver; - -use time_driver::EmbassyTimer; - -use crate::clock::Clocks; - -/// Initialize embassy -pub fn init(clocks: &Clocks, time_driver: time_driver::TimerType) { - EmbassyTimer::init(clocks, time_driver) -} - -pub(crate) struct AlarmState { - pub callback: Cell>, - pub allocated: Cell, -} - -unsafe impl Send for AlarmState {} - -impl AlarmState { - pub const fn new() -> Self { - Self { - callback: Cell::new(None), - allocated: Cell::new(false), - } - } -} - -impl Driver for EmbassyTimer { - fn now(&self) -> u64 { - EmbassyTimer::now() - } - - unsafe fn allocate_alarm(&self) -> Option { - critical_section::with(|cs| { - for (i, alarm) in self.alarms.borrow(cs).iter().enumerate() { - if !alarm.allocated.get() { - // set alarm so it is not overwritten - alarm.allocated.set(true); - self.on_alarm_allocated(i); - return Some(AlarmHandle::new(i as u8)); - } - } - None - }) - } - - fn set_alarm_callback( - &self, - alarm: embassy_time_driver::AlarmHandle, - callback: fn(*mut ()), - ctx: *mut (), - ) { - let n = alarm.id() as usize; - critical_section::with(|cs| { - let alarm = &self.alarms.borrow(cs)[n]; - alarm.callback.set(Some((callback, ctx))); - }) - } - - fn set_alarm(&self, alarm: embassy_time_driver::AlarmHandle, timestamp: u64) -> bool { - self.set_alarm(alarm, timestamp) - } -} diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index eaca683c5dd..82a7f2ee715 100644 --- a/esp-hal/src/lib.rs +++ b/esp-hal/src/lib.rs @@ -104,8 +104,6 @@ pub mod delay; pub mod dma; #[cfg(ecc)] pub mod ecc; -#[cfg(feature = "embassy")] -pub mod embassy; #[cfg(soc_etm)] pub mod etm; #[cfg(gpio)] diff --git a/esp-hal/src/timer/systimer.rs b/esp-hal/src/timer/systimer.rs index 252dc6b6b34..785748dbefe 100644 --- a/esp-hal/src/timer/systimer.rs +++ b/esp-hal/src/timer/systimer.rs @@ -227,7 +227,7 @@ where DM: Mode, { /// Set the target value of this [Alarm] - pub fn set_target(&mut self, timestamp: u64) { + pub fn set_target(&self, timestamp: u64) { self.configure(|tconf, target| unsafe { tconf.write(|w| w.period_mode().clear_bit()); // target mode target.hi().write(|w| w.hi().bits((timestamp >> 32) as u32)); @@ -238,7 +238,7 @@ where } /// Block waiting until the timer reaches the `timestamp` - pub fn wait_until(&mut self, timestamp: u64) { + pub fn wait_until(&self, timestamp: u64) { self.clear_interrupt(); self.set_target(timestamp); @@ -261,7 +261,7 @@ where DM: Mode, { /// Set the period of this [Alarm] - pub fn set_period(&mut self, period: MicrosDurationU32) { + pub fn set_period(&self, period: MicrosDurationU32) { let us = period.ticks(); let ticks = us * (SystemTimer::TICKS_PER_SECOND / 1_000_000) as u32; diff --git a/esp-hal/src/timer/timg.rs b/esp-hal/src/timer/timg.rs index f1805260055..53e2d76f5a4 100644 --- a/esp-hal/src/timer/timg.rs +++ b/esp-hal/src/timer/timg.rs @@ -611,8 +611,14 @@ impl TimerX where TG: TimerGroupInstance, { + /// Unsafely create an instance of this peripheral out of thin air. + /// + /// # Safety + /// + /// You must ensure that you're only using one instance of this type at a + /// time. #[allow(unused)] - pub(crate) unsafe fn steal() -> Self { + pub unsafe fn steal() -> Self { Self { phantom: PhantomData, } diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index ae96e3ac840..76a6f969f40 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -13,6 +13,7 @@ categories = ["embedded", "hardware-support", "no-std"] [dependencies] defmt = { version = "0.3.6", optional = true } esp-hal = { version = "0.17.0", path = "../esp-hal", default-features = false } +esp-hal-embassy = { version = "0.1.0", path = "../esp-hal-embassy", optional = true } smoltcp = { version = "0.11.0", default-features = false, features = [ "medium-ethernet", "socket-raw", @@ -61,30 +62,37 @@ default = ["log"] # chip features esp32c2 = [ "esp-hal/esp32c2", + "esp-hal-embassy?/esp32c2", "esp-wifi-sys/esp32c2", ] esp32c3 = [ "esp-hal/esp32c3", + "esp-hal-embassy?/esp32c3", "esp-wifi-sys/esp32c3", ] esp32c6 = [ "esp-hal/esp32c6", + "esp-hal-embassy?/esp32c6", "esp-wifi-sys/esp32c6", ] esp32h2 = [ "esp-hal/esp32h2", + "esp-hal-embassy?/esp32h2", "esp-wifi-sys/esp32h2", ] esp32 = [ "esp-hal/esp32", + "esp-hal-embassy?/esp32", "esp-wifi-sys/esp32", ] esp32s2 = [ "esp-hal/esp32s2", + "esp-hal-embassy?/esp32s2", "esp-wifi-sys/esp32s2", ] esp32s3 = [ "esp-hal/esp32s3", + "esp-hal-embassy?/esp32s3", "esp-wifi-sys/esp32s3", ] @@ -93,6 +101,8 @@ async = [ "dep:embassy-sync", "dep:embassy-futures", "dep:embedded-io-async", + "dep:esp-hal-embassy", + "esp-hal/async", ] embassy-net = ["dep:embassy-net-driver", "async"] @@ -131,7 +141,7 @@ features = [ "coex", "async", "embassy-net", - "esp-hal/embassy-time-timg0", + "esp-hal-embassy/time-timg0", "esp-hal/default", ] default-target = "riscv32imc-unknown-none-elf" diff --git a/esp-wifi/src/timer/riscv.rs b/esp-wifi/src/timer/riscv.rs index 68e91758cc5..18cf8daaec3 100644 --- a/esp-wifi/src/timer/riscv.rs +++ b/esp-wifi/src/timer/riscv.rs @@ -30,7 +30,7 @@ pub fn setup_timer(systimer: TimeBase) -> Result<(), esp_hal::timer::Error> { // make sure the scheduling won't start before everything is setup riscv::interrupt::disable(); - let mut alarm0 = systimer.into_periodic(); + let alarm0 = systimer.into_periodic(); alarm0.set_period(TIMESLICE_FREQUENCY.into_duration()); alarm0.clear_interrupt(); alarm0.enable_interrupt(true); @@ -83,8 +83,8 @@ extern "C" fn FROM_CPU_INTR3(trap_frame: &mut TrapFrame) { } critical_section::with(|cs| { - let mut alarm0 = ALARM0.borrow_ref_mut(cs); - let alarm0 = unwrap!(alarm0.as_mut()); + let alarm0 = ALARM0.borrow_ref(cs); + let alarm0 = unwrap!(alarm0.as_ref()); alarm0.set_period(TIMESLICE_FREQUENCY.into_duration()); alarm0.clear_interrupt(); diff --git a/examples/.cargo/config.toml b/examples/.cargo/config.toml index 9c8a7188a96..6c23d617168 100644 --- a/examples/.cargo/config.toml +++ b/examples/.cargo/config.toml @@ -28,6 +28,11 @@ rustflags = [ [env] ESP_LOGLEVEL = "info" +SSID = "SSID" +PASSWORD = "PASSWORD" +STATIC_IP = "1.1.1.1 " +GATEWAY_IP = "1.1.1.1" +HOST_IP = "1.1.1.1" [unstable] build-std = ["alloc", "core"] diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 258cab7a64e..f4d85a54a97 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -31,6 +31,7 @@ embedded-storage = "0.3.0" esp-alloc = { path = "../esp-alloc" } esp-backtrace = { path = "../esp-backtrace", features = ["exception-handler", "panic-handler", "println"] } esp-hal = { path = "../esp-hal", features = ["log"] } +esp-hal-embassy = { path = "../esp-hal-embassy", optional = true } esp-hal-smartled = { path = "../esp-hal-smartled", optional = true } esp-ieee802154 = { path = "../esp-ieee802154", optional = true } esp-println = { path = "../esp-println", features = ["log"] } @@ -56,13 +57,13 @@ usb-device = "0.3.2" usbd-serial = "0.2.1" [features] -esp32 = ["esp-hal/esp32", "esp-backtrace/esp32", "esp-println/esp32", "esp-hal-smartled/esp32", "esp-wifi?/esp32", "esp-storage?/esp32"] -esp32c2 = ["esp-hal/esp32c2", "esp-backtrace/esp32c2", "esp-println/esp32c2", "esp-wifi?/esp32c2", "esp-storage?/esp32c2"] -esp32c3 = ["esp-hal/esp32c3", "esp-backtrace/esp32c3", "esp-println/esp32c3", "esp-hal-smartled/esp32c3", "esp-wifi?/esp32c3", "esp-storage?/esp32c3"] -esp32c6 = ["esp-hal/esp32c6", "esp-backtrace/esp32c6", "esp-println/esp32c6", "esp-hal-smartled/esp32c6", "esp-ieee802154/esp32c6", "esp-wifi?/esp32c6", "esp-storage?/esp32c6"] -esp32h2 = ["esp-hal/esp32h2", "esp-backtrace/esp32h2", "esp-println/esp32h2", "esp-hal-smartled/esp32h2", "esp-ieee802154/esp32h2", "esp-wifi?/esp32h2", "esp-storage?/esp32h2"] -esp32s2 = ["esp-hal/esp32s2", "esp-backtrace/esp32s2", "esp-println/esp32s2", "esp-hal-smartled/esp32s2", "esp-wifi?/esp32s2", "esp-storage?/esp32s2"] -esp32s3 = ["esp-hal/esp32s3", "esp-backtrace/esp32s3", "esp-println/esp32s3", "esp-hal-smartled/esp32s3", "esp-wifi?/esp32s3", "esp-storage?/esp32s3"] +esp32 = ["esp-hal/esp32", "esp-backtrace/esp32", "esp-hal-embassy?/esp32", "esp-println/esp32", "esp-storage?/esp32", "esp-wifi?/esp32", "esp-hal-smartled/esp32"] +esp32c2 = ["esp-hal/esp32c2", "esp-backtrace/esp32c2", "esp-hal-embassy?/esp32c2", "esp-println/esp32c2", "esp-storage?/esp32c2", "esp-wifi?/esp32c2", ] +esp32c3 = ["esp-hal/esp32c3", "esp-backtrace/esp32c3", "esp-hal-embassy?/esp32c3", "esp-println/esp32c3", "esp-storage?/esp32c3", "esp-wifi?/esp32c3", "esp-hal-smartled/esp32c3"] +esp32c6 = ["esp-hal/esp32c6", "esp-backtrace/esp32c6", "esp-hal-embassy?/esp32c6", "esp-println/esp32c6", "esp-storage?/esp32c6", "esp-wifi?/esp32c6", "esp-hal-smartled/esp32c6", "esp-ieee802154/esp32c6"] +esp32h2 = ["esp-hal/esp32h2", "esp-backtrace/esp32h2", "esp-hal-embassy?/esp32h2", "esp-println/esp32h2", "esp-storage?/esp32h2", "esp-wifi?/esp32h2", "esp-hal-smartled/esp32h2", "esp-ieee802154/esp32h2"] +esp32s2 = ["esp-hal/esp32s2", "esp-backtrace/esp32s2", "esp-hal-embassy?/esp32s2", "esp-println/esp32s2", "esp-storage?/esp32s2", "esp-wifi?/esp32s2", "esp-hal-smartled/esp32s2"] +esp32s3 = ["esp-hal/esp32s3", "esp-backtrace/esp32s3", "esp-hal-embassy?/esp32s3", "esp-println/esp32s3", "esp-storage?/esp32s3", "esp-wifi?/esp32s3", "esp-hal-smartled/esp32s3"] esp-wifi = ["dep:esp-wifi"] @@ -71,10 +72,10 @@ async = ["esp-hal/async", "embassy-usb"] embedded-hal-02 = ["esp-hal/embedded-hal-02"] embedded-hal = ["esp-hal/embedded-hal"] -embassy = ["esp-hal/embassy"] +embassy = ["dep:esp-hal-embassy"] -embassy-time-systick-16mhz = ["esp-hal/embassy-time-systick-16mhz"] -embassy-time-timg0 = ["esp-hal/embassy-time-timg0"] +embassy-time-systimer-16mhz = ["esp-hal-embassy/time-systimer-16mhz"] +embassy-time-timg0 = ["esp-hal-embassy/time-timg0"] embassy-generic-timers = ["embassy-time/generic-queue-8"] opsram-2m = ["esp-hal/opsram-2m"] diff --git a/examples/src/bin/embassy_hello_world.rs b/examples/src/bin/embassy_hello_world.rs index 55eb879fcc0..7065e8d823f 100644 --- a/examples/src/bin/embassy_hello_world.rs +++ b/examples/src/bin/embassy_hello_world.rs @@ -14,7 +14,6 @@ use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy::{self}, peripherals::Peripherals, prelude::*, system::SystemControl, @@ -37,7 +36,7 @@ async fn main(spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); spawner.spawn(run()).ok(); diff --git a/examples/src/bin/embassy_i2c.rs b/examples/src/bin/embassy_i2c.rs index 8c57d8d2af0..679be82fc38 100644 --- a/examples/src/bin/embassy_i2c.rs +++ b/examples/src/bin/embassy_i2c.rs @@ -21,7 +21,6 @@ use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy::{self}, gpio::Io, i2c::I2C, peripherals::Peripherals, @@ -38,7 +37,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs b/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs index 4d8e8b06438..3efb2192b65 100644 --- a/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs +++ b/examples/src/bin/embassy_i2c_bmp180_calibration_data.rs @@ -22,7 +22,6 @@ use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy::{self}, gpio::Io, i2c::I2C, peripherals::Peripherals, @@ -38,7 +37,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_i2s_read.rs b/examples/src/bin/embassy_i2s_read.rs index dba429a5966..00257731a6b 100644 --- a/examples/src/bin/embassy_i2s_read.rs +++ b/examples/src/bin/embassy_i2s_read.rs @@ -23,7 +23,6 @@ use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, - embassy, gpio::Io, i2s::{asynch::*, DataFormat, I2s, Standard}, peripherals::Peripherals, @@ -41,7 +40,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_i2s_sound.rs b/examples/src/bin/embassy_i2s_sound.rs index 32bdc14404e..7d1cf0b0a1f 100644 --- a/examples/src/bin/embassy_i2s_sound.rs +++ b/examples/src/bin/embassy_i2s_sound.rs @@ -38,7 +38,6 @@ use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, - embassy::{self}, gpio::Io, i2s::{asynch::*, DataFormat, I2s, Standard}, peripherals::Peripherals, @@ -64,7 +63,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_multicore.rs b/examples/src/bin/embassy_multicore.rs index a0519ad96a5..47f14dfba5d 100644 --- a/examples/src/bin/embassy_multicore.rs +++ b/examples/src/bin/embassy_multicore.rs @@ -18,7 +18,6 @@ use esp_backtrace as _; use esp_hal::{ clock::ClockControl, cpu_control::{CpuControl, Stack}, - embassy::{self, executor::Executor}, get_core, gpio::{AnyOutput, Io, Level}, peripherals::Peripherals, @@ -26,6 +25,7 @@ use esp_hal::{ system::SystemControl, timer::timg::TimerGroup, }; +use esp_hal_embassy::Executor; use esp_println::println; use static_cell::StaticCell; @@ -59,7 +59,7 @@ async fn main(_spawner: Spawner) { let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL); diff --git a/examples/src/bin/embassy_multicore_interrupt.rs b/examples/src/bin/embassy_multicore_interrupt.rs index 2d610fffafa..fb2bf4c8ebc 100644 --- a/examples/src/bin/embassy_multicore_interrupt.rs +++ b/examples/src/bin/embassy_multicore_interrupt.rs @@ -17,7 +17,6 @@ use esp_backtrace as _; use esp_hal::{ clock::ClockControl, cpu_control::{CpuControl, Stack}, - embassy::{self, executor::InterruptExecutor}, get_core, gpio::{AnyOutput, Io, Level}, interrupt::Priority, @@ -26,6 +25,7 @@ use esp_hal::{ system::SystemControl, timer::timg::TimerGroup, }; +use esp_hal_embassy::InterruptExecutor; use esp_println::println; use static_cell::StaticCell; @@ -78,7 +78,7 @@ fn main() -> ! { let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL); diff --git a/examples/src/bin/embassy_multiprio.rs b/examples/src/bin/embassy_multiprio.rs index 4a775a429b3..d4469b7284b 100644 --- a/examples/src/bin/embassy_multiprio.rs +++ b/examples/src/bin/embassy_multiprio.rs @@ -25,13 +25,13 @@ use embassy_time::{Duration, Instant, Ticker, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy::{self, executor::InterruptExecutor}, interrupt::Priority, peripherals::Peripherals, prelude::*, system::SystemControl, timer::timg::TimerGroup, }; +use esp_hal_embassy::InterruptExecutor; use esp_println::println; use static_cell::StaticCell; @@ -79,7 +79,7 @@ async fn main(low_prio_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); static EXECUTOR: StaticCell> = StaticCell::new(); let executor = InterruptExecutor::new(system.software_interrupt_control.software_interrupt2); diff --git a/examples/src/bin/embassy_parl_io_rx.rs b/examples/src/bin/embassy_parl_io_rx.rs index daf23b4d5f2..f51a7c9a624 100644 --- a/examples/src/bin/embassy_parl_io_rx.rs +++ b/examples/src/bin/embassy_parl_io_rx.rs @@ -16,7 +16,6 @@ use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, - embassy, gpio::Io, parl_io::{no_clk_pin, BitPackOrder, ParlIoRxOnly, RxFourBits}, peripherals::Peripherals, @@ -34,7 +33,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_parl_io_tx.rs b/examples/src/bin/embassy_parl_io_tx.rs index 8a342c2d723..941cc7f3762 100644 --- a/examples/src/bin/embassy_parl_io_tx.rs +++ b/examples/src/bin/embassy_parl_io_tx.rs @@ -20,7 +20,6 @@ use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, - embassy, gpio::Io, parl_io::{ BitPackOrder, @@ -45,7 +44,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_rmt_rx.rs b/examples/src/bin/embassy_rmt_rx.rs index 356db94c430..d3039dc92c1 100644 --- a/examples/src/bin/embassy_rmt_rx.rs +++ b/examples/src/bin/embassy_rmt_rx.rs @@ -12,7 +12,6 @@ use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy::{self}, gpio::{Gpio5, Io, Level, Output}, peripherals::Peripherals, prelude::*, @@ -45,7 +44,7 @@ async fn main(spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timer_group0 = esp_hal::timer::timg::TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + esp_hal_embassy::init(&clocks, timer_group0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_rmt_tx.rs b/examples/src/bin/embassy_rmt_tx.rs index 9c254ab4007..81c88bf98bd 100644 --- a/examples/src/bin/embassy_rmt_tx.rs +++ b/examples/src/bin/embassy_rmt_tx.rs @@ -13,7 +13,6 @@ use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, gpio::Io, peripherals::Peripherals, prelude::*, @@ -31,7 +30,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_serial.rs b/examples/src/bin/embassy_serial.rs index e0ddb9a9aa4..7ce64ac11b3 100644 --- a/examples/src/bin/embassy_serial.rs +++ b/examples/src/bin/embassy_serial.rs @@ -14,7 +14,6 @@ use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, peripherals::{Peripherals, UART0}, prelude::*, system::SystemControl, @@ -81,7 +80,7 @@ async fn main(spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let mut uart0 = Uart::new_async(peripherals.UART0, &clocks); uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None)); diff --git a/examples/src/bin/embassy_spi.rs b/examples/src/bin/embassy_spi.rs index fec1f878fca..794b5000898 100644 --- a/examples/src/bin/embassy_spi.rs +++ b/examples/src/bin/embassy_spi.rs @@ -27,7 +27,6 @@ use esp_hal::{ clock::ClockControl, dma::*, dma_descriptors, - embassy::{self}, gpio::Io, peripherals::Peripherals, prelude::*, @@ -47,7 +46,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let sclk = io.pins.gpio0; diff --git a/examples/src/bin/embassy_twai.rs b/examples/src/bin/embassy_twai.rs index 9247ffc2721..2f45b8376d3 100644 --- a/examples/src/bin/embassy_twai.rs +++ b/examples/src/bin/embassy_twai.rs @@ -22,7 +22,6 @@ use embedded_can::{Frame, Id}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy::{self}, gpio::Io, interrupt, peripherals::{self, Peripherals, TWAI0}, @@ -87,7 +86,7 @@ async fn main(spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/examples/src/bin/embassy_usb_serial.rs b/examples/src/bin/embassy_usb_serial.rs index e6ca68facd1..26d10b185e2 100644 --- a/examples/src/bin/embassy_usb_serial.rs +++ b/examples/src/bin/embassy_usb_serial.rs @@ -18,7 +18,6 @@ use embassy_usb::{ use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, gpio::Io, otg_fs::{ asynch::{Config, Driver}, @@ -37,7 +36,7 @@ async fn main(_spawner: Spawner) -> () { let system = SystemControl::new(peripherals.SYSTEM); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - embassy::init(&clocks, TimerGroup::new_async(peripherals.TIMG0, &clocks)); + esp_hal_embassy::init(&clocks, TimerGroup::new_async(peripherals.TIMG0, &clocks)); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let usb = Usb::new(peripherals.USB0, io.pins.gpio19, io.pins.gpio20); diff --git a/examples/src/bin/embassy_usb_serial_jtag.rs b/examples/src/bin/embassy_usb_serial_jtag.rs index 8eb6d2c5f3b..46e5bb7117a 100644 --- a/examples/src/bin/embassy_usb_serial_jtag.rs +++ b/examples/src/bin/embassy_usb_serial_jtag.rs @@ -13,7 +13,6 @@ use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, peripherals::Peripherals, prelude::*, system::SystemControl, @@ -71,7 +70,7 @@ async fn main(spawner: Spawner) -> () { let system = SystemControl::new(peripherals.SYSTEM); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - embassy::init(&clocks, TimerGroup::new_async(peripherals.TIMG0, &clocks)); + esp_hal_embassy::init(&clocks, TimerGroup::new_async(peripherals.TIMG0, &clocks)); let (tx, rx) = UsbSerialJtag::new_async(peripherals.USB_DEVICE).split(); diff --git a/examples/src/bin/embassy_wait.rs b/examples/src/bin/embassy_wait.rs index 628c4105b82..5aff83fc491 100644 --- a/examples/src/bin/embassy_wait.rs +++ b/examples/src/bin/embassy_wait.rs @@ -13,7 +13,6 @@ use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, gpio::{Input, Io, Pull}, peripherals::Peripherals, prelude::*, @@ -29,7 +28,7 @@ async fn main(_spawner: Spawner) { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] diff --git a/examples/src/bin/esp_wifi_embassy_access_point.rs b/examples/src/bin/esp_wifi_embassy_access_point.rs index fc1ae3b8894..773211741b1 100644 --- a/examples/src/bin/esp_wifi_embassy_access_point.rs +++ b/examples/src/bin/esp_wifi_embassy_access_point.rs @@ -29,7 +29,6 @@ use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, peripherals::Peripherals, prelude::*, rng::Rng, @@ -87,7 +86,7 @@ async fn main(spawner: Spawner) -> ! { esp_wifi::wifi::new_with_mode(&init, wifi, WifiApDevice).unwrap(); let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + esp_hal_embassy::init(&clocks, timer_group0); let config = Config::ipv4_static(StaticConfigV4 { address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 2, 1), 24), diff --git a/examples/src/bin/esp_wifi_embassy_access_point_with_sta.rs b/examples/src/bin/esp_wifi_embassy_access_point_with_sta.rs index 0d03cacca6d..edc23a6d9f9 100644 --- a/examples/src/bin/esp_wifi_embassy_access_point_with_sta.rs +++ b/examples/src/bin/esp_wifi_embassy_access_point_with_sta.rs @@ -32,7 +32,6 @@ use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, peripherals::Peripherals, prelude::*, rng::Rng, @@ -95,7 +94,7 @@ async fn main(spawner: Spawner) -> ! { esp_wifi::wifi::new_ap_sta(&init, wifi).unwrap(); let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + esp_hal_embassy::init(&clocks, timer_group0); let ap_config = Config::ipv4_static(StaticConfigV4 { address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 2, 1), 24), diff --git a/examples/src/bin/esp_wifi_embassy_bench.rs b/examples/src/bin/esp_wifi_embassy_bench.rs index a33b6ec3fea..8853b6b9f39 100644 --- a/examples/src/bin/esp_wifi_embassy_bench.rs +++ b/examples/src/bin/esp_wifi_embassy_bench.rs @@ -23,7 +23,6 @@ use embassy_time::{with_timeout, Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, peripherals::Peripherals, prelude::*, rng::Rng, @@ -99,7 +98,7 @@ async fn main(spawner: Spawner) -> ! { esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap(); let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + esp_hal_embassy::init(&clocks, timer_group0); let config = Config::dhcpv4(Default::default()); diff --git a/examples/src/bin/esp_wifi_embassy_ble.rs b/examples/src/bin/esp_wifi_embassy_ble.rs index 989a459570d..a6037a173bd 100644 --- a/examples/src/bin/esp_wifi_embassy_ble.rs +++ b/examples/src/bin/esp_wifi_embassy_ble.rs @@ -28,7 +28,6 @@ use embassy_executor::Spawner; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, gpio::{Input, Io, Pull}, peripherals::*, prelude::*, @@ -73,7 +72,7 @@ async fn main(_spawner: Spawner) -> ! { let button = Input::new(io.pins.gpio9, Pull::Down); let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + esp_hal_embassy::init(&clocks, timer_group0); let mut bluetooth = peripherals.BT; diff --git a/examples/src/bin/esp_wifi_embassy_dhcp.rs b/examples/src/bin/esp_wifi_embassy_dhcp.rs index 4b1f755676f..09ac818f0d9 100644 --- a/examples/src/bin/esp_wifi_embassy_dhcp.rs +++ b/examples/src/bin/esp_wifi_embassy_dhcp.rs @@ -19,7 +19,6 @@ use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, peripherals::Peripherals, prelude::*, rng::Rng, @@ -80,7 +79,7 @@ async fn main(spawner: Spawner) -> ! { esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap(); let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + esp_hal_embassy::init(&clocks, timer_group0); let config = Config::dhcpv4(Default::default()); diff --git a/examples/src/bin/esp_wifi_embassy_esp_now.rs b/examples/src/bin/esp_wifi_embassy_esp_now.rs index 15110bba040..b23c29dc9ab 100644 --- a/examples/src/bin/esp_wifi_embassy_esp_now.rs +++ b/examples/src/bin/esp_wifi_embassy_esp_now.rs @@ -16,7 +16,6 @@ use embassy_time::{Duration, Ticker}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, peripherals::Peripherals, prelude::*, rng::Rng, @@ -57,7 +56,7 @@ async fn main(_spawner: Spawner) -> ! { println!("esp-now version {}", esp_now.get_version().unwrap()); let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + esp_hal_embassy::init(&clocks, timer_group0); let mut ticker = Ticker::every(Duration::from_secs(5)); loop { diff --git a/examples/src/bin/esp_wifi_embassy_esp_now_duplex.rs b/examples/src/bin/esp_wifi_embassy_esp_now_duplex.rs index 04b5ca6e4ba..7f0e778b7c1 100644 --- a/examples/src/bin/esp_wifi_embassy_esp_now_duplex.rs +++ b/examples/src/bin/esp_wifi_embassy_esp_now_duplex.rs @@ -16,7 +16,6 @@ use embassy_time::{Duration, Ticker}; use esp_backtrace as _; use esp_hal::{ clock::ClockControl, - embassy, peripherals::Peripherals, prelude::*, rng::Rng, @@ -66,7 +65,7 @@ async fn main(spawner: Spawner) -> ! { println!("esp-now version {}", esp_now.get_version().unwrap()); let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + esp_hal_embassy::init(&clocks, timer_group0); let (manager, sender, receiver) = esp_now.split(); let manager = mk_static!(EspNowManager<'static>, manager); diff --git a/hil-test/Cargo.toml b/hil-test/Cargo.toml index bd92454218c..943527b9bdb 100644 --- a/hil-test/Cargo.toml +++ b/hil-test/Cargo.toml @@ -82,6 +82,7 @@ embedded-hal-async = { version = "1.0.0", optional = true } embedded-hal-nb = { version = "1.0.0", optional = true } esp-backtrace = { path = "../esp-backtrace", default-features = false, features = ["exception-handler", "panic-handler", "defmt", "semihosting"] } esp-hal = { path = "../esp-hal", features = ["defmt", "embedded-hal", "embedded-hal-02"], optional = true } +esp-hal-embassy = { path = "../esp-hal-embassy", optional = true } portable-atomic = "1.6.0" [dev-dependencies] @@ -103,31 +104,34 @@ esp32 = [ "embedded-test/xtensa-semihosting", "esp-backtrace/esp32", "esp-hal/esp32", + "esp-hal-embassy/esp32", ] -esp32c2 = ["esp-backtrace/esp32c2", "esp-hal/esp32c2"] -esp32c3 = ["esp-backtrace/esp32c3", "esp-hal/esp32c3"] -esp32c6 = ["esp-backtrace/esp32c6", "esp-hal/esp32c6"] -esp32h2 = ["esp-backtrace/esp32h2", "esp-hal/esp32h2"] +esp32c2 = ["esp-backtrace/esp32c2", "esp-hal/esp32c2", "esp-hal-embassy/esp32c2"] +esp32c3 = ["esp-backtrace/esp32c3", "esp-hal/esp32c3", "esp-hal-embassy/esp32c3"] +esp32c6 = ["esp-backtrace/esp32c6", "esp-hal/esp32c6", "esp-hal-embassy/esp32c6"] +esp32h2 = ["esp-backtrace/esp32h2", "esp-hal/esp32h2", "esp-hal-embassy/esp32h2"] esp32s2 = [ "embedded-test/xtensa-semihosting", "esp-backtrace/esp32s2", "esp-hal/esp32s2", + "esp-hal-embassy/esp32s2", ] esp32s3 = [ "embedded-test/xtensa-semihosting", "esp-backtrace/esp32s3", "esp-hal/esp32s3", + "esp-hal-embassy/esp32s3", ] # Async & Embassy: async = ["dep:embedded-hal-async", "esp-hal?/async"] embassy = [ "embedded-test/embassy", "embedded-test/external-executor", - "esp-hal?/embassy", + "dep:esp-hal-embassy", ] -embassy-time-systick-16mhz = ["esp-hal?/embassy-time-systick-16mhz"] -embassy-time-systick-80mhz = ["esp-hal?/embassy-time-systick-80mhz"] -embassy-time-timg0 = ["esp-hal?/embassy-time-timg0"] +embassy-time-systimer-16mhz = ["esp-hal-embassy/time-systimer-16mhz"] +embassy-time-systimer-80mhz = ["esp-hal-embassy/time-systimer-80mhz"] +embassy-time-timg0 = ["esp-hal-embassy/time-timg0"] # https://doc.rust-lang.org/cargo/reference/profiles.html#test # Test and bench profiles inherit from dev and release respectively. diff --git a/hil-test/tests/gpio.rs b/hil-test/tests/gpio.rs index 87da6e82011..7b71515af90 100644 --- a/hil-test/tests/gpio.rs +++ b/hil-test/tests/gpio.rs @@ -17,7 +17,6 @@ use esp_backtrace as _; use esp_hal::{ clock::ClockControl, delay::Delay, - embassy, gpio::{Gpio2, Gpio4, GpioPin, Input, Io, Level, Output, Pull}, macros::handler, peripherals::Peripherals, @@ -46,7 +45,7 @@ impl<'d> Context<'d> { let delay = Delay::new(&clocks); let timg0 = TimerGroup::new_async(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timg0); + esp_hal_embassy::init(&clocks, timg0); Context { io2: Input::new(io.pins.gpio2, Pull::Down), @@ -68,7 +67,7 @@ pub fn interrupt_handler() { } #[cfg(test)] -#[embedded_test::tests(executor = esp_hal::embassy::executor::Executor::new())] +#[embedded_test::tests(executor = esp_hal_embassy::Executor::new())] mod tests { use defmt::assert_eq; use embassy_time::{Duration, Timer}; diff --git a/hil-test/tests/uart_async.rs b/hil-test/tests/uart_async.rs index 6b1ff31de0a..86efeda7d31 100644 --- a/hil-test/tests/uart_async.rs +++ b/hil-test/tests/uart_async.rs @@ -44,7 +44,7 @@ impl Context { } #[cfg(test)] -#[embedded_test::tests(executor = esp_hal::embassy::executor::Executor::new())] +#[embedded_test::tests(executor = esp_hal_embassy::Executor::new())] mod tests { use defmt::assert_eq; diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index ee73a7fc034..4c09f2cf7c6 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -22,6 +22,7 @@ pub enum Package { EspBacktrace, EspBuild, EspHal, + EspHalEmbassy, EspHalProcmacros, EspHalSmartled, EspIeee802154, diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 3012cd7b49b..018e08c1001 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -467,6 +467,21 @@ fn lint_packages(workspace: &Path, _args: LintPackagesArgs) -> Result<()> { } } + Package::EspHalEmbassy => { + // We need to specify a time driver, so we will check all + // options here (as the modules themselves are feature-gated): + for feature in ["time-systimer-16mhz", "time-timg0"] { + lint_package( + &path, + &[ + "-Zbuild-std=core", + "--target=riscv32imac-unknown-none-elf", + &format!("--features=esp32c6,{feature}"), + ], + )?; + } + } + Package::EspHalProcmacros | Package::EspRiscvRt => lint_package( &path, &["-Zbuild-std=core", "--target=riscv32imc-unknown-none-elf"], @@ -504,7 +519,7 @@ fn lint_packages(workspace: &Path, _args: LintPackagesArgs) -> Result<()> { &[ "-Zbuild-std=core", "--target=riscv32imc-unknown-none-elf", - "--features=esp32c3,wifi-default,ble,esp-now,async,embassy-net", + "--features=esp32c3,wifi-default,ble,esp-now,async,embassy-net,esp-hal-embassy/time-timg0", ], )?,