Skip to content

Commit 1139afb

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 0b7f377 commit 1139afb

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

0 commit comments

Comments
 (0)