time: replace dyn clock/alarm with a global Driver trait
This commit is contained in:
@ -6,7 +6,6 @@
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use defmt::panic;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
|
@ -8,10 +8,9 @@ mod example_common;
|
||||
use example_common::*;
|
||||
|
||||
use core::task::Poll;
|
||||
use defmt::panic;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Instant, Timer};
|
||||
use embassy_nrf::{interrupt, Peripherals};
|
||||
use embassy_nrf::Peripherals;
|
||||
|
||||
#[embassy::task]
|
||||
async fn run1() {
|
||||
|
@ -7,11 +7,10 @@
|
||||
mod example_common;
|
||||
use example_common::*;
|
||||
|
||||
use defmt::panic;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_nrf::gpio::{Input, Pull};
|
||||
use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity};
|
||||
use embassy_nrf::{interrupt, Peripherals};
|
||||
use embassy_nrf::Peripherals;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
@ -6,12 +6,10 @@
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use defmt::panic;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::traits::gpio::{WaitForHigh, WaitForLow};
|
||||
use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull};
|
||||
use embassy_nrf::gpiote::PortInput;
|
||||
use embassy_nrf::interrupt;
|
||||
use embassy_nrf::Peripherals;
|
||||
use example_common::*;
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use defmt::panic;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy::util::mpsc::TryRecvError;
|
||||
|
@ -68,7 +68,7 @@ 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};
|
||||
use embassy_nrf::interrupt;
|
||||
|
||||
#[embassy::task]
|
||||
async fn run_high() {
|
||||
@ -112,30 +112,20 @@ async fn run_low() {
|
||||
}
|
||||
}
|
||||
|
||||
static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
|
||||
static ALARM_HIGH: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
|
||||
static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::SWI1_EGU1>> = Forever::new();
|
||||
static ALARM_MED: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
|
||||
static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::SWI0_EGU0>> = Forever::new();
|
||||
static ALARM_LOW: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
|
||||
static EXECUTOR_LOW: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
|
||||
let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1)));
|
||||
rtc.start();
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
let _p = embassy_nrf::init(Default::default());
|
||||
|
||||
// High-priority executor: SWI1_EGU1, priority level 6
|
||||
let irq = interrupt::take!(SWI1_EGU1);
|
||||
irq.set_priority(interrupt::Priority::P6);
|
||||
let alarm = ALARM_HIGH.put(rtc.alarm2());
|
||||
let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq));
|
||||
executor.set_alarm(alarm);
|
||||
executor.start(|spawner| {
|
||||
unwrap!(spawner.spawn(run_high()));
|
||||
});
|
||||
@ -143,17 +133,13 @@ fn main() -> ! {
|
||||
// Medium-priority executor: SWI0_EGU0, priority level 7
|
||||
let irq = interrupt::take!(SWI0_EGU0);
|
||||
irq.set_priority(interrupt::Priority::P7);
|
||||
let alarm = ALARM_MED.put(rtc.alarm1());
|
||||
let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq));
|
||||
executor.set_alarm(alarm);
|
||||
executor.start(|spawner| {
|
||||
unwrap!(spawner.spawn(run_med()));
|
||||
});
|
||||
|
||||
// Low priority executor: runs in thread mode, using WFE/SEV
|
||||
let alarm = ALARM_LOW.put(rtc.alarm0());
|
||||
let executor = EXECUTOR_LOW.put(Executor::new());
|
||||
executor.set_alarm(alarm);
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run_low()));
|
||||
});
|
||||
|
@ -8,12 +8,11 @@ mod example_common;
|
||||
use example_common::*;
|
||||
|
||||
use core::future::pending;
|
||||
use defmt::panic;
|
||||
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 embassy_nrf::Peripherals;
|
||||
use gpiote::{OutputChannel, OutputChannelPolarity};
|
||||
|
||||
#[embassy::main]
|
||||
|
@ -5,11 +5,11 @@
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use defmt::{panic, *};
|
||||
use defmt::*;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_nrf::pwm::{Prescaler, Pwm};
|
||||
use embassy_nrf::{interrupt, Peripherals};
|
||||
use embassy_nrf::Peripherals;
|
||||
|
||||
// for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='')
|
||||
static DUTY: [u16; 1024] = [
|
||||
|
@ -7,13 +7,11 @@ use example_common::*;
|
||||
|
||||
use core::mem;
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::panic;
|
||||
|
||||
use embassy::executor::raw::Task;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy::util::Forever;
|
||||
use embassy_nrf::peripherals;
|
||||
use embassy_nrf::{interrupt, rtc};
|
||||
|
||||
async fn run1() {
|
||||
loop {
|
||||
@ -29,23 +27,14 @@ 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 = embassy_nrf::init(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 _p = embassy_nrf::init(Default::default());
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.set_alarm(alarm);
|
||||
|
||||
let run1_task = Task::new();
|
||||
let run2_task = Task::new();
|
||||
|
@ -8,7 +8,6 @@ mod example_common;
|
||||
use embassy_nrf::Peripherals;
|
||||
use example_common::*;
|
||||
|
||||
use defmt::panic;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
|
||||
|
Reference in New Issue
Block a user