Skip to content

Commit 6407aa4

Browse files
committed
Allow overriding charge limit and charge full
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 3a6c1f4 commit 6407aa4

4 files changed

Lines changed: 58 additions & 3 deletions

File tree

framework_lib/src/chromium_ec/mod.rs

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

434+
/// Let charge fully once, if currently a charge limit is set
435+
pub fn charge_limit_override(&self) -> EcResult<()> {
436+
let params = &[ChargeLimitControlModes::Override as u8, 0, 0];
437+
let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?;
438+
439+
util::assert_win_len(data.len(), 0);
440+
441+
Ok(())
442+
}
443+
444+
/// Disable all charge limits
445+
pub fn charge_limit_disable(&self) -> EcResult<()> {
446+
let params = &[ChargeLimitControlModes::Disable as u8, 0, 0];
447+
let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?;
448+
449+
util::assert_win_len(data.len(), 0);
450+
451+
Ok(())
452+
}
453+
434454
pub fn set_charge_limit(&self, min: u8, max: u8) -> EcResult<()> {
435455
// Sending bytes manually because the Set command, as opposed to the Get command,
436456
// does not return any data
@@ -509,8 +529,8 @@ impl CrosEc {
509529
pub fn set_fp_led_level(&self, level: FpLedBrightnessLevel) -> EcResult<()> {
510530
// Sending bytes manually because the Set command, as opposed to the Get command,
511531
// does not return any data
512-
let limits = &[level as u8, 0x00];
513-
let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, limits)?;
532+
let params = &[level as u8, 0x00];
533+
let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, params)?;
514534

515535
util::assert_win_len(data.len(), 0);
516536

framework_lib/src/commandline/clap_std.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,15 @@ struct ClapCli {
180180
#[arg(long)]
181181
expansion_bay: bool,
182182

183-
/// Get or set max charge limit
183+
/// Temporarily remove the charge limit and charge full
184+
#[arg(long)]
185+
charge_full: bool,
186+
187+
/// Remove min/max charge limit (Overwritten by BIOS on reboot)
188+
#[arg(long)]
189+
charge_limit_disable: bool,
190+
191+
/// Get or set max charge limit (Overwritten by BIOS on reboot)
184192
#[arg(long)]
185193
charge_limit: Option<Option<u8>>,
186194

@@ -540,6 +548,8 @@ pub fn parse(args: &[String]) -> Cli {
540548
inputdeck: args.inputdeck,
541549
inputdeck_mode: args.inputdeck_mode,
542550
expansion_bay: args.expansion_bay,
551+
charge_full: args.charge_full,
552+
charge_limit_disable: args.charge_limit_disable,
543553
charge_limit: args.charge_limit,
544554
charge_current_limit,
545555
charge_rate_limit,

framework_lib/src/commandline/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ pub struct Cli {
221221
pub inputdeck: bool,
222222
pub inputdeck_mode: Option<InputDeckModeArg>,
223223
pub expansion_bay: bool,
224+
pub charge_full: bool,
225+
pub charge_limit_disable: bool,
224226
pub charge_limit: Option<Option<u8>>,
225227
pub charge_current_limit: Option<(u32, Option<u32>)>,
226228
pub charge_rate_limit: Option<(f32, Option<f32>)>,
@@ -1442,6 +1444,10 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
14421444
print_nvidia_info();
14431445
#[cfg(not(feature = "nvidia"))]
14441446
error!("Not built with nvidia feature");
1447+
} else if args.charge_full {
1448+
print_err(ec.charge_limit_override());
1449+
} else if args.charge_limit_disable {
1450+
print_err(ec.charge_limit_disable());
14451451
} else if let Some(maybe_limit) = args.charge_limit {
14461452
print_err(handle_charge_limit(&ec, maybe_limit));
14471453
} else if let Some((limit, soc)) = args.charge_current_limit {
@@ -1919,9 +1925,21 @@ Options:
19191925
--s0ix-counter Show S0ix counter
19201926
--intrusion Show status of intrusion switch
19211927
--inputdeck Show status of the input deck
1928+
<<<<<<< LEFT
19221929
--inputdeck-mode Set input deck power mode [possible values: auto, off, on] (Laptop 12, 13, 16)
19231930
--expansion-bay Show status of the expansion bay (Laptop 16 only)
19241931
--nvidia Show NVIDIA GPU information (Laptop 16 only)
1932+
||||||| BASE
1933+
--inputdeck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only)
1934+
--expansion-bay Show status of the expansion bay (Framework 16 only)
1935+
--nvidia Show NVIDIA GPU information (Framework 16 only)
1936+
=======
1937+
--inputdeck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only)
1938+
--expansion-bay Show status of the expansion bay (Framework 16 only)
1939+
--nvidia Show NVIDIA GPU information (Framework 16 only)
1940+
--charge-full Temporarily remove the charge limit and charge full
1941+
--charge-limit-disable Remove min/max charge limit (Overwritten by BIOS on reboot)
1942+
>>>>>>> RIGHT
19251943
--charge-limit [<VAL>] Get or set battery charge limit (Percentage number as arg, e.g. '100')
19261944
--charge-current-limit [<VAL>] Get or set battery current charge limit (Percentage number as arg, e.g. '100')
19271945
--charge-rate-limit [<VAL>] Set max charge rate limit

framework_lib/src/commandline/uefi.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ pub fn parse(args: &[String]) -> Cli {
6969
inputdeck: false,
7070
inputdeck_mode: None,
7171
expansion_bay: false,
72+
charge_full: false,
73+
charge_limit_disable: false,
7274
charge_limit: None,
7375
charge_current_limit: None,
7476
charge_rate_limit: None,
@@ -276,6 +278,11 @@ pub fn parse(args: &[String]) -> Cli {
276278
found_an_option = true;
277279
} else if arg == "--nvidia" {
278280
cli.nvidia = true;
281+
} else if arg == "--charge-full" {
282+
cli.charge_full = true;
283+
found_an_option = true;
284+
} else if arg == "--charge-limit-disable" {
285+
cli.charge_limit_disable = true;
279286
found_an_option = true;
280287
} else if arg == "--charge-limit" {
281288
cli.charge_limit = if args.len() > i + 1 {

0 commit comments

Comments
 (0)