Skip to content

Commit

Permalink
MAX14636: improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
surban committed Jun 10, 2024
1 parent 96fddaf commit 8c04399
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions openemc-firmware/src/supply/max14636.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,29 @@ impl Max14636 {

/// Power supply report.
pub fn report(&self) -> PowerSupply {
match (self.sw_open.is_low(), self.chg_al_n.is_low(), self.chg_det.is_low()) {
let sw_open_low = self.sw_open.is_low();
let chg_al_n_low = self.chg_al_n.is_low();
let chg_det_low = self.chg_det.is_low();
defmt::trace!(
"MAX14636 state: sw_open={:?} chg_al_n={:?} chg_det={:?}",
!sw_open_low,
!chg_al_n_low,
!chg_det_low
);

match (sw_open_low, chg_al_n_low, chg_det_low) {
(false, true, false) => PowerSupply::UsbDcp,
(true, true, false) => PowerSupply::UsbCdp,
(true, true, true) => PowerSupply::UsbSdp,
(false, true, true) => PowerSupply::Ps2,
(false, false, true) => PowerSupply::Disconnected,
other => {
defmt::warn!("Unknown MAX14646 status: {:?}", other);
_ => {
defmt::warn!(
"MAX14636 provided invalid state: sw_open={:?} chg_al_n={:?} chg_det={:?}",
!sw_open_low,
!chg_al_n_low,
!chg_det_low
);
PowerSupply::Unknown
}
}
Expand Down

0 comments on commit 8c04399

Please sign in to comment.