Skip to content

Commit 07ffeec

Browse files
committed
touchscreen: Allow turning touch on and off
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 69b5634 commit 07ffeec

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

framework_lib/src/commandline/clap_std.rs

+6
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ struct ClapCli {
162162
#[arg(long)]
163163
tablet_mode: Option<TabletModeArg>,
164164

165+
/// Enable/disable touchscreen
166+
#[clap(value_enum)]
167+
#[arg(long)]
168+
touchscreen_enable: Option<bool>,
169+
165170
/// Get EC console, choose whether recent or to follow the output
166171
#[clap(value_enum)]
167172
#[arg(long)]
@@ -284,6 +289,7 @@ pub fn parse(args: &[String]) -> Cli {
284289
kblight: args.kblight,
285290
rgbkbd: args.rgbkbd,
286291
tablet_mode: args.tablet_mode,
292+
touchscreen_enable: args.touchscreen_enable,
287293
console: args.console,
288294
reboot_ec: args.reboot_ec,
289295
hash: args.hash.map(|x| x.into_os_string().into_string().unwrap()),

framework_lib/src/commandline/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ use crate::smbios::ConfigDigit0;
5252
use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
5353
#[cfg(feature = "hidapi")]
5454
use crate::touchpad::print_touchpad_fw_ver;
55-
#[cfg(feature = "hidapi")]
56-
use crate::touchscreen::print_touchscreen_fw_ver;
55+
#[cfg(any(feature = "hidapi", feature = "windows"))]
56+
use crate::touchscreen;
5757
#[cfg(feature = "uefi")]
5858
use crate::uefi::enable_page_break;
5959
use crate::util;
@@ -175,6 +175,7 @@ pub struct Cli {
175175
pub kblight: Option<Option<u8>>,
176176
pub rgbkbd: Vec<u64>,
177177
pub tablet_mode: Option<TabletModeArg>,
178+
pub touchscreen_enable: Option<bool>,
178179
pub console: Option<ConsoleArg>,
179180
pub reboot_ec: Option<RebootEcArg>,
180181
pub hash: Option<String>,
@@ -483,7 +484,7 @@ fn print_versions(ec: &CrosEc) {
483484
let _ignore_err = print_touchpad_fw_ver();
484485

485486
#[cfg(feature = "hidapi")]
486-
let _ignore_err = print_touchscreen_fw_ver();
487+
let _ignore_err = touchscreen::print_fw_ver();
487488
}
488489

489490
fn print_esrt() {
@@ -798,6 +799,11 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
798799
TabletModeArg::Laptop => TabletModeOverride::ForceClamshell,
799800
};
800801
ec.set_tablet_mode(mode);
802+
} else if let Some(_enable) = &args.touchscreen_enable {
803+
#[cfg(any(feature = "hidapi", feature = "windows"))]
804+
if touchscreen::enable_touch(*_enable).is_none() {
805+
error!("Failed to enable/disable touch");
806+
}
801807
} else if let Some(console_arg) = &args.console {
802808
match console_arg {
803809
ConsoleArg::Follow => {

framework_lib/src/commandline/uefi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub fn parse(args: &[String]) -> Cli {
8989
kblight: None,
9090
rgbkbd: vec![],
9191
tablet_mode: None,
92+
touchscreen_enable: None,
9293
console: None,
9394
reboot_ec: None,
9495
hash: None,

framework_lib/src/touchscreen.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,27 @@ pub trait TouchScreen {
130130

131131
Some(())
132132
}
133+
134+
fn enable_touch(&self, enable: bool) -> Option<()> {
135+
self.send_message(0x38, 0, vec![0, !enable as u8])?;
136+
Some(())
137+
}
133138
}
134139

135-
pub fn print_touchscreen_fw_ver() -> Option<()> {
140+
pub fn print_fw_ver() -> Option<()> {
136141
#[cfg(target_os = "windows")]
137142
let device = touchscreen_win::NativeWinTouchScreen::open_device()?;
138143
#[cfg(not(target_os = "windows"))]
139144
let device = HidapiTouchScreen::open_device()?;
140145

141146
device.check_fw_version()
142147
}
148+
149+
pub fn enable_touch(enable: bool) -> Option<()> {
150+
#[cfg(target_os = "windows")]
151+
let device = touchscreen_win::NativeWinTouchScreen::open_device()?;
152+
#[cfg(not(target_os = "windows"))]
153+
let device = HidapiTouchScreen::open_device()?;
154+
155+
device.enable_touch(enable)
156+
}

0 commit comments

Comments
 (0)