-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "riot-wrappers-test-gpio" | ||
version = "0.1.0" | ||
authors = ["Christian Amsüss <chrysn@fsfe.org>"] | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["staticlib"] | ||
|
||
[profile.release] | ||
panic = "abort" | ||
|
||
[dependencies] | ||
riot-wrappers = { version = "*", features = [ "set_panic_handler", "panic_handler_format" ] } | ||
riot-sys = "*" | ||
embedded-hal = "0.2.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# name of your application | ||
APPLICATION = riot-wrappers-test-gpio | ||
APPLICATION_RUST_MODULE = riot_wrappers_test_gpio | ||
BASELIBS += $(APPLICATION_RUST_MODULE).module | ||
FEATURES_REQUIRED += rust_target | ||
FEATURES_REQUIRED += periph_gpio | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![no_std] | ||
|
||
use riot_wrappers::gpio::{InputMode, OutputMode, GPIO}; | ||
use riot_wrappers::println; | ||
use riot_wrappers::riot_main; | ||
|
||
use embedded_hal::digital::v2::{InputPin, OutputPin, PinState}; | ||
|
||
riot_main!(main); | ||
|
||
fn main() { | ||
let (out_port, out_pin, in_port, in_pin, in_mode) = match riot_wrappers::BOARD { | ||
// Won't work -- currently, native GPIO don't do anything (but let's not panic already) | ||
"native" => (0, 0, 0, 1, InputMode::In), | ||
// 0.17 is LED1, 0.13 is button 1 | ||
"nrf52dk" => (0, 17, 0, 13, InputMode::InPullUp), | ||
|
||
// Better safe than drive pins that were not supposed to be driven | ||
_ => panic!("For this board, no GPIO pins were deemed safe to reconfigure."), | ||
}; | ||
let mut p_out = GPIO::from_port_and_pin(out_port, out_pin) | ||
.expect("Out pin does not exist") | ||
.configure_as_output(OutputMode::Out) | ||
.expect("Out pin could not be configured"); | ||
let p_in = GPIO::from_port_and_pin(in_port, in_pin) | ||
.expect("In pin does not exist") | ||
.configure_as_input(in_mode) | ||
.expect("In pin could not be configured"); | ||
|
||
loop { | ||
let value = p_in.is_high().unwrap(); | ||
println!("Read GPIO value {}, writing it to the out port", value); | ||
p_out.set_state(if value { PinState::High } else { PinState::Low }); | ||
} | ||
} |