Skip to content

Commit

Permalink
supply: no input current when disconnected
Browse files Browse the repository at this point in the history
When any supply detector reports a disconnected
status, treat the merged status as disconnected.
  • Loading branch information
surban committed Jun 24, 2024
1 parent 3d8d59b commit 256309a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion openemc-firmware/src/bq25713.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ where
// Enable IDPM.
self.modify(i2c, REG_CHARGE_OPTION_0_LO, |v| v | (1 << 1))?;

if self.chrg_ok {
if self.chrg_ok && limit.max_input_current_ma > 0 {
defmt::trace!("Programming maximum input current {} mA", limit.max_input_current_ma);

// Enable or disable ICO.
Expand Down
2 changes: 1 addition & 1 deletion openemc-firmware/src/supply/max14636.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Max14636 {
!chg_al_n_low,
!chg_det_low
);
PowerSupply::Unknown
PowerSupply::Disconnected
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion openemc-firmware/src/supply/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ pub enum PowerSupply {
impl PowerSupply {
/// Merge two power supply reports, returning the best available power.
pub fn merge(&self, other: &Self) -> Self {
self.max(other).clone()
if *self == Self::Disconnected || *other == Self::Disconnected {
Self::Disconnected
} else {
self.max(other).clone()
}
}

/// Whether the power supply state is unknown.
Expand Down

0 comments on commit 256309a

Please sign in to comment.