diff options
| author | Raul Alimbekov <[email protected]> | 2025-12-16 09:05:22 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-16 09:05:22 +0300 |
| commit | c9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch) | |
| tree | 6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /docs/examples | |
| parent | cde24a3ef1117653ba5ed4184102b33f745782fb (diff) | |
| parent | 5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff) | |
Merge branch 'main' into main
Diffstat (limited to 'docs/examples')
| -rw-r--r-- | docs/examples/basic/Cargo.toml | 4 | ||||
| -rw-r--r-- | docs/examples/basic/src/main.rs | 33 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-async/Cargo.toml | 2 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-async/src/main.rs | 10 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-hal/Cargo.toml | 2 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-irq/Cargo.toml | 2 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-pac/Cargo.toml | 2 |
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] |
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] | 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] |
| 3 | edition = "2018" | 3 | edition = "2024" |
| 4 | name = "embassy-basic-example" | 4 | name = "embassy-basic-example" |
| 5 | version = "0.1.0" | 5 | version = "0.1.0" |
| 6 | license = "MIT OR Apache-2.0" | 6 | license = "MIT OR Apache-2.0" |
| @@ -9,7 +9,7 @@ publish = false | |||
| 9 | [dependencies] | 9 | [dependencies] |
| 10 | embassy-executor = { version = "0.9.0", path = "../../../embassy-executor", features = ["defmt", "arch-cortex-m", "executor-thread"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../embassy-executor", features = ["defmt", "arch-cortex-m", "executor-thread"] } |
| 11 | embassy-time = { version = "0.5.0", path = "../../../embassy-time", features = ["defmt"] } | 11 | embassy-time = { version = "0.5.0", path = "../../../embassy-time", features = ["defmt"] } |
| 12 | embassy-nrf = { version = "0.8.0", path = "../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } | 12 | embassy-nrf = { version = "0.9.0", path = "../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } |
| 13 | 13 | ||
| 14 | defmt = "1.0.1" | 14 | defmt = "1.0.1" |
| 15 | defmt-rtt = "1.0.0" | 15 | defmt-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 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 6 | use embassy_nrf::Peri; |
| 7 | use embassy_time::{Duration, Timer}; | 7 | use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pull}; |
| 8 | use {defmt_rtt as _, panic_probe as _}; // global logger | 8 | use embassy_time::Timer; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | 10 | ||
| 11 | // Declare async tasks | ||
| 10 | #[embassy_executor::task] | 12 | #[embassy_executor::task] |
| 11 | async fn blinker(mut led: Output<'static>, interval: Duration) { | 13 | async 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] |
| 21 | async fn main(spawner: Spawner) { | 27 | async 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] |
| 2 | name = "blinky-async" | 2 | name = "blinky-async" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2024" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | publish = false | 7 | publish = 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 | ||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use embassy_stm32::exti::ExtiInput; | 5 | use embassy_stm32::exti::{self, ExtiInput}; |
| 6 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; | 6 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 7 | use embassy_stm32::{bind_interrupts, interrupt}; | ||
| 7 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 8 | 9 | ||
| 10 | bind_interrupts!( | ||
| 11 | pub struct Irqs{ | ||
| 12 | EXTI15_10 => exti::InterruptHandler<interrupt::typelevel::EXTI15_10 >; | ||
| 13 | }); | ||
| 14 | |||
| 9 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
| 10 | async fn main(_spawner: Spawner) { | 16 | async 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] |
| 2 | name = "blinky-hal" | 2 | name = "blinky-hal" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2024" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | publish = false | 7 | publish = 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] |
| 4 | name = "blinky-irq" | 4 | name = "blinky-irq" |
| 5 | version = "0.1.0" | 5 | version = "0.1.0" |
| 6 | edition = "2021" | 6 | edition = "2024" |
| 7 | license = "MIT OR Apache-2.0" | 7 | license = "MIT OR Apache-2.0" |
| 8 | 8 | ||
| 9 | publish = false | 9 | publish = 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] |
| 2 | name = "blinky-pac" | 2 | name = "blinky-pac" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2024" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | publish = false | 7 | publish = false |
