Skip to content

Commit

Permalink
Merge pull request #5 from RobertZ2011/minor-pdo-changes
Browse files Browse the repository at this point in the history
Minor PD changes
  • Loading branch information
RobertZ2011 authored Mar 6, 2025
2 parents c3c6316 + 6d2e3ab commit 8a92b3b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ pub enum Error<BE> {
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<T, BE> Into<Result<T, Error<BE>>> for PdError {
fn into(self) -> Result<T, Error<BE>> {
Expand Down
9 changes: 9 additions & 0 deletions src/pdo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ pub trait Common {
fn kind(&self) -> PdoKind;
/// Get the APDO kind
fn apdo_kind(&self) -> Option<ApdoKind>;
/// Return true if the PDO is a dual-rule PDO
fn is_dual_role(&self) -> bool;
}

/// Top-level PDO type
Expand All @@ -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(),
}
}
}
7 changes: 7 additions & 0 deletions src/pdo/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> for Pdo {
Expand Down
7 changes: 7 additions & 0 deletions src/pdo/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> for Pdo {
Expand Down

0 comments on commit 8a92b3b

Please sign in to comment.