Battery service: Split interface and relay logic into separate crates#780
Open
williampMSFT wants to merge 8 commits intoOpenDevicePartnership:feature/relay-splitfrom
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR splits the battery service’s public interface and its MCTP relay/serialization logic into separate crates to allow alternate service implementations to reuse the relay layer.
Changes:
- Introduces
battery-service-interfacewith the battery service trait, error type, and shared ACPI-support types. - Adds
battery-service-relayto handle ACPI request/response serialization and relay dispatch against the interface trait. - Updates
battery-serviceto implement the newBatteryServicetrait and removes the in-crate MCTP relay handler and related dependencies.
Reviewed changes
Copilot reviewed 13 out of 17 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/std/Cargo.lock | Updates example lockfile to depend on battery-service-interface after the split. |
| examples/rt633/Cargo.lock | Updates example lockfile dependency from messages crate to interface crate. |
| examples/pico-de-gallo/Cargo.lock | Updates example lockfile dependency from messages crate to interface crate. |
| Cargo.toml | Updates workspace members and workspace dependency alias from battery-service-messages to battery-service-interface, and adds battery-service-relay. |
| Cargo.lock | Updates workspace lock to include battery-service-interface and new battery-service-relay crate. |
| battery-service/src/mock.rs | Switches mock capability flag types to battery-service-interface. |
| battery-service/src/lib.rs | Implements battery_service_interface::BatteryService and removes in-crate MCTP relay handler impls. |
| battery-service/src/device.rs | Re-exports DeviceId from battery-service-interface. |
| battery-service/src/context.rs | Removes ACPI request processing tied to the old messages/relay flow and updates imports. |
| battery-service/src/acpi.rs | Refactors handlers to return interface types directly and use BatteryError. |
| battery-service/Cargo.toml | Replaces dependency on old messages crate with battery-service-interface and drops relay-related deps. |
| battery-service-relay/src/serialization.rs | New: serialization/deserialization for ACPI battery requests/responses and error mapping for relay transport. |
| battery-service-relay/src/lib.rs | New: relay handler that translates ACPI requests into BatteryService calls. |
| battery-service-relay/Cargo.toml | New: crate manifest for relay layer. |
| battery-service-messages/src/lib.rs | Removed: old combined messages + serialization crate superseded by interface + relay crates. |
| battery-service-interface/src/lib.rs | New: defines the battery service trait and shared support types/errors. |
| battery-service-interface/Cargo.toml | Renames the old messages crate package to battery-service-interface. |
kurtjd
previously approved these changes
Apr 8, 2026
Contributor
kurtjd
left a comment
There was a problem hiding this comment.
LGTM. Though similar nit as last time, just some pub items missing doc strings in the interface and relay lib.rs files.
kurtjd
previously approved these changes
Apr 8, 2026
kurtjd
previously approved these changes
Apr 8, 2026
tullom
reviewed
Apr 10, 2026
tullom
previously approved these changes
Apr 10, 2026
Contributor
tullom
left a comment
There was a problem hiding this comment.
Just one nb comment, otherwise looks good! The API looks good
kurtjd
approved these changes
Apr 10, 2026
jerrysxie
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change splits the interface for the battery service into two crates - an 'interface' crate that contains traits and support types for the public interface for the battery service, and a 'relay' crate that's written against the 'interface' crate and handles relaying messages to and from a battery service implementation over MCTP.
This split should allow OEMs to substitute their own service implementations if they want to and still reuse our relay code (or write their own relay against the stock service implementation). Additionally, splitting the relay handling from the service implementation should also allow us to add support for different kinds of relay handlers (e.g. HID) without needing to pay the code size cost of having that code on platforms that aren't using it since it's no longer invasive on the service type.
This change only moves the pieces of the battery interface that are required for the relay service into a trait; a future change will migrate the pieces that are targeted at other code running on the EC into the trait as well.