Expand description
An async device tree for Embassy.
The goal: separate what the hardware looks like from what the application does. Hardware configuration (buses, pins, devices, dependencies) is written once as a static description; a chip backend translates it into concrete Embassy HAL calls. Application code only programs against the tree, so changing boards or chips does not require changing logic.
Three parts:
device_tree!(fromembassy-dt-macros): the DSL macro that parses tree configuration and performs compile-time validation (duplicate ids, dangling dependencies, dependency cycles); declaringbackend stm32;additionally generates a typedBoardstructure.TreeDesc: the purely static,no_stddevice-tree description model (nodes, buses, devices, properties, dependencies) with validation and topological sort.init_devices: the engine that asynchronously brings devices up in dependency order, with zero heap allocation.
Example (host side):
use embassy_dt::device_tree;
device_tree! {
name "demo-board";
bus i2c0: I2c { periph: "I2C1", scl: "PB8", sda: "PB7", freq: 400_000 };
device bme280: Bme280Driver { bus: i2c0, addr: 0x76 };
}
assert_eq!(TREE.name, "demo-board");
assert_eq!(TREE.node("bme280").unwrap().prop("addr"), Some(embassy_dt::Prop::U32(0x76)));Re-exports§
pub use init::init_devices;pub use init::AsyncDevice;pub use init::DeviceError;pub use init::InitError;pub use tree::BusKind;pub use tree::NodeDesc;pub use tree::NodeId;pub use tree::NodeKind;pub use tree::Prop;pub use tree::TreeDesc;pub use tree::ValidationError;
Modules§
Macros§
- device_
tree device_tree!宏:解析设备树(Rust DSL 或 DTS/DTSI 文件),编译期校验, 生成TREE静态描述;声明backend stm32;时额外生成类型化Board。