Skip to content

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

@dclause

Description

@dclause

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

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))?;

Metadata

Metadata

Assignees

No one assigned

    Labels

    PlanMeta issuecode qualityIssue is related to refactoring or improving code quality overall.feature requestNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions