From af354d02c46084a1787fc7bae9a18886889c4d7c Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 25 Apr 2025 20:36:16 +0800 Subject: [PATCH 1/9] Rename --inputmodules to --inputdeck Prepare for compatibility with Framework 12 and Framework 13 Signed-off-by: Daniel Schaefer --- README.md | 2 +- completions/bash/framework_tool | 2 +- completions/zsh/_framework_tool | 2 +- framework_lib/src/commandline/clap_std.rs | 4 ++-- framework_lib/src/commandline/mod.rs | 6 +++--- framework_lib/src/commandline/uefi.rs | 6 +++--- support-matrices.md | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index db57686c..0e89f34b 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ Options: --dump Dump extracted UX capsule bitmap image to a file --h2o-capsule Parse UEFI Capsule information from binary file --intrusion Show status of intrusion switch - --inputmodules Show status of the input modules (Framework 16 only) + --inputdeck Show status of the input deck --input-deck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only) [possible values: auto, off, on] --expansion-bay Show status of the expansion bay (Framework 16 only) diff --git a/completions/bash/framework_tool b/completions/bash/framework_tool index 24f41d46..7278dab5 100755 --- a/completions/bash/framework_tool +++ b/completions/bash/framework_tool @@ -34,7 +34,7 @@ _framework_tool() { "--flash-ro-ec" "--flash-rw-ec" "--intrusion" - "--inputmodules" + "--inputdeck" "--input-deck-mode" "--charge-limit" "--get-gpio" diff --git a/completions/zsh/_framework_tool b/completions/zsh/_framework_tool index 70ea7516..89ca4350 100644 --- a/completions/zsh/_framework_tool +++ b/completions/zsh/_framework_tool @@ -32,7 +32,7 @@ options=( '--flash-ro-ec[Flash EC with new RO firmware from file]:flash_ro_ec' '--flash-rw-ec[Flash EC with new RW firmware from file]:flash_rw_ec' '--intrusion[Show status of intrusion switch]' - '--inputmodules[Show status of the input modules (Framework 16 only)]' + '--inputdeck[Show status of the input deck]' '--input-deck-mode[Set input deck power mode]:input_deck_mode:(auto off on)' '--charge-limit[Get or set max charge limit]:charge_limit' '--get-gpio[Get GPIO value by name]:get_gpio' diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index 38ef8f5f..b3bcaeb8 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -141,7 +141,7 @@ struct ClapCli { /// Show status of the input modules (Framework 16 only) #[arg(long)] - inputmodules: bool, + inputdeck: bool, /// Set input deck power mode [possible values: auto, off, on] (Framework 16 only) #[arg(long)] @@ -354,7 +354,7 @@ pub fn parse(args: &[String]) -> Cli { .flash_rw_ec .map(|x| x.into_os_string().into_string().unwrap()), intrusion: args.intrusion, - inputmodules: args.inputmodules, + inputdeck: args.inputdeck, input_deck_mode: args.input_deck_mode, expansion_bay: args.expansion_bay, charge_limit: args.charge_limit, diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 2a88db09..649000b2 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -171,7 +171,7 @@ pub struct Cli { pub driver: Option, pub test: bool, pub intrusion: bool, - pub inputmodules: bool, + pub inputdeck: bool, pub input_deck_mode: Option, pub expansion_bay: bool, pub charge_limit: Option>, @@ -745,7 +745,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { } else { println!(" Unable to tell"); } - } else if args.inputmodules { + } else if args.inputdeck { println!("Input Module Status:"); if let Some(status) = print_err(ec.get_input_deck_status()) { println!("Input Deck State: {:?}", status.state); @@ -1083,7 +1083,7 @@ Options: --flash-rw-ec Flash EC with new firmware from file --reboot-ec Control EC RO/RW jump [possible values: reboot, jump-ro, jump-rw, cancel-jump, disable-jump] --intrusion Show status of intrusion switch - --inputmodules Show status of the input modules (Framework 16 only) + --inputdeck Show status of the input deck --input-deck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only) --expansion-bay Show status of the expansion bay (Framework 16 only) --charge-limit [] Get or set battery charge limit (Percentage number as arg, e.g. '100') diff --git a/framework_lib/src/commandline/uefi.rs b/framework_lib/src/commandline/uefi.rs index 9d3239a5..83f76773 100644 --- a/framework_lib/src/commandline/uefi.rs +++ b/framework_lib/src/commandline/uefi.rs @@ -84,7 +84,7 @@ pub fn parse(args: &[String]) -> Cli { dump: None, h2o_capsule: None, intrusion: false, - inputmodules: false, + inputdeck: false, input_deck_mode: None, expansion_bay: false, charge_limit: None, @@ -225,8 +225,8 @@ pub fn parse(args: &[String]) -> Cli { } else if arg == "--intrusion" { cli.intrusion = true; found_an_option = true; - } else if arg == "--inputmodules" { - cli.inputmodules = true; + } else if arg == "--inputdeck" { + cli.inputdeck = true; found_an_option = true; } else if arg == "--input-deck-mode" { cli.input_deck_mode = if args.len() > i + 1 { diff --git a/support-matrices.md b/support-matrices.md index 4a4396ed..6c468160 100644 --- a/support-matrices.md +++ b/support-matrices.md @@ -37,6 +37,6 @@ | `--pd-info` | PD Communication | All | | `--privacy` | EC Communication | All | | `--intrusion` | EC Communication | All | -| `--inputmodules` | EC Communication | Framework 16 | +| `--inputdeck` | EC Communication | Framework 16 | | `--console` | EC Communication | All | -| `--kblight` | EC Communication | All, except FL16 | \ No newline at end of file +| `--kblight` | EC Communication | All, except FL16 | From 42e4d00e1a9479612dae80f53d1959850d94fc13 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 25 Apr 2025 20:39:26 +0800 Subject: [PATCH 2/9] Rename --input-deck-mode to --inputdeck-mode Align it with --inputdeck Signed-off-by: Daniel Schaefer --- completions/bash/framework_tool | 8 ++++---- completions/zsh/_framework_tool | 2 +- framework_lib/src/commandline/clap_std.rs | 4 ++-- framework_lib/src/commandline/mod.rs | 6 +++--- framework_lib/src/commandline/uefi.rs | 18 +++++++++--------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/completions/bash/framework_tool b/completions/bash/framework_tool index 7278dab5..f96fcc23 100755 --- a/completions/bash/framework_tool +++ b/completions/bash/framework_tool @@ -35,7 +35,7 @@ _framework_tool() { "--flash-rw-ec" "--intrusion" "--inputdeck" - "--input-deck-mode" + "--inputdeck-mode" "--charge-limit" "--get-gpio" "--fp-led-level" @@ -56,7 +56,7 @@ _framework_tool() { ) local devices=("bios" "ec" "pd0" "pd1" "rtm01" "rtm23" "ac-left" "ac-right") - local input_deck_modes=("auto" "off" "on") + local inputdeck_modes=("auto" "off" "on") local console_modes=("recent" "follow") local drivers=("portio" "cros-ec" "windows") local has_mec_options=("true" "false") @@ -71,8 +71,8 @@ _framework_tool() { COMPREPLY=( $(compgen -W "${options[*]}" -- "$current_word") ) elif [[ $prev_word == "--device" ]]; then COMPREPLY=( $(compgen -W "${devices[*]}" -- "$current_word") ) - elif [[ $prev_word == "--input-deck-mode" ]]; then - COMPREPLY=( $(compgen -W "${input_deck_modes[*]}" -- "$current_word") ) + elif [[ $prev_word == "--inputdeck-mode" ]]; then + COMPREPLY=( $(compgen -W "${inputdeck_modes[*]}" -- "$current_word") ) elif [[ $prev_word == "--console" ]]; then COMPREPLY=( $(compgen -W "${console_modes[*]}" -- "$current_word") ) elif [[ $prev_word == "--driver" ]]; then diff --git a/completions/zsh/_framework_tool b/completions/zsh/_framework_tool index 89ca4350..ad6aa668 100644 --- a/completions/zsh/_framework_tool +++ b/completions/zsh/_framework_tool @@ -33,7 +33,7 @@ options=( '--flash-rw-ec[Flash EC with new RW firmware from file]:flash_rw_ec' '--intrusion[Show status of intrusion switch]' '--inputdeck[Show status of the input deck]' - '--input-deck-mode[Set input deck power mode]:input_deck_mode:(auto off on)' + '--inputdeck-mode[Set input deck power mode]:inputdeck_mode:(auto off on)' '--charge-limit[Get or set max charge limit]:charge_limit' '--get-gpio[Get GPIO value by name]:get_gpio' '--fp-led-level-gpio[Get or set fingerprint LED brightness level]:fp_led_level:(high medium low ultra-low auto)' diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index b3bcaeb8..e94a330c 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -145,7 +145,7 @@ struct ClapCli { /// Set input deck power mode [possible values: auto, off, on] (Framework 16 only) #[arg(long)] - input_deck_mode: Option, + inputdeck_mode: Option, /// Show status of the expansion bay (Framework 16 only) #[arg(long)] @@ -355,7 +355,7 @@ pub fn parse(args: &[String]) -> Cli { .map(|x| x.into_os_string().into_string().unwrap()), intrusion: args.intrusion, inputdeck: args.inputdeck, - input_deck_mode: args.input_deck_mode, + inputdeck_mode: args.inputdeck_mode, expansion_bay: args.expansion_bay, charge_limit: args.charge_limit, get_gpio: args.get_gpio, diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 649000b2..b5f28f32 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -172,7 +172,7 @@ pub struct Cli { pub test: bool, pub intrusion: bool, pub inputdeck: bool, - pub input_deck_mode: Option, + pub inputdeck_mode: Option, pub expansion_bay: bool, pub charge_limit: Option>, pub get_gpio: Option, @@ -759,7 +759,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { } else { println!(" Unable to tell"); } - } else if let Some(mode) = &args.input_deck_mode { + } else if let Some(mode) = &args.inputdeck_mode { println!("Set mode to: {:?}", mode); ec.set_input_deck_mode((*mode).into()).unwrap(); } else if args.expansion_bay { @@ -1084,7 +1084,7 @@ Options: --reboot-ec Control EC RO/RW jump [possible values: reboot, jump-ro, jump-rw, cancel-jump, disable-jump] --intrusion Show status of intrusion switch --inputdeck Show status of the input deck - --input-deck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only) + --inputdeck-mode Set input deck power mode [possible values: auto, off, on] (Framework 16 only) --expansion-bay Show status of the expansion bay (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 diff --git a/framework_lib/src/commandline/uefi.rs b/framework_lib/src/commandline/uefi.rs index 83f76773..3c097344 100644 --- a/framework_lib/src/commandline/uefi.rs +++ b/framework_lib/src/commandline/uefi.rs @@ -85,7 +85,7 @@ pub fn parse(args: &[String]) -> Cli { h2o_capsule: None, intrusion: false, inputdeck: false, - input_deck_mode: None, + inputdeck_mode: None, expansion_bay: false, charge_limit: None, get_gpio: None, @@ -228,22 +228,22 @@ pub fn parse(args: &[String]) -> Cli { } else if arg == "--inputdeck" { cli.inputdeck = true; found_an_option = true; - } else if arg == "--input-deck-mode" { - cli.input_deck_mode = if args.len() > i + 1 { - let input_deck_mode = &args[i + 1]; - if input_deck_mode == "auto" { + } else if arg == "--inputdeck-mode" { + cli.inputdeck_mode = if args.len() > i + 1 { + let inputdeck_mode = &args[i + 1]; + if inputdeck_mode == "auto" { Some(InputDeckModeArg::Auto) - } else if input_deck_mode == "off" { + } else if inputdeck_mode == "off" { Some(InputDeckModeArg::Off) - } else if input_deck_mode == "on" { + } else if inputdeck_mode == "on" { Some(InputDeckModeArg::On) } else { - println!("Invalid value for --input-deck-mode: {}", input_deck_mode); + println!("Invalid value for --inputdeck-mode: {}", inputdeck_mode); None } } else { println!( - "Need to provide a value for --input-deck-mode. Either `auto`, `off`, or `on`" + "Need to provide a value for --inputdeck-mode. Either `auto`, `off`, or `on`" ); None }; From c0cfcd922021c48bd7fc0a66e0db98abf890c3f4 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 25 Apr 2025 21:02:23 +0800 Subject: [PATCH 3/9] Move input deck status into chromium_ec Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/mod.rs | 13 +++++++++++++ framework_lib/src/commandline/mod.rs | 14 +------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index e1a53c20..04d3ee3d 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -394,6 +394,19 @@ impl CrosEc { Ok(InputDeckStatus::from(status)) } + pub fn print_fw16_inputdeck_status(&self) -> EcResult<()> { + let status = self.get_input_deck_status()?; + println!("Input Deck State: {:?}", status.state); + println!("Touchpad present: {:?}", status.touchpad_present); + println!("Positions:"); + println!(" Pos 0: {:?}", status.top_row.pos0); + println!(" Pos 1: {:?}", status.top_row.pos1); + println!(" Pos 2: {:?}", status.top_row.pos2); + println!(" Pos 3: {:?}", status.top_row.pos3); + println!(" Pos 4: {:?}", status.top_row.pos4); + Ok(()) + } + pub fn set_input_deck_mode(&self, mode: DeckStateMode) -> EcResult { let status = EcRequestDeckState { mode }.send_command(self)?; diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index b5f28f32..1396f9a0 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -746,19 +746,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { println!(" Unable to tell"); } } else if args.inputdeck { - println!("Input Module Status:"); - if let Some(status) = print_err(ec.get_input_deck_status()) { - println!("Input Deck State: {:?}", status.state); - println!("Touchpad present: {:?}", status.touchpad_present); - println!("Positions:"); - println!(" Pos 0: {:?}", status.top_row.pos0); - println!(" Pos 1: {:?}", status.top_row.pos1); - println!(" Pos 2: {:?}", status.top_row.pos2); - println!(" Pos 3: {:?}", status.top_row.pos3); - println!(" Pos 4: {:?}", status.top_row.pos4); - } else { - println!(" Unable to tell"); - } + let _ = print_err(ec.print_fw16_inputdeck_status()); } else if let Some(mode) = &args.inputdeck_mode { println!("Set mode to: {:?}", mode); ec.set_input_deck_mode((*mode).into()).unwrap(); From 22cc7da6d370e0035cf12c047bc3e9146c40f851 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Fri, 25 Apr 2025 21:08:53 +0800 Subject: [PATCH 4/9] util: Add Platform::which_family Determine which family a platform belongs to Signed-off-by: Daniel Schaefer --- framework_lib/src/util.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/framework_lib/src/util.rs b/framework_lib/src/util.rs index 3fa8f505..cfb97368 100644 --- a/framework_lib/src/util.rs +++ b/framework_lib/src/util.rs @@ -40,6 +40,31 @@ pub enum Platform { GenericFramework((u16, u16), (u8, u8), bool), } +#[derive(Debug, PartialEq, Clone, Copy)] +pub enum PlatformFamily { + Framework12, + Framework13, + Framework16, + FrameworkDesktop, +} + +impl Platform { + pub fn which_family(self) -> Option { + match self { + Platform::Framework12IntelGen13 => Some(PlatformFamily::Framework12), + Platform::IntelGen11 + | Platform::IntelGen12 + | Platform::IntelGen13 + | Platform::IntelCoreUltra1 + | Platform::Framework13Amd7080 + | Platform::Framework13AmdAi300 => Some(PlatformFamily::Framework13), + Platform::Framework16Amd7080 => Some(PlatformFamily::Framework16), + Platform::FrameworkDesktopAmdAiMax300 => Some(PlatformFamily::FrameworkDesktop), + Platform::GenericFramework(..) => None, + } + } +} + #[derive(Debug)] pub struct Config { // TODO: Actually set and read this From ddf04d854315a925567b63c3f6b639a1754bbf4e Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 26 Apr 2025 00:07:02 +0800 Subject: [PATCH 5/9] chromium_ec: Add function to read Framework12 boardid Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/mod.rs | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index 04d3ee3d..564d0942 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -120,6 +120,47 @@ pub enum EcResponseStatus { Busy = 16, } +#[repr(u8)] +#[derive(Copy, Clone, Debug)] +pub enum Framework12Adc { + MainboardBoard, + PowerButtonBoard, + Psys, + AdapterCurrent, + Touchpad, + AudioBoard, +} + +/* + * PLATFORM_EC_ADC_RESOLUTION default 10 bit + * + * +------------------+-----------+--------------+---------+----------------------+ + * | BOARD VERSION | voltage | main board | GPU | Input module | + * +------------------+-----------+--------------+---------+----------------------+ + * | BOARD_VERSION_0 | 0 mv | Unused | | Reserved | + * | BOARD_VERSION_1 | 173 mv | Unused | | Reserved | + * | BOARD_VERSION_2 | 300 mv | Unused | | Reserved | + * | BOARD_VERSION_3 | 430 mv | Unused | | Reserved | + * | BOARD_VERSION_4 | 588 mv | EVT1 | | Reserved | + * | BOARD_VERSION_5 | 783 mv | Unused | | Reserved | + * | BOARD_VERSION_6 | 905 mv | Unused | | Reserved | + * | BOARD_VERSION_7 | 1033 mv | DVT1 | | Reserved | + * | BOARD_VERSION_8 | 1320 mv | DVT2 | | Generic A size | + * | BOARD_VERSION_9 | 1500 mv | PVT | | Generic B size | + * | BOARD_VERSION_10 | 1650 mv | MP | | Generic C size | + * | BOARD_VERSION_11 | 1980 mv | Unused | RID_0 | 10 Key B size | + * | BOARD_VERSION_12 | 2135 mv | Unused | RID_0,1 | Keyboard | + * | BOARD_VERSION_13 | 2500 mv | Unused | RID_0 | Touchpad | + * | BOARD_VERSION_14 | 2706 mv | Unused | | Reserved | + * | BOARD_VERSION_15 | 2813 mv | Unused | | Not installed | + * +------------------+-----------+--------------+---------+----------------------+ + */ + +const BOARD_VERSION_COUNT: usize = 16; +const BOARD_VERSION: [i32; BOARD_VERSION_COUNT] = [ + 85, 233, 360, 492, 649, 844, 965, 1094, 1380, 1562, 1710, 2040, 2197, 2557, 2766, 2814, +]; + pub fn has_mec() -> bool { let platform = smbios::get_platform().unwrap(); if let Platform::GenericFramework(_, _, has_mec) = platform { @@ -1038,6 +1079,31 @@ impl CrosEc { Ok(res.adc_value) } + pub fn read_board_id(&self, channel: Framework12Adc) -> EcResult> { + let mv = self.adc_read(channel as u8)?; + if mv < 0 { + return Err(EcError::DeviceError(format!( + "Failed to read ADC channel {}", + channel as u8 + ))); + } + + for (board_id, board_id_res) in BOARD_VERSION.iter().enumerate() { + if mv < *board_id_res { + return Ok(if board_id == 15 { + None + } else { + Some(board_id as u8) + }); + } + } + + Err(EcError::DeviceError(format!( + "Unknown board id. ADC mv: {}", + mv + ))) + } + pub fn rgbkbd_set_color(&self, start_key: u8, colors: Vec) -> EcResult<()> { for (chunk, colors) in colors.chunks(EC_RGBKBD_MAX_KEY_COUNT).enumerate() { let mut request = EcRequestRgbKbdSetColor { From d1eefd72c3e7ed4302233f2537dfd8d1b02c9081 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 26 Apr 2025 00:08:12 +0800 Subject: [PATCH 6/9] --input-deck: Print Framework12 input deck status ``` > sudo framework_tool --inputdeck Input Deck Chassis Open: false Power Button Board: Present Audio Daughterboard: Present Touchpad: Present ``` Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/mod.rs | 21 +++++++++++++++++++++ framework_lib/src/commandline/mod.rs | 10 ++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index 564d0942..21b954ff 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -435,6 +435,27 @@ impl CrosEc { Ok(InputDeckStatus::from(status)) } + pub fn print_fw12_inputdeck_status(&self) -> EcResult<()> { + let intrusion = self.get_intrusion_status()?; + let pwrbtn = self.read_board_id(Framework12Adc::PowerButtonBoard)?; + let audio = self.read_board_id(Framework12Adc::AudioBoard)?; + let tp = self.read_board_id(Framework12Adc::Touchpad)?; + + let is_present = |p| if p { "Present" } else { "Missing" }; + + println!("Input Deck"); + println!(" Chassis Open: {}", intrusion.currently_open); + println!(" Power Button Board: {}", is_present(pwrbtn.is_some())); + println!(" Audio Daughterboard: {}", is_present(audio.is_some())); + println!(" Touchpad: {}", is_present(tp.is_some())); + + Ok(()) + } + + pub fn print_fw13_inputdeck_status(&self) -> EcResult<()> { + Ok(()) + } + pub fn print_fw16_inputdeck_status(&self) -> EcResult<()> { let status = self.get_input_deck_status()?; println!("Input Deck State: {:?}", status.state); diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 1396f9a0..598a6d64 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -59,7 +59,7 @@ use crate::touchscreen; #[cfg(feature = "uefi")] use crate::uefi::enable_page_break; use crate::util; -use crate::util::{Config, Platform}; +use crate::util::{Config, Platform, PlatformFamily}; #[cfg(feature = "hidapi")] use hidapi::HidApi; use sha2::{Digest, Sha256, Sha384, Sha512}; @@ -746,7 +746,13 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { println!(" Unable to tell"); } } else if args.inputdeck { - let _ = print_err(ec.print_fw16_inputdeck_status()); + let res = match smbios::get_platform().and_then(Platform::which_family) { + Some(PlatformFamily::Framework12) => ec.print_fw12_inputdeck_status(), + Some(PlatformFamily::Framework13) => Ok(()), + Some(PlatformFamily::Framework16) => ec.print_fw16_inputdeck_status(), + _ => Ok(()), + }; + print_err(res); } else if let Some(mode) = &args.inputdeck_mode { println!("Set mode to: {:?}", mode); ec.set_input_deck_mode((*mode).into()).unwrap(); From af984dd2b127e7c3b8501115a1fdb367823b8edf Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 26 Apr 2025 22:56:33 +0800 Subject: [PATCH 7/9] chromium_ec: Add board id for 13 and 16 Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/mod.rs | 55 +++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index 21b954ff..bd410db2 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -123,12 +123,47 @@ pub enum EcResponseStatus { #[repr(u8)] #[derive(Copy, Clone, Debug)] pub enum Framework12Adc { - MainboardBoard, - PowerButtonBoard, + MainboardBoardId, + PowerButtonBoardId, Psys, AdapterCurrent, - Touchpad, - AudioBoard, + TouchpadBoardId, + AudioBoardId, +} + +#[repr(u8)] +#[derive(Copy, Clone, Debug)] +pub enum FrameworkHx20Hx30Adc { + AdapterCurrent, + Psys, + BattTemp, + TouchpadBoardId, + MainboardBoardId, + AudioBoardId, +} + +/// So far on all Nuvoton/Zephyr EC based platforms +/// Until at least Framework 13 AMD Ryzen AI 300 +#[repr(u8)] +#[derive(Copy, Clone, Debug)] +pub enum Framework13Adc { + MainboardBoardId, + Psys, + AdapterCurrent, + TouchpadBoardId, + AudioBoardId, + BattTemp, +} + +#[repr(u8)] +#[derive(Copy, Clone, Debug)] +pub enum Framework16Adc { + MainboardBoardId, + HubBoardId, + GpuBoardId0, + GpuBoardId1, + AdapterCurrent, + Psys, } /* @@ -437,9 +472,9 @@ impl CrosEc { pub fn print_fw12_inputdeck_status(&self) -> EcResult<()> { let intrusion = self.get_intrusion_status()?; - let pwrbtn = self.read_board_id(Framework12Adc::PowerButtonBoard)?; - let audio = self.read_board_id(Framework12Adc::AudioBoard)?; - let tp = self.read_board_id(Framework12Adc::Touchpad)?; + let pwrbtn = self.read_board_id(Framework12Adc::PowerButtonBoardId as u8)?; + let audio = self.read_board_id(Framework12Adc::AudioBoardId as u8)?; + let tp = self.read_board_id(Framework12Adc::TouchpadBoardId as u8)?; let is_present = |p| if p { "Present" } else { "Missing" }; @@ -1100,12 +1135,12 @@ impl CrosEc { Ok(res.adc_value) } - pub fn read_board_id(&self, channel: Framework12Adc) -> EcResult> { - let mv = self.adc_read(channel as u8)?; + pub fn read_board_id(&self, channel: u8) -> EcResult> { + let mv = self.adc_read(channel)?; if mv < 0 { return Err(EcError::DeviceError(format!( "Failed to read ADC channel {}", - channel as u8 + channel ))); } From ce17b061748afd0b2fec5a1592c946b6af0561df Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 26 Apr 2025 22:56:55 +0800 Subject: [PATCH 8/9] inputdeck: Print Framework 13 state ``` framework_tool.exe --inputdeck Input Deck Chassis Open: false Audio Daughterboard: Present Touchpad: Present ``` Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/mod.rs | 87 ++++++++++++++++++++-------- framework_lib/src/commandline/mod.rs | 2 +- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index bd410db2..cb041605 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -169,26 +169,26 @@ pub enum Framework16Adc { /* * PLATFORM_EC_ADC_RESOLUTION default 10 bit * - * +------------------+-----------+--------------+---------+----------------------+ - * | BOARD VERSION | voltage | main board | GPU | Input module | - * +------------------+-----------+--------------+---------+----------------------+ - * | BOARD_VERSION_0 | 0 mv | Unused | | Reserved | - * | BOARD_VERSION_1 | 173 mv | Unused | | Reserved | - * | BOARD_VERSION_2 | 300 mv | Unused | | Reserved | - * | BOARD_VERSION_3 | 430 mv | Unused | | Reserved | - * | BOARD_VERSION_4 | 588 mv | EVT1 | | Reserved | - * | BOARD_VERSION_5 | 783 mv | Unused | | Reserved | - * | BOARD_VERSION_6 | 905 mv | Unused | | Reserved | - * | BOARD_VERSION_7 | 1033 mv | DVT1 | | Reserved | - * | BOARD_VERSION_8 | 1320 mv | DVT2 | | Generic A size | - * | BOARD_VERSION_9 | 1500 mv | PVT | | Generic B size | - * | BOARD_VERSION_10 | 1650 mv | MP | | Generic C size | - * | BOARD_VERSION_11 | 1980 mv | Unused | RID_0 | 10 Key B size | - * | BOARD_VERSION_12 | 2135 mv | Unused | RID_0,1 | Keyboard | - * | BOARD_VERSION_13 | 2500 mv | Unused | RID_0 | Touchpad | - * | BOARD_VERSION_14 | 2706 mv | Unused | | Reserved | - * | BOARD_VERSION_15 | 2813 mv | Unused | | Not installed | - * +------------------+-----------+--------------+---------+----------------------+ + * +------------------+-----------+----------+-------------+---------+----------------------+ + * | BOARD VERSION | voltage | NPC DB V | main board | GPU | Input module | + * +------------------+-----------+----------|-------------+---------+----------------------+ + * | BOARD_VERSION_0 | 0 mV | 100 mV | Unused | | Reserved | + * | BOARD_VERSION_1 | 173 mV | 310 mV | Unused | | Reserved | + * | BOARD_VERSION_2 | 300 mV | 520 mV | Unused | | Reserved | + * | BOARD_VERSION_3 | 430 mV | 720 mV | Unused | | Reserved | + * | BOARD_VERSION_4 | 588 mV | 930 mV | EVT1 | | Reserved | + * | BOARD_VERSION_5 | 783 mV | 1130 mV | Unused | | Reserved | + * | BOARD_VERSION_6 | 905 mV | 1340 mV | Unused | | Reserved | + * | BOARD_VERSION_7 | 1033 mV | 1550 mV | DVT1 | | Reserved | + * | BOARD_VERSION_8 | 1320 mV | 1750 mV | DVT2 | | Generic A size | + * | BOARD_VERSION_9 | 1500 mV | 1960 mV | PVT | | Generic B size | + * | BOARD_VERSION_10 | 1650 mV | 2170 mV | MP | | Generic C size | + * | BOARD_VERSION_11 | 1980 mV | 2370 mV | Unused | RID_0 | 10 Key B size | + * | BOARD_VERSION_12 | 2135 mV | 2580 mV | Unused | RID_0,1 | Keyboard | + * | BOARD_VERSION_13 | 2500 mV | 2780 mV | Unused | RID_0 | Touchpad | + * | BOARD_VERSION_14 | 2706 mV | 2990 mV | Unused | | Reserved | + * | BOARD_VERSION_15 | 2813 mV | 3200 mV | Unused | | Not installed | + * +------------------+-----------+----------+-------------+---------+----------------------+ */ const BOARD_VERSION_COUNT: usize = 16; @@ -196,6 +196,10 @@ const BOARD_VERSION: [i32; BOARD_VERSION_COUNT] = [ 85, 233, 360, 492, 649, 844, 965, 1094, 1380, 1562, 1710, 2040, 2197, 2557, 2766, 2814, ]; +const BOARD_VERSION_NPC_DB: [i32; BOARD_VERSION_COUNT] = [ + 100, 311, 521, 721, 931, 1131, 1341, 1551, 1751, 1961, 2171, 2370, 2580, 2780, 2990, 3200, +]; + pub fn has_mec() -> bool { let platform = smbios::get_platform().unwrap(); if let Platform::GenericFramework(_, _, has_mec) = platform { @@ -488,6 +492,29 @@ impl CrosEc { } pub fn print_fw13_inputdeck_status(&self) -> EcResult<()> { + let intrusion = self.get_intrusion_status()?; + + let (audio, tp) = match smbios::get_platform() { + Some(Platform::IntelGen11) + | Some(Platform::IntelGen12) + | Some(Platform::IntelGen13) => ( + self.read_board_id(FrameworkHx20Hx30Adc::AudioBoardId as u8)?, + self.read_board_id(FrameworkHx20Hx30Adc::TouchpadBoardId as u8)?, + ), + + _ => ( + self.read_board_id_npc_db(Framework13Adc::AudioBoardId as u8)?, + self.read_board_id_npc_db(Framework13Adc::TouchpadBoardId as u8)?, + ), + }; + + let is_present = |p| if p { "Present" } else { "Missing" }; + + println!("Input Deck"); + println!(" Chassis Open: {}", intrusion.currently_open); + println!(" Audio Daughterboard: {}", is_present(audio.is_some())); + println!(" Touchpad: {}", is_present(tp.is_some())); + Ok(()) } @@ -1135,7 +1162,18 @@ impl CrosEc { Ok(res.adc_value) } - pub fn read_board_id(&self, channel: u8) -> EcResult> { + fn read_board_id(&self, channel: u8) -> EcResult> { + self.read_board_id_raw(channel, BOARD_VERSION) + } + fn read_board_id_npc_db(&self, channel: u8) -> EcResult> { + self.read_board_id_raw(channel, BOARD_VERSION_NPC_DB) + } + + fn read_board_id_raw( + &self, + channel: u8, + table: [i32; BOARD_VERSION_COUNT], + ) -> EcResult> { let mv = self.adc_read(channel)?; if mv < 0 { return Err(EcError::DeviceError(format!( @@ -1144,9 +1182,12 @@ impl CrosEc { ))); } - for (board_id, board_id_res) in BOARD_VERSION.iter().enumerate() { + debug!("ADC Channel {} - Measured {}mv", channel, mv); + for (board_id, board_id_res) in table.iter().enumerate() { if mv < *board_id_res { - return Ok(if board_id == 15 { + debug!("ADC Channel {} - Board ID {}", channel, board_id); + // 15 is not present, less than 2 is undefined + return Ok(if board_id == 15 || board_id < 2 { None } else { Some(board_id as u8) diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 598a6d64..75c8300a 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -748,7 +748,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { } else if args.inputdeck { let res = match smbios::get_platform().and_then(Platform::which_family) { Some(PlatformFamily::Framework12) => ec.print_fw12_inputdeck_status(), - Some(PlatformFamily::Framework13) => Ok(()), + Some(PlatformFamily::Framework13) => ec.print_fw13_inputdeck_status(), Some(PlatformFamily::Framework16) => ec.print_fw16_inputdeck_status(), _ => Ok(()), }; From 8cd99d95b2e16da0ea15ddf95cdf419d447db587 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 26 Apr 2025 22:57:40 +0800 Subject: [PATCH 9/9] inputdeck: Add chassis open state to Framework 16 --- framework_lib/src/chromium_ec/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index cb041605..ff0327d4 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -519,9 +519,11 @@ impl CrosEc { } pub fn print_fw16_inputdeck_status(&self) -> EcResult<()> { + let intrusion = self.get_intrusion_status()?; let status = self.get_input_deck_status()?; + println!("Chassis Open: {}", intrusion.currently_open); println!("Input Deck State: {:?}", status.state); - println!("Touchpad present: {:?}", status.touchpad_present); + println!("Touchpad present: {}", status.touchpad_present); println!("Positions:"); println!(" Pos 0: {:?}", status.top_row.pos0); println!(" Pos 1: {:?}", status.top_row.pos1);