Skip to content

Commit

Permalink
compare_version: Allow checking ac charging state
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Schaefer <dhs@frame.work>
  • Loading branch information
JohnAZoidberg committed Oct 21, 2024
1 parent 8935ba2 commit 33e8db8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 23 deletions.
2 changes: 2 additions & 0 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ pub enum HardwareDeviceType {
PD1,
RTM01,
RTM23,
AcLeft,
AcRight,
}

impl CrosEcDriver for CrosEc {
Expand Down
80 changes: 57 additions & 23 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Can be easily re-used from any OS or UEFI shell.
//! We have implemented both in the `framework_tool` and `framework_uefi` crates.

use alloc::format;
use alloc::string::String;
use alloc::string::ToString;
use alloc::vec::Vec;
Expand Down Expand Up @@ -525,39 +526,72 @@ fn compare_version(device: Option<HardwareDeviceType>, version: String, ec: &Cro
}
}

if device == Some(HardwareDeviceType::EC) {
let ver = print_err(ec.version_info()).unwrap_or_else(|| "UNKNOWN".to_string());
println!("Comparing EC version {:?}", ver);

if ver.contains(&version) {
return 0;
} else {
return 1;
}
}
if device == Some(HardwareDeviceType::PD0) {
if let Ok(pd_versions) = ccgx::get_pd_controller_versions(ec) {
let ver = pd_versions.controller01.active_fw_ver();
println!("Comparing PD0 version {:?}", ver);
match device {
Some(HardwareDeviceType::EC) => {
let ver = print_err(ec.version_info()).unwrap_or_else(|| "UNKNOWN".to_string());
println!("Comparing EC version {:?}", ver);

if ver.contains(&version) {
return 0;
} else {
return 1;
}
}
}
if device == Some(HardwareDeviceType::PD1) {
if let Ok(pd_versions) = ccgx::get_pd_controller_versions(ec) {
let ver = pd_versions.controller23.active_fw_ver();
println!("Comparing PD1 version {:?}", ver);

if ver.contains(&version) {
return 0;
Some(HardwareDeviceType::PD0) => {
if let Ok(pd_versions) = ccgx::get_pd_controller_versions(ec) {
let ver = pd_versions.controller01.active_fw_ver();
println!("Comparing PD0 version {:?}", ver);

if ver.contains(&version) {
return 0;
} else {
return 1;
}
}
}
Some(HardwareDeviceType::PD1) => {
if let Ok(pd_versions) = ccgx::get_pd_controller_versions(ec) {
let ver = pd_versions.controller23.active_fw_ver();
println!("Comparing PD1 version {:?}", ver);

if ver.contains(&version) {
return 0;
} else {
return 1;
}
}
}
Some(HardwareDeviceType::AcLeft) => {
if let Ok((_right, left)) = power::is_charging(ec) {
let ver = format!("{}", left as i32);
println!("Comparing AcLeft {:?}", ver);
if ver == version {
return 0;
} else {
return 1;
}
} else {
error!("Failed to get charging information");
// Not charging is the safe default
return 1;
}
}
Some(HardwareDeviceType::AcRight) => {
if let Ok((right, _left)) = power::is_charging(ec) {
let ver = format!("{}", right as i32);
println!("Comparing AcRight {:?}", ver);
if ver == version {
return 0;
} else {
return 1;
}
} else {
error!("Failed to get charging information");
// Not charging is the safe default
return 1;
}
}
None | _ => {}
}

if let Some(esrt) = esrt::get_esrt() {
Expand Down Expand Up @@ -647,7 +681,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
print_esrt();
} else if let Some(compare_version_ver) = &args.compare_version {
let compare_ret = compare_version(args.device, compare_version_ver.to_string(), &ec);
println!("Compared version: {}", compare_ret);
println!("Comparison Result: {}", compare_ret);
return compare_ret;
} else if args.intrusion {
println!("Chassis status:");
Expand Down
1 change: 1 addition & 0 deletions framework_lib/src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ pub fn get_and_print_pd_info(ec: &CrosEc) {
}

// TODO: Improve return type to be more obvious
// (right, left)
pub fn is_charging(ec: &CrosEc) -> EcResult<(bool, bool)> {
let port0 = check_ac(ec, 0)?.role == UsbPowerRoles::Sink;
let port1 = check_ac(ec, 1)?.role == UsbPowerRoles::Sink;
Expand Down

0 comments on commit 33e8db8

Please sign in to comment.