Skip to content

Commit 302d012

Browse files
Merge pull request #101 from FrameworkComputer/inputmodule-mode
2 parents e50e600 + 3d99f42 commit 302d012

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

framework_lib/src/chromium_ec/commands.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,18 @@ impl EcRequest<EcResponsePrivacySwitches> for EcRequestPrivacySwitches {
181181
}
182182
}
183183

184+
#[repr(u8)]
185+
pub enum DeckStateMode {
186+
ReadOnly = 0x00,
187+
Required = 0x01,
188+
ForceOn = 0x02,
189+
ForceOff = 0x04,
190+
}
191+
184192
#[repr(C, packed)]
185-
pub struct EcRequestDeckState {}
193+
pub struct EcRequestDeckState {
194+
pub mode: DeckStateMode,
195+
}
186196

187197
#[repr(C, packed)]
188198
pub struct EcResponseDeckState {

framework_lib/src/chromium_ec/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,16 @@ impl CrosEc {
247247
}
248248

249249
pub fn get_input_deck_status(&self) -> EcResult<InputDeckStatus> {
250-
let status = EcRequestDeckState {}.send_command(self)?;
250+
let status = EcRequestDeckState {
251+
mode: DeckStateMode::ReadOnly,
252+
}
253+
.send_command(self)?;
254+
255+
Ok(InputDeckStatus::from(status))
256+
}
257+
258+
pub fn set_input_deck_mode(&self, mode: DeckStateMode) -> EcResult<InputDeckStatus> {
259+
let status = EcRequestDeckState { mode }.send_command(self)?;
251260

252261
Ok(InputDeckStatus::from(status))
253262
}

framework_lib/src/commandline/clap_std.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use clap::Parser;
55

66
use crate::chromium_ec::CrosEcDriverType;
7-
use crate::commandline::{Cli, ConsoleArg};
7+
use crate::commandline::{Cli, ConsoleArg, InputDeckModeArg};
88

99
/// Swiss army knife for Framework laptops
1010
#[derive(Parser)]
@@ -85,6 +85,10 @@ struct ClapCli {
8585
#[arg(long)]
8686
inputmodules: bool,
8787

88+
/// Show status of the input modules (Framework 16 only)
89+
#[arg(long)]
90+
input_deck_mode: Option<InputDeckModeArg>,
91+
8892
/// Set keyboard backlight percentage or get, if no value provided
8993
#[arg(long)]
9094
kblight: Option<Option<u8>>,
@@ -137,6 +141,7 @@ pub fn parse(args: &[String]) -> Cli {
137141
.map(|x| x.into_os_string().into_string().unwrap()),
138142
intrusion: args.intrusion,
139143
inputmodules: args.inputmodules,
144+
input_deck_mode: args.input_deck_mode,
140145
kblight: args.kblight,
141146
console: args.console,
142147
driver: args.driver,

framework_lib/src/commandline/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::ccgx::device::{PdController, PdPort};
2828
use crate::ccgx::hid::{check_ccg_fw_version, find_devices, DP_CARD_PID, HDMI_CARD_PID};
2929
use crate::ccgx::{self, SiliconId::*};
3030
use crate::chromium_ec;
31+
use crate::chromium_ec::commands::DeckStateMode;
3132
use crate::chromium_ec::print_err;
3233
#[cfg(feature = "linux")]
3334
use crate::csme;
@@ -55,6 +56,23 @@ pub enum ConsoleArg {
5556
Follow,
5657
}
5758

59+
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]
60+
#[derive(Clone, Copy, Debug, PartialEq)]
61+
pub enum InputDeckModeArg {
62+
Auto,
63+
Off,
64+
On,
65+
}
66+
impl From<InputDeckModeArg> for DeckStateMode {
67+
fn from(w: InputDeckModeArg) -> DeckStateMode {
68+
match w {
69+
InputDeckModeArg::Auto => DeckStateMode::Required,
70+
InputDeckModeArg::Off => DeckStateMode::ForceOff,
71+
InputDeckModeArg::On => DeckStateMode::ForceOn,
72+
}
73+
}
74+
}
75+
5876
/// Shadows `clap_std::ClapCli` with extras for UEFI
5977
///
6078
/// The UEFI commandline currently doesn't use clap, so we need to shadow the struct.
@@ -81,6 +99,7 @@ pub struct Cli {
8199
pub test: bool,
82100
pub intrusion: bool,
83101
pub inputmodules: bool,
102+
pub input_deck_mode: Option<InputDeckModeArg>,
84103
pub kblight: Option<Option<u8>>,
85104
pub console: Option<ConsoleArg>,
86105
pub help: bool,
@@ -410,6 +429,9 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
410429
} else {
411430
println!(" Unable to tell");
412431
}
432+
} else if let Some(mode) = &args.input_deck_mode {
433+
println!("Set mode to: {:?}", mode);
434+
ec.set_input_deck_mode((*mode).into()).unwrap();
413435
} else if let Some(Some(kblight)) = args.kblight {
414436
assert!(kblight <= 100);
415437
ec.set_keyboard_backlight(kblight);

framework_lib/src/commandline/uefi.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use uefi::Identify;
1212
use crate::chromium_ec::CrosEcDriverType;
1313
use crate::commandline::Cli;
1414

15-
use super::ConsoleArg;
15+
use super::{ConsoleArg, InputDeckModeArg};
1616

1717
/// Get commandline arguments from UEFI environment
1818
pub fn get_args(boot_services: &BootServices) -> Vec<String> {
@@ -72,6 +72,7 @@ pub fn parse(args: &[String]) -> Cli {
7272
ho2_capsule: None,
7373
intrusion: false,
7474
inputmodules: false,
75+
input_deck_mode: None,
7576
kblight: None,
7677
console: None,
7778
// This is the only driver that works on UEFI
@@ -130,6 +131,27 @@ pub fn parse(args: &[String]) -> Cli {
130131
} else if arg == "--inputmodules" {
131132
cli.inputmodules = true;
132133
found_an_option = true;
134+
} else if arg == "--input-deck-mode" {
135+
cli.input_deck_mode = if args.len() > i + 1 {
136+
let input_deck_mode = &args[i + 1];
137+
if input_deck_mode == "auto" {
138+
Some(InputDeckModeArg::Auto)
139+
} else if input_deck_mode == "off" {
140+
Some(InputDeckModeArg::Off)
141+
} else if input_deck_mode == "on" {
142+
Some(InputDeckModeArg::On)
143+
} else {
144+
println!("Invalid value for --input-deck-mode: {}", input_deck_mode);
145+
None
146+
}
147+
} else {
148+
println!(
149+
"Need to provide a value for --input-deck-mode. Either `auto`, `off`, or `on`"
150+
);
151+
None
152+
};
153+
found_an_option = true;
154+
} else if arg == "-t" || arg == "--test" {
133155
} else if arg == "--kblight" {
134156
cli.kblight = if args.len() > i + 1 {
135157
if let Ok(percent) = args[i + 1].parse::<u8>() {

0 commit comments

Comments
 (0)