From ef5afdee93c14ccb8ce56e3e9329b3f5132f3f94 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 18 Feb 2024 17:32:30 -0500 Subject: [PATCH] Implement ReadAll and WritePattern modes --- ecplorer/src/args.rs | 4 +++- ecplorer/src/main.rs | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ecplorer/src/args.rs b/ecplorer/src/args.rs index 03e83a6..cf10753 100644 --- a/ecplorer/src/args.rs +++ b/ecplorer/src/args.rs @@ -38,7 +38,9 @@ pub enum Operation { }, /// Write a pattern to the whole address space WritePattern { - // TODO + /// Bytes to write to every address + #[arg(value_parser = clap_num::maybe_hex::)] + bytes: Vec, }, /// Write a value to a specific address Write { diff --git a/ecplorer/src/main.rs b/ecplorer/src/main.rs index 9ec5d06..08b4002 100644 --- a/ecplorer/src/main.rs +++ b/ecplorer/src/main.rs @@ -4,6 +4,7 @@ use smokepatio::ec::EmbeddedController; fn main() { let cli = args::Args::load(); + #[cfg(debug_assertions)] println!("args: {:?}", cli); let mut ec = EmbeddedController::new(cli.data_address, cli.cmd_address); @@ -15,11 +16,34 @@ fn main() { } match cli.op { - args::Operation::ReadAll => todo!(), + args::Operation::ReadAll => { + let (bytes_per_line, range) = if cli.extended { (16, 0..=u16::MAX) } else { (8, 0..=(u8::MAX as u16)) }; + for addr in range { + let addr_mod = addr % bytes_per_line; + if addr_mod == 0 { + print!("{:#02x}: ", addr); + } + print!("{:#02x} ", ec.get(addr)); + if addr_mod == (bytes_per_line - 1) { + println!(""); + } else { + print!(" "); + } + } + println!(""); + }, args::Operation::Read { address } => { println!("{:#02x}", ec.get(address)); }, - args::Operation::WritePattern { } => todo!(), + args::Operation::WritePattern { bytes } => { + let range = if cli.extended { 0..=u16::MAX } else { 0..=(u8::MAX as u16) }; + for addr in range { + println!("{:#02x}", addr); + for b in bytes.iter() { + ec.set(addr, *b); + } + } + }, args::Operation::Write { address, value } => { ec.set(address, value); },