From d39d171985b11bd4f8f98a5012c2f5852d867fbc Mon Sep 17 00:00:00 2001
From: joerg_wunsch <joerg_wunsch@81a1dc3b-b13d-400b-aceb-764788c761c2>
Date: Fri, 26 Aug 2011 12:35:08 +0000
Subject: [PATCH] Submitted by Juergen Weigert: bug #22720: avrdude-5.5 ignores
 buff settings in avrdude.conf (Note that the actual bug the subject is about
 has been fixed long ago.) * update.c (do_op): fix a diagnostic message *
 pgm.h: add exit_datahigh field * par.c: set and act upon the exit_datahigh
 field * avrdude.1: document the new -E options * doc/avrdude.texi: (Ditto.)

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@985 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 ChangeLog        | 12 ++++++++++++
 avrdude.1        |  6 ++++++
 avrdude.conf.in  |  3 ++-
 doc/avrdude.texi |  8 ++++++++
 par.c            | 22 ++++++++++++++++++++++
 pgm.h            |  7 +++++++
 update.c         |  2 +-
 7 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c21606d7..e6826424 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2011-08-26  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
+
+	Submitted by Juergen Weigert:
+	bug #22720: avrdude-5.5 ignores buff settings in avrdude.conf
+	(Note that the actual bug the subject is about has been fixed
+	long ago.)
+	* update.c (do_op): fix a diagnostic message
+	* pgm.h: add exit_datahigh field
+	* par.c: set and act upon the exit_datahigh field
+	* avrdude.1: document the new -E options
+	* doc/avrdude.texi: (Ditto.)
+
 2011-08-26  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	bug #33811: Parallel make fails
diff --git a/avrdude.1 b/avrdude.1
index a111970e..b7ea21f5 100644
--- a/avrdude.1
+++ b/avrdude.1
@@ -423,6 +423,12 @@ power to the MCU.
 This option will pull the
 .Ql Vcc
 pins of the parallel port down at program exit.
+.It Ar d_high
+This option will leave the 8 data pins on the parallel port active.
+.Pq \&i. \&e. Em high
+.It Ar d_low
+This option will leave the 8 data pins on the parallel port inactive.
+.Pq \&i. \&e. Em low
 .El
 .Pp
 Multiple
diff --git a/avrdude.conf.in b/avrdude.conf.in
index c7c718b8..45bbf4fe 100644
--- a/avrdude.conf.in
+++ b/avrdude.conf.in
@@ -790,7 +790,8 @@ programmer
 # From the contributor of the "xil" jtag cable:
 # The "vcc" definition isn't really vcc (the cable gets its power from
 # the programming circuit) but is necessary to switch one of the
-# buffer lines (trying to add it to the "buff" lines doesn't work).
+# buffer lines (trying to add it to the "buff" lines doesn't work in 
+# avrdude versions before 5.5j).
 # With this, TMS connects to RESET, TDI to MOSI, TDO to MISO and TCK
 # to SCK (plus vcc/gnd of course)
 programmer
diff --git a/doc/avrdude.texi b/doc/avrdude.texi
index 0ea3150f..7e7cbe7c 100644
--- a/doc/avrdude.texi
+++ b/doc/avrdude.texi
@@ -638,6 +638,14 @@ can be used to supply `Vcc' power to the MCU.
 This option will pull the `Vcc' pins of the parallel port down at
 program exit.
 
+@itemx d_high
+This option will leave the 8 data pins on the parallel port active
+(i. e. high).
+
+@itemx d_low
+This option will leave the 8 data pins on the parallel port inactive
+(i. e. low).
+
 @end table
 
 Multiple @var{exitspec} arguments can be separated with commas.
diff --git a/par.c b/par.c
index 9399c4dc..54a04cf3 100644
--- a/par.c
+++ b/par.c
@@ -303,6 +303,21 @@ static void par_close(PROGRAMMER * pgm)
     /* Leave it alone. */
     break;
   }
+
+  switch (pgm->exit_datahigh) {
+  case EXIT_DATAHIGH_ENABLED:
+    ppi_setall(&pgm->fd, PPIDATA, 0xff);
+    break;
+
+  case EXIT_DATAHIGH_DISABLED:
+    ppi_setall(&pgm->fd, PPIDATA, 0x00);
+    break;
+
+  case EXIT_DATAHIGH_UNSPEC:
+    /* Leave it alone. */
+    break;
+  }
+
   switch (pgm->exit_vcc) {
   case EXIT_VCC_ENABLED:
     par_setmany(pgm, pgm->pinno[PPI_AVR_VCC], 1);
@@ -387,6 +402,12 @@ static int par_parseexitspecs(PROGRAMMER * pgm, char *s)
     else if (strcmp(cp, "novcc") == 0) {
       pgm->exit_vcc = EXIT_VCC_DISABLED;
     }
+    else if (strcmp(cp, "d_high") == 0) {
+      pgm->exit_datahigh = EXIT_DATAHIGH_ENABLED;
+    }
+    else if (strcmp(cp, "d_low") == 0) {
+      pgm->exit_datahigh = EXIT_DATAHIGH_DISABLED;
+    }
     else {
       return -1;
     }
@@ -402,6 +423,7 @@ void par_initpgm(PROGRAMMER * pgm)
 
   pgm->exit_vcc = EXIT_VCC_UNSPEC;
   pgm->exit_reset = EXIT_RESET_UNSPEC;
+  pgm->exit_datahigh = EXIT_DATAHIGH_UNSPEC;
 
   pgm->rdy_led        = bitbang_rdy_led;
   pgm->err_led        = bitbang_err_led;
diff --git a/pgm.h b/pgm.h
index 1542b247..db4c6bc3 100644
--- a/pgm.h
+++ b/pgm.h
@@ -50,6 +50,12 @@ typedef enum {
   EXIT_RESET_DISABLED
 } exit_reset_t;
 
+typedef enum {
+  EXIT_DATAHIGH_UNSPEC,
+  EXIT_DATAHIGH_ENABLED,
+  EXIT_DATAHIGH_DISABLED
+} exit_datahigh_t;
+
 typedef struct programmer_t {
   LISTID id;
   char desc[PGM_DESCLEN];
@@ -58,6 +64,7 @@ typedef struct programmer_t {
   unsigned int pinno[N_PINS];
   exit_vcc_t exit_vcc;
   exit_reset_t exit_reset;
+  exit_datahigh_t exit_datahigh;
   int ppidata;
   int ppictrl;
   int baudrate;
diff --git a/update.c b/update.c
index 22c9de7d..4350eb8c 100644
--- a/update.c
+++ b/update.c
@@ -259,7 +259,7 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, int nowrite,
     }
     rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1);
     if (rc < 0) {
-      fprintf(stderr, "%s: write to file '%s' failed\n",
+      fprintf(stderr, "%s: read from file '%s' failed\n",
               progname, upd->filename);
       return -1;
     }