diff --git a/Cargo.lock b/Cargo.lock index d269e019f..3e240778c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,18 +17,6 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -82,43 +70,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "askama" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4" -dependencies = [ - "askama_derive", - "itoa", - "percent-encoding", - "serde", - "serde_json", -] - -[[package]] -name = "askama_derive" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f" -dependencies = [ - "askama_parser", - "memchr", - "proc-macro2", - "quote", - "rustc-hash", - "syn 2.0.106", -] - -[[package]] -name = "askama_parser" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358" -dependencies = [ - "memchr", - "winnow 0.7.13", -] - [[package]] name = "autocfg" version = "1.5.0" @@ -335,15 +286,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bd422bfb4f24a97243f60b6a4443e63d810c925d8da4bb2d8fde26a7c1d57ec" -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "cordyceps" version = "0.3.4" @@ -414,15 +356,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" -[[package]] -name = "dd-manifest-tree" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5793572036e0a6638977c7370c6afc423eac848ee8495f079b8fd3964de7b9f9" -dependencies = [ - "yaml-rust2", -] - [[package]] name = "debug-service" version = "0.1.0" @@ -474,50 +407,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" dependencies = [ - "thiserror 2.0.16", + "thiserror", ] [[package]] name = "device-driver" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af0e43acfcbb0bb3b7435cc1b1dbb33596cacfec1eb243336b74a398e0bd6cbf" +checksum = "c2e4547bd66511372d2a38ac3c1b2892c7ebf83cf0d5411c3406e496c85a1d96" dependencies = [ "defmt 0.3.100", - "device-driver-macros", "embedded-io 0.6.1", "embedded-io-async 0.6.1", ] -[[package]] -name = "device-driver-generation" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3935aec9cf5bb2ab927f59ca69faecf976190390b0ce34c6023889e9041040c0" -dependencies = [ - "anyhow", - "askama", - "bitvec", - "convert_case", - "dd-manifest-tree", - "itertools 0.14.0", - "kdl", - "proc-macro2", - "quote", - "syn 2.0.106", -] - -[[package]] -name = "device-driver-macros" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fdc68ed515c4eddff2e95371185b4becba066085bf36d50f07f09782af98e17" -dependencies = [ - "device-driver-generation", - "proc-macro2", - "syn 2.0.106", -] - [[package]] name = "document-features" version = "0.2.11" @@ -880,7 +783,7 @@ dependencies = [ [[package]] name = "embedded-usb-pd" version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-usb-pd#1a8e79d3a2ac0d2837a34b045087cf0863146f7d" +source = "git+https://github.com/OpenDevicePartnership/embedded-usb-pd#21d0e228d21ddc6ccaeffc01d98ef9a5b87941ef" dependencies = [ "aquamarine", "bincode", @@ -889,15 +792,6 @@ dependencies = [ "embedded-hal-async", ] -[[package]] -name = "encoding_rs" -version = "0.8.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" -dependencies = [ - "cfg-if", -] - [[package]] name = "equivalent" version = "1.0.2" @@ -1007,30 +901,12 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", -] - [[package]] name = "hashbrown" version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -[[package]] -name = "hashlink" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" -dependencies = [ - "hashbrown 0.14.5", -] - [[package]] name = "heapless" version = "0.8.0" @@ -1096,7 +972,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" dependencies = [ "equivalent", - "hashbrown 0.15.5", + "hashbrown", ] [[package]] @@ -1137,24 +1013,6 @@ dependencies = [ "either", ] -[[package]] -name = "itoa" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" - -[[package]] -name = "kdl" -version = "6.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12661358400b02cbbf1fbd05f0a483335490e8a6bd1867620f2eeb78f304a22f" -dependencies = [ - "miette", - "num", - "thiserror 1.0.69", - "winnow 0.6.24", -] - [[package]] name = "keyberon" version = "0.2.0" @@ -1267,7 +1125,7 @@ dependencies = [ "espi-device", "num_enum", "smbus-pec", - "thiserror 2.0.16", + "thiserror", ] [[package]] @@ -1276,28 +1134,6 @@ version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" -[[package]] -name = "miette" -version = "7.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7" -dependencies = [ - "cfg-if", - "miette-derive", - "unicode-width", -] - -[[package]] -name = "miette-derive" -version = "7.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", -] - [[package]] name = "mimxrt600-fcb" version = "0.2.2" @@ -1389,70 +1225,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "num" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" -dependencies = [ - "num-bigint", - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", -] - -[[package]] -name = "num-complex" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -1539,12 +1311,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "percent-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" - [[package]] name = "pin-project" version = "1.1.10" @@ -1769,12 +1535,6 @@ version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" -[[package]] -name = "rustc-hash" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" - [[package]] name = "rustc_version" version = "0.2.3" @@ -1799,12 +1559,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - [[package]] name = "scoped-tls" version = "1.0.1" @@ -1852,18 +1606,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "serde_json" -version = "1.0.143" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - [[package]] name = "serde_spanned" version = "0.6.9" @@ -1991,33 +1733,13 @@ dependencies = [ "uuid", ] -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - [[package]] name = "thiserror" version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" dependencies = [ - "thiserror-impl 2.0.16", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", + "thiserror-impl", ] [[package]] @@ -2098,13 +1820,13 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.7.13", + "winnow", ] [[package]] name = "tps6699x" version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/tps6699x#aa3425136216dccfb107bff6b172a49b8972bb70" +source = "git+https://github.com/OpenDevicePartnership/tps6699x#ba1b3b17ebf048fc007eb2107a4d2ab8cb545adf" dependencies = [ "bincode", "bitfield 0.19.2", @@ -2223,18 +1945,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" -[[package]] -name = "unicode-segmentation" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - -[[package]] -name = "unicode-width" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" - [[package]] name = "unty" version = "0.0.4" @@ -2495,15 +2205,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "winnow" -version = "0.6.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" -dependencies = [ - "memchr", -] - [[package]] name = "winnow" version = "0.7.13" @@ -2522,17 +2223,6 @@ dependencies = [ "tap", ] -[[package]] -name = "yaml-rust2" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1a1c0bc9823338a3bdf8c61f994f23ac004c6fa32c08cd152984499b445e8d" -dependencies = [ - "arraydeque", - "encoding_rs", - "hashlink", -] - [[package]] name = "zerocopy" version = "0.8.26" diff --git a/embedded-service/src/type_c/controller.rs b/embedded-service/src/type_c/controller.rs index b367b3473..9de50e2db 100644 --- a/embedded-service/src/type_c/controller.rs +++ b/embedded-service/src/type_c/controller.rs @@ -11,7 +11,9 @@ use embedded_usb_pd::{ ado::Ado, pdinfo::{AltMode, PowerPathStatus}, type_c::ConnectionState, + vdm::structured::Svid, }; +use heapless::Vec; use super::{ATTN_VDM_LEN, ControllerId, OTHER_VDM_LEN, external}; use crate::ipc::deferred; @@ -262,6 +264,66 @@ pub enum TypeCStateMachineState { Disabled, } +/// Response from the `Discover SVIDs REQ` message and the [`PortCommandData::GetDiscoveredSvids`] command. +// Could be changed to hold the heapless::Vec directly if they were Copy or if PortResponseData was not Copy +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub struct DiscoveredSvids { + num_sop: usize, + sop: [Svid; Self::NUM_SVIDS], + + num_sop_prime: usize, + sop_prime: [Svid; Self::NUM_SVIDS], +} + +impl DiscoveredSvids { + /// The number of SVIDs that can be reported in a single [`PortResponseData::DiscoveredSvids`] response. + const NUM_SVIDS: usize = 8; + + /// Create a new response object from `sop` and `sop_prime`. + pub fn new(sop: Vec, sop_prime: Vec) -> Self { + let num_sop = sop.len(); + let num_sop_prime = sop_prime.len(); + + let mut sop_array = [Svid(0); _]; + for (svid, dest) in sop.into_iter().zip(sop_array.iter_mut()) { + *dest = svid; + } + + let mut sop_prime_array = [Svid(0); _]; + for (svid, dest) in sop_prime.into_iter().zip(sop_prime_array.iter_mut()) { + *dest = svid; + } + + Self { + num_sop, + sop: sop_array, + num_sop_prime, + sop_prime: sop_prime_array, + } + } + + /// Returns the number of SVIDs discovered on the SOP port partner. + pub fn number_sop_svids(&self) -> usize { + self.num_sop + } + + /// Returns an iterator over the SVIDs discovered on the SOP port partner. + pub fn svid_sop(&self) -> impl ExactSizeIterator { + self.sop.iter().copied().take(self.num_sop) + } + + /// Returns the number of SVIDs discovered on the SOP' cable plug. + pub fn number_sop_prime_svids(&self) -> usize { + self.num_sop_prime + } + + /// Returns an iterator over the SVIDs discovered on the SOP' cable plug. + pub fn svid_sop_prime(&self) -> impl ExactSizeIterator { + self.sop_prime.iter().copied().take(self.num_sop_prime) + } +} + /// Port-specific command data #[derive(Copy, Clone, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -319,6 +381,14 @@ pub enum PortCommandData { }, /// Set the system power state SetSystemPowerState(SystemPowerState), + /// Get the port's discovered SVIDs + GetDiscoveredSvids, + /// Trigger a hard reset on the given port. + HardReset, + /// Get the response to a Discover Identity command sent to the given port with SOP + GetDiscoverIdentitySop, + /// Get the response to a Discover Identity command sent to the given port with SOP' + GetDiscoverIdentitySopPrime, } /// Port-specific commands @@ -363,6 +433,12 @@ pub enum PortResponseData { DpStatus(DpStatus), /// UCSI response UcsiResponse(Result, PdError>), + /// Discovered SVIDs + DiscoveredSvids(DiscoveredSvids), + /// Discover Identity SOP response + DiscoverIdentitySop(embedded_usb_pd::vdm::structured::command::discover_identity::sop::ResponseVdos), + /// Discover Identity SOP' response + DiscoverIdentitySopPrime(embedded_usb_pd::vdm::structured::command::discover_identity::sop_prime::ResponseVdos), } impl PortResponseData { @@ -711,6 +787,37 @@ pub trait Controller { port: LocalPortId, state: SystemPowerState, ) -> impl Future>>; + + /// Get the discovered SVIDs for the given port. + fn get_discovered_svids( + &mut self, + port: LocalPortId, + ) -> impl Future>>; + + /// Trigger a hard reset on the given port. + fn hard_reset(&mut self, port: LocalPortId) -> impl Future>>; + + /// Get the latest response from the Discover Identity command targeting SOP. + fn get_discover_identity_sop_response( + &mut self, + port: LocalPortId, + ) -> impl Future< + Output = Result< + embedded_usb_pd::vdm::structured::command::discover_identity::sop::ResponseVdos, + Error, + >, + >; + + /// Get the latest response from the Discover Identity command targeting SOP'. + fn get_discover_identity_sop_prime_response( + &mut self, + port: LocalPortId, + ) -> impl Future< + Output = Result< + embedded_usb_pd::vdm::structured::command::discover_identity::sop_prime::ResponseVdos, + Error, + >, + >; } /// Internal context for managing PD controllers @@ -771,6 +878,19 @@ pub(super) async fn lookup_controller(controller_id: ControllerId) -> Result<&'s .ok_or(PdError::InvalidController) } +/// Lookup the controller and local port ID for a given global port ID. +pub(super) async fn lookup_global_port( + port_id: GlobalPortId, +) -> Result<(&'static Device<'static>, LocalPortId), PdError> { + for controller in CONTEXT.controllers.iter_only::() { + if let Ok(local_port) = controller.lookup_local_port(port_id) { + return Ok((controller, local_port)); + } + } + + Err(PdError::InvalidPort) +} + /// Get total number of ports on the system pub(super) fn get_num_ports() -> usize { CONTEXT @@ -1285,6 +1405,65 @@ impl ContextToken { } } + /// Get the discovered SVIDs for the given port. + pub async fn get_discovered_svids(&self, port: GlobalPortId) -> Result { + match self + .send_port_command(port, PortCommandData::GetDiscoveredSvids) + .await? + { + PortResponseData::DiscoveredSvids(svids) => Ok(svids), + r => { + error!("Invalid response: expected discovered SVIDs, got {:?}", r); + Err(PdError::InvalidResponse) + } + } + } + + /// Trigger a hard reset on the given port. + pub async fn hard_reset(&self, port: GlobalPortId) -> Result<(), PdError> { + match self.send_port_command(port, PortCommandData::HardReset).await? { + PortResponseData::Complete => Ok(()), + _ => Err(PdError::InvalidResponse), + } + } + + /// Get the latest response from the Discover Identity command targeting SOP. + pub async fn get_discover_identity_sop_response( + &self, + port: GlobalPortId, + ) -> Result { + match self + .send_port_command(port, PortCommandData::GetDiscoverIdentitySop) + .await? + { + PortResponseData::DiscoverIdentitySop(response) => Ok(response), + r => { + error!("Invalid response: expected Discover Identity SOP response, got {:?}", r); + Err(PdError::InvalidResponse) + } + } + } + + /// Get the latest response from the Discover Identity command targeting SOP'. + pub async fn get_discover_identity_sop_prime_response( + &self, + port: GlobalPortId, + ) -> Result { + match self + .send_port_command(port, PortCommandData::GetDiscoverIdentitySopPrime) + .await? + { + PortResponseData::DiscoverIdentitySopPrime(response) => Ok(response), + r => { + error!( + "Invalid response: expected Discover Identity SOP' response, got {:?}", + r + ); + Err(PdError::InvalidResponse) + } + } + } + /// Broadcast a type-C message to all subscribers pub async fn broadcast_message(&self, message: CommsMessage) { CONTEXT.broadcaster.broadcast(message).await; diff --git a/embedded-service/src/type_c/external.rs b/embedded-service/src/type_c/external.rs index 7ebfc0bc0..b86650d1f 100644 --- a/embedded-service/src/type_c/external.rs +++ b/embedded-service/src/type_c/external.rs @@ -6,7 +6,7 @@ use embedded_usb_pd::{GlobalPortId, LocalPortId, PdError, ucsi}; use crate::type_c::{ Cached, controller::{ - PdStateMachineConfig, SystemPowerState, TbtConfig, TypeCStateMachineState, UsbControlConfig, + DiscoveredSvids, PdStateMachineConfig, SystemPowerState, TbtConfig, TypeCStateMachineState, UsbControlConfig, execute_external_ucsi_command, }, }; @@ -15,7 +15,7 @@ use super::{ ControllerId, controller::{ ControllerStatus, DpConfig, DpStatus, PortStatus, RetimerFwUpdateState, SendVdm, - execute_external_controller_command, execute_external_port_command, lookup_controller, + execute_external_controller_command, execute_external_port_command, lookup_controller, lookup_global_port, }, }; @@ -103,6 +103,14 @@ pub enum PortCommandData { }, /// Set the system power state SetSystemPowerState(SystemPowerState), + /// Get the port's discovered SVIDs + GetDiscoveredSvids, + /// Trigger a hard reset on the given port. + HardReset, + /// Get the response to a Discover Identity command sent to the given port with SOP + GetDiscoverIdentitySop, + /// Get the response to a Discover Identity command sent to the given port with SOP' + GetDiscoverIdentitySopPrime, } /// Port-specific commands @@ -127,6 +135,12 @@ pub enum PortResponseData { RetimerFwUpdateGetState(RetimerFwUpdateState), /// Get DisplayPort status GetDpStatus(DpStatus), + /// Get the port's discovered SVIDs + DiscoveredSvids(DiscoveredSvids), + /// Discover Identity response data for SOP + DiscoverIdentitySop(embedded_usb_pd::vdm::structured::command::discover_identity::sop::ResponseVdos), + /// Discover Identity response data for SOP' + DiscoverIdentitySopPrime(embedded_usb_pd::vdm::structured::command::discover_identity::sop_prime::ResponseVdos), } /// Port-specific command response @@ -247,6 +261,12 @@ pub async fn controller_port_to_global_id( lookup_controller(controller_id).await?.lookup_global_port(port_id) } +/// Convert a global port ID to a (controller ID, local port ID) +pub async fn global_port_to_controller_port(global_port: GlobalPortId) -> Result<(ControllerId, LocalPortId), PdError> { + let (controller, local_port) = lookup_global_port(global_port).await?; + Ok((controller.id(), local_port)) +} + /// Get the retimer fw update status of the given port pub async fn port_get_rt_fw_update_status(port: GlobalPortId) -> Result { match execute_external_port_command(Command::Port(PortCommand { @@ -501,3 +521,59 @@ pub async fn set_type_c_state_machine_config(port: GlobalPortId, state: TypeCSta _ => Err(PdError::InvalidResponse), } } + +/// Get the port's discovered SVIDs +pub async fn get_discovered_svids(port: GlobalPortId) -> Result { + match execute_external_port_command(Command::Port(PortCommand { + port, + data: PortCommandData::GetDiscoveredSvids, + })) + .await? + { + PortResponseData::DiscoveredSvids(svids) => Ok(svids), + _ => Err(PdError::InvalidResponse), + } +} + +/// Trigger a hard reset on the given port +pub async fn hard_reset(port: GlobalPortId) -> Result<(), PdError> { + match execute_external_port_command(Command::Port(PortCommand { + port, + data: PortCommandData::HardReset, + })) + .await? + { + PortResponseData::Complete => Ok(()), + _ => Err(PdError::InvalidResponse), + } +} + +/// Get the response to a Discover Identity command sent to the given port with SOP. +pub async fn get_discover_identity_sop_response( + port: GlobalPortId, +) -> Result { + match execute_external_port_command(Command::Port(PortCommand { + port, + data: PortCommandData::GetDiscoverIdentitySop, + })) + .await? + { + PortResponseData::DiscoverIdentitySop(vdos) => Ok(vdos), + _ => Err(PdError::InvalidResponse), + } +} + +/// Get the response to a Discover Identity command sent to the given port with SOP'. +pub async fn get_discover_identity_sop_prime_response( + port: GlobalPortId, +) -> Result { + match execute_external_port_command(Command::Port(PortCommand { + port, + data: PortCommandData::GetDiscoverIdentitySopPrime, + })) + .await? + { + PortResponseData::DiscoverIdentitySopPrime(vdos) => Ok(vdos), + _ => Err(PdError::InvalidResponse), + } +} diff --git a/examples/rt633/Cargo.lock b/examples/rt633/Cargo.lock index 2396b7838..48a8c9fab 100644 --- a/examples/rt633/Cargo.lock +++ b/examples/rt633/Cargo.lock @@ -739,7 +739,7 @@ dependencies = [ [[package]] name = "embedded-usb-pd" version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-usb-pd#9a42f07ce99a6d91032d7c9792fd87d4b4f49b6f" +source = "git+https://github.com/OpenDevicePartnership/embedded-usb-pd#21d0e228d21ddc6ccaeffc01d98ef9a5b87941ef" dependencies = [ "aquamarine", "bincode", diff --git a/examples/rt685s-evk/Cargo.lock b/examples/rt685s-evk/Cargo.lock index 0f7446af1..6117376a2 100644 --- a/examples/rt685s-evk/Cargo.lock +++ b/examples/rt685s-evk/Cargo.lock @@ -2,18 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.4" @@ -23,12 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "anyhow" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" - [[package]] name = "aquamarine" version = "0.6.0" @@ -43,49 +25,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "arraydeque" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" - -[[package]] -name = "askama" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4" -dependencies = [ - "askama_derive", - "itoa", - "percent-encoding", - "serde", - "serde_json", -] - -[[package]] -name = "askama_derive" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f" -dependencies = [ - "askama_parser", - "memchr", - "proc-macro2", - "quote", - "rustc-hash", - "syn 2.0.106", -] - -[[package]] -name = "askama_parser" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358" -dependencies = [ - "memchr", - "winnow 0.7.13", -] - [[package]] name = "autocfg" version = "1.5.0" @@ -254,15 +193,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "cordyceps" version = "0.3.4" @@ -368,15 +298,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "dd-manifest-tree" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5793572036e0a6638977c7370c6afc423eac848ee8495f079b8fd3964de7b9f9" -dependencies = [ - "yaml-rust2", -] - [[package]] name = "defmt" version = "0.3.100" @@ -415,7 +336,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" dependencies = [ - "thiserror 2.0.16", + "thiserror", ] [[package]] @@ -430,45 +351,15 @@ dependencies = [ [[package]] name = "device-driver" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af0e43acfcbb0bb3b7435cc1b1dbb33596cacfec1eb243336b74a398e0bd6cbf" +checksum = "c2e4547bd66511372d2a38ac3c1b2892c7ebf83cf0d5411c3406e496c85a1d96" dependencies = [ "defmt 0.3.100", - "device-driver-macros", "embedded-io 0.6.1", "embedded-io-async 0.6.1", ] -[[package]] -name = "device-driver-generation" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3935aec9cf5bb2ab927f59ca69faecf976190390b0ce34c6023889e9041040c0" -dependencies = [ - "anyhow", - "askama", - "bitvec", - "convert_case", - "dd-manifest-tree", - "itertools 0.14.0", - "kdl", - "proc-macro2", - "quote", - "syn 2.0.106", -] - -[[package]] -name = "device-driver-macros" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fdc68ed515c4eddff2e95371185b4becba066085bf36d50f07f09782af98e17" -dependencies = [ - "device-driver-generation", - "proc-macro2", - "syn 2.0.106", -] - [[package]] name = "document-features" version = "0.2.11" @@ -853,7 +744,7 @@ dependencies = [ [[package]] name = "embedded-usb-pd" version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-usb-pd#1a8e79d3a2ac0d2837a34b045087cf0863146f7d" +source = "git+https://github.com/OpenDevicePartnership/embedded-usb-pd#21d0e228d21ddc6ccaeffc01d98ef9a5b87941ef" dependencies = [ "aquamarine", "bincode", @@ -862,15 +753,6 @@ dependencies = [ "embedded-hal-async", ] -[[package]] -name = "encoding_rs" -version = "0.8.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" -dependencies = [ - "cfg-if", -] - [[package]] name = "espi-device" version = "0.1.0" @@ -960,24 +842,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", -] - -[[package]] -name = "hashlink" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" -dependencies = [ - "hashbrown", -] - [[package]] name = "heapless" version = "0.8.0" @@ -1056,24 +920,6 @@ dependencies = [ "either", ] -[[package]] -name = "itoa" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" - -[[package]] -name = "kdl" -version = "6.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12661358400b02cbbf1fbd05f0a483335490e8a6bd1867620f2eeb78f304a22f" -dependencies = [ - "miette", - "num", - "thiserror 1.0.69", - "winnow 0.6.24", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -1131,7 +977,7 @@ dependencies = [ "espi-device", "num_enum", "smbus-pec", - "thiserror 2.0.16", + "thiserror", ] [[package]] @@ -1140,28 +986,6 @@ version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" -[[package]] -name = "miette" -version = "7.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7" -dependencies = [ - "cfg-if", - "miette-derive", - "unicode-width", -] - -[[package]] -name = "miette-derive" -version = "7.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", -] - [[package]] name = "mimxrt600-fcb" version = "0.1.0" @@ -1230,70 +1054,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "num" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" -dependencies = [ - "num-bigint", - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", -] - -[[package]] -name = "num-complex" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -1346,12 +1106,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "percent-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" - [[package]] name = "pin-project-lite" version = "0.2.17" @@ -1496,12 +1250,6 @@ dependencies = [ "type-c-service", ] -[[package]] -name = "rustc-hash" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" - [[package]] name = "rustc_version" version = "0.2.3" @@ -1517,12 +1265,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - [[package]] name = "scoped-tls" version = "1.0.1" @@ -1564,18 +1306,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "serde_json" -version = "1.0.143" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - [[package]] name = "sharded-slab" version = "0.1.7" @@ -1678,33 +1408,13 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - [[package]] name = "thiserror" version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" dependencies = [ - "thiserror-impl 2.0.16", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", + "thiserror-impl", ] [[package]] @@ -1730,7 +1440,7 @@ dependencies = [ [[package]] name = "tps6699x" version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/tps6699x#aa3425136216dccfb107bff6b172a49b8972bb70" +source = "git+https://github.com/OpenDevicePartnership/tps6699x#ba1b3b17ebf048fc007eb2107a4d2ab8cb545adf" dependencies = [ "bincode", "bitfield 0.19.2", @@ -1838,18 +1548,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" -[[package]] -name = "unicode-segmentation" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - -[[package]] -name = "unicode-width" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" - [[package]] name = "unty" version = "0.0.4" @@ -1874,12 +1572,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "virtue" version = "0.0.18" @@ -1925,24 +1617,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "winnow" -version = "0.6.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" -dependencies = [ - "memchr", -] - -[[package]] -name = "winnow" -version = "0.7.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" -dependencies = [ - "memchr", -] - [[package]] name = "wyz" version = "0.5.1" @@ -1952,17 +1626,6 @@ dependencies = [ "tap", ] -[[package]] -name = "yaml-rust2" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1a1c0bc9823338a3bdf8c61f994f23ac004c6fa32c08cd152984499b445e8d" -dependencies = [ - "arraydeque", - "encoding_rs", - "hashlink", -] - [[package]] name = "zerocopy" version = "0.8.26" diff --git a/examples/std/Cargo.lock b/examples/std/Cargo.lock index 7f94b690f..0bdc0a366 100644 --- a/examples/std/Cargo.lock +++ b/examples/std/Cargo.lock @@ -2,18 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -23,12 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "anyhow" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" - [[package]] name = "aquamarine" version = "0.6.0" @@ -43,49 +25,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "arraydeque" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" - -[[package]] -name = "askama" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4" -dependencies = [ - "askama_derive", - "itoa", - "percent-encoding", - "serde", - "serde_json", -] - -[[package]] -name = "askama_derive" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f" -dependencies = [ - "askama_parser", - "memchr", - "proc-macro2", - "quote", - "rustc-hash", - "syn 2.0.106", -] - -[[package]] -name = "askama_parser" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358" -dependencies = [ - "memchr", - "winnow 0.7.13", -] - [[package]] name = "atty" version = "0.2.14" @@ -278,15 +217,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bd422bfb4f24a97243f60b6a4443e63d810c925d8da4bb2d8fde26a7c1d57ec" -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "cordyceps" version = "0.3.4" @@ -370,15 +300,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "dd-manifest-tree" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5793572036e0a6638977c7370c6afc423eac848ee8495f079b8fd3964de7b9f9" -dependencies = [ - "yaml-rust2", -] - [[package]] name = "debug-service" version = "0.1.0" @@ -430,49 +351,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" dependencies = [ - "thiserror 2.0.16", + "thiserror", ] [[package]] name = "device-driver" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af0e43acfcbb0bb3b7435cc1b1dbb33596cacfec1eb243336b74a398e0bd6cbf" +checksum = "c2e4547bd66511372d2a38ac3c1b2892c7ebf83cf0d5411c3406e496c85a1d96" dependencies = [ - "device-driver-macros", "embedded-io 0.6.1", "embedded-io-async 0.6.1", ] -[[package]] -name = "device-driver-generation" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3935aec9cf5bb2ab927f59ca69faecf976190390b0ce34c6023889e9041040c0" -dependencies = [ - "anyhow", - "askama", - "bitvec", - "convert_case", - "dd-manifest-tree", - "itertools 0.14.0", - "kdl", - "proc-macro2", - "quote", - "syn 2.0.106", -] - -[[package]] -name = "device-driver-macros" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fdc68ed515c4eddff2e95371185b4becba066085bf36d50f07f09782af98e17" -dependencies = [ - "device-driver-generation", - "proc-macro2", - "syn 2.0.106", -] - [[package]] name = "document-features" version = "0.2.11" @@ -756,13 +647,13 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7a4b4d10ac48d08bfe3db7688c402baadb244721f30a77ce360bd24c3dffe58" dependencies = [ - "num 0.3.1", + "num", ] [[package]] name = "embedded-usb-pd" version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-usb-pd#1a8e79d3a2ac0d2837a34b045087cf0863146f7d" +source = "git+https://github.com/OpenDevicePartnership/embedded-usb-pd#21d0e228d21ddc6ccaeffc01d98ef9a5b87941ef" dependencies = [ "aquamarine", "bincode", @@ -770,15 +661,6 @@ dependencies = [ "embedded-hal-async", ] -[[package]] -name = "encoding_rs" -version = "0.8.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" -dependencies = [ - "cfg-if", -] - [[package]] name = "env_logger" version = "0.9.3" @@ -858,24 +740,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", -] - -[[package]] -name = "hashlink" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" -dependencies = [ - "hashbrown", -] - [[package]] name = "heapless" version = "0.8.0" @@ -960,24 +824,6 @@ dependencies = [ "either", ] -[[package]] -name = "itoa" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" - -[[package]] -name = "kdl" -version = "6.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12661358400b02cbbf1fbd05f0a483335490e8a6bd1867620f2eeb78f304a22f" -dependencies = [ - "miette", - "num 0.4.3", - "thiserror 1.0.69", - "winnow 0.6.24", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -1048,7 +894,7 @@ dependencies = [ "espi-device", "num_enum", "smbus-pec", - "thiserror 2.0.16", + "thiserror", ] [[package]] @@ -1057,28 +903,6 @@ version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" -[[package]] -name = "miette" -version = "7.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7" -dependencies = [ - "cfg-if", - "miette-derive", - "unicode-width", -] - -[[package]] -name = "miette-derive" -version = "7.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", -] - [[package]] name = "mutex-traits" version = "1.0.1" @@ -1121,34 +945,10 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b7a8e9be5e039e2ff869df49155f1c06bd01ade2117ec783e56ab0932b67a8f" dependencies = [ - "num-complex 0.3.1", + "num-complex", "num-integer", "num-iter", - "num-rational 0.3.2", - "num-traits", -] - -[[package]] -name = "num" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" -dependencies = [ - "num-bigint", - "num-complex 0.4.6", - "num-integer", - "num-iter", - "num-rational 0.4.2", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", + "num-rational", "num-traits", ] @@ -1161,15 +961,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-complex" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" -dependencies = [ - "num-traits", -] - [[package]] name = "num-integer" version = "0.1.46" @@ -1201,17 +992,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-rational" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -1254,12 +1034,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "percent-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" - [[package]] name = "pin-project" version = "1.1.10" @@ -1390,12 +1164,6 @@ dependencies = [ "ufmt-write", ] -[[package]] -name = "rustc-hash" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" - [[package]] name = "rustc_version" version = "0.2.3" @@ -1411,12 +1179,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - [[package]] name = "scoped-tls" version = "1.0.1" @@ -1458,18 +1220,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "serde_json" -version = "1.0.143" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - [[package]] name = "sharded-slab" version = "0.1.7" @@ -1619,33 +1369,13 @@ dependencies = [ "uuid", ] -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - [[package]] name = "thiserror" version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" dependencies = [ - "thiserror-impl 2.0.16", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", + "thiserror-impl", ] [[package]] @@ -1671,7 +1401,7 @@ dependencies = [ [[package]] name = "tps6699x" version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/tps6699x#aa3425136216dccfb107bff6b172a49b8972bb70" +source = "git+https://github.com/OpenDevicePartnership/tps6699x#ba1b3b17ebf048fc007eb2107a4d2ab8cb545adf" dependencies = [ "bincode", "bitfield 0.19.2", @@ -1779,18 +1509,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" -[[package]] -name = "unicode-segmentation" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - -[[package]] -name = "unicode-width" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" - [[package]] name = "unty" version = "0.0.4" @@ -1815,12 +1533,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "virtue" version = "0.0.18" @@ -2131,24 +1843,6 @@ version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" -[[package]] -name = "winnow" -version = "0.6.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" -dependencies = [ - "memchr", -] - -[[package]] -name = "winnow" -version = "0.7.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" -dependencies = [ - "memchr", -] - [[package]] name = "wyz" version = "0.5.1" @@ -2158,17 +1852,6 @@ dependencies = [ "tap", ] -[[package]] -name = "yaml-rust2" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1a1c0bc9823338a3bdf8c61f994f23ac004c6fa32c08cd152984499b445e8d" -dependencies = [ - "arraydeque", - "encoding_rs", - "hashlink", -] - [[package]] name = "zerocopy" version = "0.8.26" diff --git a/examples/std/src/lib/type_c/mock_controller.rs b/examples/std/src/lib/type_c/mock_controller.rs index 0ddecd56f..2c6764897 100644 --- a/examples/std/src/lib/type_c/mock_controller.rs +++ b/examples/std/src/lib/type_c/mock_controller.rs @@ -6,8 +6,9 @@ use embedded_services::{ power::policy::PowerCapability, type_c::{ controller::{ - AttnVdm, ControllerStatus, DpConfig, DpPinConfig, DpStatus, OtherVdm, PdStateMachineConfig, PortStatus, - RetimerFwUpdateState, SendVdm, SystemPowerState, TbtConfig, TypeCStateMachineState, UsbControlConfig, + AttnVdm, ControllerStatus, DiscoveredSvids, DpConfig, DpPinConfig, DpStatus, OtherVdm, + PdStateMachineConfig, PortStatus, RetimerFwUpdateState, SendVdm, SystemPowerState, TbtConfig, + TypeCStateMachineState, UsbControlConfig, }, event::PortEvent, }, @@ -340,6 +341,36 @@ impl embedded_services::type_c::controller::Controller for Controller<'_> { debug!("Set power state for port {port:?}: {state:?}"); Ok(()) } + + async fn get_discovered_svids(&mut self, port: LocalPortId) -> Result> { + debug!("Get discovered SVIDs for port {port:?}"); + Ok(DiscoveredSvids::default()) + } + + async fn hard_reset(&mut self, port: LocalPortId) -> Result<(), Error> { + debug!("Hard reset for port {port:?}"); + Ok(()) + } + + async fn get_discover_identity_sop_response( + &mut self, + port: LocalPortId, + ) -> Result> + { + debug!("Get Discover Identity SOP response for port {port:?}"); + Err(Error::Pd(PdError::Failed)) + } + + async fn get_discover_identity_sop_prime_response( + &mut self, + port: LocalPortId, + ) -> Result< + embedded_usb_pd::vdm::structured::command::discover_identity::sop_prime::ResponseVdos, + Error, + > { + debug!("Get Discover Identity SOP' response for port {port:?}"); + Err(Error::Pd(PdError::Failed)) + } } pub struct Validator; diff --git a/supply-chain/audits.toml b/supply-chain/audits.toml index 5bb38a458..a13008070 100644 --- a/supply-chain/audits.toml +++ b/supply-chain/audits.toml @@ -204,6 +204,12 @@ criteria = "safe-to-deploy" version = "1.0.7" notes = "no_std device driver toolkit. Unsafe limited to ops.rs bitfield load/store using get_unchecked with documented invariants; fuzz-tested against bitvec. No build script, no proc macros, no filesystem/network/process access. Assisted-by: copilot-chat:claude-opus-4.6 cargo-vet" +[[audits.device-driver]] +who = "Adam Sasine " +criteria = "safe-to-deploy" +delta = "1.0.7 -> 1.0.9" +notes = "Fixes compilation bugs for large registers but does not change invariants or testing strategy." + [[audits.device-driver-generation]] who = "Jerry Xie " criteria = "safe-to-deploy" diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index edf4c338a..9d90c2088 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -21,13 +21,6 @@ when = "2025-08-16" user-id = 55123 user-login = "rust-lang-owner" -[[publisher.encoding_rs]] -version = "0.8.35" -when = "2024-10-24" -user-id = 4484 -user-login = "hsivonen" -user-name = "Henri Sivonen" - [[publisher.libc]] version = "0.2.175" when = "2025-08-11" @@ -82,13 +75,6 @@ user-id = 3618 user-login = "dtolnay" user-name = "David Tolnay" -[[publisher.ryu]] -version = "1.0.20" -when = "2025-03-04" -user-id = 3618 -user-login = "dtolnay" -user-name = "David Tolnay" - [[publisher.scoped-tls]] version = "1.0.1" when = "2022-10-31" @@ -96,13 +82,6 @@ user-id = 1 user-login = "alexcrichton" user-name = "Alex Crichton" -[[publisher.serde_json]] -version = "1.0.143" -when = "2025-08-19" -user-id = 3618 -user-login = "dtolnay" -user-name = "David Tolnay" - [[publisher.smallvec]] version = "1.15.1" when = "2025-06-06" @@ -152,20 +131,6 @@ user-id = 3618 user-login = "dtolnay" user-name = "David Tolnay" -[[publisher.unicode-segmentation]] -version = "1.12.0" -when = "2024-09-13" -user-id = 1139 -user-login = "Manishearth" -user-name = "Manish Goregaokar" - -[[publisher.unicode-width]] -version = "0.1.14" -when = "2024-09-19" -user-id = 1139 -user-login = "Manishearth" -user-name = "Manish Goregaokar" - [[publisher.windows]] version = "0.61.3" when = "2025-06-12" @@ -1441,7 +1406,7 @@ aggregated-from = "https://chromium.googlesource.com/chromiumos/third_party/rust [[audits.mozilla.wildcard-audits.encoding_rs]] who = "Henri Sivonen " criteria = "safe-to-deploy" -user-id = 4484 # Henri Sivonen (hsivonen) +user-id = 4484 start = "2019-02-26" end = "2025-10-23" notes = "I, Henri Sivonen, wrote encoding_rs for Gecko and have reviewed contributions by others. There are two caveats to the certification: 1) The crate does things that are documented to be UB but that do not appear to actually be UB due to integer types differing from the general rule; https://github.com/hsivonen/encoding_rs/issues/79 . 2) It would be prudent to re-review the code that reinterprets buffers of integers as SIMD vectors; see https://github.com/hsivonen/encoding_rs/issues/87 ." @@ -1450,7 +1415,7 @@ aggregated-from = "https://hg.mozilla.org/mozilla-central/raw-file/tip/supply-ch [[audits.mozilla.wildcard-audits.unicode-segmentation]] who = "Manish Goregaokar " criteria = "safe-to-deploy" -user-id = 1139 # Manish Goregaokar (Manishearth) +user-id = 1139 start = "2019-05-15" end = "2026-02-01" notes = "All code written or reviewed by Manish" @@ -1459,7 +1424,7 @@ aggregated-from = "https://hg.mozilla.org/mozilla-central/raw-file/tip/supply-ch [[audits.mozilla.wildcard-audits.unicode-width]] who = "Manish Goregaokar " criteria = "safe-to-deploy" -user-id = 1139 # Manish Goregaokar (Manishearth) +user-id = 1139 start = "2019-12-05" end = "2026-02-01" notes = "All code written or reviewed by Manish" diff --git a/type-c-service/src/driver/tps6699x.rs b/type-c-service/src/driver/tps6699x.rs index b2a1375f2..8f1830eac 100644 --- a/type-c-service/src/driver/tps6699x.rs +++ b/type-c-service/src/driver/tps6699x.rs @@ -13,8 +13,8 @@ use embedded_hal_async::i2c::I2c; use embedded_services::power::policy::PowerCapability; use embedded_services::type_c::ATTN_VDM_LEN; use embedded_services::type_c::controller::{ - self, AttnVdm, Controller, ControllerStatus, DpPinConfig, OtherVdm, PortStatus, SendVdm, TbtConfig, - TypeCStateMachineState, UsbControlConfig, + self, AttnVdm, Controller, ControllerStatus, DiscoveredSvids, DpPinConfig, OtherVdm, PortStatus, SendVdm, + TbtConfig, TypeCStateMachineState, UsbControlConfig, }; use embedded_services::type_c::event::PortEvent; use embedded_services::{debug, error, trace, type_c, warn}; @@ -24,6 +24,7 @@ use embedded_usb_pd::pdo::{Common, Contract, Rdo, sink, source}; use embedded_usb_pd::type_c::Current as TypecCurrent; use embedded_usb_pd::ucsi::lpm; use embedded_usb_pd::{DataRole, Error, LocalPortId, PdError, PlugOrientation, PowerRole}; +use heapless::Vec; use tps6699x::MAX_SUPPORTED_PORTS; use tps6699x::asynchronous::embassy as tps6699x_drv; use tps6699x::asynchronous::fw_update::UpdateTarget; @@ -844,6 +845,65 @@ impl Controller for Tps6699x<'_, M, B> { self.tps6699x.set_sx_app_config(port, driver_state).await } + + async fn get_discovered_svids(&mut self, port: LocalPortId) -> Result> { + let svids = self.tps6699x.get_discovered_svids(port).await?; + debug!("{:?} discovered SVIDs: {:?}", port, svids); + let mut sop = Vec::new(); + for svid in svids.svid_sop().take(sop.capacity()) { + let _ = sop.push(svid); + } + + let mut sop_prime = Vec::new(); + for svid in svids.svid_sop_prime().take(sop_prime.capacity()) { + let _ = sop_prime.push(svid); + } + + let svids = DiscoveredSvids::new(sop, sop_prime); + Ok(svids) + } + + async fn hard_reset(&mut self, port: LocalPortId) -> Result<(), Error> { + match self.tps6699x.execute_hrst(port).await? { + ReturnValue::Success => Ok(()), + r => { + debug!("Error executing hard reset on port {}: {:#?}", port.0, r); + Err(Error::Pd(PdError::InvalidResponse)) + } + } + } + + async fn get_discover_identity_sop_response( + &mut self, + port: LocalPortId, + ) -> Result> + { + let data = self.tps6699x.get_received_sop_identity_data(port).await?; + match data.try_into() { + Ok(vdos) => Ok(vdos), + Err(e) => { + debug!("Error deserializing Received SOP Identity Data: {:?}", e); + Err(Error::Pd(PdError::Serialize)) + } + } + } + + async fn get_discover_identity_sop_prime_response( + &mut self, + port: LocalPortId, + ) -> Result< + embedded_usb_pd::vdm::structured::command::discover_identity::sop_prime::ResponseVdos, + Error, + > { + let data = self.tps6699x.get_received_sop_prime_identity_data(port).await?; + match data.try_into() { + Ok(vdos) => Ok(vdos), + Err(e) => { + debug!("Error deserializing Received SOP Prime Identity Data: {:?}", e); + Err(Error::Pd(PdError::Serialize)) + } + } + } } impl<'a, M: RawMutex, BUS: I2c> AsRef> for Tps6699x<'a, M, BUS> { diff --git a/type-c-service/src/service/port.rs b/type-c-service/src/service/port.rs index 0a7bdf9a5..199d95b9f 100644 --- a/type-c-service/src/service/port.rs +++ b/type-c-service/src/service/port.rs @@ -74,6 +74,15 @@ impl<'a> Service<'a> { external::PortCommandData::SetSystemPowerState(state) => { self.process_set_power_state(command.port, state).await } + external::PortCommandData::GetDiscoveredSvids => self.process_get_discovered_svids(command.port).await, + external::PortCommandData::HardReset => self.process_hard_reset(command.port).await, + external::PortCommandData::GetDiscoverIdentitySop => { + self.process_get_discover_identity_sop_response(command.port).await + } + external::PortCommandData::GetDiscoverIdentitySopPrime => { + self.process_get_discover_identity_sop_prime_response(command.port) + .await + } } } @@ -286,4 +295,47 @@ impl<'a> Service<'a> { external::Response::Port(status.map(|_| external::PortResponseData::Complete)) } + + /// Process [`external::PortCommandData::GetDiscoveredSvids`] command + async fn process_get_discovered_svids(&self, port_id: GlobalPortId) -> external::Response<'static> { + let status = self.context.get_discovered_svids(port_id).await; + if let Err(e) = status { + error!("Error getting discovered SVIDs: {:#?}", e); + } + + external::Response::Port(status.map(external::PortResponseData::DiscoveredSvids)) + } + + /// Process [`external::PortCommandData::HardReset`] command + async fn process_hard_reset(&self, port_id: GlobalPortId) -> external::Response<'static> { + let status = self.context.hard_reset(port_id).await; + if let Err(e) = status { + error!("Error executing hard reset: {:#?}", e); + } + + external::Response::Port(status.map(|_| external::PortResponseData::Complete)) + } + + /// Process [`external::PortCommandData::GetDiscoverIdentitySop`] command + async fn process_get_discover_identity_sop_response(&self, port_id: GlobalPortId) -> external::Response<'static> { + let status = self.context.get_discover_identity_sop_response(port_id).await; + if let Err(e) = status { + error!("Error getting Discover Identity SOP response: {:#?}", e); + } + + external::Response::Port(status.map(external::PortResponseData::DiscoverIdentitySop)) + } + + /// Process [`external::PortCommandData::GetDiscoverIdentitySopPrime`] command + async fn process_get_discover_identity_sop_prime_response( + &self, + port_id: GlobalPortId, + ) -> external::Response<'static> { + let status = self.context.get_discover_identity_sop_prime_response(port_id).await; + if let Err(e) = status { + error!("Error getting Discover Identity SOP' response: {:#?}", e); + } + + external::Response::Port(status.map(external::PortResponseData::DiscoverIdentitySopPrime)) + } } diff --git a/type-c-service/src/wrapper/pd.rs b/type-c-service/src/wrapper/pd.rs index ebde3e802..a9b233c98 100644 --- a/type-c-service/src/wrapper/pd.rs +++ b/type-c-service/src/wrapper/pd.rs @@ -424,6 +424,40 @@ where }, } } + controller::PortCommandData::GetDiscoveredSvids => { + match controller.get_discovered_svids(local_port).await { + Ok(svids) => Ok(controller::PortResponseData::DiscoveredSvids(svids)), + Err(e) => match e { + Error::Bus(_) => Err(PdError::Failed), + Error::Pd(e) => Err(e), + }, + } + } + controller::PortCommandData::HardReset => match controller.hard_reset(local_port).await { + Ok(()) => Ok(controller::PortResponseData::Complete), + Err(e) => match e { + Error::Bus(_) => Err(PdError::Failed), + Error::Pd(e) => Err(e), + }, + }, + controller::PortCommandData::GetDiscoverIdentitySop => { + match controller.get_discover_identity_sop_response(local_port).await { + Ok(vdos) => Ok(controller::PortResponseData::DiscoverIdentitySop(vdos)), + Err(e) => match e { + Error::Bus(_) => Err(PdError::Failed), + Error::Pd(e) => Err(e), + }, + } + } + controller::PortCommandData::GetDiscoverIdentitySopPrime => { + match controller.get_discover_identity_sop_prime_response(local_port).await { + Ok(vdos) => Ok(controller::PortResponseData::DiscoverIdentitySopPrime(vdos)), + Err(e) => match e { + Error::Bus(_) => Err(PdError::Failed), + Error::Pd(e) => Err(e), + }, + } + } }) }