Update examples.
This commit is contained in:
parent
76196c424a
commit
b3858441f7
@ -26,5 +26,5 @@ panic-probe = "0.1.0"
|
|||||||
nrf52840-hal = { version = "0.11.0" }
|
nrf52840-hal = { version = "0.11.0" }
|
||||||
embassy = { version = "0.1.0", path = "../embassy" }
|
embassy = { version = "0.1.0", path = "../embassy" }
|
||||||
embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt-trace", "52840"] }
|
embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt-trace", "52840"] }
|
||||||
futures = { version = "0.3.5", default-features = false }
|
futures = { version = "0.3.7", default-features = false, features = ["async-await"] }
|
||||||
cortex-m-rtic = { git = "https://github.com/rtic-rs/cortex-m-rtic", branch = "master"}
|
cortex-m-rtic = { git = "https://github.com/rtic-rs/cortex-m-rtic", branch = "master"}
|
@ -6,15 +6,12 @@
|
|||||||
mod example_common;
|
mod example_common;
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
use core::pin::Pin;
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use embassy::io::{AsyncBufRead, AsyncBufReadExt, AsyncWrite, AsyncWriteExt};
|
|
||||||
use embassy_nrf::gpiote;
|
|
||||||
use futures::pin_mut;
|
|
||||||
use nrf52840_hal::gpio;
|
use nrf52840_hal::gpio;
|
||||||
|
|
||||||
use embassy::executor::{task, Executor};
|
use embassy::executor::{task, Executor};
|
||||||
static EXECUTOR: Executor = Executor::new(|| cortex_m::asm::sev());
|
use embassy::util::Forever;
|
||||||
|
use embassy_nrf::gpiote;
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
async fn run() {
|
async fn run() {
|
||||||
@ -28,7 +25,7 @@ async fn run() {
|
|||||||
let pin1 = port0.p0_11.into_pullup_input().degrade();
|
let pin1 = port0.p0_11.into_pullup_input().degrade();
|
||||||
let button1 = async {
|
let button1 = async {
|
||||||
let ch = g
|
let ch = g
|
||||||
.new_input_channel(&pin1, gpiote::EventPolarity::HiToLo)
|
.new_input_channel(pin1, gpiote::EventPolarity::HiToLo)
|
||||||
.dewrap();
|
.dewrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@ -40,7 +37,7 @@ async fn run() {
|
|||||||
let pin2 = port0.p0_12.into_pullup_input().degrade();
|
let pin2 = port0.p0_12.into_pullup_input().degrade();
|
||||||
let button2 = async {
|
let button2 = async {
|
||||||
let ch = g
|
let ch = g
|
||||||
.new_input_channel(&pin2, gpiote::EventPolarity::LoToHi)
|
.new_input_channel(pin2, gpiote::EventPolarity::LoToHi)
|
||||||
.dewrap();
|
.dewrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@ -52,7 +49,7 @@ async fn run() {
|
|||||||
let pin3 = port0.p0_24.into_pullup_input().degrade();
|
let pin3 = port0.p0_24.into_pullup_input().degrade();
|
||||||
let button3 = async {
|
let button3 = async {
|
||||||
let ch = g
|
let ch = g
|
||||||
.new_input_channel(&pin3, gpiote::EventPolarity::Toggle)
|
.new_input_channel(pin3, gpiote::EventPolarity::Toggle)
|
||||||
.dewrap();
|
.dewrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@ -64,7 +61,7 @@ async fn run() {
|
|||||||
let pin4 = port0.p0_25.into_pullup_input().degrade();
|
let pin4 = port0.p0_25.into_pullup_input().degrade();
|
||||||
let button4 = async {
|
let button4 = async {
|
||||||
let ch = g
|
let ch = g
|
||||||
.new_input_channel(&pin4, gpiote::EventPolarity::Toggle)
|
.new_input_channel(pin4, gpiote::EventPolarity::Toggle)
|
||||||
.dewrap();
|
.dewrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@ -76,16 +73,17 @@ async fn run() {
|
|||||||
futures::join!(button1, button2, button3, button4);
|
futures::join!(button1, button2, button3, button4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
unsafe {
|
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi));
|
||||||
EXECUTOR.spawn(run()).dewrap();
|
executor.spawn(run()).dewrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
EXECUTOR.run();
|
executor.run();
|
||||||
cortex_m::asm::wfe();
|
cortex_m::asm::wfe();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,8 @@ async fn run_med() {
|
|||||||
cortex_m::asm::delay(32_000_000); // ~1 second
|
cortex_m::asm::delay(32_000_000); // ~1 second
|
||||||
|
|
||||||
let end = Instant::now();
|
let end = Instant::now();
|
||||||
let ms = end.duration_since(start).into_ticks() / 33;
|
let ms = end.duration_since(start).as_ticks() / 33;
|
||||||
info!(" [med] done in {:u32} ms", ms);
|
info!(" [med] done in {:u64} ms", ms);
|
||||||
|
|
||||||
Timer::after(Duration::from_ticks(23421)).await;
|
Timer::after(Duration::from_ticks(23421)).await;
|
||||||
}
|
}
|
||||||
@ -103,8 +103,8 @@ async fn run_low() {
|
|||||||
cortex_m::asm::delay(64_000_000); // ~2 seconds
|
cortex_m::asm::delay(64_000_000); // ~2 seconds
|
||||||
|
|
||||||
let end = Instant::now();
|
let end = Instant::now();
|
||||||
let ms = end.duration_since(start).into_ticks() / 33;
|
let ms = end.duration_since(start).as_ticks() / 33;
|
||||||
info!("[low] done in {:u32} ms", ms);
|
info!("[low] done in {:u64} ms", ms);
|
||||||
|
|
||||||
Timer::after(Duration::from_ticks(32983)).await;
|
Timer::after(Duration::from_ticks(32983)).await;
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@ mod example_common;
|
|||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use embassy::flash::Flash;
|
|
||||||
use embassy_nrf::qspi;
|
|
||||||
use nrf52840_hal::gpio;
|
use nrf52840_hal::gpio;
|
||||||
|
|
||||||
use embassy::executor::{task, Executor};
|
use embassy::executor::{task, Executor};
|
||||||
static EXECUTOR: Executor = Executor::new(|| cortex_m::asm::sev());
|
use embassy::flash::Flash;
|
||||||
|
use embassy::util::Forever;
|
||||||
|
use embassy_nrf::qspi;
|
||||||
|
|
||||||
const PAGE_SIZE: usize = 4096;
|
const PAGE_SIZE: usize = 4096;
|
||||||
|
|
||||||
@ -115,16 +115,17 @@ async fn run() {
|
|||||||
info!("done!")
|
info!("done!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
unsafe {
|
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi));
|
||||||
EXECUTOR.spawn(run()).dewrap();
|
executor.spawn(run()).dewrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
EXECUTOR.run();
|
executor.run();
|
||||||
cortex_m::asm::wfe();
|
cortex_m::asm::wfe();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,13 @@ use example_common::*;
|
|||||||
|
|
||||||
use core::mem::MaybeUninit;
|
use core::mem::MaybeUninit;
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use embassy::executor::{task, Executor};
|
use nrf52840_hal::clocks;
|
||||||
|
|
||||||
|
use embassy::executor::{task, TimerExecutor};
|
||||||
use embassy::time::{Clock, Duration, Timer};
|
use embassy::time::{Clock, Duration, Timer};
|
||||||
|
use embassy::util::Forever;
|
||||||
use embassy_nrf::pac;
|
use embassy_nrf::pac;
|
||||||
use embassy_nrf::rtc;
|
use embassy_nrf::rtc;
|
||||||
use nrf52840_hal::clocks;
|
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
async fn run1() {
|
async fn run1() {
|
||||||
@ -30,8 +32,8 @@ async fn run2() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut RTC: MaybeUninit<rtc::RTC<pac::RTC1>> = MaybeUninit::uninit();
|
static RTC: Forever<rtc::RTC<pac::RTC1>> = Forever::new();
|
||||||
static mut EXECUTOR: MaybeUninit<Executor<rtc::Alarm<pac::RTC1>>> = MaybeUninit::uninit();
|
static EXECUTOR: Forever<TimerExecutor<rtc::Alarm<pac::RTC1>>> = Forever::new();
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
@ -44,28 +46,18 @@ fn main() -> ! {
|
|||||||
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
|
.set_lfclk_src_external(clocks::LfOscConfiguration::NoExternalNoBypass)
|
||||||
.start_lfclk();
|
.start_lfclk();
|
||||||
|
|
||||||
let rtc: &'static _ = unsafe {
|
let rtc = RTC.put(rtc::RTC::new(p.RTC1));
|
||||||
let ptr = RTC.as_mut_ptr();
|
|
||||||
ptr.write(rtc::RTC::new(p.RTC1));
|
|
||||||
&*ptr
|
|
||||||
};
|
|
||||||
|
|
||||||
rtc.start();
|
rtc.start();
|
||||||
|
|
||||||
unsafe { embassy::time::set_clock(rtc) };
|
unsafe { embassy::time::set_clock(rtc) };
|
||||||
|
|
||||||
let executor: &'static _ = unsafe {
|
let executor = EXECUTOR.put(TimerExecutor::new(rtc.alarm0(), cortex_m::asm::sev));
|
||||||
let ptr = EXECUTOR.as_mut_ptr();
|
|
||||||
ptr.write(Executor::new(rtc.alarm0(), cortex_m::asm::sev));
|
|
||||||
&*ptr
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
executor.spawn(run1()).dewrap();
|
||||||
executor.spawn(run1()).dewrap();
|
executor.spawn(run2()).dewrap();
|
||||||
executor.spawn(run2()).dewrap();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
executor.run();
|
executor.run();
|
||||||
cortex_m::asm::wfe();
|
cortex_m::asm::wfe();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,13 @@ mod example_common;
|
|||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use embassy::io::{AsyncBufRead, AsyncBufReadExt, AsyncWrite, AsyncWriteExt};
|
|
||||||
use embassy_nrf::uarte;
|
|
||||||
use futures::pin_mut;
|
use futures::pin_mut;
|
||||||
use nrf52840_hal::gpio;
|
use nrf52840_hal::gpio;
|
||||||
|
|
||||||
use embassy::executor::{task, Executor};
|
use embassy::executor::{task, Executor};
|
||||||
static EXECUTOR: Executor = Executor::new(|| cortex_m::asm::sev());
|
use embassy::io::{AsyncBufRead, AsyncBufReadExt, AsyncWrite, AsyncWriteExt};
|
||||||
|
use embassy::util::Forever;
|
||||||
|
use embassy_nrf::uarte;
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
async fn run() {
|
async fn run() {
|
||||||
@ -64,16 +64,17 @@ async fn run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
unsafe {
|
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi));
|
||||||
EXECUTOR.spawn(run()).dewrap();
|
executor.spawn(run()).dewrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
EXECUTOR.run();
|
executor.run();
|
||||||
cortex_m::asm::wfe();
|
cortex_m::asm::wfe();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user