Skip to content

Commit f82adae

Browse files
committed
Allow overriding charge limit and charge full
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 456e7dc commit f82adae

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

framework_lib/src/chromium_ec/mod.rs

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

288+
/// Let charge fully once, if currently a charge limit is set
289+
pub fn charge_limit_override(&self) -> EcResult<()> {
290+
let params = &[ChargeLimitControlModes::Override as u8, 0, 0];
291+
let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?;
292+
293+
util::assert_win_len(data.len(), 0);
294+
295+
Ok(())
296+
}
297+
298+
/// Disable all charge limits
299+
pub fn charge_limit_disable(&self) -> EcResult<()> {
300+
let params = &[ChargeLimitControlModes::Disable as u8, 0, 0];
301+
let data = self.send_command(EcCommands::ChargeLimitControl as u16, 0, params)?;
302+
303+
util::assert_win_len(data.len(), 0);
304+
305+
Ok(())
306+
}
307+
288308
pub fn set_charge_limit(&self, min: u8, max: u8) -> EcResult<()> {
289309
// Sending bytes manually because the Set command, as opposed to the Get command,
290310
// does not return any data
@@ -316,8 +336,8 @@ impl CrosEc {
316336
pub fn set_fp_led_level(&self, level: FpLedBrightnessLevel) -> EcResult<()> {
317337
// Sending bytes manually because the Set command, as opposed to the Get command,
318338
// does not return any data
319-
let limits = &[level as u8, 0x00];
320-
let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, limits)?;
339+
let params = &[level as u8, 0x00];
340+
let data = self.send_command(EcCommands::FpLedLevelControl as u16, 0, params)?;
321341

322342
util::assert_win_len(data.len(), 0);
323343

framework_lib/src/commandline/clap_std.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,15 @@ struct ClapCli {
129129
#[arg(long)]
130130
input_deck_mode: Option<InputDeckModeArg>,
131131

132-
/// Get or set max charge limit
132+
/// Temporarily remove the charge limit and charge full
133+
#[arg(long)]
134+
charge_full: bool,
135+
136+
/// Remove min/max charge limit (Overwritten by BIOS on reboot)
137+
#[arg(long)]
138+
charge_limit_disable: bool,
139+
140+
/// Get or set max charge limit (Overwritten by BIOS on reboot)
133141
#[arg(long)]
134142
charge_limit: Option<Option<u8>>,
135143

@@ -265,6 +273,8 @@ pub fn parse(args: &[String]) -> Cli {
265273
intrusion: args.intrusion,
266274
inputmodules: args.inputmodules,
267275
input_deck_mode: args.input_deck_mode,
276+
charge_full: args.charge_full,
277+
charge_limit_disable: args.charge_limit_disable,
268278
charge_limit: args.charge_limit,
269279
get_gpio: args.get_gpio,
270280
fp_brightness: args.fp_brightness,

framework_lib/src/commandline/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ pub struct Cli {
157157
pub intrusion: bool,
158158
pub inputmodules: bool,
159159
pub input_deck_mode: Option<InputDeckModeArg>,
160+
pub charge_full: bool,
161+
pub charge_limit_disable: bool,
160162
pub charge_limit: Option<Option<u8>>,
161163
pub get_gpio: Option<String>,
162164
pub fp_brightness: Option<Option<FpBrightnessArg>>,
@@ -732,6 +734,10 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
732734
} else if let Some(mode) = &args.input_deck_mode {
733735
println!("Set mode to: {:?}", mode);
734736
ec.set_input_deck_mode((*mode).into()).unwrap();
737+
} else if args.charge_full {
738+
print_err(ec.charge_limit_override());
739+
} else if args.charge_limit_disable {
740+
print_err(ec.charge_limit_disable());
735741
} else if let Some(maybe_limit) = args.charge_limit {
736742
print_err(handle_charge_limit(&ec, maybe_limit));
737743
} else if let Some(gpio_name) = &args.get_gpio {
@@ -1007,6 +1013,8 @@ Options:
10071013
--intrusion Show status of intrusion switch
10081014
--inputmodules Show status of the input modules (Framework 16 only)
10091015
--input-deck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only)
1016+
--charge-full Temporarily remove the charge limit and charge full
1017+
--charge-limit-disable Remove min/max charge limit (Overwritten by BIOS on reboot)
10101018
--charge-limit [<VAL>] Get or set battery charge limit (Percentage number as arg, e.g. '100')
10111019
--get-gpio <GET_GPIO> Get GPIO value by name
10121020
--fp-brightness [<VAL>]Get or set fingerprint LED brightness level [possible values: high, medium, low]

framework_lib/src/commandline/uefi.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ pub fn parse(args: &[String]) -> Cli {
8282
intrusion: false,
8383
inputmodules: false,
8484
input_deck_mode: None,
85+
charge_full: false,
86+
charge_limit_disable: false,
8587
charge_limit: None,
8688
get_gpio: None,
8789
fp_brightness: None,
@@ -178,6 +180,12 @@ pub fn parse(args: &[String]) -> Cli {
178180
None
179181
};
180182
found_an_option = true;
183+
} else if arg == "--charge-full" {
184+
cli.charge_full = true;
185+
found_an_option = true;
186+
} else if arg == "--charge-limit-override" {
187+
cli.charge_limit_disable = true;
188+
found_an_option = true;
181189
} else if arg == "--charge-limit" {
182190
cli.charge_limit = if args.len() > i + 1 {
183191
if let Ok(percent) = args[i + 1].parse::<u8>() {

0 commit comments

Comments
 (0)