Skip to content

Commit 6474a2a

Browse files
committed
Add --ptp-mode command
Can check and change ptp mode ``` > sudo framework_tool --ptp-mode ptp > sudo framework_tool --ptp-mode mouse > sudo framework_tool --ptp-mode mouse > sudo framework_tool --ptp-mode ptp > sudo framework_tool --ptp-mode ptp Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent deb7c7a commit 6474a2a

6 files changed

Lines changed: 684 additions & 2 deletions

File tree

framework_lib/src/commandline/clap_std.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use clap_num::maybe_hex;
1212
use crate::chromium_ec::commands::SetGpuSerialMagic;
1313
use crate::chromium_ec::CrosEcDriverType;
1414
use crate::commandline::{
15-
Cli, ConsoleArg, FpBrightnessArg, HardwareDeviceType, InputDeckModeArg, LogLevel, RebootEcArg,
16-
TabletModeArg,
15+
Cli, ConsoleArg, FpBrightnessArg, HardwareDeviceType, InputDeckModeArg, LogLevel, PtpModeArg,
16+
RebootEcArg, TabletModeArg,
1717
};
1818

1919
/// Swiss army knife for Framework laptops
@@ -233,6 +233,11 @@ struct ClapCli {
233233
#[arg(long)]
234234
stylus_battery: bool,
235235

236+
/// Get or set precision touchpad mode
237+
#[clap(value_enum)]
238+
#[arg(long)]
239+
ptp_mode: Option<Option<PtpModeArg>>,
240+
236241
/// Get EC console, choose whether recent or to follow the output
237242
#[clap(value_enum)]
238243
#[arg(long)]
@@ -523,6 +528,7 @@ pub fn parse(args: &[String]) -> Cli {
523528
tablet_mode: args.tablet_mode,
524529
touchscreen_enable: args.touchscreen_enable,
525530
stylus_battery: args.stylus_battery,
531+
ptp_mode: args.ptp_mode,
526532
console: args.console,
527533
reboot_ec: args.reboot_ec,
528534
ec_hib_delay: args.ec_hib_delay,

framework_lib/src/commandline/mod.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ use crate::smbios::ConfigDigit0;
6161
use crate::smbios::{get_smbios, is_framework};
6262
#[cfg(feature = "hidapi")]
6363
use crate::touchpad::print_touchpad_fw_ver;
64+
#[cfg(target_os = "linux")]
65+
use crate::touchpad_ptp;
66+
#[cfg(all(feature = "hidapi", windows))]
67+
use crate::touchpad_ptp_win;
6468
#[cfg(feature = "hidapi")]
6569
use crate::touchscreen;
6670
#[cfg(feature = "rusb")]
@@ -132,6 +136,13 @@ pub enum InputDeckModeArg {
132136
Off,
133137
On,
134138
}
139+
140+
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]
141+
#[derive(Clone, Copy, Debug, PartialEq)]
142+
pub enum PtpModeArg {
143+
Mouse,
144+
Ptp,
145+
}
135146
impl From<InputDeckModeArg> for DeckStateMode {
136147
fn from(w: InputDeckModeArg) -> DeckStateMode {
137148
match w {
@@ -211,6 +222,7 @@ pub struct Cli {
211222
pub tablet_mode: Option<TabletModeArg>,
212223
pub touchscreen_enable: Option<bool>,
213224
pub stylus_battery: bool,
225+
pub ptp_mode: Option<Option<PtpModeArg>>,
214226
pub console: Option<ConsoleArg>,
215227
pub reboot_ec: Option<RebootEcArg>,
216228
pub ec_hib_delay: Option<Option<u32>>,
@@ -299,6 +311,7 @@ pub fn parse(args: &[String]) -> Cli {
299311
// tablet_mode
300312
// touchscreen_enable
301313
stylus_battery: cli.stylus_battery,
314+
// ptp_mode
302315
console: cli.console,
303316
reboot_ec: cli.reboot_ec,
304317
// ec_hib_delay
@@ -1463,6 +1476,50 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
14631476
print_stylus_battery_level();
14641477
#[cfg(not(feature = "hidapi"))]
14651478
error!("Not build with hidapi feature");
1479+
} else if let Some(ptp_arg) = &args.ptp_mode {
1480+
#[cfg(target_os = "linux")]
1481+
match ptp_arg {
1482+
None => match touchpad_ptp::get_ptp_mode() {
1483+
Some(0) => println!("mouse"),
1484+
Some(3) => println!("ptp"),
1485+
Some(v) => println!("unknown ({})", v),
1486+
None => error!("Failed to read PTP mode"),
1487+
},
1488+
Some(PtpModeArg::Mouse) => {
1489+
if touchpad_ptp::set_ptp_mode(0).is_none() {
1490+
error!("Failed to set PTP mode to mouse");
1491+
}
1492+
}
1493+
Some(PtpModeArg::Ptp) => {
1494+
if touchpad_ptp::set_ptp_mode(3).is_none() {
1495+
error!("Failed to set PTP mode to ptp");
1496+
}
1497+
}
1498+
}
1499+
#[cfg(all(feature = "hidapi", windows))]
1500+
match ptp_arg {
1501+
None => match touchpad_ptp_win::get_ptp_mode() {
1502+
Some(0) => println!("mouse"),
1503+
Some(3) => println!("ptp"),
1504+
Some(v) => println!("unknown ({})", v),
1505+
None => error!("Failed to read PTP mode"),
1506+
},
1507+
Some(PtpModeArg::Mouse) => {
1508+
if touchpad_ptp_win::set_ptp_mode(0).is_none() {
1509+
error!("Failed to set PTP mode to mouse");
1510+
}
1511+
}
1512+
Some(PtpModeArg::Ptp) => {
1513+
if touchpad_ptp_win::set_ptp_mode(3).is_none() {
1514+
error!("Failed to set PTP mode to ptp");
1515+
}
1516+
}
1517+
}
1518+
#[cfg(not(any(target_os = "linux", all(feature = "hidapi", windows))))]
1519+
{
1520+
let _ = ptp_arg;
1521+
error!("PTP mode not supported on this platform");
1522+
}
14661523
} else if let Some(console_arg) = &args.console {
14671524
match console_arg {
14681525
ConsoleArg::Follow => {

framework_lib/src/commandline/uefi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub fn parse(args: &[String]) -> Cli {
8080
tablet_mode: None,
8181
touchscreen_enable: None,
8282
stylus_battery: false,
83+
ptp_mode: None,
8384
console: None,
8485
reboot_ec: None,
8586
ec_hib_delay: None,

framework_lib/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ pub mod inputmodule;
2323
pub mod nvme;
2424
#[cfg(feature = "hidapi")]
2525
pub mod touchpad;
26+
#[cfg(target_os = "linux")]
27+
pub mod touchpad_ptp;
28+
#[cfg(all(feature = "hidapi", windows))]
29+
pub mod touchpad_ptp_win;
2630
#[cfg(feature = "hidapi")]
2731
pub mod touchscreen;
2832
#[cfg(all(feature = "hidapi", windows))]

0 commit comments

Comments
 (0)