embassy_dt/lib.rs
1#![no_std]
2#![forbid(unsafe_code)]
3#![warn(missing_docs)]
4
5//! An async device tree for [Embassy](https://github.com/embassy-rs/embassy).
6//!
7//! The goal: separate *what the hardware looks like* from *what the application
8//! does*. Hardware configuration (buses, pins, devices, dependencies) is written once
9//! as a static description; a chip backend translates it into concrete Embassy HAL
10//! calls. Application code only programs against the tree, so changing boards or chips
11//! does not require changing logic.
12//!
13//! Three parts:
14//!
15//! - [`device_tree!`] (from `embassy-dt-macros`): the DSL macro that parses tree
16//! configuration and performs **compile-time validation** (duplicate ids, dangling
17//! dependencies, dependency cycles); declaring `backend stm32;` additionally
18//! generates a typed `Board` structure.
19//! - [`TreeDesc`]: the purely static, `no_std` device-tree description model (nodes,
20//! buses, devices, properties, dependencies) with validation and topological sort.
21//! - [`init_devices`]: the engine that asynchronously brings devices up in dependency
22//! order, with zero heap allocation.
23//!
24//! Example (host side):
25//!
26//! ```rust
27//! use embassy_dt::device_tree;
28//!
29//! device_tree! {
30//! name "demo-board";
31//! bus i2c0: I2c { periph: "I2C1", scl: "PB8", sda: "PB7", freq: 400_000 };
32//! device bme280: Bme280Driver { bus: i2c0, addr: 0x76 };
33//! }
34//!
35//! # fn main() {
36//! assert_eq!(TREE.name, "demo-board");
37//! assert_eq!(TREE.node("bme280").unwrap().prop("addr"), Some(embassy_dt::Prop::U32(0x76)));
38//! # }
39//! ```
40
41pub mod init;
42pub mod tree;
43
44pub use embassy_dt_macros::device_tree;
45pub use init::{init_devices, AsyncDevice, DeviceError, InitError};
46pub use tree::{BusKind, NodeDesc, NodeId, NodeKind, Prop, TreeDesc, ValidationError};