Skip to content

Conversation

@tullom
Copy link
Contributor

@tullom tullom commented Jan 27, 2026

Part of the larger embedded-services refactor work.

Power policy v0.2.0 refactor

  • Make power policy context explicit, generic, and injectable
  • Remove all global/singleton usage, making the context generic over channel size and requiring explicit passing of context references
  • Updates all examples and Type-C service code to use explicit, generic policy context parameters

@tullom tullom self-assigned this Jan 27, 2026
@tullom tullom force-pushed the power-policy-refactor branch from d5b5263 to adc2f92 Compare January 27, 2026 00:24
@tullom tullom marked this pull request as ready for review January 27, 2026 00:34
@tullom tullom requested review from a team as code owners January 27, 2026 00:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the power-policy integration to be instance-based and const-generic over the policy channel size, and wires the Type‑C service and examples to the new API.

Changes:

  • Refactors embedded_services::power::policy to replace the global singleton context with a generic Context<const POLICY_CHANNEL_SIZE: usize>, and makes device::Device/policy actions const‑generic and context‑aware.
  • Updates the power-policy service (PowerPolicy) and Type‑C controller wrapper (ControllerWrapper) to depend on an explicit Context<POLICY_CHANNEL_SIZE>, threading this through construction, registration, and tasks.
  • Adjusts all Type‑C and power-policy examples (std and rt685s‑evk) to create and pass explicit power-policy contexts and policy instances, and to use the new generic device/container types.

Reviewed changes

Copilot reviewed 21 out of 29 changed files in this pull request and generated no comments.

Show a summary per file
File Description
type-c-service/src/wrapper/vdm.rs Extends ControllerWrapper impl to include the POLICY_CHANNEL_SIZE const generic to match the updated struct definition.
type-c-service/src/wrapper/power.rs Makes all power-policy device references generic over POLICY_CHANNEL_SIZE and aligns method signatures (e.g. get_power_device, contract handlers) with the new device type.
type-c-service/src/wrapper/pd.rs Updates ControllerWrapper impl block to include POLICY_CHANNEL_SIZE, keeping PD-related methods consistent with the new wrapper type.
type-c-service/src/wrapper/mod.rs Adds POLICY_CHANNEL_SIZE to ControllerWrapper, threads it into backing registration, power-device accessors, plug/contract handlers, and register, and requires a typed power-policy Context.
type-c-service/src/wrapper/dp.rs Adjusts DisplayPort-related ControllerWrapper impl to use the new const‑generic wrapper type.
type-c-service/src/wrapper/cfu.rs Updates CFU-related ControllerWrapper impl to include the POLICY_CHANNEL_SIZE const generic.
type-c-service/src/wrapper/backing.rs Makes backing storage, registration, and backing structures generic over POLICY_CHANNEL_SIZE, constructing power::policy::device::Device<POLICY_CHANNEL_SIZE> from a passed-in Context<POLICY_CHANNEL_SIZE>.
type-c-service/src/task.rs Extends task_closure and task to be const‑generic over POLICY_CHANNEL_SIZE, adding a power-policy Context parameter and passing it through to Service::register_comms and ControllerWrapper::register.
type-c-service/src/service/mod.rs Changes register_comms to take a power_policy::policy::Context<POLICY_CHANNEL_SIZE> and use it to register the Type‑C service as a power-policy message receiver.
power-policy-service/src/task.rs Replaces internal singleton creation with an explicit PowerPolicy<POLICY_CHANNEL_SIZE> argument; registers comms, then optional non‑Type‑C power devices and chargers via the policy’s context, and runs the processing loop.
power-policy-service/src/provider.rs Makes provider‑side PowerPolicy methods generic over POLICY_CHANNEL_SIZE and iterates devices as device::Device<POLICY_CHANNEL_SIZE>.
power-policy-service/src/lib.rs Refactors PowerPolicy into PowerPolicy<const POLICY_CHANNEL_SIZE: usize> holding a concrete policy::Context<POLICY_CHANNEL_SIZE>, adds a new constructor, and updates internal methods to use generic devices and context.
power-policy-service/src/consumer.rs Updates consumer-side logic to work with PowerPolicy<POLICY_CHANNEL_SIZE>, including iterating Device<POLICY_CHANNEL_SIZE> from the context and using context methods like check_chargers_ready/init_chargers.
examples/std/src/lib/type_c/mod.rs Adds DummyCharger and DummyPowerDevice<POLICY_CHANNEL_SIZE> container types implementing the appropriate charger/power device container traits for examples.
examples/std/src/lib/type_c/mock_controller.rs Introduces a POWER_POLICY_CHANNEL_SIZE const and updates the Wrapper type alias to ControllerWrapper<..., Validator, POWER_POLICY_CHANNEL_SIZE>.
examples/std/src/bin/type_c/unconstrained.rs Parameterizes the example over POLICY_CHANNEL_SIZE, constructs a PowerPolicy<POLICY_CHANNEL_SIZE> and Storage<..., POLICY_CHANNEL_SIZE> wired to power_service.context, and passes the context into the Type‑C service tasks and wrappers.
examples/std/src/bin/type_c/ucsi.rs Mirrors the unconstrained example changes for the UCSI scenario: creates a PowerPolicy<POLICY_CHANNEL_SIZE>, passes its context into Type‑C storage/wrappers and service tasks, and runs the power-policy task with dummy devices.
examples/std/src/bin/type_c/service.rs Similar wiring of a PowerPolicy<POLICY_CHANNEL_SIZE> and its Context into the mock Type‑C service example, including storage creation and service/task parameter updates.
examples/std/src/bin/type_c/external.rs External Type‑C example now creates a standalone policy::Context<POLICY_CHANNEL_SIZE>, uses it to construct Type‑C storage/wrapper, and passes it into the Type‑C service task.
examples/std/src/bin/type_c/basic.rs Basic Type‑C example updated to use power::policy::device::Device<POWER_POLICY_CHANNEL_SIZE> and a policy::Context<POWER_POLICY_CHANNEL_SIZE>; however, the Controller::new signature incorrectly references crate::power::policy::policy::Context, which does not exist in this crate and will not compile.
examples/std/src/bin/power_policy.rs Power-policy standalone example refactored to use PowerPolicy<POWER_POLICY_CHANNEL_SIZE> and policy::device::Device<POWER_POLICY_CHANNEL_SIZE>, registering devices and message receivers through the instance Context.
examples/rt685s-evk/src/lib.rs Adds DummyCharger and DummyPowerDevice<POLICY_CHANNEL_SIZE> types to support the rt685s-evk power-policy examples.
examples/rt685s-evk/src/bin/type_c_cfu.rs Wires in POLICY_CHANNEL_SIZE, instantiates a PowerPolicy<POLICY_CHANNEL_SIZE>, updates the Wrapper alias and Storage<..., POLICY_CHANNEL_SIZE>, and passes the power-policy context through to the Type‑C service.
examples/rt685s-evk/src/bin/type_c.rs Similar to type_c_cfu.rs: introduces POLICY_CHANNEL_SIZE, constructs PowerPolicy<POLICY_CHANNEL_SIZE>/Storage<..., POLICY_CHANNEL_SIZE>, and threads the context into service and wrapper setup.
embedded-service/src/power/policy/policy.rs Replaces the global static context with a generic, instantiable Context<POLICY_CHANNEL_SIZE>, moves registration and request/charger helpers onto this type, and updates device/charger iteration and action helpers to be const‑generic.
embedded-service/src/power/policy/mod.rs Removes the re-export of the old global register_device helper, leaving init as the only re-export from policy.
embedded-service/src/power/policy/device.rs Makes Device const‑generic, adds a Context<CHANNEL_SIZE> back-reference, and updates its API (and DeviceContainer) to propagate the channel-size generic and support context-based request dispatch.
embedded-service/src/power/policy/action/policy.rs Refactors policy action state machines (Policy and AnyState) to track the device’s channel-size const generic and use device::Device<N>.
embedded-service/src/power/policy/action/device.rs Refactors device action state machines to be const‑generic, routing all policy requests through the device’s context_ref and keeping state transitions consistent with the new Device<N> and Context API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tullom tullom merged commit c6f2ee0 into OpenDevicePartnership:v0.2.0 Jan 27, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants