Merge pull request #120 from embassy-rs/main-nrf
nrf: add main macro support
This commit is contained in:
commit
95726b730b
@ -8,10 +8,11 @@ edition = "2018"
|
||||
syn = { version = "1.0.39", features = ["full", "extra-traits"] }
|
||||
quote = "1.0.7"
|
||||
darling = "0.10.2"
|
||||
proc-macro2 = "1.0.24"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[features]
|
||||
stm32 = []
|
||||
nrf = []
|
||||
nrf = []
|
||||
|
62
embassy-macros/src/chip/nrf.rs
Normal file
62
embassy-macros/src/chip/nrf.rs
Normal file
@ -0,0 +1,62 @@
|
||||
use darling::FromMeta;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
#[derive(Debug, FromMeta)]
|
||||
pub enum HfclkSource {
|
||||
Internal,
|
||||
ExternalXtal,
|
||||
}
|
||||
|
||||
impl Default for HfclkSource {
|
||||
fn default() -> Self {
|
||||
Self::Internal
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, FromMeta)]
|
||||
pub enum LfclkSource {
|
||||
InternalRC,
|
||||
Synthesized,
|
||||
ExternalXtal,
|
||||
ExternalLowSwing,
|
||||
ExternalFullSwing,
|
||||
}
|
||||
|
||||
impl Default for LfclkSource {
|
||||
fn default() -> Self {
|
||||
Self::InternalRC
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, FromMeta)]
|
||||
pub struct Args {
|
||||
#[darling(default)]
|
||||
pub hfclk_source: HfclkSource,
|
||||
#[darling(default)]
|
||||
pub lfclk_source: LfclkSource,
|
||||
}
|
||||
|
||||
pub fn generate(args: Args) -> TokenStream {
|
||||
let hfclk_source = format_ident!("{}", format!("{:?}", args.hfclk_source));
|
||||
let lfclk_source = format_ident!("{}", format!("{:?}", args.lfclk_source));
|
||||
|
||||
quote!(
|
||||
use embassy_nrf::{interrupt, peripherals, rtc};
|
||||
|
||||
let mut config = embassy_nrf::system::Config::default();
|
||||
config.hfclk_source = embassy_nrf::system::HfclkSource::#hfclk_source;
|
||||
config.lfclk_source = embassy_nrf::system::LfclkSource::#lfclk_source;
|
||||
unsafe { embassy_nrf::system::configure(config) };
|
||||
|
||||
let mut rtc = rtc::RTC::new(unsafe { <peripherals::RTC1 as embassy::util::Steal>::steal() }, interrupt::take!(RTC1));
|
||||
let rtc = unsafe { make_static(&mut rtc) };
|
||||
rtc.start();
|
||||
let mut alarm = rtc.alarm0();
|
||||
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
let alarm = unsafe { make_static(&mut alarm) };
|
||||
)
|
||||
}
|
51
embassy-macros/src/chip/stm32.rs
Normal file
51
embassy-macros/src/chip/stm32.rs
Normal file
@ -0,0 +1,51 @@
|
||||
use darling::FromMeta;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
#[derive(Debug, FromMeta)]
|
||||
pub struct Args {
|
||||
#[darling(default)]
|
||||
pub use_hse: Option<u32>,
|
||||
#[darling(default)]
|
||||
pub sysclk: Option<u32>,
|
||||
#[darling(default)]
|
||||
pub pclk1: Option<u32>,
|
||||
}
|
||||
|
||||
pub fn generate(args: Args) -> TokenStream {
|
||||
let mut clock_cfg_args = quote! {};
|
||||
if args.use_hse.is_some() {
|
||||
let mhz = args.use_hse.unwrap();
|
||||
clock_cfg_args = quote! { #clock_cfg_args.use_hse(#mhz.mhz()) };
|
||||
}
|
||||
|
||||
if args.sysclk.is_some() {
|
||||
let mhz = args.sysclk.unwrap();
|
||||
clock_cfg_args = quote! { #clock_cfg_args.sysclk(#mhz.mhz()) };
|
||||
}
|
||||
|
||||
if args.pclk1.is_some() {
|
||||
let mhz = args.pclk1.unwrap();
|
||||
clock_cfg_args = quote! { #clock_cfg_args.pclk1(#mhz.mhz()) };
|
||||
}
|
||||
|
||||
quote!(
|
||||
use embassy_stm32::{rtc, interrupt, Peripherals, pac, hal::rcc::RccExt, hal::time::U32Ext};
|
||||
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let rcc = dp.RCC.constrain();
|
||||
let clocks = rcc.cfgr#clock_cfg_args.freeze();
|
||||
|
||||
unsafe { Peripherals::set_peripherals(clocks) };
|
||||
|
||||
let mut rtc = rtc::RTC::new(dp.TIM3, interrupt::take!(TIM3), clocks);
|
||||
let rtc = unsafe { make_static(&mut rtc) };
|
||||
rtc.start();
|
||||
let mut alarm = rtc.alarm1();
|
||||
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
let alarm = unsafe { make_static(&mut alarm) };
|
||||
)
|
||||
}
|
@ -191,22 +191,21 @@ pub fn interrupt_take(item: TokenStream) -> TokenStream {
|
||||
result.into()
|
||||
}
|
||||
|
||||
#[derive(Debug, FromMeta)]
|
||||
struct MainMacroArgs {
|
||||
#[darling(default)]
|
||||
use_hse: Option<u32>,
|
||||
#[darling(default)]
|
||||
sysclk: Option<u32>,
|
||||
#[darling(default)]
|
||||
pclk1: Option<u32>,
|
||||
}
|
||||
#[cfg(feature = "nrf")]
|
||||
#[path = "chip/nrf.rs"]
|
||||
mod chip;
|
||||
|
||||
#[cfg(feature = "stm32")]
|
||||
#[path = "chip/stm32.rs"]
|
||||
mod chip;
|
||||
|
||||
#[cfg(any(feature = "nrf", feature = "stm32"))]
|
||||
#[proc_macro_attribute]
|
||||
pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let macro_args = syn::parse_macro_input!(args as syn::AttributeArgs);
|
||||
let mut task_fn = syn::parse_macro_input!(item as syn::ItemFn);
|
||||
|
||||
let macro_args = match MainMacroArgs::from_list(¯o_args) {
|
||||
let macro_args = match chip::Args::from_list(¯o_args) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
return TokenStream::from(e.write_errors());
|
||||
@ -254,55 +253,30 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let name = task_fn.sig.ident.clone();
|
||||
let task_fn_body = task_fn.block.clone();
|
||||
|
||||
let mut clock_cfg_args = quote! {};
|
||||
if macro_args.use_hse.is_some() {
|
||||
let mhz = macro_args.use_hse.unwrap();
|
||||
clock_cfg_args = quote! { #clock_cfg_args.use_hse(#mhz.mhz()) };
|
||||
}
|
||||
|
||||
if macro_args.sysclk.is_some() {
|
||||
let mhz = macro_args.sysclk.unwrap();
|
||||
clock_cfg_args = quote! { #clock_cfg_args.sysclk(#mhz.mhz()) };
|
||||
}
|
||||
|
||||
if macro_args.pclk1.is_some() {
|
||||
let mhz = macro_args.pclk1.unwrap();
|
||||
clock_cfg_args = quote! { #clock_cfg_args.pclk1(#mhz.mhz()) };
|
||||
}
|
||||
let chip_setup = chip::generate(macro_args);
|
||||
|
||||
let result = quote! {
|
||||
static __embassy_rtc: embassy::util::Forever<embassy_stm32::rtc::RTC<embassy_stm32::pac::TIM3>> = embassy::util::Forever::new();
|
||||
static __embassy_alarm: embassy::util::Forever<embassy_stm32::rtc::Alarm<embassy_stm32::pac::TIM3>> = embassy::util::Forever::new();
|
||||
static __embassy_executor: embassy::util::Forever<embassy::executor::Executor> = embassy::util::Forever::new();
|
||||
|
||||
#[embassy::executor::task]
|
||||
#[embassy::task]
|
||||
async fn __embassy_main(#args) {
|
||||
#task_fn_body
|
||||
}
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
fn main() -> ! {
|
||||
use embassy::executor::Executor;
|
||||
use embassy_stm32::{rtc, interrupt, Peripherals, pac, hal::rcc::RccExt, hal::time::U32Ext};
|
||||
unsafe fn make_static<T>(t: &mut T) -> &'static mut T {
|
||||
::core::mem::transmute(t)
|
||||
}
|
||||
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let rcc = dp.RCC.constrain();
|
||||
let clocks = rcc.cfgr#clock_cfg_args.freeze();
|
||||
#chip_setup
|
||||
|
||||
unsafe { Peripherals::set_peripherals(clocks) };
|
||||
|
||||
let rtc = __embassy_rtc.put(rtc::RTC::new(dp.TIM3, interrupt::take!(TIM3), clocks));
|
||||
rtc.start();
|
||||
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
let alarm = __embassy_alarm.put(rtc.alarm1());
|
||||
let executor = __embassy_executor.put(Executor::new());
|
||||
let mut executor = ::embassy::executor::Executor::new();
|
||||
let executor = unsafe { make_static(&mut executor) };
|
||||
executor.set_alarm(alarm);
|
||||
|
||||
executor.run(|spawner| {
|
||||
spawner.spawn(__embassy_main(spawner)).unwrap();
|
||||
})
|
||||
|
||||
}
|
||||
};
|
||||
result.into()
|
||||
|
@ -8,19 +8,17 @@
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::panic;
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
|
||||
use embassy::util::{Forever, Steal};
|
||||
use embassy_nrf::gpio::NoPin;
|
||||
use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, peripherals, rtc, uarte, Peripherals};
|
||||
use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals};
|
||||
use example_common::*;
|
||||
use futures::pin_mut;
|
||||
|
||||
#[task]
|
||||
async fn run() {
|
||||
let p = unsafe { Peripherals::steal() };
|
||||
#[embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = Peripherals::take().unwrap();
|
||||
|
||||
let mut config = uarte::Config::default();
|
||||
config.parity = uarte::Parity::EXCLUDED;
|
||||
@ -70,27 +68,3 @@ async fn run() {
|
||||
info!("write done");
|
||||
}
|
||||
}
|
||||
|
||||
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
|
||||
static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let p = unwrap!(embassy_nrf::Peripherals::take());
|
||||
|
||||
unsafe { embassy_nrf::system::configure(Default::default()) };
|
||||
let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1)));
|
||||
rtc.start();
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
let alarm = ALARM.put(rtc.alarm0());
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.set_alarm(alarm);
|
||||
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run()));
|
||||
});
|
||||
}
|
||||
|
@ -10,15 +10,12 @@ mod example_common;
|
||||
use example_common::*;
|
||||
|
||||
use core::task::Poll;
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::panic;
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Instant, Timer};
|
||||
use embassy::util::Forever;
|
||||
use embassy_nrf::peripherals;
|
||||
use embassy_nrf::{interrupt, rtc};
|
||||
use embassy_nrf::interrupt;
|
||||
|
||||
#[task]
|
||||
#[embassy::task]
|
||||
async fn run1() {
|
||||
loop {
|
||||
info!("DING DONG");
|
||||
@ -26,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();
|
||||
@ -42,27 +39,9 @@ async fn run3() {
|
||||
.await;
|
||||
}
|
||||
|
||||
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
|
||||
static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let p = unwrap!(embassy_nrf::Peripherals::take());
|
||||
|
||||
unsafe { embassy_nrf::system::configure(Default::default()) };
|
||||
let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1)));
|
||||
rtc.start();
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
let alarm = ALARM.put(rtc.alarm0());
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.set_alarm(alarm);
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run1()));
|
||||
unwrap!(spawner.spawn(run2()));
|
||||
unwrap!(spawner.spawn(run3()));
|
||||
});
|
||||
#[embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
unwrap!(spawner.spawn(run1()));
|
||||
unwrap!(spawner.spawn(run2()));
|
||||
unwrap!(spawner.spawn(run3()));
|
||||
}
|
||||
|
@ -9,17 +9,14 @@
|
||||
mod example_common;
|
||||
use example_common::*;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::panic;
|
||||
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::util::Forever;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_nrf::gpio::{Input, Pull};
|
||||
use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity};
|
||||
use embassy_nrf::{interrupt, Peripherals};
|
||||
|
||||
#[task]
|
||||
async fn run() {
|
||||
#[embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = Peripherals::take().unwrap();
|
||||
let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE));
|
||||
|
||||
@ -80,15 +77,3 @@ async fn run() {
|
||||
|
||||
futures::join!(button1, button2, button3, button4);
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run()));
|
||||
});
|
||||
}
|
||||
|
@ -9,11 +9,9 @@
|
||||
mod example_common;
|
||||
|
||||
use core::pin::Pin;
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::panic;
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::traits::gpio::{WaitForHigh, WaitForLow};
|
||||
use embassy::util::Forever;
|
||||
use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull};
|
||||
use embassy_nrf::gpiote::{self, PortInput};
|
||||
use embassy_nrf::interrupt;
|
||||
@ -29,8 +27,8 @@ async fn button(n: usize, mut pin: PortInput<'static, AnyPin>) {
|
||||
}
|
||||
}
|
||||
|
||||
#[task]
|
||||
async fn run() {
|
||||
#[embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = Peripherals::take().unwrap();
|
||||
|
||||
let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE));
|
||||
@ -53,15 +51,3 @@ async fn run() {
|
||||
);
|
||||
futures::join!(button1, button2, button3, button4);
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run()));
|
||||
});
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -7,23 +7,19 @@
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use core::future::pending;
|
||||
|
||||
use example_common::*;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use core::future::pending;
|
||||
use defmt::panic;
|
||||
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::util::Forever;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
|
||||
use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity};
|
||||
use embassy_nrf::ppi::Ppi;
|
||||
use embassy_nrf::{interrupt, Peripherals};
|
||||
use gpiote::{OutputChannel, OutputChannelPolarity};
|
||||
|
||||
#[task]
|
||||
async fn run() {
|
||||
#[embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = Peripherals::take().unwrap();
|
||||
let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE));
|
||||
|
||||
@ -94,18 +90,7 @@ async fn run() {
|
||||
info!("Press button 2 to turn on LED 1");
|
||||
info!("Press button 3 to turn off LED 1");
|
||||
info!("Press button 4 to toggle LEDs 1 and 2");
|
||||
|
||||
// Block forever so the above drivers don't get dropped
|
||||
pending::<()>().await;
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run()));
|
||||
});
|
||||
}
|
||||
|
@ -8,11 +8,9 @@
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::{assert_eq, panic};
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::traits::flash::Flash;
|
||||
use embassy::util::Forever;
|
||||
use embassy_nrf::Peripherals;
|
||||
use embassy_nrf::{interrupt, qspi};
|
||||
use example_common::*;
|
||||
@ -25,8 +23,8 @@ const PAGE_SIZE: usize = 4096;
|
||||
#[repr(C, align(4))]
|
||||
struct AlignedBuf([u8; 4096]);
|
||||
|
||||
#[task]
|
||||
async fn run() {
|
||||
#[embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = Peripherals::take().unwrap();
|
||||
|
||||
let csn = p.P0_17;
|
||||
@ -96,15 +94,3 @@ async fn run() {
|
||||
|
||||
info!("done!")
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run()));
|
||||
});
|
||||
}
|
||||
|
@ -8,21 +8,19 @@
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::panic;
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::util::Forever;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::util::Steal;
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::{interrupt, rtc, spim};
|
||||
use embassy_nrf::{peripherals, Peripherals};
|
||||
use embassy_nrf::Peripherals;
|
||||
use embassy_nrf::{interrupt, spim};
|
||||
use embassy_traits::spi::FullDuplex;
|
||||
use embedded_hal::digital::v2::*;
|
||||
use example_common::*;
|
||||
use futures::pin_mut;
|
||||
|
||||
#[task]
|
||||
async fn run() {
|
||||
#[embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
info!("running!");
|
||||
|
||||
let p = unsafe { Peripherals::steal() };
|
||||
@ -84,29 +82,3 @@ async fn run() {
|
||||
|
||||
info!("erevid: {=[?]}", rx);
|
||||
}
|
||||
|
||||
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
|
||||
static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let p = unwrap!(embassy_nrf::Peripherals::take());
|
||||
|
||||
unsafe { embassy_nrf::system::configure(Default::default()) };
|
||||
let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1)));
|
||||
rtc.start();
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
let alarm = ALARM.put(rtc.alarm0());
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.set_alarm(alarm);
|
||||
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run()));
|
||||
});
|
||||
}
|
||||
|
@ -9,14 +9,11 @@
|
||||
mod example_common;
|
||||
use example_common::*;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::panic;
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy::util::Forever;
|
||||
use embassy_nrf::{interrupt, peripherals, rtc};
|
||||
|
||||
#[task]
|
||||
#[embassy::task]
|
||||
async fn run1() {
|
||||
loop {
|
||||
info!("BIG INFREQUENT TICK");
|
||||
@ -24,7 +21,7 @@ async fn run1() {
|
||||
}
|
||||
}
|
||||
|
||||
#[task]
|
||||
#[embassy::task]
|
||||
async fn run2() {
|
||||
loop {
|
||||
info!("tick");
|
||||
@ -32,26 +29,8 @@ async fn run2() {
|
||||
}
|
||||
}
|
||||
|
||||
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
|
||||
static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let p = unwrap!(embassy_nrf::Peripherals::take());
|
||||
|
||||
unsafe { embassy_nrf::system::configure(Default::default()) };
|
||||
let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1)));
|
||||
rtc.start();
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
let alarm = ALARM.put(rtc.alarm0());
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.set_alarm(alarm);
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run1()));
|
||||
unwrap!(spawner.spawn(run2()));
|
||||
});
|
||||
#[embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
unwrap!(spawner.spawn(run1()));
|
||||
unwrap!(spawner.spawn(run2()));
|
||||
}
|
||||
|
@ -9,17 +9,16 @@
|
||||
mod example_common;
|
||||
use example_common::*;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::panic;
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::traits::uart::{Read, Write};
|
||||
use embassy::util::{Forever, Steal};
|
||||
use embassy::util::Steal;
|
||||
use embassy_nrf::gpio::NoPin;
|
||||
use embassy_nrf::{interrupt, peripherals, rtc, uarte, Peripherals};
|
||||
use embassy_nrf::{interrupt, uarte, Peripherals};
|
||||
use futures::pin_mut;
|
||||
|
||||
#[task]
|
||||
async fn run() {
|
||||
#[embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = unsafe { Peripherals::steal() };
|
||||
|
||||
let mut config = uarte::Config::default();
|
||||
@ -74,27 +73,3 @@ async fn run() {
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
|
||||
static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let p = unwrap!(embassy_nrf::Peripherals::take());
|
||||
|
||||
unsafe { embassy_nrf::system::configure(Default::default()) };
|
||||
let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1)));
|
||||
rtc.start();
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
let alarm = ALARM.put(rtc.alarm0());
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.set_alarm(alarm);
|
||||
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run()));
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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();
|
||||
|
@ -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<UsbBus<USB>>) {
|
||||
info!("Async task");
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
pub use embassy_macros::{main, task};
|
||||
|
||||
use core::marker::PhantomData;
|
||||
use core::ptr::NonNull;
|
||||
use core::{mem, ptr};
|
||||
|
@ -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 {
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user