diff --git a/CHANGELOG.md b/CHANGELOG.md index 70c856142..70b93eff1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added basic `LP-I2C` driver for C6 (#1185) - Ensuring that the random number generator is TRNG. (#1200) - ESP32-C6: Add timer wakeup source for deepsleep (#1201) +- Introduce `InterruptExecutor::spawner()` (#1211) ### Fixed diff --git a/esp-hal/src/embassy/executor/interrupt.rs b/esp-hal/src/embassy/executor/interrupt.rs index b5d80bddf..18f2164f4 100644 --- a/esp-hal/src/embassy/executor/interrupt.rs +++ b/esp-hal/src/embassy/executor/interrupt.rs @@ -175,4 +175,19 @@ where let executor = unsafe { (*self.executor.get()).assume_init_ref() }; executor.spawner().make_send() } + + /// Get a SendSpawner for this executor + /// + /// This returns a [`SendSpawner`] you can use to spawn tasks on this + /// executor. + /// + /// This MUST only be called on an executor that has already been started. + /// The function will panic otherwise. + pub fn spawner(&'static self) -> SendSpawner { + if self.core.load(Ordering::Acquire) == usize::MAX { + panic!("InterruptExecutor::spawner() called on uninitialized executor."); + } + let executor = unsafe { (&*self.executor.get()).assume_init_ref() }; + executor.spawner().make_send() + } }