Skip to content

Commit

Permalink
pdo: expand storage types to cover common units
Browse files Browse the repository at this point in the history
Using e.g. si::u8::ElectricPotential with a base unit of decivolts can
not be converted to milivolts (which is the obvious conversion) as the
u8 milivolts range is only 0 - 255mv.. Same for current. Expand the
storage to 16 bits so the full range can be exposes as milivolt/miliamp

Signed-off-by: Sjoerd Simons <[email protected]>
  • Loading branch information
sjoerdsimons committed May 29, 2024
1 parent a8c7ab6 commit 8622122
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions usb-pd/src/messages/pdo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,16 @@ bitfield! {
}

impl SPRProgrammablePowerSupply {
pub fn max_voltage(&self) -> si::u8::ElectricPotential {
si::u8::ElectricPotential::new::<decivolt>(self.raw_max_voltage())
pub fn max_voltage(&self) -> si::u16::ElectricPotential {
si::u16::ElectricPotential::new::<decivolt>(self.raw_max_voltage().into())
}

pub fn min_voltage(&self) -> si::u8::ElectricPotential {
si::u8::ElectricPotential::new::<decivolt>(self.raw_min_voltage())
pub fn min_voltage(&self) -> si::u16::ElectricPotential {
si::u16::ElectricPotential::new::<decivolt>(self.raw_min_voltage().into())
}

pub fn max_current(&self) -> si::u8::ElectricCurrent {
si::u8::ElectricCurrent::new::<_50milliamperes>(self.raw_max_current())
pub fn max_current(&self) -> si::u16::ElectricCurrent {
si::u16::ElectricCurrent::new::<_50milliamperes>(self.raw_max_current().into())
}
}

Expand All @@ -216,8 +216,8 @@ impl EPRAdjustableVoltageSupply {
si::u16::ElectricPotential::new::<decivolt>(self.raw_max_voltage())
}

pub fn min_voltage(&self) -> si::u8::ElectricPotential {
si::u8::ElectricPotential::new::<decivolt>(self.raw_min_voltage())
pub fn min_voltage(&self) -> si::u16::ElectricPotential {
si::u16::ElectricPotential::new::<decivolt>(self.raw_min_voltage().into())
}

pub fn pd_power(&self) -> si::u8::Power {
Expand Down

0 comments on commit 8622122

Please sign in to comment.