From 2808fdba95de26b9da8a3029cf39753622fbac8f Mon Sep 17 00:00:00 2001 From: Rajas Paranjpe <52586855+ChocolateLoverRaj@users.noreply.github.com> Date: Tue, 4 Jun 2024 21:39:48 -0700 Subject: [PATCH] fp-stats command --- crosec/src/commands/fp_stats.rs | 29 +++++++++++++++++++++++++++++ crosec/src/commands/mod.rs | 2 ++ ectool/src/main.rs | 8 ++++++++ 3 files changed, 39 insertions(+) create mode 100644 crosec/src/commands/fp_stats.rs diff --git a/crosec/src/commands/fp_stats.rs b/crosec/src/commands/fp_stats.rs new file mode 100644 index 0000000..f9b7700 --- /dev/null +++ b/crosec/src/commands/fp_stats.rs @@ -0,0 +1,29 @@ +use std::ffi::c_int; + +use bytemuck::{Pod, Zeroable}; + +use crate::{ec_command::ec_command_bytemuck, EcCmdResult}; + +use super::CrosEcCmd; + +#[repr(C, packed)] +#[derive(Pod, Zeroable, Clone, Copy, Debug)] +pub struct EcResponseFpStats { + pub capture_time_us: u32, + pub matching_time_us: u32, + pub overall_time_us: u32, + pub overall_t0: OverallT0, + pub timestamps_invalid: u8, + pub template_matched: i8, +} + +#[repr(C, packed)] +#[derive(Pod, Zeroable, Clone, Copy, Debug)] +pub struct OverallT0 { + pub lo: u32, + pub hi: u32, +} + +pub fn fp_stats(fd: c_int) -> EcCmdResult { + ec_command_bytemuck(CrosEcCmd::FpStats, 0, &(), fd) +} diff --git a/crosec/src/commands/mod.rs b/crosec/src/commands/mod.rs index 8c4c8c0..bf588ae 100644 --- a/crosec/src/commands/mod.rs +++ b/crosec/src/commands/mod.rs @@ -17,12 +17,14 @@ pub enum CrosEcCmd { ConsoleSnapshot = 0x0097, ConsoleRead = 0x0098, FpInfo = 0x0403, + FpStats = 0x0407, BatteryGetStatic = 0x0600, } pub mod board_version; pub mod charge_control; pub mod fp_info; +pub mod fp_stats; pub mod get_chip_info; pub mod get_cmd_versions; pub mod get_features; diff --git a/ectool/src/main.rs b/ectool/src/main.rs index 5a1de98..f059d21 100644 --- a/ectool/src/main.rs +++ b/ectool/src/main.rs @@ -4,6 +4,7 @@ use std::os::fd::AsRawFd; use clap::{Parser, Subcommand, ValueEnum}; use color_eyre::eyre::Result; use crosec::commands::fp_info::fp_info; +use crosec::commands::fp_stats::fp_stats; use crosec::commands::get_protocol_info::get_protocol_info; use num_traits::cast::FromPrimitive; @@ -90,6 +91,7 @@ enum Commands { command: Option, }, FpInfo, + FpStats, } #[derive(Subcommand)] @@ -272,6 +274,12 @@ fn main() -> Result<()> { let info = fp_info(fd)?; println!("{info:#?}"); } + Commands::FpStats => { + let file = File::open(CROS_FP_PATH).unwrap(); + let fd = file.as_raw_fd(); + let stats = fp_stats(fd)?; + println!("{stats:#?}"); + } } Ok(())