diff --git a/framework_lib/src/chromium_ec/command.rs b/framework_lib/src/chromium_ec/command.rs index 54b8db52..86b50c92 100644 --- a/framework_lib/src/chromium_ec/command.rs +++ b/framework_lib/src/chromium_ec/command.rs @@ -60,6 +60,7 @@ pub enum EcCommands { FlashNotified = 0x3E01, /// Change charge limit ChargeLimitControl = 0x3E03, + DisablePs2Emulation = 0x3E08, /// Get/Set Fingerprint LED brightness FpLedLevelControl = 0x3E0E, /// Get information about the current chassis open/close status diff --git a/framework_lib/src/chromium_ec/commands.rs b/framework_lib/src/chromium_ec/commands.rs index 38cafeb6..d3bc4d8f 100644 --- a/framework_lib/src/chromium_ec/commands.rs +++ b/framework_lib/src/chromium_ec/commands.rs @@ -1048,6 +1048,17 @@ impl EcRequest for EcRequestChargeLimitControl { /// TODO: Use this pub const EC_CHARGE_LIMIT_RESTORE: u8 = 0x7F; +#[repr(C, packed)] +pub struct EcRequestDisablePs2Emulation { + pub disable: u8, +} + +impl EcRequest<()> for EcRequestDisablePs2Emulation { + fn command_id() -> EcCommands { + EcCommands::DisablePs2Emulation + } +} + #[repr(u8)] #[derive(Debug, FromPrimitive)] pub enum FpLedBrightnessLevel { diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index afdaef0c..2ea843f3 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -596,6 +596,13 @@ impl CrosEc { Ok((kblight.duty / (PWM_MAX_DUTY / 100)) as u8) } + pub fn ps2_emulation_enable(&self, enable: bool) -> EcResult<()> { + EcRequestDisablePs2Emulation { + disable: !enable as u8, + } + .send_command(self) + } + pub fn fan_set_rpm(&self, fan: Option, rpm: u32) -> EcResult<()> { if let Some(fan_idx) = fan { EcRequestPwmSetFanTargetRpmV1 { rpm, fan_idx }.send_command(self) diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index 76784a5f..735267d8 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -188,6 +188,11 @@ struct ClapCli { #[arg(long, value_parser=maybe_hex::)] rgbkbd: Vec, + /// Control PS2 touchpad emulation (DEBUG COMMAND, if touchpad not working, reboot system) + #[clap(value_enum, hide(true))] + #[arg(long)] + ps2_enable: Option, + /// Set tablet mode override #[clap(value_enum)] #[arg(long)] @@ -393,6 +398,7 @@ pub fn parse(args: &[String]) -> Cli { fp_brightness: args.fp_brightness, kblight: args.kblight, rgbkbd: args.rgbkbd, + ps2_enable: args.ps2_enable, tablet_mode: args.tablet_mode, touchscreen_enable: args.touchscreen_enable, stylus_battery: args.stylus_battery, diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index b2a324f1..5df3e642 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -182,6 +182,7 @@ pub struct Cli { pub fp_brightness: Option>, pub kblight: Option>, pub rgbkbd: Vec, + pub ps2_enable: Option, pub tablet_mode: Option, pub touchscreen_enable: Option, pub stylus_battery: bool, @@ -819,6 +820,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { }); ec.rgbkbd_set_color(start_key, colors.collect()).unwrap(); } + } else if let Some(enable) = args.ps2_enable { + print_err(ec.ps2_emulation_enable(enable)); } else if let Some(None) = args.kblight { print!("Keyboard backlight: "); if let Some(percentage) = print_err(ec.get_keyboard_backlight()) { diff --git a/framework_lib/src/commandline/uefi.rs b/framework_lib/src/commandline/uefi.rs index 1fd9e5d8..b02667dd 100644 --- a/framework_lib/src/commandline/uefi.rs +++ b/framework_lib/src/commandline/uefi.rs @@ -95,6 +95,7 @@ pub fn parse(args: &[String]) -> Cli { fp_brightness: None, kblight: None, rgbkbd: vec![], + ps2_enable: None, tablet_mode: None, touchscreen_enable: None, stylus_battery: false, @@ -361,6 +362,26 @@ pub fn parse(args: &[String]) -> Cli { println!("--rgbkbd requires at least 2 arguments, the start key and an RGB value"); vec![] } + } else if arg == "--ps2-enable" { + cli.ps2_enable = if args.len() > i + 1 { + let enable_arg = &args[i + 1]; + if enable_arg == "true" { + Some(true) + } else if enable_arg == "false" { + Some(false) + } else { + println!( + "Need to provide a value for --ps2-enable: '{}'. {}", + args[i + 1], + "Must be `true` or `false`", + ); + None + } + } else { + println!("Need to provide a value for --tablet-mode. One of: `auto`, `tablet` or `laptop`"); + None + }; + found_an_option = true; } else if arg == "--tablet-mode" { cli.tablet_mode = if args.len() > i + 1 { let tablet_mode_arg = &args[i + 1];