Skip to content

Commit

Permalink
Add fan_tach command
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 authored and crawfxrd committed Dec 13, 2023
1 parent 47b0704 commit dd9ca6b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/common/include/common/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
15 changes: 15 additions & 0 deletions tool/src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum Cmd {
SetNoInput = 19,
SecurityGet = 20,
SecuritySet = 21,
FanTach = 22,
}

const CMD_SPI_FLAG_READ: u8 = 1 << 0;
Expand Down Expand Up @@ -327,6 +328,20 @@ impl<A: Access> Ec<A> {
self.command(Cmd::SecuritySet, &mut data)
}

/// Read fan tachometer by fan index
pub unsafe fn fan_tach(&mut self, index: u8) -> Result<u16, Error> {
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<Box<dyn Access>>
where A: 'static {
Ec {
Expand Down
25 changes: 22 additions & 3 deletions tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ unsafe fn fan_set(ec: &mut Ec<Box<dyn Access>>, index: u8, duty: u8) -> Result<(
ec.fan_set(index, duty)
}

unsafe fn fan_tach(ec: &mut Ec<Box<dyn Access>>, index: u8) -> Result<(), Error> {
let tach = ec.fan_tach(index)?;
println!("{}", tach);

Ok(())
}

unsafe fn keymap_get(ec: &mut Ec<Box<dyn Access>>, layer: u8, output: u8, input: u8) -> Result<(), Error> {
let value = ec.keymap_get(layer, output, input)?;
println!("{:04X}", value);
Expand Down Expand Up @@ -312,6 +319,9 @@ enum SubCommand {
index: u8,
duty: Option<u8>,
},
FanTach {
index: u8,
},
Flash {
path: String,
},
Expand Down Expand Up @@ -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> {
Expand All @@ -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());
Expand Down Expand Up @@ -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(()) => (),
Expand Down

0 comments on commit dd9ca6b

Please sign in to comment.