Motivation:
The current device instantiation API (e.g. Button::new_inverted_pullup, etc.) pis ergonomic but not scalable as the number of options grows. It’s also tightly coupled to runtime code and doesn’t support config-based instantiation (TOML/YAML/JSON), which limits flexibility for many real-world use cases.
We propose to replace the current serde support (tied to live device instances) with Builder-based configuration objects for all hardware devices. Builders can optionally be made serializable via a feature-flagged "serde".
Expectation:
Proposal
Introduce per-device Builder types (possibly named Config when exposed via serde), e.g. ButtonBuilder. These will:
- Be used to construct devices fluently in Rust code.
- Be optionally serializable/deserializable via serde (with a feature flag).
- Completely replace the existing serde implementation, which currently exposes live device types to serialization.
Example
let button = ButtonBuilder::new()
.pin(2)
.pullup()
.inverted()
.debounce(20)
.build(&board)?;
Or from config file (enabled with serde):
[[buttons]]
pin = 2
pull = "up"
inverted = true
debounce = 20
Parsed all devices and built:
#[cfg(feature = "serde")]
let config: DeviceConfig= toml::from_str(...)?;
config.buttons.into_iter().try_for_each(|b| b.build(&board))?;
Motivation:
The current device instantiation API (e.g.
Button::new_inverted_pullup, etc.) pis ergonomic but not scalable as the number of options grows. It’s also tightly coupled to runtime code and doesn’t support config-based instantiation (TOML/YAML/JSON), which limits flexibility for many real-world use cases.We propose to replace the current serde support (tied to live device instances) with Builder-based configuration objects for all hardware devices. Builders can optionally be made serializable via a feature-flagged "serde".
Expectation:
Proposal
Introduce per-device Builder types (possibly named Config when exposed via serde), e.g. ButtonBuilder. These will:
Example
Or from config file (enabled with serde):
Parsed all devices and built: