Skip to content

Commit

Permalink
Merge pull request #17 from FrameworkComputer/cmd-version
Browse files Browse the repository at this point in the history
chromium_ec: Add function to check command version support
  • Loading branch information
JohnAZoidberg authored Oct 31, 2023
2 parents 4115a75 + 0075593 commit b812ab8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum EcCommands {
GetBuildInfo = 0x04,
/// Command to read data from EC memory map
ReadMemMap = 0x07,
GetCmdVersions = 0x08,
PwmGetKeyboardBacklight = 0x0022,
PwmSetKeyboardBacklight = 0x0023,
I2cPassthrough = 0x9e,
Expand Down
36 changes: 36 additions & 0 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,42 @@ impl EcRequest<EcResponseGetVersion> for EcRequestGetVersion {
}
}

#[repr(C, packed)]
pub struct EcRequestGetCmdVersionsV0 {
pub cmd: u8,
}
#[repr(C, packed)]
#[derive(Debug, Clone, Copy)]
pub struct EcResponseGetCmdVersionsV0 {
pub version_mask: u32,
}
impl EcRequest<EcResponseGetCmdVersionsV0> for EcRequestGetCmdVersionsV0 {
fn command_id() -> EcCommands {
EcCommands::GetCmdVersions
}
fn command_version() -> u8 {
0
}
}

#[repr(C, packed)]
pub struct EcRequestGetCmdVersionsV1 {
pub cmd: u32,
}
#[repr(C, packed)]
#[derive(Debug, Clone, Copy)]
pub struct EcResponseGetCmdVersionsV1 {
pub version_mask: u32,
}
impl EcRequest<EcResponseGetCmdVersionsV1> for EcRequestGetCmdVersionsV1 {
fn command_id() -> EcCommands {
EcCommands::GetCmdVersions
}
fn command_version() -> u8 {
1
}
}

#[repr(C, packed)]
pub struct EcRequestPwmSetKeyboardBacklight {
pub percent: u8,
Expand Down
12 changes: 12 additions & 0 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ impl CrosEc {
}
}

pub fn cmd_version_supported(&self, cmd: u16, version: u8) -> EcResult<bool> {
let res = EcRequestGetCmdVersionsV1 { cmd: cmd.into() }.send_command(self);
let mask = if let Ok(res) = res {
res.version_mask
} else {
let res = EcRequestGetCmdVersionsV0 { cmd: cmd as u8 }.send_command(self)?;
res.version_mask
};

Ok(mask & (1 << version) > 0)
}

pub fn dump_mem_region(&self) -> Option<Vec<u8>> {
// Crashes on Linux cros_ec driver if we read the last byte
self.read_memory(0x00, EC_MEMMAP_SIZE - 1)
Expand Down

0 comments on commit b812ab8

Please sign in to comment.