Skip to content

Commit

Permalink
Add help text for -E exitspec
Browse files Browse the repository at this point in the history
  • Loading branch information
MCUdude committed Jul 29, 2024
1 parent 95b4e78 commit 3c679b1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 25 deletions.
19 changes: 17 additions & 2 deletions src/flip2.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ static int flip2_paged_write(const PROGRAMMER *pgm, const AVRPART *part, const A
// Parse the -E option flag
static int flip2_parseexitspecs(PROGRAMMER *pgm, const char *sp) {
char *cp, *s, *str = mmt_strdup(sp);
int rv = 0;
bool help = false;

s = str;
while ((cp = strtok(s, ","))) {
Expand All @@ -506,12 +508,25 @@ static int flip2_parseexitspecs(PROGRAMMER *pgm, const char *sp) {
pgm->exit_reset = EXIT_RESET_DISABLED;
continue;
}
if (str_eq(cp, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
}

if (!help) {
pmsg_error("invalid exitspec parameter -E %s\n", cp);
rv = -1;
}
msg_error("%s -c %s exitspec parameter options:\n", progname, pgmid);
msg_error(" -E reset Application will not start automatically after programming session\n");
msg_error(" -E noreset Application will start automatically after programming session\n");
msg_error(" -E help Show this help menu and exit\n");
mmt_free(str);
return -1;
return rv;
}

mmt_free(str);
return 0;
return rv;
}

static int flip2_read_sig_bytes(const PROGRAMMER *pgm, const AVRPART *part, const AVRMEM *mem) {
Expand Down
19 changes: 17 additions & 2 deletions src/linuxspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ static int linuxspi_chip_erase(const PROGRAMMER *pgm, const AVRPART *p) {

static int linuxspi_parseexitspecs(PROGRAMMER *pgm, const char *sp) {
char *cp, *s, *str = mmt_strdup(sp);
int rv = 0;
bool help = false;

s = str;
while ((cp = strtok(s, ","))) {
Expand All @@ -393,12 +395,25 @@ static int linuxspi_parseexitspecs(PROGRAMMER *pgm, const char *sp) {
pgm->exit_reset = EXIT_RESET_DISABLED;
continue;
}
if (str_eq(cp, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
}

if (!help) {
pmsg_error("invalid exitspec parameter -E %s\n", cp);
rv = -1;
}
msg_error("%s -c %s exitspec parameter options:\n", progname, pgmid);
msg_error(" -E reset Programmer will keep the reset line low after programming session\n");
msg_error(" -E noreset Programmer will not keep the reset line low after programming session\n");
msg_error(" -E help Show this help menu and exit\n");
mmt_free(str);
return -1;
return rv;
}

mmt_free(str);
return 0;
return rv;
}

static int linuxspi_parseextparams(const PROGRAMMER *pgm, const LISTID extparms) {
Expand Down
13 changes: 8 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1440,11 +1440,14 @@ int main(int argc, char * argv [])
if (pgm->parseexitspecs == NULL) {
pmsg_warning("-E option not supported by this programmer type\n");
exitspecs = NULL;
}
else if (pgm->parseexitspecs(pgm, exitspecs) < 0) {
usage();
exitrc = 1;
goto main_exit;
} else {
int rc = pgm->parseexitspecs(pgm, exitspecs);
if(rc == LIBAVRDUDE_EXIT)
exit(0);
if(rc < 0) {
pmsg_error("unable to parse list of -E parameters\n");
exit(1);
}
}
}

Expand Down
55 changes: 39 additions & 16 deletions src/par.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,36 +335,59 @@ static void par_close(PROGRAMMER *pgm) {
*/
static int par_parseexitspecs(PROGRAMMER *pgm, const char *sp) {
char *cp, *s, *str = mmt_strdup(sp);
int rv = 0;
bool help = false;

s = str;
while((cp = strtok(s, ","))) {
if(str_eq(cp, "reset"))
s = NULL;
if(str_eq(cp, "reset")) {
pgm->exit_reset = EXIT_RESET_ENABLED;

else if(str_eq(cp, "noreset"))
continue;
}
if(str_eq(cp, "noreset")) {
pgm->exit_reset = EXIT_RESET_DISABLED;

else if(str_eq(cp, "vcc"))
continue;
}
if(str_eq(cp, "vcc")) {
pgm->exit_vcc = EXIT_VCC_ENABLED;

else if(str_eq(cp, "novcc"))
continue;
}
if(str_eq(cp, "novcc")) {
pgm->exit_vcc = EXIT_VCC_DISABLED;

else if(str_eq(cp, "d_high"))
continue;
}
if(str_eq(cp, "d_high")) {
pgm->exit_datahigh = EXIT_DATAHIGH_ENABLED;

else if(str_eq(cp, "d_low"))
continue;
}
if(str_eq(cp, "d_low")) {
pgm->exit_datahigh = EXIT_DATAHIGH_DISABLED;
continue;
}
if (str_eq(cp, "help")) {
help = true;
rv = LIBAVRDUDE_EXIT;
}

else {
mmt_free(str);
return -1;
if (!help) {
pmsg_error("invalid exitspec parameter -E %s\n", cp);
rv = -1;
}
s = NULL; // Only call strtok() once with the actual string
msg_error("%s -c %s exitspec parameter options:\n", progname, pgmid);
msg_error(" -E reset Programmer will keep the reset line low after programming session\n");
msg_error(" -E noreset Programmer will not keep the reset line low after programming session\n");
msg_error(" -E vcc Programmer VCC pin(s) remain active after programming session\n");
msg_error(" -E novcc Programmer VCC pin(s) turned off after programming session\n");
msg_error(" -E d_high Set all 8 programmer data pins high after programming session\n");
msg_error(" -E d_low Set all 8 programmer data pins low after programming session\n");
msg_error(" -E help Show this help menu and exit\n");
mmt_free(str);
return rv;
}

mmt_free(str);
return 0;
return rv;
}

void par_initpgm(PROGRAMMER *pgm) {
Expand Down

0 comments on commit 3c679b1

Please sign in to comment.