Skip to content

Type c port traits#774

Draft
RobertZ2011 wants to merge 6 commits intoOpenDevicePartnership:v0.2.0from
RobertZ2011:type-c-port-traits
Draft

Type c port traits#774
RobertZ2011 wants to merge 6 commits intoOpenDevicePartnership:v0.2.0from
RobertZ2011:type-c-port-traits

Conversation

@RobertZ2011
Copy link
Copy Markdown
Contributor

No description provided.

@RobertZ2011 RobertZ2011 self-assigned this Apr 1, 2026
Copilot AI review requested due to automatic review settings April 1, 2026 22:34
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

This PR refactors the Type‑C service/wrapper event flow and introduces new per-port capability traits in type-c-interface, while updating examples and event plumbing to use the new EventData-based power-policy pubsub wiring.

Changes:

  • Add new Type‑C port capability traits (Pd, Usb, Ucsi, Retimer, DisplayPort, Thunderbolt, state machine traits) under type-c-interface/src/port/*.
  • Refactor type-c-service to remove generic PSU coupling in Service, introduce a dedicated EventReceiver, and update the task API + examples accordingly.
  • Extend proxy channel payloads to carry both power-policy and port commands/responses.

Reviewed changes

Copilot reviewed 27 out of 32 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
type-c-service/src/wrapper/proxy.rs Introduces PortProxy* command/response enums and updates proxy channel/device types to use them.
type-c-service/src/wrapper/power.rs Renames/retargets the “power command” wait path to return PortProxyCommandData.
type-c-service/src/wrapper/pd.rs Refactors port-command processing to return Result<PortResponseData, PdError> and use local port indexing.
type-c-service/src/wrapper/mod.rs Updates wrapper event loop selection and routes proxy port/power commands into wrapper events/outputs.
type-c-service/src/wrapper/message.rs Replaces deferred TCPM request event with a simpler EventPortCommand + changes output shape.
type-c-service/src/task.rs Replaces closure-based task loop with a default loop that consumes EventReceiver events and calls Service::process_event.
type-c-service/src/service/mod.rs Refactors Service state ownership, adds EventReceiver to drive the event loop, updates event processing entrypoint.
type-c-service/src/service/power.rs Updates power-policy event handling to operate on &mut self with new state layout.
type-c-service/src/service/ucsi.rs Refactors UCSI processing to mutate self.state.ucsi directly (no internal mutex).
type-c-service/src/service/pd.rs Adjusts PD helper impl to match new Service<'_> shape.
type-c-service/src/service/vdm.rs Adjusts VDM helper impl to match new Service<'_> shape.
type-c-service/src/service/registration.rs Adds a new Registration trait and ArrayRegistration implementation for port registration.
type-c-service/src/service/port.rs Removes now-obsolete wait_port_flags helper (moved into EventReceiver).
type-c-service/src/driver/tps6699x.rs Updates controller status API to use non-generic ControllerStatus.
type-c-interface/src/service/context.rs Updates internal/controller response and controller status APIs to remove 'static response lifetime generics.
type-c-interface/src/port/mod.rs Adds new port capability submodules and updates response/controller-status types to non-generic forms.
type-c-interface/src/port/pd.rs Adds core Pd port trait.
type-c-interface/src/port/retimer.rs Adds Retimer trait.
type-c-interface/src/port/state_machine.rs Adds Type‑C and PD state machine traits.
type-c-interface/src/port/usb.rs Adds Usb trait.
type-c-interface/src/port/ucsi.rs Adds Ucsi trait.
type-c-interface/src/port/displayport.rs Adds DisplayPort trait.
type-c-interface/src/port/thunderbolt.rs Adds Thunderbolt trait.
power-policy-interface/src/service/event.rs Makes EventData clonable for pubsub/publisher use.
embedded-service/src/lib.rs Exposes new bus_error module.
embedded-service/src/event.rs Adds pubsub Sender/Receiver impls and MapSender usage helpers.
embedded-service/src/bus_error.rs Introduces BusError trait for bus-specific associated error typing.
examples/std/src/bin/type_c/unconstrained.rs Updates example wiring to use EventData pubsub + MapSender, and new Type‑C task signature.
examples/std/src/bin/type_c/ucsi.rs Updates example wiring to use EventData pubsub + MapSender, and new Type‑C task signature.
examples/std/src/bin/type_c/service.rs Updates example wiring to use EventData pubsub + MapSender, and new Type‑C task signature.
examples/rt685s-evk/src/bin/type_c.rs Updates embedded example wiring to use EventData pubsub + MapSender, and new Type‑C task signature.
examples/rt685s-evk/src/bin/type_c_cfu.rs Updates embedded example wiring to use EventData pubsub + MapSender, and new Type‑C task signature.

Comment on lines +8 to +13
/// Core PD trait containing base functionality from the PD spec.
pub trait Pd: BusError {
/// Returns the port status
fn get_port_status(&mut self) -> impl Future<Output = Result<PortStatus, Error<Self::BusError>>>;

/// Clear the dead battery flag
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

This new trait uses impl Future<...> in method signatures but does not import core::future::Future, so it will not compile. Add use core::future::Future; (or fully qualify core::future::Future) in this module.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +13
pub trait Usb: Pd {
/// Set USB control configuration
fn set_usb_control(&mut self, config: UsbControlConfig) -> impl Future<Output = Result<(), Error<Self::BusError>>>;

/// Get USB control configuration
fn get_usb_control(&mut self) -> impl Future<Output = Result<UsbControlConfig, Error<Self::BusError>>>;
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

This new trait uses impl Future<...> in method signatures but does not import core::future::Future, so it will not compile. Add use core::future::Future; (or fully qualify core::future::Future) in this module.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +12
pub trait DisplayPort: Pd {
/// Get DisplayPort status
fn get_dp_status(&mut self) -> impl Future<Output = Result<DpStatus, Error<Self::BusError>>>;
/// Set DisplayPort configuration
fn set_dp_config(&mut self, config: DpConfig) -> impl Future<Output = Result<(), Error<Self::BusError>>>;
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

This new trait uses impl Future<...> in method signatures but does not import core::future::Future, so it will not compile. Add use core::future::Future; (or fully qualify core::future::Future) in this module.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +12
pub trait Thunderbolt: Pd {
/// Set Thunderbolt configuration
fn set_tbt_config(&mut self, config: TbtConfig) -> impl Future<Output = Result<(), Error<Self::BusError>>>;
/// Get Thunderbolt configuration
fn get_tbt_config(&mut self) -> impl Future<Output = Result<TbtConfig, Error<Self::BusError>>>;
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

This new trait uses impl Future<...> in method signatures but does not import core::future::Future, so it will not compile. Add use core::future::Future; (or fully qualify core::future::Future) in this module.

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +13
/// Trait for ports that support Type-C state machine operations
pub trait TypeCStateMachine: Pd {
/// Set Type-C state-machine configuration
fn set_type_c_state_machine_config(
&mut self,
state: TypeCStateMachineState,
) -> impl Future<Output = Result<(), Error<Self::BusError>>>;
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

This new trait uses impl Future<...> in method signatures but does not import core::future::Future, so it will not compile. Add use core::future::Future; (or fully qualify core::future::Future) in this module.

Copilot uses AI. Check for mistakes.
Comment on lines +384 to 388
select4(
self.wait_port_pending(&controller_state, &mut controller),
self.wait_power_command(),
self.registration.pd_controller.receive(),
self.wait_port_command(),
self.wait_cfu_command(),
self.wait_sink_ready_timeout(),
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

wait_next() no longer selects over self.registration.pd_controller.receive() / deferred Type‑C commands. Since Context::send_port_command* and Context::send_controller_command* still route through type_c_interface::port::Device::execute_command(), those calls will block forever without a task servicing the deferred channel. Reintroduce handling of pd_controller.receive() (and respond with the appropriate type_c_interface::port::Response) or move that command-handling loop elsewhere so Context APIs (e.g., Context::set_unconstrained_power) continue to work.

Copilot uses AI. Check for mistakes.
Comment on lines +101 to +105
/// Wait for a port command
///
/// Returns (local port ID, deferred request)
/// DROP SAFETY: Call to a select over drop safe futures
pub(super) async fn wait_power_command(&self) -> (LocalPortId, CommandData) {
pub(super) async fn wait_port_command(&self) -> (LocalPortId, PortProxyCommandData) {
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

The doc comment says this returns a "deferred request", but the function now returns PortProxyCommandData (not a deferred request type). Please update the comment to match the actual return value/semantics to avoid confusion when wiring new proxy commands.

Copilot uses AI. Check for mistakes.
Comment on lines 101 to 105
/// Controller command output data
pub struct OutputControllerCommand<'a> {
/// Controller request
pub request: deferred::Request<'a, GlobalRawMutex, port::Command, port::Response<'static>>,
pub struct OutputControllerCommand {
/// Port ID
pub port: LocalPortId,
/// Response
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

OutputControllerCommand (and its doc comment) no longer represents a controller/TCPM deferred command; it now carries a per-port Result<PortResponseData, PdError> that is routed back via PortProxyResponseData::Port. Renaming this type/variant (and its comment) to reflect "port command" responses would prevent confusion and reduce the chance of incorrectly wiring future controller-level commands.

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +9
use core::{future::ready, marker::PhantomData};

use core::marker::PhantomData;
use crate::error;

use embassy_sync::channel::{DynamicReceiver, DynamicSender};
use embassy_sync::{
channel::{DynamicReceiver, DynamicSender},
pubsub::{DynImmediatePublisher, DynSubscriber, WaitResult},
};
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

This module now uses impl Future<...> in the Sender/Receiver trait method signatures (later in the file), but core::future::Future is not imported anywhere, which will fail to compile. Add use core::future::Future; (or fully qualify core::future::Future) in this module.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,27 @@
//! Types and traits related to registration for the type-C service.
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

Doc comment has an extra space: "Types and traits" → "Types and traits".

Suggested change
//! Types and traits related to registration for the type-C service.
//! Types and traits related to registration for the type-C service.

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