Skip to content

Commit

Permalink
Get EC features
Browse files Browse the repository at this point in the history
  • Loading branch information
ChocolateLoverRaj committed May 18, 2024
1 parent 24faae6 commit 64d21da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
15 changes: 15 additions & 0 deletions crosec/src/commands/get_features.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use bytemuck::{Pod, Zeroable};
use crate::{ec_command, EcCmdResult, EcInterface};
use crate::commands::CrosEcCmd;

#[repr(C)]
#[derive(Pod, Zeroable, Copy, Clone)]
struct EcResponseGetFeatures {
flags: u64,
}

pub fn ec_cmd_get_features() -> EcCmdResult<u64> {
let response = ec_command(CrosEcCmd::GetFeatures, 0, Default::default(), EcInterface::Default)?;
let response = bytemuck::from_bytes::<EcResponseGetFeatures>(&response);
Ok(response.flags)
}
2 changes: 2 additions & 0 deletions crosec/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub enum CrosEcCmd {
GetChipInfo = 0x0005,
GetBoardVersion = 0x0006,
GetCmdVersions = 0x0008,
GetFeatures = 0x000D,
SetFanTargetRpm = 0x0021,
}

Expand All @@ -18,3 +19,4 @@ pub mod version;
pub mod board_version;
pub mod set_fan_target_rpm;
pub mod get_cmd_versions;
pub mod get_features;
9 changes: 8 additions & 1 deletion ectool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crosec::commands::{CrosEcCmd, get_chip_info::ec_cmd_get_chip_info, hello::ec
use crosec::commands::board_version::ec_cmd_board_version;
use crosec::commands::get_cmd_versions::ec_cmd_get_cmd_versions;
use num_traits::cast::FromPrimitive;
use crosec::commands::get_features::ec_cmd_get_features;
use crosec::commands::set_fan_target_rpm::ec_cmd_set_fan_target_rpm;

#[derive(Parser)]
Expand Down Expand Up @@ -31,7 +32,9 @@ enum Commands {
rpm: u32,
#[arg()]
index: Option<u8>
}
},
/// Get supported features
GetFeatures
}

fn main() -> Result<()> {
Expand Down Expand Up @@ -88,6 +91,10 @@ fn main() -> Result<()> {
println!("Set RPM to {rpm} for all fans");
}
}
},
Commands::GetFeatures => {
let features = ec_cmd_get_features()?;
println!("EC supported features: {features:#b}");
}
}

Expand Down

0 comments on commit 64d21da

Please sign in to comment.