Repository navigation
feat(battery)!: integrate power-policy notifications - #976
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The _PIF mapping treats outlet-powered sources as unlimited wattage, discarding known adapter power limits.
1 open issue
What changed in this PR
This PR connects power-policy notifications to per-fuel-gauge caches, allowing battery ACPI queries to report external-power state without locking PSUs. It introduces a breaking registration requirement for power-policy routing.
Changes:
- Add configurable routing and cached external-power state for independent or shared sources.
- Combine notification handling with periodic battery polling, with cancellation and backpressure tests.
- Update interfaces, examples, dependencies, and integration documentation.
| File | Description |
|---|---|
tcpm-service/src/service/event_receiver.rs |
Reuse the shared power-policy subscriber. |
power-policy-interface/src/service/event.rs |
Add a generic subscriber and forwarding tests. |
power-policy-interface/src/psu/mod.rs |
Default PSU state to detached. |
examples/std/src/bin/power_policy.rs |
Demonstrate source-specific routing to two gauges. |
examples/std/src/bin/battery.rs |
Combine notifications with battery polling. |
examples/std/Cargo.lock |
Update example dependencies. |
examples/pico-de-gallo/src/bin/battery.rs |
Supply the required default router. |
examples/pico-de-gallo/Cargo.lock |
Update example dependencies. |
Cargo.lock |
Record runtime and test dependencies. |
battery-service/src/routing.rs |
Define routing policies and cache updates. |
battery-service/src/registration.rs |
Require a router for each registration. |
battery-service/src/lib.rs |
Validate and apply routed notifications. |
battery-service/src/event_receiver.rs |
Combine polling and notification waits fairly. |
battery-service/src/acpi.rs |
Read cached power state and add integration tests. |
battery-service/README.md |
Document routing, delivery, and cache semantics. |
battery-service/Cargo.toml |
Add async selection and test dependencies. |
battery-service-relay/src/lib.rs |
Document shared-reference handler support. |
battery-service-interface/src/lib.rs |
Define power-query semantics and shared-reference forwarding. |
battery-service-interface/src/fuel_gauge.rs |
Store external-power state in each gauge. |
battery-service-interface/Cargo.toml |
Add power-policy dependency and logging features. |
Review effort: Balanced
|
One final thought: I'd like us to keep connection state, energy constraints, and output capability as separate concepts, expressed through explicit domain types rather than magic integers. An outlet-powered source can still have a finite wattage limit. Note that getting there may require dedicated refactor PRs 👍 The goal is to preserve that context in the code so the next person doesn't have to rediscover it. Keep protocol encodings at the boundary, let the types enforce what they can, and document and test the relationships they can't. Excuse the shameless plug, but I wrote about this in Making Smaller Things, Thirty-Six Registers, and Six Entries. |
c01bcff to
472bf9c
Compare
Cache routed power-policy updates in each fuel gauge and use them for ACPI power-source queries. Share a power-policy subscriber with TCPM and integrate event handling into the battery examples. BREAKING CHANGE: Registrations must provide a power-policy router; ArrayRegistration now requires its routing type and value. Assisted-by: GitHub Copilot:gpt-6-astra
Exercise cached ACPI power reporting, custom routing, validation, backpressure, and cancellation. Cover subscriber forwarding and fair polling, and enable the mock dependencies needed by these tests. Assisted-by: GitHub Copilot:gpt-6-astra
Describe cache semantics, routing options, delivery requirements, and polling integration. Clarify shared-reference support in the relay. Assisted-by: GitHub Copilot:gpt-6-astra
ACPI defines the _PIF power fields as the source's rated maximums and reserves only 0xFFFFFFFF, meaning unavailable. Power-policy notifications carry the negotiated contract instead, and unconstrained_power marks an outlet-powered source, not unlimited wattage. Reporting the contract, or 0xFFFFFFFE for unconstrained sources, misstated the rating to the host. Report both ratings as unavailable and remove UNLIMITED_POWER_MW. The unconstrained override now only affects _PSR. Tests check the cached contract and unconstrained flag directly, so routing coverage no longer depends on _PIF wattage. Assisted-by: GitHub Copilot:claude-opus-5.5
Explain why PowerPolicySubscriber is a separate field type: composite receivers can await it alongside other fields because each future borrows only its own field, while &mut self helper methods on the composite would each borrow the whole struct. Assisted-by: GitHub Copilot:claude-opus-5.5
472bf9c to
3d10c3d
Compare

Power-policy notifications now update each fuel gauge's external-power cache, so ACPI _PSR and _PIF report connection state and available power without taking PSU locks. Custom routing supports independent or shared sources, and the existing battery task handles notifications alongside polling.
Registrations now require a power-policy router. Updated examples and documentation cover the setup, with tests for routing, backpressure, and cancellation.
Assisted-by: GitHub Copilot:gpt-6-astra