diff --git a/src/commands/get_chip_info.rs b/src/commands/get_chip_info.rs index cf61e38..3c82003 100644 --- a/src/commands/get_chip_info.rs +++ b/src/commands/get_chip_info.rs @@ -1,4 +1,4 @@ -use crate::commands::CrosEcCmds; +use crate::commands::CrosEcCmd; use crate::crosec::dev::ec_command; use crate::crosec::EcCmdResult; use std::mem::size_of; @@ -22,7 +22,7 @@ pub fn ec_cmd_get_chip_info() -> EcCmdResult<(String, String, String)> { let params_slice = unsafe { slice::from_raw_parts(params_ptr, size_of::()) }; - let result = ec_command(CrosEcCmds::GetChipInfo as u32, 0, params_slice)?; + let result = ec_command(CrosEcCmd::GetChipInfo, 0, params_slice)?; let response: EcResponseGetChipInfo = unsafe { std::ptr::read(result.as_ptr() as *const _) }; let vendor = String::from_utf8(response.vendor.to_vec()).unwrap_or(String::from("")); diff --git a/src/commands/hello.rs b/src/commands/hello.rs index 4275812..d054637 100644 --- a/src/commands/hello.rs +++ b/src/commands/hello.rs @@ -1,4 +1,4 @@ -use crate::commands::CrosEcCmds; +use crate::commands::CrosEcCmd; use crate::crosec::dev::ec_command; use crate::crosec::EcCmdResult; use std::mem::size_of; @@ -24,7 +24,7 @@ pub fn ec_cmd_hello() -> EcCmdResult { let params_ptr = ¶ms as *const _ as *const u8; let params_slice = unsafe { slice::from_raw_parts(params_ptr, size_of::()) }; - let result = ec_command(CrosEcCmds::Hello as u32, 0, params_slice)?; + let result = ec_command(CrosEcCmd::Hello, 0, params_slice)?; let response: EcResponseHello = unsafe { std::ptr::read(result.as_ptr() as *const _) }; Ok(response.out_data == EXPECTED_OUTPUT) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index e9587ab..b9c4cc2 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,4 +1,5 @@ -pub enum CrosEcCmds { +#[repr(u32)] +pub enum CrosEcCmd { Hello = 0x0001, Version = 0x0002, GetBuildInfo = 0x0004, diff --git a/src/commands/version.rs b/src/commands/version.rs index ca35f1a..3ce43ec 100644 --- a/src/commands/version.rs +++ b/src/commands/version.rs @@ -1,4 +1,4 @@ -use crate::commands::CrosEcCmds; +use crate::commands::CrosEcCmd; use crate::crosec::dev::ec_command; use crate::crosec::dev::BUF_SIZE; use crate::crosec::EcCmdResult; @@ -41,7 +41,7 @@ pub fn ec_cmd_version() -> EcCmdResult<(String, String, String, String, String)> let params_slice = unsafe { slice::from_raw_parts(params_ptr, size_of::()) }; - let result = ec_command(CrosEcCmds::Version as u32, 0, params_slice)?; + let result = ec_command(CrosEcCmd::Version, 0, params_slice)?; let response: EcResponseVersionV1 = unsafe { std::ptr::read(result.as_ptr() as *const _) }; let ro_ver = String::from_utf8(response.version_string_ro.to_vec()).unwrap_or(String::from("")); @@ -59,7 +59,7 @@ pub fn ec_cmd_version() -> EcCmdResult<(String, String, String, String, String)> let build_string_ptr = &build_string as *const _ as *const u8; let build_string_slice = unsafe { slice::from_raw_parts(build_string_ptr, BUF_SIZE) }; - let result = ec_command(CrosEcCmds::GetBuildInfo as u32, 0, build_string_slice)?; + let result = ec_command(CrosEcCmd::GetBuildInfo, 0, build_string_slice)?; let response: [u8; BUF_SIZE] = unsafe { std::ptr::read(result.as_ptr() as *const _) }; let build_info = String::from_utf8(response.to_vec()).unwrap_or(String::from("")); diff --git a/src/crosec/dev.rs b/src/crosec/dev.rs index 8b890df..0f9d350 100644 --- a/src/crosec/dev.rs +++ b/src/crosec/dev.rs @@ -1,3 +1,4 @@ +use crate::commands::CrosEcCmd; use crate::crosec::EcCmdResult; use crate::crosec::EcError; use nix::ioctl_readwrite; @@ -21,7 +22,7 @@ struct _CrosEcCommandV2 { #[repr(C)] struct CrosEcCommandV2 { version: u32, - command: u32, + command: CrosEcCmd, outsize: u32, insize: u32, result: u32, @@ -46,7 +47,7 @@ fn init() { }; } -pub fn ec_command(command: u32, command_version: u8, data: &[u8]) -> EcCmdResult> { +pub fn ec_command(command: CrosEcCmd, command_version: u8, data: &[u8]) -> EcCmdResult> { init(); let size = std::cmp::min(IN_SIZE, data.len());