mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-10-29 21:30:54 +00:00
Reduce amount of samples for nrf5340
This commit is contained in:
parent
0a27b6cedb
commit
2baebabf4d
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -13,7 +13,8 @@
|
||||
// Declare for the target you wish to develop
|
||||
// "embassy-executor/Cargo.toml",
|
||||
// "embassy-sync/Cargo.toml",
|
||||
"examples/nrf/Cargo.toml",
|
||||
"examples/nrf52840/Cargo.toml",
|
||||
//"examples/nrf5340/Cargo.toml",
|
||||
// "examples/nrf-rtos-trace/Cargo.toml",
|
||||
// "examples/rp/Cargo.toml",
|
||||
// "examples/std/Cargo.toml",
|
||||
|
@ -1,26 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::interrupt;
|
||||
use embassy_nrf::timer::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut t = Timer::new_awaitable(p.TIMER0, interrupt::take!(TIMER0));
|
||||
// default frequency is 1MHz, so this triggers every second
|
||||
t.cc(0).write(1_000_000);
|
||||
// clear the timer value on cc[0] compare match
|
||||
t.cc(0).short_compare_clear();
|
||||
t.start();
|
||||
|
||||
loop {
|
||||
// wait for compare match
|
||||
t.cc(0).wait().await;
|
||||
info!("hardware timer tick");
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::buffered_uarte::{BufferedUarte, State};
|
||||
use embassy_nrf::{interrupt, uarte};
|
||||
use embedded_io::asynch::{BufRead, Write};
|
||||
use futures::pin_mut;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut config = uarte::Config::default();
|
||||
config.parity = uarte::Parity::EXCLUDED;
|
||||
config.baudrate = uarte::Baudrate::BAUD115200;
|
||||
|
||||
let mut tx_buffer = [0u8; 4096];
|
||||
let mut rx_buffer = [0u8; 4096];
|
||||
|
||||
let irq = interrupt::take!(SERIAL0);
|
||||
let mut state = State::new();
|
||||
// Please note - important to have hardware flow control (https://github.com/embassy-rs/embassy/issues/536)
|
||||
let u = BufferedUarte::new(
|
||||
&mut state,
|
||||
p.UARTETWISPI0,
|
||||
p.TIMER0,
|
||||
p.PPI_CH0,
|
||||
p.PPI_CH1,
|
||||
irq,
|
||||
p.P0_08,
|
||||
p.P0_06,
|
||||
p.P0_07,
|
||||
p.P0_05,
|
||||
config,
|
||||
&mut rx_buffer,
|
||||
&mut tx_buffer,
|
||||
);
|
||||
pin_mut!(u);
|
||||
|
||||
info!("uarte initialized!");
|
||||
|
||||
unwrap!(u.write_all(b"Hello!\r\n").await);
|
||||
info!("wrote hello in uart!");
|
||||
|
||||
loop {
|
||||
info!("reading...");
|
||||
let buf = unwrap!(u.fill_buf().await);
|
||||
info!("read done, got {}", buf);
|
||||
|
||||
// Read bytes have to be explicitly consumed, otherwise fill_buf() will return them again
|
||||
let n = buf.len();
|
||||
u.consume(n);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::unwrap;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
|
||||
use embassy_sync::channel::Channel;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
enum LedState {
|
||||
On,
|
||||
Off,
|
||||
}
|
||||
|
||||
static CHANNEL: Channel<ThreadModeRawMutex, LedState, 1> = Channel::new();
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn my_task() {
|
||||
loop {
|
||||
CHANNEL.send(LedState::On).await;
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
CHANNEL.send(LedState::Off).await;
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut led = Output::new(p.P0_28, Level::Low, OutputDrive::Standard);
|
||||
|
||||
unwrap!(spawner.spawn(my_task()));
|
||||
|
||||
loop {
|
||||
match CHANNEL.recv().await {
|
||||
LedState::On => led.set_high(),
|
||||
LedState::Off => led.set_low(),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::unwrap;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin};
|
||||
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
|
||||
use embassy_sync::channel::{Channel, Receiver, Sender};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use static_cell::StaticCell;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
enum LedState {
|
||||
On,
|
||||
Off,
|
||||
}
|
||||
|
||||
static CHANNEL: StaticCell<Channel<NoopRawMutex, LedState, 1>> = StaticCell::new();
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) {
|
||||
loop {
|
||||
sender.send(LedState::On).await;
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
sender.send(LedState::Off).await;
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedState, 1>) {
|
||||
let mut led = Output::new(led, Level::Low, OutputDrive::Standard);
|
||||
|
||||
loop {
|
||||
match receiver.recv().await {
|
||||
LedState::On => led.set_high(),
|
||||
LedState::Off => led.set_low(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let channel = CHANNEL.init(Channel::new());
|
||||
|
||||
unwrap!(spawner.spawn(send_task(channel.sender())));
|
||||
unwrap!(spawner.spawn(recv_task(p.P0_28.degrade(), channel.receiver())));
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::task(pool_size = 4)]
|
||||
async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) {
|
||||
loop {
|
||||
pin.wait_for_low().await;
|
||||
info!("Button {:?} pressed!", n);
|
||||
pin.wait_for_high().await;
|
||||
info!("Button {:?} released!", n);
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
info!("Starting!");
|
||||
|
||||
let btn1 = Input::new(p.P0_23.degrade(), Pull::Up);
|
||||
let btn2 = Input::new(p.P0_24.degrade(), Pull::Up);
|
||||
let btn3 = Input::new(p.P0_08.degrade(), Pull::Up);
|
||||
let btn4 = Input::new(p.P0_09.degrade(), Pull::Up);
|
||||
|
||||
unwrap!(spawner.spawn(button_task(1, btn1)));
|
||||
unwrap!(spawner.spawn(button_task(2, btn2)));
|
||||
unwrap!(spawner.spawn(button_task(3, btn3)));
|
||||
unwrap!(spawner.spawn(button_task(4, btn4)));
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::{interrupt, uarte};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut config = uarte::Config::default();
|
||||
config.parity = uarte::Parity::EXCLUDED;
|
||||
config.baudrate = uarte::Baudrate::BAUD115200;
|
||||
|
||||
let irq = interrupt::take!(SERIAL0);
|
||||
let uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P0_08, p.P0_06, config);
|
||||
let (mut tx, mut rx) = uart.split_with_idle(p.TIMER0, p.PPI_CH0, p.PPI_CH1);
|
||||
|
||||
info!("uarte initialized!");
|
||||
|
||||
// Message must be in SRAM
|
||||
let mut buf = [0; 8];
|
||||
buf.copy_from_slice(b"Hello!\r\n");
|
||||
|
||||
unwrap!(tx.write(&buf).await);
|
||||
info!("wrote hello in uart!");
|
||||
|
||||
loop {
|
||||
info!("reading...");
|
||||
let n = unwrap!(rx.read_until_idle(&mut buf).await);
|
||||
info!("got {} bytes", n);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::peripherals::UARTETWISPI0;
|
||||
use embassy_nrf::uarte::UarteRx;
|
||||
use embassy_nrf::{interrupt, uarte};
|
||||
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
|
||||
use embassy_sync::channel::Channel;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new();
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut config = uarte::Config::default();
|
||||
config.parity = uarte::Parity::EXCLUDED;
|
||||
config.baudrate = uarte::Baudrate::BAUD115200;
|
||||
|
||||
let irq = interrupt::take!(SERIAL0);
|
||||
let uart = uarte::Uarte::new(p.UARTETWISPI0, irq, p.P1_00, p.P1_01, config);
|
||||
let (mut tx, rx) = uart.split();
|
||||
|
||||
info!("uarte initialized!");
|
||||
|
||||
// Spawn a task responsible purely for reading
|
||||
|
||||
unwrap!(spawner.spawn(reader(rx)));
|
||||
|
||||
// Message must be in SRAM
|
||||
{
|
||||
let mut buf = [0; 23];
|
||||
buf.copy_from_slice(b"Type 8 chars to echo!\r\n");
|
||||
|
||||
unwrap!(tx.write(&buf).await);
|
||||
info!("wrote hello in uart!");
|
||||
}
|
||||
|
||||
// Continue reading in this main task and write
|
||||
// back out the buffer we receive from the read
|
||||
// task.
|
||||
loop {
|
||||
let buf = CHANNEL.recv().await;
|
||||
info!("writing...");
|
||||
unwrap!(tx.write(&buf).await);
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn reader(mut rx: UarteRx<'static, UARTETWISPI0>) {
|
||||
let mut buf = [0; 8];
|
||||
loop {
|
||||
info!("reading...");
|
||||
unwrap!(rx.read(&mut buf).await);
|
||||
CHANNEL.send(buf).await;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user