2020-09-22 16:03:43 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
#[path = "../example_common.rs"]
|
|
|
|
mod example_common;
|
|
|
|
use example_common::*;
|
|
|
|
|
|
|
|
use cortex_m_rt::entry;
|
|
|
|
use futures::pin_mut;
|
|
|
|
use nrf52840_hal::gpio;
|
|
|
|
|
2020-10-19 19:15:24 +00:00
|
|
|
use embassy::executor::{task, Executor};
|
2020-10-31 21:37:24 +00:00
|
|
|
use embassy::io::{AsyncBufRead, AsyncBufReadExt, AsyncWrite, AsyncWriteExt};
|
|
|
|
use embassy::util::Forever;
|
|
|
|
use embassy_nrf::uarte;
|
2020-09-24 20:04:45 +00:00
|
|
|
|
|
|
|
#[task]
|
2020-09-22 16:03:43 +00:00
|
|
|
async fn run() {
|
|
|
|
let p = embassy_nrf::pac::Peripherals::take().dewrap();
|
|
|
|
|
|
|
|
let port0 = gpio::p0::Parts::new(p.P0);
|
|
|
|
|
|
|
|
let pins = uarte::Pins {
|
|
|
|
rxd: port0.p0_08.into_floating_input().degrade(),
|
|
|
|
txd: port0
|
|
|
|
.p0_06
|
|
|
|
.into_push_pull_output(gpio::Level::Low)
|
|
|
|
.degrade(),
|
|
|
|
cts: None,
|
|
|
|
rts: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
let u = uarte::Uarte::new(
|
|
|
|
p.UARTE0,
|
|
|
|
pins,
|
|
|
|
uarte::Parity::EXCLUDED,
|
|
|
|
uarte::Baudrate::BAUD115200,
|
|
|
|
);
|
|
|
|
pin_mut!(u);
|
|
|
|
|
|
|
|
info!("uarte initialized!");
|
|
|
|
|
|
|
|
u.write_all(b"Hello!\r\n").await.dewrap();
|
|
|
|
info!("wrote hello in uart!");
|
|
|
|
|
|
|
|
// Simple demo, reading 8-char chunks and echoing them back reversed.
|
|
|
|
loop {
|
|
|
|
info!("reading...");
|
|
|
|
let mut buf = [0u8; 8];
|
|
|
|
u.read_exact(&mut buf).await.dewrap();
|
|
|
|
info!("read done, got {:[u8]}", buf);
|
|
|
|
|
|
|
|
// Reverse buf
|
|
|
|
for i in 0..4 {
|
|
|
|
let tmp = buf[i];
|
|
|
|
buf[i] = buf[7 - i];
|
|
|
|
buf[7 - i] = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
info!("writing...");
|
|
|
|
u.write_all(&buf).await.dewrap();
|
|
|
|
info!("write done");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-31 21:37:24 +00:00
|
|
|
static EXECUTOR: Forever<Executor> = Forever::new();
|
|
|
|
|
2020-09-22 16:03:43 +00:00
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
info!("Hello World!");
|
|
|
|
|
2020-10-31 21:37:24 +00:00
|
|
|
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi));
|
|
|
|
executor.spawn(run()).dewrap();
|
2020-09-24 20:04:45 +00:00
|
|
|
|
2020-10-31 21:37:24 +00:00
|
|
|
loop {
|
|
|
|
executor.run();
|
|
|
|
cortex_m::asm::wfe();
|
2020-09-22 16:03:43 +00:00
|
|
|
}
|
|
|
|
}
|