From f82adae9febc89c7f40581af4563b4ced83c3e5b Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Tue, 26 Nov 2024 18:57:26 +0800 Subject: [PATCH] Allow overriding charge limit and charge full Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/mod.rs | 24 +++++++++++++++++++++-- framework_lib/src/commandline/clap_std.rs | 12 +++++++++++- framework_lib/src/commandline/mod.rs | 8 ++++++++ framework_lib/src/commandline/uefi.rs | 8 ++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index 137a37fe..b7bd756b 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -285,6 +285,26 @@ impl CrosEc { Ok((status.microphone == 1, status.camera == 1)) } + /// Let charge fully once, if currently a charge limit is set + pub fn charge_limit_override(&self) -> EcResult<()> { + let params = &[ChargeLimitControlModes::Override as u8, 0, 0]; + let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?; + + util::assert_win_len(data.len(), 0); + + Ok(()) + } + + /// Disable all charge limits + pub fn charge_limit_disable(&self) -> EcResult<()> { + let params = &[ChargeLimitControlModes::Disable as u8, 0, 0]; + let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?; + + util::assert_win_len(data.len(), 0); + + Ok(()) + } + pub fn set_charge_limit(&self, min: u8, max: u8) -> EcResult<()> { // Sending bytes manually because the Set command, as opposed to the Get command, // does not return any data @@ -316,8 +336,8 @@ impl CrosEc { pub fn set_fp_led_level(&self, level: FpLedBrightnessLevel) -> EcResult<()> { // Sending bytes manually because the Set command, as opposed to the Get command, // does not return any data - let limits = &[level as u8, 0x00]; - let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, limits)?; + let params = &[level as u8, 0x00]; + let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, params)?; util::assert_win_len(data.len(), 0); diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index 140cb151..4861ccb0 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -129,7 +129,15 @@ struct ClapCli { #[arg(long)] input_deck_mode: Option, - /// Get or set max charge limit + /// Temporarily remove the charge limit and charge full + #[arg(long)] + charge_full: bool, + + /// Remove min/max charge limit (Overwritten by BIOS on reboot) + #[arg(long)] + charge_limit_disable: bool, + + /// Get or set max charge limit (Overwritten by BIOS on reboot) #[arg(long)] charge_limit: Option>, @@ -265,6 +273,8 @@ pub fn parse(args: &[String]) -> Cli { intrusion: args.intrusion, inputmodules: args.inputmodules, input_deck_mode: args.input_deck_mode, + charge_full: args.charge_full, + charge_limit_disable: args.charge_limit_disable, charge_limit: args.charge_limit, get_gpio: args.get_gpio, fp_brightness: args.fp_brightness, diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index e911f773..acdfbd09 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -157,6 +157,8 @@ pub struct Cli { pub intrusion: bool, pub inputmodules: bool, pub input_deck_mode: Option, + pub charge_full: bool, + pub charge_limit_disable: bool, pub charge_limit: Option>, pub get_gpio: Option, pub fp_brightness: Option>, @@ -732,6 +734,10 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { } else if let Some(mode) = &args.input_deck_mode { println!("Set mode to: {:?}", mode); ec.set_input_deck_mode((*mode).into()).unwrap(); + } else if args.charge_full { + print_err(ec.charge_limit_override()); + } else if args.charge_limit_disable { + print_err(ec.charge_limit_disable()); } else if let Some(maybe_limit) = args.charge_limit { print_err(handle_charge_limit(&ec, maybe_limit)); } else if let Some(gpio_name) = &args.get_gpio { @@ -1007,6 +1013,8 @@ Options: --intrusion Show status of intrusion switch --inputmodules Show status of the input modules (Framework 16 only) --input-deck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only) + --charge-full Temporarily remove the charge limit and charge full + --charge-limit-disable Remove min/max charge limit (Overwritten by BIOS on reboot) --charge-limit [] Get or set battery charge limit (Percentage number as arg, e.g. '100') --get-gpio Get GPIO value by name --fp-brightness []Get or set fingerprint LED brightness level [possible values: high, medium, low] diff --git a/framework_lib/src/commandline/uefi.rs b/framework_lib/src/commandline/uefi.rs index 69dee466..9a8a7195 100644 --- a/framework_lib/src/commandline/uefi.rs +++ b/framework_lib/src/commandline/uefi.rs @@ -82,6 +82,8 @@ pub fn parse(args: &[String]) -> Cli { intrusion: false, inputmodules: false, input_deck_mode: None, + charge_full: false, + charge_limit_disable: false, charge_limit: None, get_gpio: None, fp_brightness: None, @@ -178,6 +180,12 @@ pub fn parse(args: &[String]) -> Cli { None }; found_an_option = true; + } else if arg == "--charge-full" { + cli.charge_full = true; + found_an_option = true; + } else if arg == "--charge-limit-override" { + cli.charge_limit_disable = true; + found_an_option = true; } else if arg == "--charge-limit" { cli.charge_limit = if args.len() > i + 1 { if let Ok(percent) = args[i + 1].parse::() {