Implement ReadAll and WritePattern modes
This commit is contained in:
parent
821f538f6d
commit
ef5afdee93
2 changed files with 29 additions and 3 deletions
|
@ -38,7 +38,9 @@ pub enum Operation {
|
||||||
},
|
},
|
||||||
/// Write a pattern to the whole address space
|
/// Write a pattern to the whole address space
|
||||||
WritePattern {
|
WritePattern {
|
||||||
// TODO
|
/// Bytes to write to every address
|
||||||
|
#[arg(value_parser = clap_num::maybe_hex::<u8>)]
|
||||||
|
bytes: Vec<u8>,
|
||||||
},
|
},
|
||||||
/// Write a value to a specific address
|
/// Write a value to a specific address
|
||||||
Write {
|
Write {
|
||||||
|
|
|
@ -4,6 +4,7 @@ use smokepatio::ec::EmbeddedController;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = args::Args::load();
|
let cli = args::Args::load();
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
println!("args: {:?}", cli);
|
println!("args: {:?}", cli);
|
||||||
|
|
||||||
let mut ec = EmbeddedController::new(cli.data_address, cli.cmd_address);
|
let mut ec = EmbeddedController::new(cli.data_address, cli.cmd_address);
|
||||||
|
@ -15,11 +16,34 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
match cli.op {
|
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 } => {
|
args::Operation::Read { address } => {
|
||||||
println!("{:#02x}", ec.get(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 } => {
|
args::Operation::Write { address, value } => {
|
||||||
ec.set(address, value);
|
ec.set(address, value);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue