diff --git a/src/lib.rs b/src/lib.rs index 1617f7b..7ae2188 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,6 +69,14 @@ pub enum Error { Pd(PdError), } +/// Power role +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub enum PowerRole { + Sink, + Source, +} + #[allow(clippy::from_over_into)] impl Into>> for PdError { fn into(self) -> Result> { diff --git a/src/pdo/mod.rs b/src/pdo/mod.rs index d8d58ed..ff66bed 100644 --- a/src/pdo/mod.rs +++ b/src/pdo/mod.rs @@ -120,6 +120,8 @@ pub trait Common { fn kind(&self) -> PdoKind; /// Get the APDO kind fn apdo_kind(&self) -> Option; + /// Return true if the PDO is a dual-rule PDO + fn is_dual_role(&self) -> bool; } /// Top-level PDO type @@ -144,4 +146,11 @@ impl Common for Pdo { Pdo::Sink(pdo) => pdo.apdo_kind(), } } + + fn is_dual_role(&self) -> bool { + match self { + Pdo::Source(pdo) => pdo.is_dual_role(), + Pdo::Sink(pdo) => pdo.is_dual_role(), + } + } } diff --git a/src/pdo/sink.rs b/src/pdo/sink.rs index bcdd28d..86c3a3f 100644 --- a/src/pdo/sink.rs +++ b/src/pdo/sink.rs @@ -38,6 +38,13 @@ impl Common for Pdo { _ => None, } } + + fn is_dual_role(&self) -> bool { + match self { + Pdo::Fixed(data) => data.dual_role_power, + _ => false, + } + } } impl TryFrom for Pdo { diff --git a/src/pdo/source.rs b/src/pdo/source.rs index 6a9a916..f5046f0 100644 --- a/src/pdo/source.rs +++ b/src/pdo/source.rs @@ -38,6 +38,13 @@ impl Common for Pdo { _ => None, } } + + fn is_dual_role(&self) -> bool { + match self { + Pdo::Fixed(data) => data.dual_role_power, + _ => false, + } + } } impl TryFrom for Pdo {