Type-C: Trait refactor and clean-up#821
Merged
RobertZ2011 merged 9 commits intoMay 13, 2026
Merged
Conversation
c8babd9 to
33d85d6
Compare
a157448 to
8673763
Compare
Contributor
There was a problem hiding this comment.
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-servicecontroller wrappers, bridge layer, and the TPS6699x driver to implement and use the new trait structure and simplifiedPdError-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. |
8673763 to
9ca6e31
Compare
jerrysxie
requested changes
May 7, 2026
0e1725c to
dd7b740
Compare
jerrysxie
approved these changes
May 7, 2026
kurtjd
approved these changes
May 12, 2026
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.
This information is too hardware specific to expose it in a trait.
dd7b740 to
a715226
Compare
tullom
approved these changes
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor traits and do some general clean-up.
Controllertrait into its own module.Controllertrait into multiple traits.