Type c port traits#774
Conversation
Update message types in preperation for implementing port traits on the proxy.
There was a problem hiding this comment.
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) undertype-c-interface/src/port/*. - Refactor
type-c-serviceto remove generic PSU coupling inService, introduce a dedicatedEventReceiver, 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. |
| /// 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 |
There was a problem hiding this comment.
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.
| 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>>>; |
There was a problem hiding this comment.
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.
| 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>>>; |
There was a problem hiding this comment.
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.
| 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>>>; |
There was a problem hiding this comment.
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.
| /// 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>>>; |
There was a problem hiding this comment.
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.
| 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(), |
There was a problem hiding this comment.
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.
| /// 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) { |
There was a problem hiding this comment.
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.
| /// 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 |
There was a problem hiding this comment.
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.
| 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}, | ||
| }; |
There was a problem hiding this comment.
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.
| @@ -0,0 +1,27 @@ | |||
| //! Types and traits related to registration for the type-C service. | |||
There was a problem hiding this comment.
Doc comment has an extra space: "Types and traits" → "Types and traits".
| //! Types and traits related to registration for the type-C service. | |
| //! Types and traits related to registration for the type-C service. |
No description provided.