aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2021-12-10 12:46:41 +0100
committerUlf Lilleengen <[email protected]>2021-12-10 12:46:41 +0100
commite5d4d0952b78ef343f14205f5ebd3f1d7804f9e8 (patch)
tree2286467ce8c28f8eb7858d4fd33863ac52b81f65 /docs
parent9b01eed1956421dd7c0ad644f77e14a05ab92923 (diff)
Add doc-specific example and add it to CI
Diffstat (limited to 'docs')
-rw-r--r--docs/modules/ROOT/examples/basic/.cargo/config.toml6
-rw-r--r--docs/modules/ROOT/examples/basic/Cargo.toml18
-rw-r--r--docs/modules/ROOT/examples/basic/src/main.rs30
-rw-r--r--docs/modules/ROOT/pages/basic_application.adoc30
4 files changed, 62 insertions, 22 deletions
diff --git a/docs/modules/ROOT/examples/basic/.cargo/config.toml b/docs/modules/ROOT/examples/basic/.cargo/config.toml
new file mode 100644
index 000000000..c75b5c539
--- /dev/null
+++ b/docs/modules/ROOT/examples/basic/.cargo/config.toml
@@ -0,0 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip nRF52840_xxAA"
4
5[build]
6target = "thumbv7em-none-eabi"
diff --git a/docs/modules/ROOT/examples/basic/Cargo.toml b/docs/modules/ROOT/examples/basic/Cargo.toml
new file mode 100644
index 000000000..a683a28bf
--- /dev/null
+++ b/docs/modules/ROOT/examples/basic/Cargo.toml
@@ -0,0 +1,18 @@
1[package]
2authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018"
4name = "embassy-basic-example"
5version = "0.1.0"
6
7[dependencies]
8embassy = { version = "0.1.0", path = "../../../../embassy", features = ["defmt"] }
9embassy-traits = { version = "0.1.0", path = "../../../../embassy-traits", features = ["defmt"] }
10embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] }
11
12defmt = "0.3"
13defmt-rtt = "0.3"
14
15cortex-m = "0.7.3"
16cortex-m-rt = "0.7.0"
17embedded-hal = "0.2.6"
18panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/docs/modules/ROOT/examples/basic/src/main.rs b/docs/modules/ROOT/examples/basic/src/main.rs
new file mode 100644
index 000000000..0152b40bb
--- /dev/null
+++ b/docs/modules/ROOT/examples/basic/src/main.rs
@@ -0,0 +1,30 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::*;
9
10use embassy::executor::Spawner;
11use embassy::time::{Duration, Timer};
12use embassy_nrf::gpio::{Level, Output, OutputDrive};
13use embassy_nrf::Peripherals;
14use embedded_hal::digital::v2::OutputPin;
15
16#[embassy::task]
17async fn blinker(mut led: Output<'static, P0_13>, interval: Duration) {
18 loop {
19 unwrap!(led.set_high());
20 Timer::after(interval).await;
21 unwrap!(led.set_low());
22 Timer::after(interval).await;
23 }
24}
25
26#[embassy::main]
27async fn main(spawner: Spawner, p: Peripherals) {
28 let led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
29 unwrap!(spawner.spawn(blinker(led, Duration::from_millis(300))));
30}
diff --git a/docs/modules/ROOT/pages/basic_application.adoc b/docs/modules/ROOT/pages/basic_application.adoc
index 53aaa3d7d..c2849927a 100644
--- a/docs/modules/ROOT/pages/basic_application.adoc
+++ b/docs/modules/ROOT/pages/basic_application.adoc
@@ -2,8 +2,9 @@
2 2
3So you've got one of the xref:examples.adoc[examples] running, but what now? Let's go through a simple Embassy application for the nRF52 DK to understand it better. 3So you've got one of the xref:examples.adoc[examples] running, but what now? Let's go through a simple Embassy application for the nRF52 DK to understand it better.
4 4
5== Main
5 6
6== The main 7The full example can be found link:https://github.com/embassy-rs/embassy/tree/book-poc/docs/modules/ROOT/examples/basic[here].
7 8
8=== Rust Nightly 9=== Rust Nightly
9 10
@@ -11,9 +12,7 @@ The first thing you'll notice is a few declarations stating that Embassy require
11 12
12[source,rust] 13[source,rust]
13---- 14----
14#![no_std] 15include::example$basic/src/main.rs[lines="1..3"]
15#![no_main]
16#![feature(type_alias_impl_trait)]
17---- 16----
18 17
19=== Dealing with errors 18=== Dealing with errors
@@ -22,8 +21,7 @@ Then, what follows are some declarations on how to deal with panics and faults.
22 21
23[source,rust] 22[source,rust]
24---- 23----
25use defmt_rtt as _; 24include::example$basic/src/main.rs[lines="5..6"]
26use panic_probe as _;
27---- 25----
28 26
29=== Task declaration 27=== Task declaration
@@ -32,15 +30,7 @@ After a bit of import declaration, the tasks run by the application should be de
32 30
33[source,rust] 31[source,rust]
34---- 32----
35#[embassy::task] 33include::example$basic/src/main.rs[lines="16..24"]
36async fn blinker(led: Output<'static, P0_13>, interval: Duration) {
37 loop {
38 let _ = led.set_high();
39 Timer::after(interval).await;
40 let _ = led.set_low();
41 Timer::after(interval).await;
42 }
43}
44---- 34----
45 35
46An embassy task must be declared `async`, and may NOT take generic arguments. In this case, we are handed the LED that should be blinked and the interval of the blinking. 36An embassy task must be declared `async`, and may NOT take generic arguments. In this case, we are handed the LED that should be blinked and the interval of the blinking.
@@ -53,13 +43,9 @@ The main entry point of an Embassy application is defined using the `#[embassy::
53 43
54The `Spawner` is the way the main application spawns other tasks. The `Peripherals` type holds all peripherals that the application may use. In this case, we want to configure one of the pins as a GPIO output driving the LED: 44The `Spawner` is the way the main application spawns other tasks. The `Peripherals` type holds all peripherals that the application may use. In this case, we want to configure one of the pins as a GPIO output driving the LED:
55 45
56[source, rust] 46[source,rust]
57---- 47----
58#[embassy::main] 48include::example$basic/src/main.rs[lines="26..30"]
59async fn main(spawner: Spawner, p: Peripherals) {
60 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
61 let _ = spawner.spawn(blinker(led, Duration::from_millis(300)));
62}
63---- 49----
64 50
65 51
@@ -78,7 +64,7 @@ The project definition needs to contain the embassy dependencies:
78 64
79[source,toml] 65[source,toml]
80---- 66----
81include::example$examples/nrf/Cargo.toml[lines="9..11"] 67include::example$basic/Cargo.toml[lines="8..10"]
82---- 68----
83 69
84Depending on your microcontroller, you may need to replace `embassy-nrf` with something else (`embassy-stm32` for STM32. Remember to update feature flags as well). 70Depending on your microcontroller, you may need to replace `embassy-nrf` with something else (`embassy-stm32` for STM32. Remember to update feature flags as well).