Skip to main content

Crate embassy_dt

Crate embassy_dt 

Source
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! (from embassy-dt-macros): the DSL macro that parses tree configuration and performs compile-time validation (duplicate ids, dangling dependencies, dependency cycles); declaring backend stm32; additionally generates a typed Board structure.
  • TreeDesc: the purely static, no_std device-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§

init
依赖序异步上线引擎。
tree
设备树的静态描述模型。

Macros§

device_tree
device_tree! 宏:解析设备树(Rust DSL 或 DTS/DTSI 文件),编译期校验, 生成 TREE 静态描述;声明 backend stm32; 时额外生成类型化 Board。