Added command for generating the kopyto
This commit is contained in:
30
README.md
30
README.md
@@ -2,31 +2,33 @@
|
||||
|
||||
## Installation instructions
|
||||
|
||||
No need to clone this repo manually. You'll just need to install the Rust toolchain.
|
||||
No need to clone this repo manually. You'll just need to install the Rust toolchain and SDCC.
|
||||
|
||||
```bash
|
||||
# All OSes
|
||||
cargo install --git https://git.zumepro.cz/michal.prochazka/tulflash
|
||||
```
|
||||
|
||||
## Flashing Intel HEX binaries
|
||||
## Running the example program
|
||||
|
||||
```bash
|
||||
# Generate the example program (only needed to run once):
|
||||
tulflash example
|
||||
|
||||
# Compile, flash and monitor the example program:
|
||||
tulflash run example.c:
|
||||
|
||||
# note: `tulflash run example.c` is the thing as `tulflash write --cmd "sdcc example.c" --monitor example.ihx`
|
||||
```
|
||||
|
||||
If the flash fails, try to add `--slow` before `run` (should not be needed though).
|
||||
|
||||
## Manually flashing Intel HEX binaries
|
||||
|
||||
```bash
|
||||
# All OSes, automatically detects the correct serial port
|
||||
tulflash write <path-to-hex>
|
||||
```
|
||||
|
||||
If the flash fails, try to add `--slow` before `write` (should not be needed though).
|
||||
|
||||
The tool also allows reading and erasing the chip, figure that out on your own if you need that (although `tulflash --help` might guide you if you ask it nicely).
|
||||
|
||||
## Example program
|
||||
|
||||
You'll need to clone this repo (or just [download the file](example.c)) and install SDCC:
|
||||
|
||||
```bash
|
||||
tulflash run example.c
|
||||
|
||||
# Same thing as `tulflash write --cmd "sdcc example.c" --monitor example.ihx`
|
||||
```
|
||||
|
||||
|
18
src/args.rs
18
src/args.rs
@@ -24,7 +24,8 @@ pub enum ArgCommand {
|
||||
Write(ArgWrite),
|
||||
Erase(ArgErase),
|
||||
Monitor(ArgMonitor),
|
||||
Run(ArgRun)
|
||||
Run(ArgRun),
|
||||
Example(ArgExample)
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
@@ -90,6 +91,11 @@ pub struct ArgWrite {
|
||||
#[argp(subcommand, name = "erase")]
|
||||
pub struct ArgErase {}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
#[argp(description = "Opens the serial monitor.")]
|
||||
#[argp(subcommand, name = "monitor")]
|
||||
pub struct ArgMonitor {}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
#[argp(description = "Handy shorthand for `write --cmd \"sdcc <srcpath>\" --monitor <hexpath>`.")]
|
||||
#[argp(subcommand, name = "run")]
|
||||
@@ -100,9 +106,13 @@ pub struct ArgRun {
|
||||
}
|
||||
|
||||
#[derive(FromArgs)]
|
||||
#[argp(description = "Opens the serial monitor.")]
|
||||
#[argp(subcommand, name = "monitor")]
|
||||
pub struct ArgMonitor {}
|
||||
#[argp(description = "Generates a \"stub\" C file for the TUL výukový přípravek™.")]
|
||||
#[argp(subcommand, name = "example")]
|
||||
pub struct ArgExample {
|
||||
#[argp(positional)]
|
||||
#[argp(description = "Path to the source C file to be generated.")]
|
||||
pub path: Option<OsString>
|
||||
}
|
||||
|
||||
pub fn parse() -> Args {
|
||||
let args: Args = argp::parse_args_or_exit(argp::DEFAULT);
|
||||
|
26
src/main.rs
26
src/main.rs
@@ -272,9 +272,32 @@ fn run_chip(args: ArgRun, target: &mut PhysicalTarget) -> Result<(), Error> {
|
||||
}, target)
|
||||
}
|
||||
|
||||
fn gen_example(args: ArgExample) -> Result<(), Error> {
|
||||
let path = PathBuf::from(args.path.unwrap_or(OsString::from("example.c")));
|
||||
|
||||
if path.try_exists()? {
|
||||
Err(Error::other("File already exists"))?
|
||||
}
|
||||
|
||||
std::fs::write(&path, include_bytes!("../example.c"))?;
|
||||
|
||||
let path = path.to_string_lossy();
|
||||
println!("Example source code generated to `{}`.", path);
|
||||
println!("Execute `tulflash run \"{}\"` to run it.", path);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = args::parse();
|
||||
|
||||
if let ArgCommand::Example(args) = args.command {
|
||||
if let Err(err) = gen_example(args) {
|
||||
println!("Error generating example source code: {}", err);
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
let start = SystemTime::now();
|
||||
|
||||
let port = args.port.or_else(|| {
|
||||
@@ -300,7 +323,8 @@ fn main() {
|
||||
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::Run(args) => run_chip(args, &mut target)
|
||||
ArgCommand::Run(args) => run_chip(args, &mut target),
|
||||
ArgCommand::Example(_) => unreachable!()
|
||||
};
|
||||
|
||||
if let Err(err) = res {
|
||||
|
Reference in New Issue
Block a user