Skip to content

Commit 301ccb7

Browse files
committed
Various cleanups from github comments
Apply some clarifications and minor code changes based on github review comments. Signed-off-by: David Brown <[email protected]>
1 parent eb38aec commit 301ccb7

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

samples/blinky/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
name = "rustapp"
77
version = "0.1.0"
88
edition = "2021"
9-
description = "A sample hello world application in Rust"
9+
description = "Blink an LED forever using the GPIO API"
1010
license = "Apache-2.0 or MIT"
1111

1212
[lib]

samples/blinky/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
fn main() {
2+
// This call will make make config entries available in the code for every device tree node, to
3+
// allow conditional compilation based on whether it is present in the device tree.
4+
// For example, it will be possible to have:
5+
// ```rust
6+
// #[cfg(dt = "aliases::led0")]
7+
// ```
28
zephyr_build::dt_cfgs();
39
}

samples/blinky/sample.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# See doc/develop/test/twister.rst for what is here.
12
sample:
23
name: Blinky Sample
34
tests:

zephyr-build/src/devicetree.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ mod parse;
3030

3131
pub use augment::{Augment, load_augments};
3232

33+
/// Representation of a parsed device tree.
3334
pub struct DeviceTree {
3435
/// The root of the tree.
3536
root: Rc<Node>,
3637
/// All of the labels.
3738
labels: BTreeMap<String, Rc<Node>>,
3839
}
3940

40-
// This is a single node in the devicetree.
41+
// A single node in a [`DeviceTree`].
4142
pub struct Node {
4243
// The name of the node itself.
4344
name: String,
@@ -90,27 +91,22 @@ pub enum Word {
9091
}
9192

9293
impl DeviceTree {
93-
/// Decode the zephyr.dts and devicetree_generated.h files from the build and build an internal
94+
/// Decode the `zephyr.dts` and `devicetree_generated.h` files from the build and build an internal
9495
/// representation of the devicetree itself.
9596
pub fn new<P1: AsRef<Path>, P2: AsRef<Path>>(dts_path: P1, dt_gen: P2) -> DeviceTree {
9697
let ords = OrdMap::new(dt_gen);
9798

9899
let dts = std::fs::read_to_string(dts_path)
99100
.expect("Reading zephyr.dts file");
100101
let dt = parse::parse(&dts, &ords);
101-
dt.resolve_phandles();
102-
dt.set_parents();
103-
dt
104-
}
105102

106-
/// Walk the node tree, fixing any phandles to include their reference.
107-
fn resolve_phandles(&self) {
108-
self.root.phandle_walk(&self.labels);
109-
}
103+
// Walk the node tree, fixing any phandles to include their reference.
104+
dt.root.phandle_walk(&dt.labels);
110105

111-
/// Walk the node tree, setting each node's parent appropriately.
112-
fn set_parents(&self) {
113-
self.root.parent_walk();
106+
// Walk the node tree, setting each node's parent appropriately.
107+
dt.root.parent_walk();
108+
109+
dt
114110
}
115111
}
116112

zephyr-build/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub fn build_kconfig_mod() {
8484
fn import_dt() -> DeviceTree {
8585
let zephyr_dts = env::var("ZEPHYR_DTS").expect("ZEPHYR_DTS must be set");
8686
let gen_include = env::var("BINARY_DIR_INCLUDE_GENERATED")
87-
.expect("BINARY_DIR_INCLUDE_GENERATED");
87+
.expect("BINARY_DIR_INCLUDE_GENERATED must be set");
8888

8989
let generated = format!("{}/devicetree_generated.h", gen_include);
9090
DeviceTree::new(&zephyr_dts, generated)

0 commit comments

Comments
 (0)