Skip to content

Commit 57b2e98

Browse files
committed
Allow overriding charge limit and charge full
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 96a7608 commit 57b2e98

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

framework_lib/src/chromium_ec/mod.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,26 @@ impl CrosEc {
279279
Ok((status.microphone == 1, status.camera == 1))
280280
}
281281

282+
/// Let charge fully once, if currently a charge limit is set
283+
pub fn charge_limit_override(&self) -> EcResult<()> {
284+
let params = &[ChargeLimitControlModes::Override as u8, 0, 0];
285+
let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?;
286+
287+
util::assert_win_len(data.len(), 0);
288+
289+
Ok(())
290+
}
291+
292+
/// Disable all charge limits
293+
pub fn charge_limit_disable(&self) -> EcResult<()> {
294+
let params = &[ChargeLimitControlModes::Disable as u8, 0, 0];
295+
let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?;
296+
297+
util::assert_win_len(data.len(), 0);
298+
299+
Ok(())
300+
}
301+
282302
pub fn set_charge_limit(&self, min: u8, max: u8) -> EcResult<()> {
283303
// Sending bytes manually because the Set command, as opposed to the Get command,
284304
// does not return any data
@@ -310,8 +330,8 @@ impl CrosEc {
310330
pub fn set_fp_led_level(&self, level: FpLedBrightnessLevel) -> EcResult<()> {
311331
// Sending bytes manually because the Set command, as opposed to the Get command,
312332
// does not return any data
313-
let limits = &[level as u8, 0x00];
314-
let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, limits)?;
333+
let params = &[level as u8, 0x00];
334+
let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, params)?;
315335

316336
util::assert_win_len(data.len(), 0);
317337

framework_lib/src/commandline/clap_std.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ struct ClapCli {
124124
#[arg(long)]
125125
input_deck_mode: Option<InputDeckModeArg>,
126126

127-
/// Get or set max charge limit
127+
/// Temporarily remove the charge limit and charge full
128+
#[arg(long)]
129+
charge_full: bool,
130+
131+
/// Remove min/max charge limit (Overwritten by BIOS on reboot)
132+
#[arg(long)]
133+
charge_limit_disable: bool,
134+
135+
/// Get or set max charge limit (Overwritten by BIOS on reboot)
128136
#[arg(long)]
129137
charge_limit: Option<Option<u8>>,
130138

@@ -250,6 +258,8 @@ pub fn parse(args: &[String]) -> Cli {
250258
intrusion: args.intrusion,
251259
inputmodules: args.inputmodules,
252260
input_deck_mode: args.input_deck_mode,
261+
charge_full: args.charge_full,
262+
charge_limit_disable: args.charge_limit_disable,
253263
charge_limit: args.charge_limit,
254264
fp_brightness: args.fp_brightness,
255265
kblight: args.kblight,

framework_lib/src/commandline/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ pub struct Cli {
147147
pub intrusion: bool,
148148
pub inputmodules: bool,
149149
pub input_deck_mode: Option<InputDeckModeArg>,
150+
pub charge_full: bool,
151+
pub charge_limit_disable: bool,
150152
pub charge_limit: Option<Option<u8>>,
151153
pub fp_brightness: Option<Option<FpBrightnessArg>>,
152154
pub kblight: Option<Option<u8>>,
@@ -718,6 +720,10 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
718720
} else if let Some(mode) = &args.input_deck_mode {
719721
println!("Set mode to: {:?}", mode);
720722
ec.set_input_deck_mode((*mode).into()).unwrap();
723+
} else if args.charge_full {
724+
print_err(ec.charge_limit_override());
725+
} else if args.charge_limit_disable {
726+
print_err(ec.charge_limit_disable());
721727
} else if let Some(maybe_limit) = args.charge_limit {
722728
print_err(handle_charge_limit(&ec, maybe_limit));
723729
} else if let Some(maybe_brightness) = &args.fp_brightness {

framework_lib/src/commandline/uefi.rs

+8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ pub fn parse(args: &[String]) -> Cli {
8181
intrusion: false,
8282
inputmodules: false,
8383
input_deck_mode: None,
84+
charge_full: false,
85+
charge_limit_disable: false,
8486
charge_limit: None,
8587
fp_brightness: None,
8688
kblight: None,
@@ -172,6 +174,12 @@ pub fn parse(args: &[String]) -> Cli {
172174
None
173175
};
174176
found_an_option = true;
177+
} else if arg == "--charge-full" {
178+
cli.charge_full = true;
179+
found_an_option = true;
180+
} else if arg == "--charge-limit-override" {
181+
cli.charge_limit_disable = true;
182+
found_an_option = true;
175183
} else if arg == "--charge-limit" {
176184
cli.charge_limit = if args.len() > i + 1 {
177185
if let Ok(percent) = args[i + 1].parse::<u8>() {

0 commit comments

Comments
 (0)