Skip to content

Commit

Permalink
feat(embassy): provide a GPIO API unified across architectures (futur…
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 authored Jul 17, 2024
2 parents 50bbc81 + e1d2450 commit 0306391
Show file tree
Hide file tree
Showing 41 changed files with 2,232 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
args: --verbose --locked --features no-boards -p riot-rs -p riot-rs-boards -p riot-rs-chips -p riot-rs-debug -p riot-rs-embassy -p riot-rs-macros -p riot-rs-random -p riot-rs-rt -p riot-rs-threads -p riot-rs-utils

- name: rustdoc
run: RUSTDOCFLAGS='-D warnings' cargo doc -p riot-rs --features no-boards,bench,threading,random,csprng,hwrng
run: RUSTDOCFLAGS='-D warnings' cargo doc -p riot-rs --features no-boards,bench,external-interrupts,threading,random,csprng,hwrng

- name: rustfmt
run: cargo fmt --check --all
Expand Down
68 changes: 61 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ members = [
"src/riot-rs-macros",
"src/riot-rs-random",
"tests/benchmarks/bench_sched_yield",
"tests/gpio",
"tests/gpio-interrupt-nrf",
"tests/gpio-interrupt-stm32",
]

exclude = ["src/lib"]
Expand Down Expand Up @@ -43,6 +46,8 @@ portable-atomic = { version = "1.6.0", default-features = false, features = [
] }

embassy-executor = { version = "0.5", default-features = false }
embassy-futures = { version = "0.1.1", default-features = false }
embassy-hal-internal = { version = "0.1.0", default-features = false }
embassy-net = { version = "0.4", default-features = false }
embassy-net-driver-channel = { version = "0.2.0", default-features = false }
embassy-nrf = { version = "0.1", default-features = false }
Expand All @@ -52,6 +57,9 @@ embassy-sync = { version = "0.6", default-features = false }
embassy-time = { version = "0.3", default-features = false }
embassy-usb = { version = "0.1", default-features = false }

embedded-hal = { version = "1.0.0", default-features = false }
embedded-hal-async = { version = "1.0.0", default-features = false }

esp-hal = { git = "https://github.com/kaspar030/esp-hal", branch = "for-riot-rs-2024-06-14", default-features = false }
esp-hal-embassy = { git = "https://github.com/kaspar030/esp-hal", branch = "for-riot-rs-2024-06-14", default-features = false }
esp-println = { version = "0.9.0" }
Expand Down
1 change: 1 addition & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[default.extend-words]
hax = "hax"
hsi = "hsi"
extint = "extint" # External interrupt

[default.extend-identifiers]
celcius = "celcius" # Until embedded-aht20 is fixed
Expand Down
18 changes: 18 additions & 0 deletions examples/blinky/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "blinky"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
publish = false

[lints]
workspace = true

[dependencies]
embassy-executor = { workspace = true }
embassy-time = { workspace = true }
riot-rs = { path = "../../src/riot-rs", features = [
"external-interrupts",
"time",
] }
riot-rs-boards = { path = "../../src/riot-rs-boards" }
11 changes: 11 additions & 0 deletions examples/blinky/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# blinky

## About

This application is demonstrating basic GPIO output usage with RIOT-rs.

## How to run

In this folder, run

laze build -b nrf52840dk run
14 changes: 14 additions & 0 deletions examples/blinky/laze.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apps:
- name: blinky
context:
# list of contexts that have an entry in `pins.rs`
- esp
- microbit-v2
- nrf52840dk
- nrf5340dk
- rp
- st-nucleo-f401re
- st-nucleo-h755zi-q
- st-nucleo-wb55
selects:
- ?release
23 changes: 23 additions & 0 deletions examples/blinky/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![no_main]
#![no_std]
#![feature(type_alias_impl_trait)]
#![feature(used_with_arg)]

mod pins;

use embassy_time::{Duration, Timer};
use riot_rs::embassy::gpio::{Level, Output};

#[riot_rs::task(autostart, peripherals)]
async fn blinky(peripherals: pins::LedPeripherals) {
let mut led = Output::new(peripherals.led, Level::Low);

// The micro:bit uses an LED matrix; pull the column line low.
#[cfg(context = "microbit-v2")]
let _led_col1 = Output::new(peripherals.led_col1, Level::Low);

loop {
led.toggle();
Timer::after(Duration::from_millis(500)).await;
}
}
28 changes: 28 additions & 0 deletions examples/blinky/src/pins.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use riot_rs::embassy::arch::peripherals;

#[cfg(context = "microbit-v2")]
riot_rs::define_peripherals!(LedPeripherals {
led_col1: P0_28,
led: P0_21,
});

#[cfg(context = "nrf52840dk")]
riot_rs::define_peripherals!(LedPeripherals { led: P0_13 });

#[cfg(context = "nrf5340dk")]
riot_rs::define_peripherals!(LedPeripherals { led: P0_28 });

#[cfg(context = "rp")]
riot_rs::define_peripherals!(LedPeripherals { led: PIN_1 });

#[cfg(context = "esp")]
riot_rs::define_peripherals!(LedPeripherals { led: GPIO_0 });

#[cfg(context = "st-nucleo-f401re")]
riot_rs::define_peripherals!(LedPeripherals { led: PA5 });

#[cfg(context = "st-nucleo-h755zi-q")]
riot_rs::define_peripherals!(LedPeripherals { led: PB0 });

#[cfg(context = "st-nucleo-wb55")]
riot_rs::define_peripherals!(LedPeripherals { led: PB5 });
19 changes: 19 additions & 0 deletions examples/gpio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "gpio"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
publish = false

[lints]
workspace = true

[dependencies]
embassy-executor = { workspace = true }
embassy-futures = { workspace = true }
embassy-time = { workspace = true }
riot-rs = { path = "../../src/riot-rs", features = [
"external-interrupts",
"time",
] }
riot-rs-boards = { path = "../../src/riot-rs-boards" }
11 changes: 11 additions & 0 deletions examples/gpio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# gpio

## About

This application is testing GPIO usage with RIOT-rs.

## How to run

In this folder, run

laze build -b nrf52840dk run
4 changes: 4 additions & 0 deletions examples/gpio/laze.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apps:
- name: gpio
selects:
- ?release
39 changes: 39 additions & 0 deletions examples/gpio/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#![no_main]
#![no_std]
#![feature(type_alias_impl_trait)]
#![feature(used_with_arg)]

mod pins;

use embassy_time::{Duration, Timer};
use riot_rs::embassy::gpio::{Input, Level, Output, Pull};

#[riot_rs::task(autostart, peripherals)]
async fn blinky(peripherals: pins::Peripherals) {
let mut led1 = Output::new(peripherals.led1, Level::Low);

#[allow(unused_variables)]
let pull = Pull::Up;
#[cfg(context = "st-nucleo-h755zi-q")]
let pull = Pull::None;

let mut btn1 = Input::builder(peripherals.btn1, pull)
.build_with_interrupt()
.unwrap();

// The micro:bit uses an LED matrix; pull the column line low.
#[cfg(context = "microbit-v2")]
let _led_col1 = Output::new(peripherals.led_col1, Level::Low);

loop {
// Wait for the button being pressed or 300 ms, whichever comes first.
let _ = embassy_futures::select::select(
btn1.wait_for_low(),
Timer::after(Duration::from_millis(300)),
)
.await;

led1.toggle();
Timer::after(Duration::from_millis(100)).await;
}
}
Loading

0 comments on commit 0306391

Please sign in to comment.