Added command for generating the kopyto
This commit is contained in:
30
README.md
30
README.md
@@ -2,31 +2,33 @@
|
|||||||
|
|
||||||
## Installation instructions
|
## 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
|
```bash
|
||||||
# All OSes
|
# All OSes
|
||||||
cargo install --git https://git.zumepro.cz/michal.prochazka/tulflash
|
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
|
```bash
|
||||||
# All OSes, automatically detects the correct serial port
|
# All OSes, automatically detects the correct serial port
|
||||||
tulflash write <path-to-hex>
|
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).
|
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),
|
Write(ArgWrite),
|
||||||
Erase(ArgErase),
|
Erase(ArgErase),
|
||||||
Monitor(ArgMonitor),
|
Monitor(ArgMonitor),
|
||||||
Run(ArgRun)
|
Run(ArgRun),
|
||||||
|
Example(ArgExample)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromArgs)]
|
#[derive(FromArgs)]
|
||||||
@@ -90,6 +91,11 @@ pub struct ArgWrite {
|
|||||||
#[argp(subcommand, name = "erase")]
|
#[argp(subcommand, name = "erase")]
|
||||||
pub struct ArgErase {}
|
pub struct ArgErase {}
|
||||||
|
|
||||||
|
#[derive(FromArgs)]
|
||||||
|
#[argp(description = "Opens the serial monitor.")]
|
||||||
|
#[argp(subcommand, name = "monitor")]
|
||||||
|
pub struct ArgMonitor {}
|
||||||
|
|
||||||
#[derive(FromArgs)]
|
#[derive(FromArgs)]
|
||||||
#[argp(description = "Handy shorthand for `write --cmd \"sdcc <srcpath>\" --monitor <hexpath>`.")]
|
#[argp(description = "Handy shorthand for `write --cmd \"sdcc <srcpath>\" --monitor <hexpath>`.")]
|
||||||
#[argp(subcommand, name = "run")]
|
#[argp(subcommand, name = "run")]
|
||||||
@@ -100,9 +106,13 @@ pub struct ArgRun {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromArgs)]
|
#[derive(FromArgs)]
|
||||||
#[argp(description = "Opens the serial monitor.")]
|
#[argp(description = "Generates a \"stub\" C file for the TUL výukový přípravek™.")]
|
||||||
#[argp(subcommand, name = "monitor")]
|
#[argp(subcommand, name = "example")]
|
||||||
pub struct ArgMonitor {}
|
pub struct ArgExample {
|
||||||
|
#[argp(positional)]
|
||||||
|
#[argp(description = "Path to the source C file to be generated.")]
|
||||||
|
pub path: Option<OsString>
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse() -> Args {
|
pub fn parse() -> Args {
|
||||||
let args: Args = argp::parse_args_or_exit(argp::DEFAULT);
|
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)
|
}, 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() {
|
fn main() {
|
||||||
let args = args::parse();
|
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 start = SystemTime::now();
|
||||||
|
|
||||||
let port = args.port.or_else(|| {
|
let port = args.port.or_else(|| {
|
||||||
@@ -300,7 +323,8 @@ fn main() {
|
|||||||
ArgCommand::Write(args) => write_chip(args, &mut target),
|
ArgCommand::Write(args) => write_chip(args, &mut target),
|
||||||
ArgCommand::Erase(args) => erase_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)
|
ArgCommand::Run(args) => run_chip(args, &mut target),
|
||||||
|
ArgCommand::Example(_) => unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
|
Reference in New Issue
Block a user