Skip to content

Commit 0c65b75

Browse files
committed
tests: drivers: gpio-async: Basic gpio setup (WIP)
Enable the gpios, driving a single column, and reading a single row in a loop with a delay. This will be the gpio we will monitor. Signed-off-by: David Brown <[email protected]>
1 parent 1d1b57c commit 0c65b75

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

tests/drivers/gpio-async/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ CONFIG_RUST=y
1010

1111
CONFIG_RUST_ALLOC=y
1212
# CONFIG_LOG=y
13+
CONFIG_GPIO=y
1314

1415
CONFIG_LOG_BACKEND_RTT=n

tests/drivers/gpio-async/src/lib.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
extern crate alloc;
77

8-
use zephyr::embassy::Executor;
8+
use embassy_time::{Duration, Timer};
9+
use zephyr::{embassy::Executor, raw::{GPIO_INPUT, GPIO_OUTPUT_ACTIVE, GPIO_PULL_DOWN}};
910

1011
use embassy_executor::Spawner;
1112
use log::info;
@@ -29,4 +30,31 @@ extern "C" fn rust_main() {
2930
async fn main(spawner: Spawner) {
3031
info!("Hello world");
3132
let _ = spawner;
33+
34+
let mut col0 = zephyr::devicetree::labels::col0::get_instance().unwrap();
35+
let mut row0 = zephyr::devicetree::labels::row0::get_instance().unwrap();
36+
let mut gpio_token = unsafe { zephyr::device::gpio::GpioToken::get_instance().unwrap() };
37+
38+
unsafe {
39+
col0.configure(&mut gpio_token, GPIO_OUTPUT_ACTIVE);
40+
col0.set(&mut gpio_token, true);
41+
row0.configure(&mut gpio_token, GPIO_INPUT | GPIO_PULL_DOWN);
42+
}
43+
44+
let mut last = false;
45+
46+
loop {
47+
let current = unsafe { row0.get(&mut gpio_token) };
48+
// info!("Current: {:?}", current);
49+
if current != last {
50+
if current {
51+
info!("Pressed");
52+
} else {
53+
info!("Released");
54+
}
55+
last = current;
56+
}
57+
58+
Timer::after(Duration::from_millis(25)).await;
59+
}
3260
}

0 commit comments

Comments
 (0)