dclause / dclause/hermes-five

META: Introduce Builder-based configuration system for hardware devices (with optional serde support)

Open
#45 0 comments 0 reactions 0 assignees View on GitHub
code quality feature request Plan
Dominant language
Rust
Stars
38
Forks
1
PR merge metrics
No merged PRs in 30d

Description

**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:**
- [ ] All current serde-related serialization/deserialization is removed from runtime types.
- [ ] All devices (and appropriate hardware structures) expose a Builder struct for construction.
- [ ] An optional feature "serde" allows serialization/deserialization of these builders.
- [ ] Builders may be renamed to Config when exposed via serde to make their intent clearer.

**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**
```rust
let button = ButtonBuilder::new()
.pin(2)
.pullup()
.inverted()
.debounce(20)
.build(&board)?;
```
Or from config file (enabled with serde):
```toml
[[buttons]]
pin = 2
pull = "up"
inverted = true
debounce = 20
```
Parsed all devices and built:
```rust
#[cfg(feature = "serde")]
let config: DeviceConfig= toml::from_str(...)?;
config.buttons.into_iter().try_for_each(|b| b.build(&board))?;
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.