Added convenient run
shorthand
This commit is contained in:
@@ -25,7 +25,8 @@ The tool also allows reading and erasing the chip, figure that out on your own i
|
||||
You'll need to clone this repo (or just [download the file](example.c)) and install SDCC:
|
||||
|
||||
```
|
||||
sdcc example.c
|
||||
tulflash write example.ihx
|
||||
tulflash run example.c
|
||||
|
||||
# Same thing as `tulflash write --cmd "sdcc example.c" --monitor example.ihx`
|
||||
```
|
||||
|
||||
|
12
src/args.rs
12
src/args.rs
@@ -23,7 +23,8 @@ pub enum ArgCommand {
|
||||
Read(ArgRead),
|
||||
Write(ArgWrite),
|
||||
Erase(ArgErase),
|
||||
Monitor(ArgMonitor)
|
||||
Monitor(ArgMonitor),
|
||||
Run(ArgRun)
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
@@ -89,6 +90,15 @@ pub struct ArgWrite {
|
||||
#[argp(subcommand, name = "erase")]
|
||||
pub struct ArgErase {}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
#[argp(description = "Handy shorthand for `write --cmd \"sdcc <srcpath>\" --monitor <hexpath>`.")]
|
||||
#[argp(subcommand, name = "run")]
|
||||
pub struct ArgRun {
|
||||
#[argp(positional)]
|
||||
#[argp(description = "Path to the source C file.")]
|
||||
pub path: OsString
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
#[argp(description = "Opens the serial monitor.")]
|
||||
#[argp(subcommand, name = "monitor")]
|
||||
|
21
src/main.rs
21
src/main.rs
@@ -1,5 +1,6 @@
|
||||
use std::ffi::OsString;
|
||||
use std::io::{Cursor, Error, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use pbr::ProgressBar;
|
||||
@@ -249,9 +250,26 @@ fn erase_chip(_args: ArgErase, target: &mut PhysicalTarget) -> Result<(), Error>
|
||||
|
||||
fn monitor_chip(_args: ArgMonitor, target: &mut PhysicalTarget) -> Result<(), Error> {
|
||||
let _ = Monitor::new().run(target.port())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_chip(args: ArgRun, target: &mut PhysicalTarget) -> Result<(), Error> {
|
||||
let path = PathBuf::from(&args.path).with_extension("ihx").into_os_string();
|
||||
let cmd = Some(OsString::from(format!("sdcc \"{}\"", unsafe { String::from_utf8_unchecked(args.path.into_encoded_bytes()) })));
|
||||
|
||||
write_chip(ArgWrite {
|
||||
path,
|
||||
cmd,
|
||||
start: 0,
|
||||
end: 65535,
|
||||
bin: false,
|
||||
skip_verify: false,
|
||||
write_individual: false,
|
||||
monitor: true
|
||||
}, target)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = args::parse();
|
||||
|
||||
@@ -279,7 +297,8 @@ fn main() {
|
||||
ArgCommand::Read(args) => read_chip(args, &mut target),
|
||||
ArgCommand::Write(args) => write_chip(args, &mut target),
|
||||
ArgCommand::Erase(args) => erase_chip(args, &mut target),
|
||||
ArgCommand::Monitor(args) => monitor_chip(args, &mut target)
|
||||
ArgCommand::Monitor(args) => monitor_chip(args, &mut target),
|
||||
ArgCommand::Run(args) => run_chip(args, &mut target)
|
||||
};
|
||||
|
||||
if let Err(err) = res {
|
||||
|
Reference in New Issue
Block a user