Skip to content

Commit

Permalink
style: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
lleyton committed Mar 11, 2024
1 parent 96a9d92 commit 66e642b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/bin/ectool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crosec_rs::commands::get_chip_info::ec_cmd_get_chip_info;
use crosec_rs::commands::hello::ec_cmd_hello;
use crosec_rs::commands::version::ec_cmd_version;
use crosec_rs::commands::get_chip_info::ec_cmd_get_chip_info;

fn main() {
println!("Hello command");
Expand All @@ -12,7 +12,7 @@ fn main() {
}

println!("Version command");
let (ro_ver, rw_ver, firmware_copy, build_info, tool_version) = ec_cmd_version();
let (ro_ver, rw_ver, firmware_copy, build_info, tool_version) = ec_cmd_version();
println!("RO version: {ro_ver}");
println!("RW version: {rw_ver}");
println!("Firmware copy: {firmware_copy}");
Expand Down
3 changes: 2 additions & 1 deletion src/commands/get_chip_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ pub fn ec_cmd_get_chip_info() -> (String, String, String) {
};

let params_ptr = &params as *const _ as *const u8;
let params_slice = unsafe { slice::from_raw_parts(params_ptr, size_of::<EcResponseGetChipInfo>()) };
let params_slice =
unsafe { slice::from_raw_parts(params_ptr, size_of::<EcResponseGetChipInfo>()) };

let result = ec_command(CrosEcCmds::GetChipInfo as u32, 0, params_slice)
.unwrap_or_else(|error| panic!("EC error: {error:?}"));
Expand Down
2 changes: 1 addition & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pub enum CrosEcCmds {
GetChipInfo = 0x0005,
}

pub mod get_chip_info;
pub mod hello;
pub mod version;
pub mod get_chip_info;
22 changes: 11 additions & 11 deletions src/commands/version.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::commands::CrosEcCmds;
use crate::crosec::dev::ec_command;
use crate::crosec::dev::BUF_SIZE;
use num_traits::FromPrimitive;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use std::mem::size_of;
use std::slice;

Expand All @@ -19,11 +19,11 @@ struct EcResponseVersionV1 {

#[derive(FromPrimitive)]
enum EcImage {
EcImageUnknown = 0,
EcImageRo = 1,
EcImageRw = 2,
EcImageRoB = 3,
EcImageRwB = 4,
EcImageUnknown = 0,
EcImageRo = 1,
EcImageRw = 2,
EcImageRoB = 3,
EcImageRwB = 4,
}

pub fn ec_cmd_version() -> (String, String, String, String, String) {
Expand All @@ -37,7 +37,8 @@ pub fn ec_cmd_version() -> (String, String, String, String, String) {

let build_string: [u8; BUF_SIZE] = [0; BUF_SIZE];
let params_ptr = &params as *const _ as *const u8;
let params_slice = unsafe { slice::from_raw_parts(params_ptr, size_of::<EcResponseVersionV1>()) };
let params_slice =
unsafe { slice::from_raw_parts(params_ptr, size_of::<EcResponseVersionV1>()) };

let result = ec_command(CrosEcCmds::Version as u32, 0, params_slice)
.unwrap_or_else(|error| panic!("EC error: {error:?}"));
Expand All @@ -46,21 +47,20 @@ pub fn ec_cmd_version() -> (String, String, String, String, String) {
let ro_ver = String::from_utf8(response.version_string_ro.to_vec()).unwrap_or(String::from(""));
let rw_ver = String::from_utf8(response.version_string_rw.to_vec()).unwrap_or(String::from(""));

let image =
match FromPrimitive::from_u32(response.current_image) {
let image = match FromPrimitive::from_u32(response.current_image) {
Some(EcImage::EcImageUnknown) => String::from("Unknown"),
Some(EcImage::EcImageRo) => String::from("RO"),
Some(EcImage::EcImageRw) => String::from("RW"),
Some(EcImage::EcImageRoB) => String::from("RO B"),
Some(EcImage::EcImageRwB) => String::from("RW B"),
None => String::from("Unknown"),
};

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)
.unwrap_or_else(|error| panic!("EC error: {error:?}"));
.unwrap_or_else(|error| panic!("EC error: {error:?}"));
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(""));
Expand Down

0 comments on commit 66e642b

Please sign in to comment.