Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Battery + Charger Summary

In this section, we built a complete Battery + Charger component set, validating their interactions in a functioning Battery Subsystem through both unit and integration tests.

What We Did

In the process, we established key patterns that will carry forward into similar subsystems:

  • Component Architecture

    • Explored the roles of the Component, HAL layer, Device, and Controller.
    • Used Generic Types to enable dependency injection and flexible implementation choices.
    • Registered the Device to introduce a new subsystem into the runtime.
  • Event-Driven Behavior

    • Defined and handled BatteryEvent messages via the Controller to enact behavior.
  • Asynchronous Integration

    • Adapted async tasks using embassy::executor and #[embassy_executor::task] to run under both std (for development and testing) and embedded (no-std) environments.
  • Testing Support

    • Implemented comprehensive unit tests for the Battery and Charger subsystems.
    • Added integration tests to verify runtime behavior across components.

What We Omitted (For Simplicity)

This exercise focused on illustrating patterns -— not delivering production-grade code. Accordingly:

  • We did not fully implement the Smart Battery specification.
    Features such as removable batteries, dynamic BatteryMode handling, or full status reporting were omitted for simplicity.

  • Our simulations of battery behavior and charger policy were intentionally lightweight.
    The goal was to simulate dynamic behavior, not to mirror real-world electrical characteristics.

  • Error handling was minimal.
    A real embedded system would avoid panic!() in favor of structured error recovery and system notification. Here, we favored visibility and simplicity.

These trade-offs allowed us to focus on demonstrating patterns and validate essential integration behavior.