From d7c3a38efceacbd5a326c84c6e0bbef44b06e97c Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 29 Mar 2021 03:00:48 +0200 Subject: [PATCH] Reexport macros at root, use eveywhere as `#[embassy::task]` --- embassy-macros/src/lib.rs | 2 +- embassy-nrf-examples/src/bin/executor_fairness_test.rs | 8 ++++---- embassy-nrf-examples/src/bin/multiprio.rs | 8 ++++---- embassy-nrf-examples/src/bin/timer.rs | 6 +++--- embassy-std-examples/src/bin/serial.rs | 3 +-- embassy-std-examples/src/bin/tick.rs | 3 +-- embassy-stm32f4-examples/src/bin/can.rs | 4 ++-- embassy-stm32f4-examples/src/bin/exti.rs | 4 ++-- embassy-stm32f4-examples/src/bin/rtc_async.rs | 5 ++--- embassy-stm32f4-examples/src/bin/serial.rs | 4 ++-- embassy-stm32f4-examples/src/bin/usb_serial.rs | 4 ++-- embassy/src/executor/mod.rs | 2 -- embassy/src/executor/timer.rs | 6 +++--- embassy/src/lib.rs | 2 +- embassy/src/util/signal.rs | 2 +- 15 files changed, 29 insertions(+), 34 deletions(-) diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 26b49b2e4..145714f22 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs @@ -256,7 +256,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { let chip_setup = chip::generate(macro_args); let result = quote! { - #[embassy::executor::task] + #[embassy::task] async fn __embassy_main(#args) { #task_fn_body } diff --git a/embassy-nrf-examples/src/bin/executor_fairness_test.rs b/embassy-nrf-examples/src/bin/executor_fairness_test.rs index e82e5475b..3ea74316e 100644 --- a/embassy-nrf-examples/src/bin/executor_fairness_test.rs +++ b/embassy-nrf-examples/src/bin/executor_fairness_test.rs @@ -11,11 +11,11 @@ use example_common::*; use core::task::Poll; use defmt::panic; -use embassy::executor::{task, Spawner}; +use embassy::executor::Spawner; use embassy::time::{Duration, Instant, Timer}; use embassy_nrf::interrupt; -#[task] +#[embassy::task] async fn run1() { loop { info!("DING DONG"); @@ -23,14 +23,14 @@ async fn run1() { } } -#[task] +#[embassy::task] async fn run2() { loop { Timer::at(Instant::from_ticks(0)).await; } } -#[task] +#[embassy::task] async fn run3() { futures::future::poll_fn(|cx| { cx.waker().wake_by_ref(); diff --git a/embassy-nrf-examples/src/bin/multiprio.rs b/embassy-nrf-examples/src/bin/multiprio.rs index aa2824f6b..c6228a1ea 100644 --- a/embassy-nrf-examples/src/bin/multiprio.rs +++ b/embassy-nrf-examples/src/bin/multiprio.rs @@ -66,13 +66,13 @@ use example_common::*; use cortex_m_rt::entry; use defmt::panic; -use embassy::executor::{task, Executor, InterruptExecutor}; +use embassy::executor::{Executor, InterruptExecutor}; use embassy::interrupt::InterruptExt; use embassy::time::{Duration, Instant, Timer}; use embassy::util::Forever; use embassy_nrf::{interrupt, peripherals, rtc}; -#[task] +#[embassy::task] async fn run_high() { loop { info!(" [high] tick!"); @@ -80,7 +80,7 @@ async fn run_high() { } } -#[task] +#[embassy::task] async fn run_med() { loop { let start = Instant::now(); @@ -97,7 +97,7 @@ async fn run_med() { } } -#[task] +#[embassy::task] async fn run_low() { loop { let start = Instant::now(); diff --git a/embassy-nrf-examples/src/bin/timer.rs b/embassy-nrf-examples/src/bin/timer.rs index 6116aa60d..a2b717bc1 100644 --- a/embassy-nrf-examples/src/bin/timer.rs +++ b/embassy-nrf-examples/src/bin/timer.rs @@ -10,10 +10,10 @@ mod example_common; use example_common::*; use defmt::panic; -use embassy::executor::{task, Spawner}; +use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -#[task] +#[embassy::task] async fn run1() { loop { info!("BIG INFREQUENT TICK"); @@ -21,7 +21,7 @@ async fn run1() { } } -#[task] +#[embassy::task] async fn run2() { loop { info!("tick"); diff --git a/embassy-std-examples/src/bin/serial.rs b/embassy-std-examples/src/bin/serial.rs index 6d628fe14..79f10c418 100644 --- a/embassy-std-examples/src/bin/serial.rs +++ b/embassy-std-examples/src/bin/serial.rs @@ -6,7 +6,6 @@ mod serial_port; use async_io::Async; -use embassy::executor::task; use embassy::io::AsyncBufReadExt; use embassy::util::Forever; use embassy_std::Executor; @@ -15,7 +14,7 @@ use nix::sys::termios; use self::serial_port::SerialPort; -#[task] +#[embassy::task] async fn run() { // Open the serial port. let baudrate = termios::BaudRate::B115200; diff --git a/embassy-std-examples/src/bin/tick.rs b/embassy-std-examples/src/bin/tick.rs index 96eef067c..47713f7ba 100644 --- a/embassy-std-examples/src/bin/tick.rs +++ b/embassy-std-examples/src/bin/tick.rs @@ -2,13 +2,12 @@ #![feature(impl_trait_in_bindings)] #![feature(type_alias_impl_trait)] -use embassy::executor::task; use embassy::time::{Duration, Timer}; use embassy::util::Forever; use embassy_std::Executor; use log::*; -#[task] +#[embassy::task] async fn run() { loop { info!("tick"); diff --git a/embassy-stm32f4-examples/src/bin/can.rs b/embassy-stm32f4-examples/src/bin/can.rs index 5ffde2471..c34c0a2a4 100644 --- a/embassy-stm32f4-examples/src/bin/can.rs +++ b/embassy-stm32f4-examples/src/bin/can.rs @@ -11,13 +11,13 @@ use example_common::{panic, *}; use bxcan::filter::Mask32; use cortex_m_rt::entry; -use embassy::executor::{task, Executor}; +use embassy::executor::Executor; use embassy::util::Forever; use embassy_stm32f4::{can, interrupt}; use stm32f4xx_hal::prelude::*; use stm32f4xx_hal::{can::Can, stm32}; -#[task] +#[embassy::task] async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { let gpioa = dp.GPIOA.split(); diff --git a/embassy-stm32f4-examples/src/bin/exti.rs b/embassy-stm32f4-examples/src/bin/exti.rs index 9b2535b1c..9879de408 100644 --- a/embassy-stm32f4-examples/src/bin/exti.rs +++ b/embassy-stm32f4-examples/src/bin/exti.rs @@ -10,7 +10,7 @@ mod example_common; use example_common::{panic, *}; use cortex_m_rt::entry; -use embassy::executor::{task, Executor}; +use embassy::executor::Executor; use embassy::traits::gpio::*; use embassy::util::Forever; use embassy_stm32f4::exti::ExtiPin; @@ -19,7 +19,7 @@ use futures::pin_mut; use stm32f4xx_hal::prelude::*; use stm32f4xx_hal::stm32; -#[task] +#[embassy::task] async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { let gpioa = dp.GPIOA.split(); diff --git a/embassy-stm32f4-examples/src/bin/rtc_async.rs b/embassy-stm32f4-examples/src/bin/rtc_async.rs index 1927d01bf..f2757294d 100644 --- a/embassy-stm32f4-examples/src/bin/rtc_async.rs +++ b/embassy-stm32f4-examples/src/bin/rtc_async.rs @@ -11,12 +11,11 @@ use example_common::*; use defmt::panic; use embassy; use embassy::executor::Spawner; -use embassy::task; use embassy::time::{Duration, Timer}; use embassy_stm32f4; use embassy_stm32f4::hal; -#[task] +#[embassy::task] async fn run1() { loop { info!("BIG INFREQUENT TICK"); @@ -24,7 +23,7 @@ async fn run1() { } } -#[task] +#[embassy::task] async fn run2() { loop { info!("tick"); diff --git a/embassy-stm32f4-examples/src/bin/serial.rs b/embassy-stm32f4-examples/src/bin/serial.rs index c8e7f288f..925fd68ff 100644 --- a/embassy-stm32f4-examples/src/bin/serial.rs +++ b/embassy-stm32f4-examples/src/bin/serial.rs @@ -11,7 +11,7 @@ use example_common::{panic, *}; use cortex_m::singleton; use cortex_m_rt::entry; -use embassy::executor::{task, Executor}; +use embassy::executor::Executor; use embassy::traits::uart::{Read, Write}; use embassy::util::Forever; use embassy_stm32f4::interrupt; @@ -22,7 +22,7 @@ use stm32f4xx_hal::prelude::*; use stm32f4xx_hal::serial::config::Config; use stm32f4xx_hal::stm32; -#[task] +#[embassy::task] async fn run(dp: stm32::Peripherals, _cp: cortex_m::Peripherals) { dp.DBGMCU.cr.modify(|_, w| { w.dbg_sleep().set_bit(); diff --git a/embassy-stm32f4-examples/src/bin/usb_serial.rs b/embassy-stm32f4-examples/src/bin/usb_serial.rs index f1c4631d7..6d3b2cc14 100644 --- a/embassy-stm32f4-examples/src/bin/usb_serial.rs +++ b/embassy-stm32f4-examples/src/bin/usb_serial.rs @@ -10,7 +10,7 @@ use example_common::*; use cortex_m_rt::entry; use defmt::panic; -use embassy::executor::{task, Executor}; +use embassy::executor::Executor; use embassy::interrupt::InterruptExt; use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; use embassy::time::{Duration, Timer}; @@ -25,7 +25,7 @@ use stm32f4xx_hal::prelude::*; use usb_device::bus::UsbBusAllocator; use usb_device::prelude::*; -#[task] +#[embassy::task] async fn run1(bus: &'static mut UsbBusAllocator>) { info!("Async task"); diff --git a/embassy/src/executor/mod.rs b/embassy/src/executor/mod.rs index b2c42190f..8a3a8991a 100644 --- a/embassy/src/executor/mod.rs +++ b/embassy/src/executor/mod.rs @@ -1,5 +1,3 @@ -pub use embassy_macros::{main, task}; - use core::marker::PhantomData; use core::ptr::NonNull; use core::{mem, ptr}; diff --git a/embassy/src/executor/timer.rs b/embassy/src/executor/timer.rs index 541f96f59..774613ebf 100644 --- a/embassy/src/executor/timer.rs +++ b/embassy/src/executor/timer.rs @@ -60,7 +60,7 @@ impl Timer { /// use embassy::executor::task; /// use embassy::time::{Duration, Timer}; /// - /// #[task] + /// #[embassy::task] /// async fn demo_sleep_seconds() { /// // suspend this task for one second. /// Timer::after(Duration::from_secs(1)).await; @@ -104,7 +104,7 @@ impl Future for Timer { /// use embassy::time::{Duration, Timer}; /// # fn foo() {} /// -/// #[task] +/// #[embassy::task] /// async fn ticker_example_0() { /// loop { /// foo(); @@ -129,7 +129,7 @@ impl Future for Timer { /// use futures::StreamExt; /// # fn foo(){} /// -/// #[task] +/// #[embassy::task] /// async fn ticker_example_1() { /// let mut ticker = Ticker::every(Duration::from_secs(1)); /// loop { diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 482d5b367..af05a794b 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs @@ -17,8 +17,8 @@ pub mod io; pub mod time; pub mod util; +pub use embassy_macros::*; pub use embassy_traits as traits; -pub use executor::{main, task}; #[doc(hidden)] /// Implementation details for embassy macros. DO NOT USE. diff --git a/embassy/src/util/signal.rs b/embassy/src/util/signal.rs index 749b32247..e4629bf9f 100644 --- a/embassy/src/util/signal.rs +++ b/embassy/src/util/signal.rs @@ -122,7 +122,7 @@ unsafe impl cortex_m::interrupt::Nr for NrWrap { /// use embassy::util::InterruptFuture; /// use embassy::executor::task; /// use embassy_stm32f4::interrupt; // Adjust this to your MCU's embassy HAL. -/// #[task] +/// #[embassy::task] /// async fn demo_interrupt_future() { /// // Using STM32f446 interrupt names, adjust this to your application as necessary. /// // Wait for TIM2 to tick.