Skip to content

Commit 27d4127

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 92560cc commit 27d4127

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

0 commit comments

Comments
 (0)