Skip to content

Commit f584a2b

Browse files
Merge pull request #139 from FrameworkComputer/ps2-control
Add --ps2-enable to control ps2 emulation
2 parents d30f728 + 98810c5 commit f584a2b

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

framework_lib/src/chromium_ec/command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub enum EcCommands {
6161
FlashNotified = 0x3E01,
6262
/// Change charge limit
6363
ChargeLimitControl = 0x3E03,
64+
DisablePs2Emulation = 0x3E08,
6465
/// Get/Set Fingerprint LED brightness
6566
FpLedLevelControl = 0x3E0E,
6667
/// Get information about the current chassis open/close status

framework_lib/src/chromium_ec/commands.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,17 @@ impl EcRequest<EcResponseChargeLimitControl> for EcRequestChargeLimitControl {
12311231
/// TODO: Use this
12321232
pub const EC_CHARGE_LIMIT_RESTORE: u8 = 0x7F;
12331233

1234+
#[repr(C, packed)]
1235+
pub struct EcRequestDisablePs2Emulation {
1236+
pub disable: u8,
1237+
}
1238+
1239+
impl EcRequest<()> for EcRequestDisablePs2Emulation {
1240+
fn command_id() -> EcCommands {
1241+
EcCommands::DisablePs2Emulation
1242+
}
1243+
}
1244+
12341245
#[repr(u8)]
12351246
#[derive(Debug, FromPrimitive)]
12361247
pub enum FpLedBrightnessLevel {

framework_lib/src/chromium_ec/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,13 @@ impl CrosEc {
633633
Ok((kblight.duty / (PWM_MAX_DUTY / 100)) as u8)
634634
}
635635

636+
pub fn ps2_emulation_enable(&self, enable: bool) -> EcResult<()> {
637+
EcRequestDisablePs2Emulation {
638+
disable: !enable as u8,
639+
}
640+
.send_command(self)
641+
}
642+
636643
pub fn fan_set_rpm(&self, fan: Option<u32>, rpm: u32) -> EcResult<()> {
637644
if let Some(fan_idx) = fan {
638645
EcRequestPwmSetFanTargetRpmV1 { rpm, fan_idx }.send_command(self)

framework_lib/src/commandline/clap_std.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ struct ClapCli {
188188
#[arg(long, value_parser=maybe_hex::<u64>)]
189189
rgbkbd: Vec<u64>,
190190

191+
/// Control PS2 touchpad emulation (DEBUG COMMAND, if touchpad not working, reboot system)
192+
#[clap(value_enum, hide(true))]
193+
#[arg(long)]
194+
ps2_enable: Option<bool>,
195+
191196
/// Set tablet mode override
192197
#[clap(value_enum)]
193198
#[arg(long)]
@@ -393,6 +398,7 @@ pub fn parse(args: &[String]) -> Cli {
393398
fp_brightness: args.fp_brightness,
394399
kblight: args.kblight,
395400
rgbkbd: args.rgbkbd,
401+
ps2_enable: args.ps2_enable,
396402
tablet_mode: args.tablet_mode,
397403
touchscreen_enable: args.touchscreen_enable,
398404
stylus_battery: args.stylus_battery,

framework_lib/src/commandline/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ pub struct Cli {
182182
pub fp_brightness: Option<Option<u8>>,
183183
pub kblight: Option<Option<u8>>,
184184
pub rgbkbd: Vec<u64>,
185+
pub ps2_enable: Option<bool>,
185186
pub tablet_mode: Option<TabletModeArg>,
186187
pub touchscreen_enable: Option<bool>,
187188
pub stylus_battery: bool,
@@ -823,6 +824,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
823824
});
824825
ec.rgbkbd_set_color(start_key, colors.collect()).unwrap();
825826
}
827+
} else if let Some(enable) = args.ps2_enable {
828+
print_err(ec.ps2_emulation_enable(enable));
826829
} else if let Some(None) = args.kblight {
827830
print!("Keyboard backlight: ");
828831
if let Some(percentage) = print_err(ec.get_keyboard_backlight()) {

framework_lib/src/commandline/uefi.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub fn parse(args: &[String]) -> Cli {
9595
fp_brightness: None,
9696
kblight: None,
9797
rgbkbd: vec![],
98+
ps2_enable: None,
9899
tablet_mode: None,
99100
touchscreen_enable: None,
100101
stylus_battery: false,
@@ -361,6 +362,26 @@ pub fn parse(args: &[String]) -> Cli {
361362
println!("--rgbkbd requires at least 2 arguments, the start key and an RGB value");
362363
vec![]
363364
}
365+
} else if arg == "--ps2-enable" {
366+
cli.ps2_enable = if args.len() > i + 1 {
367+
let enable_arg = &args[i + 1];
368+
if enable_arg == "true" {
369+
Some(true)
370+
} else if enable_arg == "false" {
371+
Some(false)
372+
} else {
373+
println!(
374+
"Need to provide a value for --ps2-enable: '{}'. {}",
375+
args[i + 1],
376+
"Must be `true` or `false`",
377+
);
378+
None
379+
}
380+
} else {
381+
println!("Need to provide a value for --tablet-mode. One of: `auto`, `tablet` or `laptop`");
382+
None
383+
};
384+
found_an_option = true;
364385
} else if arg == "--tablet-mode" {
365386
cli.tablet_mode = if args.len() > i + 1 {
366387
let tablet_mode_arg = &args[i + 1];

0 commit comments

Comments
 (0)