Skip to content

Commit 66d51fc

Browse files
committed
update package
- Add embassy example - improve timer API - restructure examples
1 parent 405cc08 commit 66d51fc

File tree

20 files changed

+645
-149
lines changed

20 files changed

+645
-149
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ members = [
55
"va108xx",
66
"va108xx-hal",
77
"examples/simple",
8+
"examples/rtic",
9+
"examples/embassy",
810
"board-tests",
911
]
1012

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ This workspace contains the following released crates:
1919

2020
It also contains the following helper crates:
2121

22-
- The `board-tests` contains an application which can be used to test the libraries on the
23-
board.
24-
- The `examples` crates contains various example applications for the HAL and the PAC.
22+
- The [`board-tests`](https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/src/branch/main/board-tests)
23+
contains an application which can be used to test the libraries on the board.
24+
- The [`examples`](https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/src/branch/main/examples)
25+
folder contains various example applications crates using the HAL and the PAC.
26+
This folder also contains dedicated example applications using the
27+
[`RTIC`](https://rtic.rs/2/book/en/) and [`embassy`](https://github.com/embassy-rs/embassy)
28+
native Rust RTOSes.
2529

2630
## Using the `.cargo/config.toml` file
2731

board-tests/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
cortex-m-rtic = "1"
8-
panic-halt = "0.2"
97
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
108
cortex-m-rt = "0.7"
9+
panic-halt = "0.2"
1110
rtt-target = "0.5"
1211
panic-rtt-target = "0.1.3"
1312
embedded-hal = "1"

examples/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
VA108xx Example Applications
2+
========
3+
4+
This folder contains various examples
5+
Consult the main README first for setup of the repository.
6+
7+
## Simple examples
8+
9+
```rs
10+
cargo run --example blinky
11+
```
12+
13+
You can have a look at the `simple/examples` folder to see all available simple examples
14+
15+
## RTIC example
16+
17+
```rs
18+
cargo run --bin rtic-example
19+
```
20+
21+
## Embassy example
22+
23+
```rs
24+
cargo run --bin embassy-example
25+
```

examples/embassy/Cargo.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
name = "embassy-example"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
8+
cortex-m-rt = "0.7"
9+
embedded-hal = "1"
10+
11+
rtt-target = { version = "0.5" }
12+
panic-rtt-target = { version = "0.1" }
13+
critical-section = "1"
14+
portable-atomic = { version = "1", features = ["unsafe-assume-single-core"]}
15+
16+
embassy-sync = { version = "0.6.0" }
17+
embassy-time = { version = "0.3.2" }
18+
embassy-time-driver = { version = "0.1" }
19+
20+
[dependencies.once_cell]
21+
version = "1"
22+
default-features = false
23+
features = ["critical-section"]
24+
25+
[dependencies.embassy-executor]
26+
version = "0.6.0"
27+
features = [
28+
"arch-cortex-m",
29+
"executor-thread",
30+
"executor-interrupt",
31+
"integrated-timers",
32+
]
33+
34+
[dependencies.va108xx-hal]
35+
path = "../../va108xx-hal"
36+
37+
[features]
38+
default = ["ticks-hz-1_000"]
39+
ticks-hz-1_000 = ["embassy-time/tick-hz-1_000"]
40+
ticks-hz-32_768 = ["embassy-time/tick-hz-32_768"]

examples/embassy/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![no_std]
2+
pub mod time_driver;
3+
4+
pub use time_driver::init;

examples/embassy/src/main.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![no_std]
2+
#![no_main]
3+
use embassy_executor::Spawner;
4+
use embassy_time::{Duration, Instant, Ticker};
5+
use embedded_hal::digital::StatefulOutputPin;
6+
use panic_rtt_target as _;
7+
use rtt_target::{rprintln, rtt_init_print};
8+
use va108xx_hal::{gpio::PinsA, pac, prelude::*};
9+
10+
const SYSCLK_FREQ: Hertz = Hertz::from_raw(50_000_000);
11+
12+
// main is itself an async function.
13+
#[embassy_executor::main]
14+
async fn main(_spawner: Spawner) {
15+
rtt_init_print!();
16+
rprintln!("-- VA108xx Embassy Demo --");
17+
18+
let mut dp = pac::Peripherals::take().unwrap();
19+
20+
// Safety: Only called once here.
21+
unsafe { embassy_example::init(&mut dp.sysconfig, SYSCLK_FREQ, dp.tim23, dp.tim22) };
22+
23+
let porta = PinsA::new(&mut dp.sysconfig, Some(dp.ioconfig), dp.porta);
24+
let mut led0 = porta.pa10.into_readable_push_pull_output();
25+
let mut led1 = porta.pa7.into_readable_push_pull_output();
26+
let mut led2 = porta.pa6.into_readable_push_pull_output();
27+
let mut ticker = Ticker::every(Duration::from_secs(1));
28+
loop {
29+
ticker.next().await;
30+
rprintln!("Current time: {}", Instant::now().as_secs());
31+
led0.toggle().ok();
32+
led1.toggle().ok();
33+
led2.toggle().ok();
34+
}
35+
}

0 commit comments

Comments
 (0)