Skip to content

Commit 85bfbde

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 1139afb commit 85bfbde

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
@@ -95,12 +95,37 @@ pub mod gpio {
9595
pub(crate) device: *const raw::device,
9696
}
9797

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

106131
pub mod flash {

0 commit comments

Comments
 (0)