Skip to content

Commit

Permalink
Add type-C current definition
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertZ2011 committed Feb 21, 2025
1 parent b261022 commit 0036b11
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod asynchronous;
pub mod pdo;
pub mod type_c;

/// Port ID new type
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
29 changes: 29 additions & 0 deletions src/type_c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// Type-C current
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Current {
/// Default USB current
#[default]
UsbDefault,
/// 1.5A
Current1A5,
/// 3A0
Current3A0,
}

impl Current {
/// Returns the current in mA
pub fn to_ma(self, is_usb2: bool) -> u16 {
match self {
Current::UsbDefault => {
if is_usb2 {
500
} else {
900
}
}
Current::Current1A5 => 1500,
Current::Current3A0 => 3000,
}
}
}

0 comments on commit 0036b11

Please sign in to comment.