type-c-service: Remove external messaging#757
type-c-service: Remove external messaging#757RobertZ2011 wants to merge 4 commits intoOpenDevicePartnership:v0.2.0from
Conversation
There was a problem hiding this comment.
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 introducedservice::context::Contextto 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 requiresNamed. - 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 (CommsMessage → Event, 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
Futureis referenced in theSender/Receivertrait signatures but isn’t imported in this module. As written, this file won’t compile; add an explicituse core::future::Future;(or qualifycore::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.
abb3a3f to
1c7441a
Compare
1c7441a to
85631d0
Compare
There was a problem hiding this comment.
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 migratestype-c-serviceto 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.
56285c8 to
1661f1b
Compare
There was a problem hiding this comment.
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 UsciChangeIndicatorappears to use an inconsistent acronym (UCSI vs USCI). Consider renaming the type (and this variant payload) toUcsiChangeIndicatorto match the UCSI spec andEvent::UcsiCci.
1661f1b to
bdca3d6
Compare
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
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.
| use type_c_interface::service::event::{Event, UsciChangeIndicator}; | |
| use type_c_interface::service::event::{Event as TypeCEvent, UsciChangeIndicator}; |
| "dep:log", | ||
| "embassy-sync/log", | ||
| "embassy-time/log", | ||
| "embedded-services/log", |
There was a problem hiding this comment.
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.
| "embedded-services/log", | |
| "embedded-services/log", | |
| "embedded-usb-pd/log", |
type-c-interfacecrate.