@@ -328,6 +328,43 @@ void linuxgpio_teardown(PROGRAMMER *pgm) {
328328 pgm -> cookie = NULL ;
329329}
330330
331+ static int linuxgpio_parseexitspecs (PROGRAMMER * pgm , const char * sp ) {
332+ char * cp , * s , * str = mmt_strdup (sp );
333+ int rv = 0 ;
334+ bool help = false;
335+
336+ s = str ;
337+ while ((cp = strtok (s , "," ))) {
338+ s = NULL ;
339+ if (str_eq (cp , "reset" )) {
340+ pgm -> exit_reset = EXIT_RESET_ENABLED ;
341+ continue ;
342+ }
343+ if (str_eq (cp , "noreset" )) {
344+ pgm -> exit_reset = EXIT_RESET_DISABLED ;
345+ continue ;
346+ }
347+ if (str_eq (cp , "help" )) {
348+ help = true;
349+ rv = LIBAVRDUDE_EXIT ;
350+ }
351+
352+ if (!help ) {
353+ pmsg_error ("invalid exitspec parameter -E %s\n" , cp );
354+ rv = -1 ;
355+ }
356+ msg_error ("%s -c %s exitspec parameter options:\n" , progname , pgmid );
357+ msg_error (" -E reset Programmer will keep the reset line low after programming session\n" );
358+ msg_error (" -E noreset Programmer will not keep the reset line low after programming session\n" );
359+ msg_error (" -E help Show this help menu and exit\n" );
360+ mmt_free (str );
361+ return rv ;
362+ }
363+
364+ mmt_free (str );
365+ return rv ;
366+ }
367+
331368// libgpiod backend for the linuxgpio programmer
332369
333370#ifdef HAVE_LIBGPIOD
@@ -585,21 +622,26 @@ static void linuxgpio_libgpiod_close(PROGRAMMER *pgm) {
585622 }
586623 }
587624
588- // Configure RESET as input.
589- if (linuxgpio_libgpiod_lines [PIN_AVR_RESET ] != NULL ) {
625+ if (pgm -> exit_reset == EXIT_RESET_ENABLED ) // Exit with RESET pin high
626+ pgm -> setpin (pgm , PIN_AVR_RESET , 1 );
627+ else if (pgm -> exit_reset == EXIT_RESET_ENABLED ) // Exit with RESET pin low
628+ pgm -> setpin (pgm , PIN_AVR_RESET , 0 );
629+ else { // Exit with RESET pin as input (default behaviour)
630+ if (linuxgpio_libgpiod_lines [PIN_AVR_RESET ] != NULL ) {
590631
591- #if HAVE_LIBGPIOD_V1_6 || HAVE_LIBGPIOD_V2
592- int r = gpiod_line_set_direction_input (linuxgpio_libgpiod_lines [PIN_AVR_RESET ]);
593- #else
594- int r = gpiod_line_set_direction_input (& linuxgpio_libgpiod_lines [PIN_AVR_RESET ]);
595- #endif
632+ #if HAVE_LIBGPIOD_V1_6 || HAVE_LIBGPIOD_V2
633+ int r = gpiod_line_set_direction_input (linuxgpio_libgpiod_lines [PIN_AVR_RESET ]);
634+ #else
635+ int r = gpiod_line_set_direction_input (& linuxgpio_libgpiod_lines [PIN_AVR_RESET ]);
636+ #endif
596637
597- if (r != 0 ) {
598- msg_error ("failed to set pin %u to input: %s\n" ,
599- linuxgpio_get_gpio_num (linuxgpio_libgpiod_lines [PIN_AVR_RESET ]), strerror (errno ));
638+ if (r != 0 ) {
639+ msg_error ("failed to set pin %u to input: %s\n" ,
640+ linuxgpio_get_gpio_num (linuxgpio_libgpiod_lines [PIN_AVR_RESET ]), strerror (errno ));
641+ }
642+ gpiod_line_release (linuxgpio_libgpiod_lines [PIN_AVR_RESET ]);
643+ linuxgpio_libgpiod_lines [PIN_AVR_RESET ] = NULL ;
600644 }
601- gpiod_line_release (linuxgpio_libgpiod_lines [PIN_AVR_RESET ]);
602- linuxgpio_libgpiod_lines [PIN_AVR_RESET ] = NULL ;
603645 }
604646}
605647
@@ -713,6 +755,7 @@ void linuxgpio_initpgm(PROGRAMMER *pgm) {
713755 pgm -> write_byte = avr_write_byte_default ;
714756 pgm -> setup = linuxgpio_setup ;
715757 pgm -> teardown = linuxgpio_teardown ;
758+ pgm -> parseexitspecs = linuxgpio_parseexitspecs ;
716759
717760#ifdef HAVE_LIBGPIOD
718761 if (libgpiod_is_working ()) {
0 commit comments