Skip to content

Commit

Permalink
chromium_ec: Human readable command trace
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Schaefer <[email protected]>
  • Loading branch information
JohnAZoidberg committed Oct 20, 2023
1 parent 57bca72 commit 9980f9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ use core::prelude::rust_2021::derive;
use alloc::format;
use alloc::vec;
use alloc::vec::Vec;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;

use crate::util;

use super::{CrosEc, CrosEcDriver, EcError, EcResult};

// u16
#[non_exhaustive]
#[derive(Debug)]
#[derive(Debug, FromPrimitive)]
#[repr(u16)]
pub enum EcCommands {
GetVersion = 0x02,
GetBuildInfo = 0x04,
Expand Down Expand Up @@ -61,6 +63,7 @@ pub enum EcCommands {
/// Get hardware diagnostics
GetHwDiag = 0x3E1C,
}

pub trait EcRequest<R> {
fn command_id() -> EcCommands;
// Can optionally override this
Expand Down Expand Up @@ -111,7 +114,10 @@ pub trait EcRequestRaw<R> {
};
let response =
ec.send_command(Self::command_id_u16(), Self::command_version(), &request)?;
trace!("send_command<{:X?}>", Self::command_id_u16()); // TODO: name if possible
trace!(
"send_command<{:X?}>",
<EcCommands as FromPrimitive>::from_u16(Self::command_id_u16())
);
trace!(" Request: {:?}", request);
trace!(" Response: {:?}", response);
Ok(response)
Expand Down
5 changes: 3 additions & 2 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use alloc::vec;
use alloc::vec::Vec;
#[cfg(feature = "uefi")]
use core::prelude::rust_2021::derive;
use num_traits::FromPrimitive;

pub use command::EcRequestRaw;
use commands::*;
Expand Down Expand Up @@ -374,8 +375,8 @@ impl CrosEcDriver for CrosEc {
}
fn send_command(&self, command: u16, command_version: u8, data: &[u8]) -> EcResult<Vec<u8>> {
debug!(
"send_command(command=0x{:X}, ver={:?}, data_len={:?})",
command,
"send_command(command={:X?}, ver={:?}, data_len={:?})",
<EcCommands as FromPrimitive>::from_u16(command),
command_version,
data.len()
);
Expand Down

0 comments on commit 9980f9a

Please sign in to comment.