Skip to content

Type-C: Trait refactor and clean-up#821

Merged
RobertZ2011 merged 9 commits into
OpenDevicePartnership:v0.2.0from
RobertZ2011:type-c-trait-refactor
May 13, 2026
Merged

Type-C: Trait refactor and clean-up#821
RobertZ2011 merged 9 commits into
OpenDevicePartnership:v0.2.0from
RobertZ2011:type-c-trait-refactor

Conversation

@RobertZ2011
Copy link
Copy Markdown
Contributor

@RobertZ2011 RobertZ2011 commented May 4, 2026

Refactor traits and do some general clean-up.

  • Move Controller trait into its own module.
  • Remove bus error type from traits to make it easier to abstract over PD hardware.
  • Break-up Controller trait into multiple traits.
  • Introduce corresponding port-level traits.

@RobertZ2011 RobertZ2011 self-assigned this May 4, 2026
@RobertZ2011 RobertZ2011 force-pushed the type-c-trait-refactor branch 2 times, most recently from c8babd9 to 33d85d6 Compare May 6, 2026 21:31
@RobertZ2011 RobertZ2011 changed the title Type c trait refactor Type-C: Trait refactor and clean-up May 6, 2026
@RobertZ2011 RobertZ2011 force-pushed the type-c-trait-refactor branch from a157448 to 8673763 Compare May 6, 2026 21:43
@RobertZ2011 RobertZ2011 requested review from Copilot May 6, 2026 21:49
Copy link
Copy Markdown
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

Refactors the Type‑C interface and service to split the monolithic controller trait into smaller controller- and port-level traits, while also removing bus error types from the public traits to better abstract over PD hardware implementations.

Changes:

  • Introduces type_c_interface::{control, controller, port::*} modules to separate control types from controller/port traits.
  • Updates type-c-service controller wrappers, bridge layer, and the TPS6699x driver to implement and use the new trait structure and simplified PdError-only error model.
  • Updates examples and service code to the new module paths and response types.

Reviewed changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
type-c-service/src/service/vdm.rs Updates VDM type imports to new control::vdm module.
type-c-service/src/service/mod.rs Switches PortStatus import to new control::pd location.
type-c-service/src/driver/tps6699x.rs Splits trait impls, removes bus error exposure, and normalizes errors to PdError.
type-c-service/src/controller/mod.rs Adapts port event processing to new Pd trait and PdError return types.
type-c-service/src/controller/pd.rs Implements new port-level PD traits and updates internal helpers to return PdError.
type-c-service/src/controller/power.rs Updates power-policy integration for new controller/port trait split and PdError mapping.
type-c-service/src/controller/retimer.rs Adds port-level retimer trait forwarding implementation.
type-c-service/src/controller/type_c.rs Adds port-level Type‑C state machine trait forwarding implementation.
type-c-service/src/controller/ucsi.rs Adds port-level UCSI LPM trait forwarding implementation.
type-c-service/src/controller/max_sink_voltage.rs Adds port-level max-sink-voltage trait forwarding implementation.
type-c-service/src/controller/electrical_disconnect.rs Adds port-level electrical-disconnect trait forwarding implementation.
type-c-service/src/bridge/mod.rs Updates bridge bounds and command handling to new controller traits and response type.
type-c-service/src/bridge/event_receiver.rs Updates deferred request/response types to non-lifetime Response.
type-c-interface/src/lib.rs Exposes new control, controller, and ucsi modules.
type-c-interface/src/control/mod.rs Adds control-type module namespace.
type-c-interface/src/control/pd.rs Moves PortStatus and PD config types into control::pd.
type-c-interface/src/control/dp.rs Moves DP config/status types into control::dp.
type-c-interface/src/control/power.rs Moves system power state enum into control::power.
type-c-interface/src/control/retimer.rs Moves retimer FW update state enum into control::retimer.
type-c-interface/src/control/tbt.rs Moves Thunderbolt config type into control::tbt.
type-c-interface/src/control/type_c.rs Moves Type‑C state machine state enum into control::type_c.
type-c-interface/src/control/usb.rs Moves USB control config type into control::usb.
type-c-interface/src/control/vdm.rs Moves VDM types/constants into control::vdm.
type-c-interface/src/controller/mod.rs Introduces top-level controller trait and ControllerId in new module.
type-c-interface/src/controller/pd.rs Introduces controller-level PD trait(s) parameterized by LocalPortId.
type-c-interface/src/controller/power.rs Introduces controller-level system power state trait.
type-c-interface/src/controller/retimer.rs Introduces controller-level retimer trait.
type-c-interface/src/controller/type_c.rs Introduces controller-level Type‑C state machine trait.
type-c-interface/src/controller/max_sink_voltage.rs Introduces controller-level max sink voltage trait.
type-c-interface/src/controller/electrical_disconnect.rs Introduces controller-level electrical disconnect trait.
type-c-interface/src/port/mod.rs Removes old monolithic controller trait/types; keeps IPC device/command wiring.
type-c-interface/src/port/pd.rs Adds port-level PD trait(s) without LocalPortId parameter.
type-c-interface/src/port/power.rs Adds port-level system power state trait.
type-c-interface/src/port/retimer.rs Adds port-level retimer trait.
type-c-interface/src/port/type_c.rs Adds port-level Type‑C state machine trait.
type-c-interface/src/port/max_sink_voltage.rs Adds port-level max sink voltage trait.
type-c-interface/src/port/electrical_disconnect.rs Adds port-level electrical disconnect trait.
type-c-interface/src/ucsi.rs Adds UCSI LPM trait in the interface crate.
type-c-interface/src/service/event.rs Updates service event type imports to new control::* modules.
type-c-interface/src/service/context.rs Updates context wiring for new control/controller modules and simplified internal responses.
examples/std/src/lib/type_c/mock_controller.rs Updates mock controller to implement new controller traits.
examples/std/src/bin/type_c/basic.rs Updates example to new controller IDs and removes controller status path.
examples/std/src/bin/type_c/service.rs Updates example imports/types for new module layout.
examples/std/src/bin/type_c/ucsi.rs Updates UCSI example imports/types for new module layout.
examples/std/src/bin/type_c/unconstrained.rs Updates example imports for moved ControllerId.
examples/rt685s-evk/src/bin/type_c.rs Updates embedded example imports/types for new module layout.
examples/rt685s-evk/src/bin/type_c_cfu.rs Updates embedded example imports/types for new module layout.

Comment thread type-c-interface/src/ucsi.rs
Comment thread type-c-interface/src/port/pd.rs
Comment thread type-c-interface/src/port/type_c.rs
Comment thread type-c-interface/src/port/retimer.rs
Comment thread type-c-interface/src/port/power.rs Outdated
Comment thread type-c-interface/src/controller/type_c.rs
Comment thread type-c-interface/src/controller/electrical_disconnect.rs
Comment thread type-c-interface/src/controller/max_sink_voltage.rs
Comment thread type-c-service/src/controller/mod.rs Outdated
Comment thread type-c-interface/src/control/pd.rs Outdated
@RobertZ2011 RobertZ2011 force-pushed the type-c-trait-refactor branch from 8673763 to 9ca6e31 Compare May 6, 2026 21:57
@RobertZ2011 RobertZ2011 marked this pull request as ready for review May 6, 2026 22:00
@RobertZ2011 RobertZ2011 requested review from a team as code owners May 6, 2026 22:00
Comment thread type-c-service/src/bridge/mod.rs
Comment thread type-c-interface/src/controller/power.rs Outdated
Comment thread type-c-interface/src/control/vdm.rs Outdated
@RobertZ2011 RobertZ2011 force-pushed the type-c-trait-refactor branch from 0e1725c to dd7b740 Compare May 7, 2026 18:15
@RobertZ2011 RobertZ2011 requested a review from jerrysxie May 7, 2026 18:20
Move the `Controller` trait into its own module, and create a dedicated
module for types used as arguments/return values for various PD
functions.
The `Controller` trait is meant to abstract over PD controller hardware.
However, the current implementation exposes the underlying bus error
type. This isn't particulary useful, leaks implementation details, and
makes code more complicated when using enum dispatch. Remove it.
Implementators of this trait should log bus-specific error information
and return a `PdError`.
Break-up this trait to make everything more modular.
The LPM command contains the port number. Combine controller and port
ucsi traits.
@RobertZ2011 RobertZ2011 force-pushed the type-c-trait-refactor branch from dd7b740 to a715226 Compare May 13, 2026 15:17
@RobertZ2011 RobertZ2011 merged commit a6db5b4 into OpenDevicePartnership:v0.2.0 May 13, 2026
16 checks passed
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.

5 participants