From dd9ca6be17f5d184d9acb31c5b4c62e8eca9764a Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 3 Jun 2023 10:03:07 -0600 Subject: [PATCH] Add fan_tach command --- src/common/include/common/command.h | 2 ++ tool/src/ec.rs | 15 +++++++++++++++ tool/src/main.rs | 25 ++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/common/include/common/command.h b/src/common/include/common/command.h index 15c1ad31e..501adc564 100644 --- a/src/common/include/common/command.h +++ b/src/common/include/common/command.h @@ -50,6 +50,8 @@ enum Command { CMD_SECURITY_GET = 20, // Set security state CMD_SECURITY_SET = 21, + // Get fan tachometer + CMD_FAN_TACH = 22, //TODO }; diff --git a/tool/src/ec.rs b/tool/src/ec.rs index 0bd793784..4281c5977 100644 --- a/tool/src/ec.rs +++ b/tool/src/ec.rs @@ -39,6 +39,7 @@ enum Cmd { SetNoInput = 19, SecurityGet = 20, SecuritySet = 21, + FanTach = 22, } const CMD_SPI_FLAG_READ: u8 = 1 << 0; @@ -327,6 +328,20 @@ impl Ec { self.command(Cmd::SecuritySet, &mut data) } + /// Read fan tachometer by fan index + pub unsafe fn fan_tach(&mut self, index: u8) -> Result { + let mut data = [ + index, + 0, + 0 + ]; + self.command(Cmd::FanTach, &mut data)?; + Ok( + (data[1] as u16) | + ((data[2] as u16) << 8) + ) + } + pub fn into_dyn(self) -> Ec> where A: 'static { Ec { diff --git a/tool/src/main.rs b/tool/src/main.rs index cc936271a..7302914b6 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -269,6 +269,13 @@ unsafe fn fan_set(ec: &mut Ec>, index: u8, duty: u8) -> Result<( ec.fan_set(index, duty) } +unsafe fn fan_tach(ec: &mut Ec>, index: u8) -> Result<(), Error> { + let tach = ec.fan_tach(index)?; + println!("{}", tach); + + Ok(()) +} + unsafe fn keymap_get(ec: &mut Ec>, layer: u8, output: u8, input: u8) -> Result<(), Error> { let value = ec.keymap_get(layer, output, input)?; println!("{:04X}", value); @@ -312,6 +319,9 @@ enum SubCommand { index: u8, duty: Option, }, + FanTach { + index: u8, + }, Flash { path: String, }, @@ -377,8 +387,6 @@ struct Args { } fn main() { - //.subcommand(Command::new("security").arg(Arg::new("state").value_parser(["lock", "unlock"]))) - let args = Args::parse(); let get_ec = || -> Result<_, Error> { @@ -404,7 +412,9 @@ fn main() { // System76 launch_2 (0x3384, 0x0006, 1) | // System76 launch_heavy_1 - (0x3384, 0x0007, 1) => { + (0x3384, 0x0007, 1) | + // System76 thelio_io_2 + (0x3384, 0x000B, 1) => { let device = info.open_device(&api)?; let access = AccessHid::new(device, 10, 100)?; return Ok(Ec::new(access)?.into_dyn()); @@ -451,6 +461,15 @@ fn main() { }, } }, + SubCommand::FanTach { index } => { + match unsafe { fan_tach(&mut ec, index) } { + Ok(()) => (), + Err(err) => { + eprintln!("failed to get fan {} tachometer: {:X?}", index, err); + process::exit(1); + }, + } + }, SubCommand::Flash { path } => { match unsafe { flash(&mut ec, &path, SpiTarget::Main) } { Ok(()) => (),