Skip to content

type-c-service: Remove external messaging#757

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

type-c-service: Remove external messaging#757
RobertZ2011 wants to merge 4 commits intoOpenDevicePartnership:v0.2.0from
RobertZ2011:type-c-refactor-remove-external

Conversation

@RobertZ2011
Copy link
Contributor

@RobertZ2011 RobertZ2011 commented Mar 18, 2026

  • External messaging is no longer needed as functions can now be called directly.
  • Break-out type-c-interface crate.
  • Remove context arguments from functions.

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.

@RobertZ2011 RobertZ2011 force-pushed the type-c-refactor-remove-external branch from abb3a3f to 1c7441a Compare March 23, 2026 18:21
@RobertZ2011 RobertZ2011 force-pushed the type-c-refactor-remove-external branch from 1c7441a to 85631d0 Compare March 25, 2026 20:42
Copilot AI review requested due to automatic review settings March 25, 2026 20:56
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 by extracting the Type‑C controller/event API surface into a new type-c-interface crate and updating type-c-service to use that interface while removing the previous “external” command path and caller-managed intrusive list wiring.

Changes:

  • Introduces type-c-interface (port types/events + service::context::Context) and migrates type-c-service to depend on it.
  • Removes the old type-c-service::type_c::{controller, external} implementation and updates wrappers/service/driver code to the new interface types.
  • Updates example applications and lockfiles to the new architecture (currently incomplete / broken in places).

Reviewed changes

Copilot reviewed 28 out of 38 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
type-c-service/src/wrapper/vdm.rs Switches controller/event imports to type_c_interface.
type-c-service/src/wrapper/pd.rs Migrates command/response types to type_c_interface::port equivalents.
type-c-service/src/wrapper/mod.rs Updates docs/imports and changes controller registration to use type_c_interface::service::context::Context.
type-c-service/src/wrapper/message.rs Repoints deferred controller command types to type_c_interface::port.
type-c-service/src/wrapper/dp.rs Uses type_c_interface::port::Controller trait.
type-c-service/src/wrapper/cfu.rs Uses type_c_interface::port::Controller trait.
type-c-service/src/wrapper/backing.rs Registration/storage types updated to reference type_c_interface context/device/types.
type-c-service/src/util.rs Removes old re-exports/types (moved into type-c-interface), keeps utility helpers.
type-c-service/src/type_c/external.rs Deleted: removes external command definitions/handlers.
type-c-service/src/type_c/controller.rs Deleted: moves controller API/types into type-c-interface.
type-c-service/src/task.rs Trait bounds and registration call updated to new interface context.
type-c-service/src/service/vdm.rs Service VDM helpers now call context directly (no intrusive list parameter).
type-c-service/src/service/ucsi.rs UCSI handling updated to query ports via context and broadcast type_c_interface::service::event::Event.
type-c-service/src/service/power.rs Updates event types and removes controllers-list dependence.
type-c-service/src/service/port.rs Deletes external port command processing (external path removed).
type-c-service/src/service/pd.rs PD alert retrieval now uses context directly.
type-c-service/src/service/mod.rs Removes external command event loop path and intrusive list field; adopts type_c_interface context.
type-c-service/src/service/controller.rs Deleted: external controller command handling removed.
type-c-service/src/lib.rs Removes pub mod type_c, switches event imports to type_c_interface.
type-c-service/src/driver/tps6699x.rs Driver updated to implement/use type_c_interface::port types and constants.
type-c-service/Cargo.toml Adds dependency + feature wiring for type-c-interface.
type-c-interface/src/lib.rs New crate root exporting port and service.
type-c-interface/Cargo.toml New crate manifest with defmt/log feature plumbing.
type-c-interface/src/port/mod.rs New: extracted port/controller commands, responses, types, and constants.
type-c-interface/src/port/event.rs New: extracted port event bitfields + iterators + tests.
type-c-interface/src/service/mod.rs New: exports context and event modules.
type-c-interface/src/service/event.rs New: defines service broadcast event types.
type-c-interface/src/service/context.rs New: owns controller intrusive list + provides async command helpers and broadcasting.
examples/std/src/bin/type_c/unconstrained.rs Updated context initialization (but currently inconsistent with later usage).
examples/std/src/bin/type_c/ucsi.rs Updated context usage (currently incomplete; large block commented out).
examples/std/src/bin/type_c/service.rs Updated context usage/imports (currently still references removed modules).
examples/std/src/bin/type_c/basic.rs Updated context usage/imports (currently still references removed modules).
examples/rt685s-evk/src/bin/type_c.rs Updated context initialization (currently imports non-existent wrapper::controller::ControllerId / missing re-export).
examples/rt685s-evk/src/bin/type_c_cfu.rs Updated context initialization (currently missing NoopSender import and uses non-existent wrapper::controller::ControllerId).
examples/std/Cargo.lock Adds type-c-interface to the example dependency graph.
examples/rt685s-evk/Cargo.lock Adds type-c-interface to the example dependency graph.
Cargo.toml Adds type-c-interface as a workspace member + workspace dependency path.
Cargo.lock Adds type-c-interface package entry and dependency edges.
Comments suppressed due to low confidence (1)

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

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

Also remove context function arguments.
Copilot AI review requested due to automatic review settings March 25, 2026 21:19
@RobertZ2011 RobertZ2011 force-pushed the type-c-refactor-remove-external branch from 56285c8 to 1661f1b Compare March 25, 2026 21:19
@RobertZ2011 RobertZ2011 changed the title Type c refactor remove external type-c-service: Remove external messaging Mar 25, 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

Copilot reviewed 31 out of 41 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (2)

type-c-interface/src/service/event.rs:5

  • Typo in doc comment: "acessory" should be "accessory".
    type-c-interface/src/service/event.rs:32
  • UsciChangeIndicator appears to use an inconsistent acronym (UCSI vs USCI). Consider renaming the type (and this variant payload) to UcsiChangeIndicator to match the UCSI spec and Event::UcsiCci.

@RobertZ2011 RobertZ2011 force-pushed the type-c-refactor-remove-external branch from 1661f1b to bdca3d6 Compare March 25, 2026 21:25
@RobertZ2011 RobertZ2011 marked this pull request as ready for review March 25, 2026 21:31
@RobertZ2011 RobertZ2011 requested a review from a team as a code owner March 25, 2026 21:31
Copilot AI review requested due to automatic review settings March 25, 2026 21:31
@RobertZ2011 RobertZ2011 requested a review from a team as a code owner March 25, 2026 21:31
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

Copilot reviewed 31 out of 41 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

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

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

};
use embedded_usb_pd::ucsi::{GlobalCommand, ResponseData, lpm, ppm};
use embedded_usb_pd::{PdError, PowerRole};
use type_c_interface::service::event::{Event, UsciChangeIndicator};
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

use super::*; brings the service’s own Event type into scope, and this file also imports type_c_interface::service::event::Event. This results in a duplicate Event name in the same module (won’t compile). Rename one of the imports (e.g., Event as TypeCEvent) or avoid glob-importing super::* here.

Suggested change
use type_c_interface::service::event::{Event, UsciChangeIndicator};
use type_c_interface::service::event::{Event as TypeCEvent, UsciChangeIndicator};

Copilot uses AI. Check for mistakes.
"dep:log",
"embassy-sync/log",
"embassy-time/log",
"embedded-services/log",
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The log feature doesn’t forward embedded-usb-pd/log, even though this crate depends on embedded-usb-pd (and the defmt feature forwards embedded-usb-pd/defmt). This makes type-c-interface’s log feature incomplete/inconsistent; consider adding "embedded-usb-pd/log" to the log feature list.

Suggested change
"embedded-services/log",
"embedded-services/log",
"embedded-usb-pd/log",

Copilot uses AI. Check for mistakes.
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