Skip to content

Type c refactor remove external#757

Draft
RobertZ2011 wants to merge 14 commits intoOpenDevicePartnership:v0.2.0from
RobertZ2011:type-c-refactor-remove-external
Draft

Type c refactor remove external#757
RobertZ2011 wants to merge 14 commits intoOpenDevicePartnership:v0.2.0from
RobertZ2011:type-c-refactor-remove-external

Conversation

@RobertZ2011
Copy link
Contributor

No description provided.

Rename the current `'a` lifetime to `'device` for clarity. Introduce a
separate `device_storage` lifetime since a single lifetime
overconstrains things and can lead to situations where borrows live too
long and lead to issues with drops.
A receiver might only care that an event has happened and not what PSU
generated the event. Currently, such a receiver would have to be generic
over a PSU type that it never uses. Introduce `EventData` as a version
of `Event` for use in these cases. Also rename `D` generic argument to
`PSU` for clarity.
Add event broadcasting based on `Sender<_>` trait, a few utility
structs, and update tests to check broadcast events.
Rename to match corresponding registration struct.
Move `type_c` module code into existing files.
Copilot AI review requested due to automatic review settings March 18, 2026 18:46
@RobertZ2011 RobertZ2011 self-assigned this Mar 18, 2026
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 Type‑C service to remove the old type_c::external/controller surface area and consolidate controller registration/messaging under the service wrapper, while also evolving power‑policy to use a registration abstraction and emit service events to listeners.

Changes:

  • Type‑C: moved controller + event definitions into wrapper::{controller,event} and introduced service::context::Context to own controller registration/lookup (instead of passing an intrusive list around).
  • Power policy: introduced service::registration::{Registration, ArrayRegistration} and updated service/task/tests/examples to use it; PSU now requires Named.
  • Added/updated tests for provider/consumer/unconstrained power policy flows.

Reviewed changes

Copilot reviewed 40 out of 49 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
type-c-service/src/wrapper/vdm.rs Updates imports to new wrapper module layout.
type-c-service/src/wrapper/proxy.rs Implements Named for proxy PSU device to satisfy new PSU bounds.
type-c-service/src/wrapper/pd.rs Repoints controller imports to wrapper::controller.
type-c-service/src/wrapper/mod.rs Exposes new wrapper modules and switches controller registration to service::context::Context.
type-c-service/src/wrapper/message.rs Repoints controller/event imports to wrapper modules.
type-c-service/src/wrapper/event.rs New TCPM event bitfields + iterators and unit tests.
type-c-service/src/wrapper/dp.rs Updates controller import path to wrapper controller.
type-c-service/src/wrapper/controller.rs New consolidated PD controller types/traits under wrapper.
type-c-service/src/wrapper/cfu.rs Updates controller trait import path.
type-c-service/src/wrapper/backing.rs Updates stored context/controller types to new service/wrapper structures.
type-c-service/src/util.rs Strips legacy type_c module exports, leaving utility functions/constants.
type-c-service/src/type_c/external.rs Deletes legacy external command API.
type-c-service/src/type_c/controller.rs Deletes legacy controller/context implementation (migrated to service::context).
type-c-service/src/task.rs Uses wrapper controller trait and new registration entry point.
type-c-service/src/service/vdm.rs Removes intrusive list dependency; routes via service::context.
type-c-service/src/service/ucsi.rs Refactors UCSI handling to call into service::context and introduces local UcsiResponse.
type-c-service/src/service/power.rs Removes intrusive list plumbing; calls into context directly.
type-c-service/src/service/port.rs Removes legacy external command handling; keeps event streaming.
type-c-service/src/service/pd.rs Removes intrusive list dependency; routes via service::context.
type-c-service/src/service/mod.rs Refactors event loop away from external commands; switches to service event types (but currently contains conflict markers).
type-c-service/src/service/event.rs Renames comms message types (CommsMessageEvent, etc.).
type-c-service/src/service/controller.rs Removes external controller command processing.
type-c-service/src/service/context.rs New context that owns controller list, command routing, and broadcasting.
type-c-service/src/lib.rs Removes type_c module export; switches re-exports to wrapper event types.
type-c-service/src/driver/tps6699x.rs Updates imports/types to new wrapper controller + util module.
power-policy-service/tests/unconstrained.rs New async test for unconstrained consumer selection behavior.
power-policy-service/tests/provider.rs New async tests covering provider connect/upgrade/disconnect flows.
power-policy-service/tests/consumer.rs Refactors + expands consumer tests to assert service events.
power-policy-service/tests/common/mod.rs Adds shared harness with ArrayRegistration and service event channel plumbing.
power-policy-service/tests/common/mock.rs Updates mock PSU simulation API; implements Named.
power-policy-service/src/service/task.rs Updates task signature to use Registration and ArrayEventReceivers.
power-policy-service/src/service/registration.rs New registration abstraction for PSUs + service event senders.
power-policy-service/src/service/provider.rs Updates provider logic to use registration and emits provider events; adds provider removal helper.
power-policy-service/src/service/mod.rs Converts service to generic Registration, implements broadcasting via registered senders.
power-policy-service/src/service/consumer.rs Updates consumer selection logic to iterate registered PSUs.
power-policy-service/src/psu.rs Renames receivers helper to ArrayEventReceivers.
power-policy-service/Cargo.toml Comment formatting cleanup.
power-policy-interface/src/service/event.rs Adds device-less EventData and conversion from Event.
power-policy-interface/src/psu/mod.rs Changes Psu to extend Named (removes fn name() from trait).
examples/std/src/bin/type_c/unconstrained.rs Updates example wiring to new context + power policy registration.
examples/std/src/bin/type_c/ucsi.rs Updates example wiring; temporarily comments out OPM task logic.
examples/std/src/bin/type_c/service.rs Updates example wiring to new context + power policy registration.
examples/std/src/bin/type_c/basic.rs Updates controller registration to use service::context::Context.
examples/std/src/bin/power_policy.rs Updates example service registration and adds Named impl for example device.
examples/rt685s-evk/src/bin/type_c_cfu.rs Updates embedded example wiring to new context + power policy registration.
examples/rt685s-evk/src/bin/type_c.rs Updates embedded example wiring to new context + power policy registration; removes external calls.
embedded-service/src/named.rs Introduces Named trait in embedded-services.
embedded-service/src/lib.rs Exposes new named module.
embedded-service/src/event.rs Adds NoopSender and MapSender helpers (but currently missing an import for Future).
Comments suppressed due to low confidence (2)

embedded-service/src/event.rs:15

  • Future is referenced in the Sender/Receiver trait signatures but isn’t imported in this module. As written, this file won’t compile; add an explicit use core::future::Future; (or qualify core::future::Future) at the top.
//! Common traits for event senders and receivers

use core::marker::PhantomData;

use embassy_sync::channel::{DynamicReceiver, DynamicSender};

/// Common event sender trait
pub trait Sender<E> {
    /// Attempt to send an event
    ///
    /// Return none if the event cannot currently be sent
    fn try_send(&mut self, event: E) -> Option<()>;
    /// Send an event
    fn send(&mut self, event: E) -> impl Future<Output = ()>;
}

type-c-service/src/service/event.rs:6

  • Typo in doc comment: "acessory" should be "accessory".

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +222 to 234
<<<<<<< HEAD
pub(crate) fn controllers(&self) -> &'a intrusive_list::IntrusiveList {
self.controllers
=======
/// Register the Type-C service with the power policy service
pub fn register_comms(
&'static self,
_power_policy_context: &power_policy_service::service::context::Context,
) -> Result<(), intrusive_list::Error> {
// TODO
Ok(())
>>>>>>> d141e7e (type-c-service: Clean up module structure)
}
Comment on lines 61 to 67
/// PPM get capabilities implementation
fn process_get_capabilities(&self, controllers: &intrusive_list::IntrusiveList) -> ppm::ResponseData {
fn process_get_capabilities(&self) -> ppm::ResponseData {
debug!("Get PPM capabilities: {:?}", self.config.ucsi_capabilities);
let mut capabilities = self.config.ucsi_capabilities;
capabilities.num_connectors = external::get_num_ports(controllers) as u8;
// TODO: implement this when the refactoring stabilizes
capabilities.num_connectors = 0;
ppm::ResponseData::GetCapability(capabilities)
Comment on lines +483 to +485
/// Covert a local port ID to a global port ID
pub fn lookup_global_port(&self, port: LocalPortId) -> Result<GlobalPortId, PdError> {
Ok(*self.ports.get(port.0 as usize).ok_or(PdError::InvalidParams)?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants