Skip to content

Commit 28f7ec6

Browse files
committed
zephyr: device: gpio: Add a few more methods
Add methods for get and set of pin logical values. Signed-off-by: David Brown <[email protected]>
1 parent bcc9ee4 commit 28f7ec6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

zephyr/src/device/gpio.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//! pervasively throughout Zephyr device drivers. As such, most of the calls in this module are
88
//! unsafe.
99
10+
use core::ffi::c_int;
11+
1012
use super::Unique;
1113
use crate::raw;
1214

@@ -147,4 +149,18 @@ impl GpioPin {
147149
raw::gpio_pin_toggle_dt(&self.pin);
148150
}
149151
}
152+
153+
/// Set the logical level of the pin.
154+
pub unsafe fn set(&mut self, _token: &mut GpioToken, value: bool) {
155+
raw::gpio_pin_set_dt(&self.pin, value as c_int);
156+
}
157+
158+
/// Read the logical level of the pin.
159+
pub unsafe fn get(&mut self, _token: &mut GpioToken) -> bool {
160+
match raw::gpio_pin_get_dt(&self.pin) {
161+
0 => false,
162+
1 => true,
163+
_ => panic!("TODO: Handle gpio get error"),
164+
}
165+
}
150166
}

0 commit comments

Comments
 (0)