Skip to content

Commit dd9ca6b

Browse files
jackpot51crawfxrd
authored andcommitted
Add fan_tach command
1 parent 47b0704 commit dd9ca6b

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/common/include/common/command.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ enum Command {
5050
CMD_SECURITY_GET = 20,
5151
// Set security state
5252
CMD_SECURITY_SET = 21,
53+
// Get fan tachometer
54+
CMD_FAN_TACH = 22,
5355
//TODO
5456
};
5557

tool/src/ec.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum Cmd {
3939
SetNoInput = 19,
4040
SecurityGet = 20,
4141
SecuritySet = 21,
42+
FanTach = 22,
4243
}
4344

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

331+
/// Read fan tachometer by fan index
332+
pub unsafe fn fan_tach(&mut self, index: u8) -> Result<u16, Error> {
333+
let mut data = [
334+
index,
335+
0,
336+
0
337+
];
338+
self.command(Cmd::FanTach, &mut data)?;
339+
Ok(
340+
(data[1] as u16) |
341+
((data[2] as u16) << 8)
342+
)
343+
}
344+
330345
pub fn into_dyn(self) -> Ec<Box<dyn Access>>
331346
where A: 'static {
332347
Ec {

tool/src/main.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ unsafe fn fan_set(ec: &mut Ec<Box<dyn Access>>, index: u8, duty: u8) -> Result<(
269269
ec.fan_set(index, duty)
270270
}
271271

272+
unsafe fn fan_tach(ec: &mut Ec<Box<dyn Access>>, index: u8) -> Result<(), Error> {
273+
let tach = ec.fan_tach(index)?;
274+
println!("{}", tach);
275+
276+
Ok(())
277+
}
278+
272279
unsafe fn keymap_get(ec: &mut Ec<Box<dyn Access>>, layer: u8, output: u8, input: u8) -> Result<(), Error> {
273280
let value = ec.keymap_get(layer, output, input)?;
274281
println!("{:04X}", value);
@@ -312,6 +319,9 @@ enum SubCommand {
312319
index: u8,
313320
duty: Option<u8>,
314321
},
322+
FanTach {
323+
index: u8,
324+
},
315325
Flash {
316326
path: String,
317327
},
@@ -377,8 +387,6 @@ struct Args {
377387
}
378388

379389
fn main() {
380-
//.subcommand(Command::new("security").arg(Arg::new("state").value_parser(["lock", "unlock"])))
381-
382390
let args = Args::parse();
383391

384392
let get_ec = || -> Result<_, Error> {
@@ -404,7 +412,9 @@ fn main() {
404412
// System76 launch_2
405413
(0x3384, 0x0006, 1) |
406414
// System76 launch_heavy_1
407-
(0x3384, 0x0007, 1) => {
415+
(0x3384, 0x0007, 1) |
416+
// System76 thelio_io_2
417+
(0x3384, 0x000B, 1) => {
408418
let device = info.open_device(&api)?;
409419
let access = AccessHid::new(device, 10, 100)?;
410420
return Ok(Ec::new(access)?.into_dyn());
@@ -451,6 +461,15 @@ fn main() {
451461
},
452462
}
453463
},
464+
SubCommand::FanTach { index } => {
465+
match unsafe { fan_tach(&mut ec, index) } {
466+
Ok(()) => (),
467+
Err(err) => {
468+
eprintln!("failed to get fan {} tachometer: {:X?}", index, err);
469+
process::exit(1);
470+
},
471+
}
472+
},
454473
SubCommand::Flash { path } => {
455474
match unsafe { flash(&mut ec, &path, SpiTarget::Main) } {
456475
Ok(()) => (),

0 commit comments

Comments
 (0)