Skip to content

Commit 6c6e977

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 27d4127 commit 6c6e977

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
@@ -89,12 +89,37 @@ pub mod gpio {
8989
pub(crate) device: *const raw::device,
9090
}
9191

92+
impl Gpio {
93+
/// Verify that the device is ready for use. At a minimum, this means the device has been
94+
/// successfully initialized.
95+
pub fn is_ready(&self) -> bool {
96+
unsafe {
97+
raw::device_is_ready(self.device)
98+
}
99+
}
100+
}
101+
92102
/// A GpioPin represents a single pin on a gpio device. This is a lightweight wrapper around
93103
/// the Zephyr `gpio_dt_spec` structure.
94104
#[allow(dead_code)]
95105
pub struct GpioPin {
96106
pub(crate) pin: raw::gpio_dt_spec,
97107
}
108+
109+
impl GpioPin {
110+
/// Verify that the device is ready for use. At a minimum, this means the device has been
111+
/// successfully initialized.
112+
pub fn is_ready(&self) -> bool {
113+
self.get_gpio().is_ready()
114+
}
115+
116+
/// Get the underlying Gpio device.
117+
pub fn get_gpio(&self) -> Gpio {
118+
Gpio {
119+
device: self.pin.port,
120+
}
121+
}
122+
}
98123
}
99124

100125
pub mod flash {

0 commit comments

Comments
 (0)