diff --git a/framework_lib/src/chromium_ec/command.rs b/framework_lib/src/chromium_ec/command.rs index e3140f6..c823678 100644 --- a/framework_lib/src/chromium_ec/command.rs +++ b/framework_lib/src/chromium_ec/command.rs @@ -30,6 +30,7 @@ pub enum EcCommands { FlashProtect = 0x15, PwmGetKeyboardBacklight = 0x0022, PwmSetKeyboardBacklight = 0x0023, + GpioGet = 0x93, I2cPassthrough = 0x9e, ConsoleSnapshot = 0x97, ConsoleRead = 0x98, diff --git a/framework_lib/src/chromium_ec/commands.rs b/framework_lib/src/chromium_ec/commands.rs index 75a60a2..5a1add1 100644 --- a/framework_lib/src/chromium_ec/commands.rs +++ b/framework_lib/src/chromium_ec/commands.rs @@ -180,6 +180,25 @@ impl EcRequest for EcRequestPwmGetKeyboardBac } } +#[repr(C, packed)] +pub struct EcRequestGpioGetV0 { + pub name: [u8; 32], +} + +#[repr(C, packed)] +pub struct EcResponseGpioGetV0 { + pub val: u8, +} + +impl EcRequest for EcRequestGpioGetV0 { + fn command_id() -> EcCommands { + EcCommands::GpioGet + } + fn command_version() -> u8 { + 0 + } +} + #[repr(C, packed)] pub struct EcRequestReboot {} diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index 067a3e2..570e2eb 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -854,6 +854,17 @@ impl CrosEc { } .send_command(self) } + + pub fn get_gpio(&self, name: &str) -> EcResult { + const MAX_LEN: usize = 32; + let mut request = EcRequestGpioGetV0 { name: [0; MAX_LEN] }; + + let end = MAX_LEN.min(name.len()); + request.name[..end].copy_from_slice(name[..end].as_bytes()); + + let res = request.send_command(self)?; + Ok(res.val == 1) + } } #[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))] diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index 54f8ba9..92dd77c 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -128,6 +128,10 @@ struct ClapCli { #[arg(long)] charge_limit: Option>, + /// Get GPIO value by name + #[arg(long)] + get_gpio: Option, + /// Get or set fingerprint LED brightness #[arg(long)] fp_brightness: Option>, @@ -251,6 +255,7 @@ pub fn parse(args: &[String]) -> Cli { inputmodules: args.inputmodules, input_deck_mode: args.input_deck_mode, charge_limit: args.charge_limit, + get_gpio: args.get_gpio, fp_brightness: args.fp_brightness, kblight: args.kblight, console: args.console, diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index d5c415a..8266eea 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -148,6 +148,7 @@ pub struct Cli { pub inputmodules: bool, pub input_deck_mode: Option, pub charge_limit: Option>, + pub get_gpio: Option, pub fp_brightness: Option>, pub kblight: Option>, pub console: Option, @@ -720,6 +721,13 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { ec.set_input_deck_mode((*mode).into()).unwrap(); } else if let Some(maybe_limit) = args.charge_limit { print_err(handle_charge_limit(&ec, maybe_limit)); + } else if let Some(gpio_name) = &args.get_gpio { + print!("Getting GPIO value {}: ", gpio_name); + if let Ok(value) = ec.get_gpio(gpio_name) { + println!("{:?}", value); + } else { + println!("Not found"); + } } else if let Some(maybe_brightness) = &args.fp_brightness { print_err(handle_fp_brightness(&ec, *maybe_brightness)); } else if let Some(Some(kblight)) = args.kblight { @@ -979,6 +987,7 @@ Options: --inputmodules Show status of the input modules (Framework 16 only) --input-deck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only) --charge-limit [] Get or set battery charge limit (Percentage number as arg, e.g. '100') + --get-gpio Get GPIO value by name --fp-brightness []Get or set fingerprint LED brightness level [possible values: high, medium, low] --kblight [] Set keyboard backlight percentage or get, if no value provided --console Get EC console, choose whether recent or to follow the output [possible values: recent, follow] diff --git a/framework_lib/src/commandline/uefi.rs b/framework_lib/src/commandline/uefi.rs index b2e381f..3a656fe 100644 --- a/framework_lib/src/commandline/uefi.rs +++ b/framework_lib/src/commandline/uefi.rs @@ -82,6 +82,7 @@ pub fn parse(args: &[String]) -> Cli { inputmodules: false, input_deck_mode: None, charge_limit: None, + get_gpio: None, fp_brightness: None, kblight: None, console: None, @@ -187,6 +188,13 @@ pub fn parse(args: &[String]) -> Cli { Some(None) }; found_an_option = true; + } else if arg == "--get-gpio" { + cli.get_gpio = if args.len() > i + 1 { + Some(args[i + 1].clone()) + } else { + None + }; + found_an_option = true; } else if arg == "--kblight" { cli.kblight = if args.len() > i + 1 { if let Ok(percent) = args[i + 1].parse::() {