Skip to content

Commit 3d99f42

Browse files
committed
fl16: Allow setting input deck mode
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 94b7e13 commit 3d99f42

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)]
@@ -81,6 +81,10 @@ struct ClapCli {
8181
#[arg(long)]
8282
inputmodules: bool,
8383

84+
/// Show status of the input modules (Framework 16 only)
85+
#[arg(long)]
86+
input_deck_mode: Option<InputDeckModeArg>,
87+
8488
/// Set keyboard backlight percentage or get, if no value provided
8589
#[arg(long)]
8690
kblight: Option<Option<u8>>,
@@ -130,6 +134,7 @@ pub fn parse(args: &[String]) -> Cli {
130134
.map(|x| x.into_os_string().into_string().unwrap()),
131135
intrusion: args.intrusion,
132136
inputmodules: args.inputmodules,
137+
input_deck_mode: args.input_deck_mode,
133138
kblight: args.kblight,
134139
console: args.console,
135140
driver: args.driver,

framework_lib/src/commandline/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::ccgx::hid::{
3030
};
3131
use crate::ccgx::{self, SiliconId::*};
3232
use crate::chromium_ec;
33+
use crate::chromium_ec::commands::DeckStateMode;
3334
use crate::chromium_ec::print_err;
3435
#[cfg(feature = "linux")]
3536
use crate::csme;
@@ -57,6 +58,23 @@ pub enum ConsoleArg {
5758
Follow,
5859
}
5960

61+
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]
62+
#[derive(Clone, Copy, Debug, PartialEq)]
63+
pub enum InputDeckModeArg {
64+
Auto,
65+
Off,
66+
On,
67+
}
68+
impl From<InputDeckModeArg> for DeckStateMode {
69+
fn from(w: InputDeckModeArg) -> DeckStateMode {
70+
match w {
71+
InputDeckModeArg::Auto => DeckStateMode::Required,
72+
InputDeckModeArg::Off => DeckStateMode::ForceOff,
73+
InputDeckModeArg::On => DeckStateMode::ForceOn,
74+
}
75+
}
76+
}
77+
6078
/// Shadows `clap_std::ClapCli` with extras for UEFI
6179
///
6280
/// The UEFI commandline currently doesn't use clap, so we need to shadow the struct.
@@ -82,6 +100,7 @@ pub struct Cli {
82100
pub test: bool,
83101
pub intrusion: bool,
84102
pub inputmodules: bool,
103+
pub input_deck_mode: Option<InputDeckModeArg>,
85104
pub kblight: Option<Option<u8>>,
86105
pub console: Option<ConsoleArg>,
87106
pub help: bool,
@@ -398,6 +417,9 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
398417
} else {
399418
println!(" Unable to tell");
400419
}
420+
} else if let Some(mode) = &args.input_deck_mode {
421+
println!("Set mode to: {:?}", mode);
422+
ec.set_input_deck_mode((*mode).into()).unwrap();
401423
} else if let Some(Some(kblight)) = args.kblight {
402424
assert!(kblight <= 100);
403425
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> {
@@ -71,6 +71,7 @@ pub fn parse(args: &[String]) -> Cli {
7171
ho2_capsule: None,
7272
intrusion: false,
7373
inputmodules: false,
74+
input_deck_mode: None,
7475
kblight: None,
7576
console: None,
7677
// This is the only driver that works on UEFI
@@ -129,6 +130,27 @@ pub fn parse(args: &[String]) -> Cli {
129130
} else if arg == "--inputmodules" {
130131
cli.inputmodules = true;
131132
found_an_option = true;
133+
} else if arg == "--input-deck-mode" {
134+
cli.input_deck_mode = if args.len() > i + 1 {
135+
let input_deck_mode = &args[i + 1];
136+
if input_deck_mode == "auto" {
137+
Some(InputDeckModeArg::Auto)
138+
} else if input_deck_mode == "off" {
139+
Some(InputDeckModeArg::Off)
140+
} else if input_deck_mode == "on" {
141+
Some(InputDeckModeArg::On)
142+
} else {
143+
println!("Invalid value for --input-deck-mode: {}", input_deck_mode);
144+
None
145+
}
146+
} else {
147+
println!(
148+
"Need to provide a value for --input-deck-mode. Either `auto`, `off`, or `on`"
149+
);
150+
None
151+
};
152+
found_an_option = true;
153+
} else if arg == "-t" || arg == "--test" {
132154
} else if arg == "--kblight" {
133155
cli.kblight = if args.len() > i + 1 {
134156
if let Ok(percent) = args[i + 1].parse::<u8>() {

0 commit comments

Comments
 (0)