Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fan_tach command #363

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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