Skip to content

Commit 81d4bac

Browse files
committed
zephyr: sys: gpio: Add is_ready method
The is_ready method on both `Gpio` and `GpioPin` will ultimately call the underlying `device_is_ready` entry. Signed-off-by: David Brown <[email protected]>
1 parent 94a76f4 commit 81d4bac

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

zephyr/src/sys.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,37 @@ pub mod gpio {
9393
pub(crate) device: *const raw::device,
9494
}
9595

96+
impl Gpio {
97+
/// Verify that the device is ready for use. At a minimum, this means the device has been
98+
/// successfully initialized.
99+
pub fn is_ready(&self) -> bool {
100+
unsafe {
101+
raw::device_is_ready(self.device)
102+
}
103+
}
104+
}
105+
96106
/// A GpioPin represents a single pin on a gpio device. This is a lightweight wrapper around
97107
/// the Zephyr `gpio_dt_spec` structure.
98108
#[allow(dead_code)]
99109
pub struct GpioPin {
100110
pub(crate) pin: raw::gpio_dt_spec,
101111
}
112+
113+
impl GpioPin {
114+
/// Verify that the device is ready for use. At a minimum, this means the device has been
115+
/// successfully initialized.
116+
pub fn is_ready(&self) -> bool {
117+
self.get_gpio().is_ready()
118+
}
119+
120+
/// Get the underlying Gpio device.
121+
pub fn get_gpio(&self) -> Gpio {
122+
Gpio {
123+
device: self.pin.port,
124+
}
125+
}
126+
}
102127
}
103128

104129
pub mod flash {

0 commit comments

Comments
 (0)