aboutsummaryrefslogtreecommitdiff
path: root/docs/examples
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples')
-rw-r--r--docs/examples/basic/Cargo.toml4
-rw-r--r--docs/examples/basic/src/main.rs33
-rw-r--r--docs/examples/layer-by-layer/blinky-async/Cargo.toml2
-rw-r--r--docs/examples/layer-by-layer/blinky-async/src/main.rs10
-rw-r--r--docs/examples/layer-by-layer/blinky-hal/Cargo.toml2
-rw-r--r--docs/examples/layer-by-layer/blinky-irq/Cargo.toml2
-rw-r--r--docs/examples/layer-by-layer/blinky-pac/Cargo.toml2
7 files changed, 39 insertions, 16 deletions
diff --git a/docs/examples/basic/Cargo.toml b/docs/examples/basic/Cargo.toml
index b90180853..495e484f8 100644
--- a/docs/examples/basic/Cargo.toml
+++ b/docs/examples/basic/Cargo.toml
@@ -1,6 +1,6 @@
1[package] 1[package]
2authors = ["Dario Nieuwenhuis <[email protected]>"] 2authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018" 3edition = "2024"
4name = "embassy-basic-example" 4name = "embassy-basic-example"
5version = "0.1.0" 5version = "0.1.0"
6license = "MIT OR Apache-2.0" 6license = "MIT OR Apache-2.0"
@@ -9,7 +9,7 @@ publish = false
9[dependencies] 9[dependencies]
10embassy-executor = { version = "0.9.0", path = "../../../embassy-executor", features = ["defmt", "arch-cortex-m", "executor-thread"] } 10embassy-executor = { version = "0.9.0", path = "../../../embassy-executor", features = ["defmt", "arch-cortex-m", "executor-thread"] }
11embassy-time = { version = "0.5.0", path = "../../../embassy-time", features = ["defmt"] } 11embassy-time = { version = "0.5.0", path = "../../../embassy-time", features = ["defmt"] }
12embassy-nrf = { version = "0.8.0", path = "../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } 12embassy-nrf = { version = "0.9.0", path = "../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] }
13 13
14defmt = "1.0.1" 14defmt = "1.0.1"
15defmt-rtt = "1.0.0" 15defmt-rtt = "1.0.0"
diff --git a/docs/examples/basic/src/main.rs b/docs/examples/basic/src/main.rs
index 6e274bacb..42797612c 100644
--- a/docs/examples/basic/src/main.rs
+++ b/docs/examples/basic/src/main.rs
@@ -3,24 +3,41 @@
3 3
4use defmt::*; 4use defmt::*;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_nrf::gpio::{Level, Output, OutputDrive}; 6use embassy_nrf::Peri;
7use embassy_time::{Duration, Timer}; 7use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pull};
8use {defmt_rtt as _, panic_probe as _}; // global logger 8use embassy_time::Timer;
9use {defmt_rtt as _, panic_probe as _};
9 10
11// Declare async tasks
10#[embassy_executor::task] 12#[embassy_executor::task]
11async fn blinker(mut led: Output<'static>, interval: Duration) { 13async fn blink(pin: Peri<'static, AnyPin>) {
14 let mut led = Output::new(pin, Level::Low, OutputDrive::Standard);
15
12 loop { 16 loop {
17 // Timekeeping is globally available, no need to mess with hardware timers.
13 led.set_high(); 18 led.set_high();
14 Timer::after(interval).await; 19 Timer::after_millis(150).await;
15 led.set_low(); 20 led.set_low();
16 Timer::after(interval).await; 21 Timer::after_millis(150).await;
17 } 22 }
18} 23}
19 24
25// Main is itself an async task as well.
20#[embassy_executor::main] 26#[embassy_executor::main]
21async fn main(spawner: Spawner) { 27async fn main(spawner: Spawner) {
28 // Initialize the embassy-nrf HAL.
22 let p = embassy_nrf::init(Default::default()); 29 let p = embassy_nrf::init(Default::default());
23 30
24 let led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); 31 // Spawned tasks run in the background, concurrently.
25 spawner.spawn(unwrap!(blinker(led, Duration::from_millis(300)))); 32 spawner.spawn(blink(p.P0_13.into()).unwrap());
33
34 let mut button = Input::new(p.P0_11, Pull::Up);
35 loop {
36 // Asynchronously wait for GPIO events, allowing other tasks
37 // to run, or the core to sleep.
38 button.wait_for_low().await;
39 info!("Button pressed!");
40 button.wait_for_high().await;
41 info!("Button released!");
42 }
26} 43}
diff --git a/docs/examples/layer-by-layer/blinky-async/Cargo.toml b/docs/examples/layer-by-layer/blinky-async/Cargo.toml
index ec718022c..797ae3097 100644
--- a/docs/examples/layer-by-layer/blinky-async/Cargo.toml
+++ b/docs/examples/layer-by-layer/blinky-async/Cargo.toml
@@ -1,7 +1,7 @@
1[package] 1[package]
2name = "blinky-async" 2name = "blinky-async"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2024"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
6 6
7publish = false 7publish = false
diff --git a/docs/examples/layer-by-layer/blinky-async/src/main.rs b/docs/examples/layer-by-layer/blinky-async/src/main.rs
index 004602816..007f7da46 100644
--- a/docs/examples/layer-by-layer/blinky-async/src/main.rs
+++ b/docs/examples/layer-by-layer/blinky-async/src/main.rs
@@ -2,15 +2,21 @@
2#![no_main] 2#![no_main]
3 3
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_stm32::exti::ExtiInput; 5use embassy_stm32::exti::{self, ExtiInput};
6use embassy_stm32::gpio::{Level, Output, Pull, Speed}; 6use embassy_stm32::gpio::{Level, Output, Pull, Speed};
7use embassy_stm32::{bind_interrupts, interrupt};
7use {defmt_rtt as _, panic_probe as _}; 8use {defmt_rtt as _, panic_probe as _};
8 9
10bind_interrupts!(
11 pub struct Irqs{
12 EXTI15_10 => exti::InterruptHandler<interrupt::typelevel::EXTI15_10 >;
13});
14
9#[embassy_executor::main] 15#[embassy_executor::main]
10async fn main(_spawner: Spawner) { 16async fn main(_spawner: Spawner) {
11 let p = embassy_stm32::init(Default::default()); 17 let p = embassy_stm32::init(Default::default());
12 let mut led = Output::new(p.PB14, Level::Low, Speed::VeryHigh); 18 let mut led = Output::new(p.PB14, Level::Low, Speed::VeryHigh);
13 let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); 19 let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up, Irqs);
14 20
15 loop { 21 loop {
16 button.wait_for_any_edge().await; 22 button.wait_for_any_edge().await;
diff --git a/docs/examples/layer-by-layer/blinky-hal/Cargo.toml b/docs/examples/layer-by-layer/blinky-hal/Cargo.toml
index 4a0b03a83..802b8b32e 100644
--- a/docs/examples/layer-by-layer/blinky-hal/Cargo.toml
+++ b/docs/examples/layer-by-layer/blinky-hal/Cargo.toml
@@ -1,7 +1,7 @@
1[package] 1[package]
2name = "blinky-hal" 2name = "blinky-hal"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2024"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
6 6
7publish = false 7publish = false
diff --git a/docs/examples/layer-by-layer/blinky-irq/Cargo.toml b/docs/examples/layer-by-layer/blinky-irq/Cargo.toml
index 3c4bf8446..d1b893a1e 100644
--- a/docs/examples/layer-by-layer/blinky-irq/Cargo.toml
+++ b/docs/examples/layer-by-layer/blinky-irq/Cargo.toml
@@ -3,7 +3,7 @@
3[package] 3[package]
4name = "blinky-irq" 4name = "blinky-irq"
5version = "0.1.0" 5version = "0.1.0"
6edition = "2021" 6edition = "2024"
7license = "MIT OR Apache-2.0" 7license = "MIT OR Apache-2.0"
8 8
9publish = false 9publish = false
diff --git a/docs/examples/layer-by-layer/blinky-pac/Cargo.toml b/docs/examples/layer-by-layer/blinky-pac/Cargo.toml
index 0d4711da2..fa093a3af 100644
--- a/docs/examples/layer-by-layer/blinky-pac/Cargo.toml
+++ b/docs/examples/layer-by-layer/blinky-pac/Cargo.toml
@@ -1,7 +1,7 @@
1[package] 1[package]
2name = "blinky-pac" 2name = "blinky-pac"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2024"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
6 6
7publish = false 7publish = false