Skip to content

Commit 2d43f14

Browse files
committed
Allow overriding charge limit and charge full
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent e6b839e commit 2d43f14

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

framework_lib/src/chromium_ec/mod.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,26 @@ impl CrosEc {
418418
Ok((status.microphone == 1, status.camera == 1))
419419
}
420420

421+
/// Let charge fully once, if currently a charge limit is set
422+
pub fn charge_limit_override(&self) -> EcResult<()> {
423+
let params = &[ChargeLimitControlModes::Override as u8, 0, 0];
424+
let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?;
425+
426+
util::assert_win_len(data.len(), 0);
427+
428+
Ok(())
429+
}
430+
431+
/// Disable all charge limits
432+
pub fn charge_limit_disable(&self) -> EcResult<()> {
433+
let params = &[ChargeLimitControlModes::Disable as u8, 0, 0];
434+
let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?;
435+
436+
util::assert_win_len(data.len(), 0);
437+
438+
Ok(())
439+
}
440+
421441
pub fn set_charge_limit(&self, min: u8, max: u8) -> EcResult<()> {
422442
// Sending bytes manually because the Set command, as opposed to the Get command,
423443
// does not return any data
@@ -496,8 +516,8 @@ impl CrosEc {
496516
pub fn set_fp_led_level(&self, level: FpLedBrightnessLevel) -> EcResult<()> {
497517
// Sending bytes manually because the Set command, as opposed to the Get command,
498518
// does not return any data
499-
let limits = &[level as u8, 0x00];
500-
let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, limits)?;
519+
let params = &[level as u8, 0x00];
520+
let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, params)?;
501521

502522
util::assert_win_len(data.len(), 0);
503523

framework_lib/src/commandline/clap_std.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,15 @@ struct ClapCli {
163163
#[arg(long)]
164164
expansion_bay: bool,
165165

166-
/// Get or set max charge limit
166+
/// Temporarily remove the charge limit and charge full
167+
#[arg(long)]
168+
charge_full: bool,
169+
170+
/// Remove min/max charge limit (Overwritten by BIOS on reboot)
171+
#[arg(long)]
172+
charge_limit_disable: bool,
173+
174+
/// Get or set max charge limit (Overwritten by BIOS on reboot)
167175
#[arg(long)]
168176
charge_limit: Option<Option<u8>>,
169177

@@ -452,6 +460,8 @@ pub fn parse(args: &[String]) -> Cli {
452460
inputdeck: args.inputdeck,
453461
inputdeck_mode: args.inputdeck_mode,
454462
expansion_bay: args.expansion_bay,
463+
charge_full: args.charge_full,
464+
charge_limit_disable: args.charge_limit_disable,
455465
charge_limit: args.charge_limit,
456466
charge_current_limit,
457467
charge_rate_limit,

framework_lib/src/commandline/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ pub struct Cli {
200200
pub inputdeck: bool,
201201
pub inputdeck_mode: Option<InputDeckModeArg>,
202202
pub expansion_bay: bool,
203+
pub charge_full: bool,
204+
pub charge_limit_disable: bool,
203205
pub charge_limit: Option<Option<u8>>,
204206
pub charge_current_limit: Option<(u32, Option<u32>)>,
205207
pub charge_rate_limit: Option<(f32, Option<f32>)>,
@@ -1368,6 +1370,10 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
13681370
print_nvidia_info();
13691371
#[cfg(not(feature = "nvidia"))]
13701372
error!("Not built with nvidia feature");
1373+
} else if args.charge_full {
1374+
print_err(ec.charge_limit_override());
1375+
} else if args.charge_limit_disable {
1376+
print_err(ec.charge_limit_disable());
13711377
} else if let Some(maybe_limit) = args.charge_limit {
13721378
print_err(handle_charge_limit(&ec, maybe_limit));
13731379
} else if let Some((limit, soc)) = args.charge_current_limit {
@@ -1803,6 +1809,8 @@ Options:
18031809
--inputdeck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only)
18041810
--expansion-bay Show status of the expansion bay (Framework 16 only)
18051811
--nvidia Show NVIDIA GPU information (Framework 16 only)
1812+
--charge-full Temporarily remove the charge limit and charge full
1813+
--charge-limit-disable Remove min/max charge limit (Overwritten by BIOS on reboot)
18061814
--charge-limit [<VAL>] Get or set battery charge limit (Percentage number as arg, e.g. '100')
18071815
--charge-current-limit [<VAL>] Get or set battery current charge limit (Percentage number as arg, e.g. '100')
18081816
--get-gpio <GET_GPIO> Get GPIO value by name or all, if no name provided

framework_lib/src/commandline/uefi.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub fn parse(args: &[String]) -> Cli {
6262
inputdeck: false,
6363
inputdeck_mode: None,
6464
expansion_bay: false,
65+
charge_full: false,
66+
charge_limit_disable: false,
6567
charge_limit: None,
6668
charge_current_limit: None,
6769
charge_rate_limit: None,
@@ -254,6 +256,11 @@ pub fn parse(args: &[String]) -> Cli {
254256
found_an_option = true;
255257
} else if arg == "--nvidia" {
256258
cli.nvidia = true;
259+
} else if arg == "--charge-full" {
260+
cli.charge_full = true;
261+
found_an_option = true;
262+
} else if arg == "--charge-limit-disable" {
263+
cli.charge_limit_disable = true;
257264
found_an_option = true;
258265
} else if arg == "--charge-limit" {
259266
cli.charge_limit = if args.len() > i + 1 {

0 commit comments

Comments
 (0)