Skip to content

Commit ca8cb49

Browse files
committed
zephyr: sys: Create wrappers for gpio and flash
Create two modules with wrappers for Zephyr gpio and flash devices. These have no methods, but allow the DT generated code to compile, with `get_instance` methods that return these values. Signed-off-by: David Brown <[email protected]>
1 parent dd2f908 commit ca8cb49

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

zephyr/src/sys.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,51 @@ pub mod critical {
7676
}
7777
}
7878
}
79+
80+
pub mod gpio {
81+
//! Most devices in Zephyr operate on a `struct device`. This provides untyped access to
82+
//! devices. We want to have stronger typing in the Zephyr interfaces, so most of these types
83+
//! will be wrapped in another structure. This wraps a Gpio device, and provides methods to
84+
//! most of the operations on gpios.
85+
86+
use crate::raw;
87+
88+
/// A single instance of a zephyr device to manage a gpio controller. A gpio controller
89+
/// represents a set of gpio pins, that are generally operated on by the same hardware block.
90+
pub struct Gpio {
91+
/// The underlying device itself.
92+
#[allow(dead_code)]
93+
pub(crate) device: *const raw::device,
94+
}
95+
96+
/// A GpioPin represents a single pin on a gpio device. This is a lightweight wrapper around
97+
/// the Zephyr `gpio_dt_spec` structure.
98+
#[allow(dead_code)]
99+
pub struct GpioPin {
100+
pub(crate) pin: raw::gpio_dt_spec,
101+
}
102+
}
103+
104+
pub mod flash {
105+
//! Device wrappers for flash controllers, and flash partitions.
106+
107+
use crate::raw;
108+
109+
#[allow(dead_code)]
110+
pub struct FlashController {
111+
pub(crate) device: *const raw::device,
112+
}
113+
114+
/// A wrapper for flash partitions. There is no Zephyr struct that corresponds with this
115+
/// information, which is typically used in a more direct underlying manner.
116+
#[allow(dead_code)]
117+
pub struct FlashPartition {
118+
/// The underlying controller.
119+
#[allow(dead_code)]
120+
pub(crate) controller: FlashController,
121+
#[allow(dead_code)]
122+
pub(crate) offset: u32,
123+
#[allow(dead_code)]
124+
pub(crate) size: u32,
125+
}
126+
}

0 commit comments

Comments
 (0)