Common subdirectories: avrdude/.deps and avrdude-952-patched/.deps
Common subdirectories: avrdude/autom4te.cache and avrdude-952-patched/autom4te.cache
diff -x .svn -Nu avrdude/avrdude.conf.in avrdude-952-patched/avrdude.conf.in
--- avrdude/avrdude.conf.in	2011-08-24 08:51:28.683931900 +1000
+++ avrdude-952-patched/avrdude.conf.in	2011-07-25 23:32:36.485176800 +1000
@@ -395,34 +395,6 @@
   vfyled = ~ 13;
 ;
 
-# UM232H from FTDI and Glyn.com.au
-# J1: Connect pin 2 and 3 for USB power.
-# J2: Connect pin 2 and 3 for USB power.
-# J2: Pin 7 is SCK
-#   : Pin 8 is MOSI
-#   : Pin 9 is MISO
-#	: Pin 11 is RST
-# Use the -b flag to set the SPI clock rate eg -b 3700000 is the fastest I could get
-# a 16MHz Atmega1280 to program.  The 232H is conviniently 5V tolerant.
-programmer
-  id	= "UM232H";
-  desc	= "FT232H based module from FTDI and Glyn.com.au";
-  type	= avrftdi;
-  usbvid     = 0x0403;
-# Note: This PID is reserved for generic H devices and 
-# should be programmed into the EEPROM
-   usbpid    = 0x6014;
-  usbdev = "A";
-  usbvendor  = "";
-  usbproduct = "";
-  usbsn      = "";
-#ISP-signals 
-  sck    = 1;
-  mosi   = 2;
-  miso   = 3;
-  reset  = 5;
-;
-
 programmer
   id    = "avrisp";
   desc  = "Atmel AVR ISP";
diff -x .svn -Nu avrdude/avrftdi.c avrdude-952-patched/avrftdi.c
--- avrdude/avrftdi.c	2011-07-28 09:31:12.332504100 +1000
+++ avrdude-952-patched/avrftdi.c	2011-07-25 23:32:36.498177500 +1000
@@ -38,12 +38,11 @@
 #include "pgm.h"
 #include "avrftdi.h"
 
-#ifdef HAVE_LIBUSB_1_0
+#ifdef HAVE_LIBUSB
 #ifdef HAVE_LIBFTDI
 
 #include <ftdi.h>
-
-#include <libusb.h>
+#include <usb.h>
 
 /* This is for running the code without having a FTDI-device.
  * The generated code is useless! For debugging purposes only.
@@ -56,7 +55,7 @@
 static struct ftdi_context ftdic;
 static uint16_t pin_value, pin_direction, pin_inversion, led_mask;
 static int type; /**type is  bcdDevice. C/D is 0x500 H is 0x700 4H is 0x800*/
-static int ftype; /** is from FTDI. Use TYPE_2232C, TYPE_232H, TYPE_2232H, or TYPE_4232H*/
+static int ftype; /** is from FTDI. Use TYPE_2232C, TYPE_2232H, or TYPE_4232H*/
 
 static void buf_dump(unsigned char *buf, int len, char *desc, int offset, int width)
 {
@@ -72,51 +71,63 @@
 	fprintf(stderr, "%s end\n", desc);
 }
 
-/*
- * The *232H series can clock up to 30MHz.  Older chips like the 232C clock up to 6MHz.
- * This function will select which mode is appropriate based on the device.
+/* we use this to sync with the ftdi or flush the data path to the ftdi
+ * (USB stack, caches in USB hubs, instruction cache in the ftdi).
+ * This code is based on the assumption the ftdi_read call will return
+ * iff the instruction has been processed by the FTDI and therefore all
+ * other instructions before that. As sync/flush instruction we read the
+ * state of the lower GPIO pins and flush the data back immediately.
+ * This cannot be used, if there is outstanding data, because it will
+ * eat one byte.
+ * XXX: This is new and might very well be a buggy.
  */
+static int avrftdi_flush(void)
+{
+	/* 0x81: read i/p low byte
+	 * 0x87: flush data back immediately
+	 */
+	unsigned char buf[] = { 0x81, 0x87 };
+
+#ifndef DRYRUN
+	E(ftdi_write_data(&ftdic, buf, sizeof(buf)) != sizeof(buf));
+	/* the read command we use for sync/flush gives us back one byte;
+	 * we need to read it.
+	 */
+	E(ftdi_read_data(&ftdic, buf, 1) != 1);
+#endif
+	return 0;
+}
+
 static int set_frequency(uint32_t freq)
 {
 	uint32_t divisor;
 	uint8_t buf[3];
-	uint32_t clkfreq;
 
-	if(ftype == TYPE_2232C)
-	{
-		clkfreq = SPICLK6MHZ;
-	}
-	else
-	{
-		clkfreq = SPICLK30MHZ;
-		buf[0] = DIS_DIV_5;
-		E(ftdi_write_data(&ftdic, buf, 1) < 0);
-	}
-
-
-	divisor = (clkfreq / freq) - 1;
+	/* divisor on 6000000 / freq - 1 */
+	divisor = (6000000 / freq) - 1;
 	if (divisor < 0) {
-		fprintf(stderr, "%s failure: Frequency too high (%u > %dHz)\n", progname, freq, clkfreq);
-		fprintf(stderr, "resetting Frequency to %dHz\n",clkfreq);
+		fprintf(stderr, "%s failure: Frequency too high (%u > 6 MHz)\n", progname, freq);
+		fprintf(stderr, "resetting Frequency to 6MHz\n");
 		divisor = 0;
 	}
 
 	if (divisor > 65535) {
-		fprintf(stderr, "%s failure: Frequency too low (%u < %fHz)\n", progname, freq, (float)clkfreq/65535.0f);
-		fprintf(stderr, "resetting Frequency to %fHz\n",(float)clkfreq/65535.0f);
+		fprintf(stderr, "%s failure: Frequency too low (%u < 91.553 Hz)\n", progname, freq);
+		fprintf(stderr, "resetting Frequency to 91.553Hz\n");
 		divisor = 65535;
 	}
 
 	if(verbose)
-		fprintf(stderr, "%s info: clock divisor: 0x%04x Actual SPI ClK freq: %fHz\n", progname, divisor, clkfreq/(float)(divisor+1));
+		fprintf(stderr, "%s info: clock divisor: 0x%04x\n", progname, divisor);
 
-	buf[0] = TCK_DIVISOR;
+	buf[0] = 0x86;
 	buf[1] = (uint8_t)(divisor & 0xff);
 	buf[2] = (uint8_t)((divisor >> 8) & 0xff);
 
 #ifndef DRYRUN
 	E(ftdi_write_data(&ftdic, buf, 3) < 0);
 #endif
+
 	return 0;
 }
 
@@ -146,8 +157,6 @@
 		mlim=11;
 	else if(TYPE_2232H == ftype)
 		mlim=15;
-	else if(TYPE_232H == ftype)
-		mlim=11;
 	else{
 		printf("Unknown type %d (0x%x)\n",ftype,ftype);
 		mlim=15;
@@ -196,8 +205,6 @@
 		mlim=12;
 	else if(TYPE_2232H == ftype)
 		mlim=16;
-	else if(TYPE_232H == ftype)
-		mlim=11;
 	else{
 		printf("Unknown type %d (0x%x)\n",ftype,ftype);
 		mlim=16;
@@ -236,10 +243,10 @@
 	if(verbose > 2)
 		fprintf(stderr, "%s info: direction: 0x%04x, value: 0x%04x, inversion: 0x%04x\n", progname, pin_direction, pin_value, pin_inversion);
 
-	buf[0] = SET_BITS_LOW;
+	buf[0] = 0x80;
 	buf[1] = pin_value & 0xff;
 	buf[2] = pin_direction & 0xff;
-	buf[3] = SET_BITS_HIGH;
+	buf[3] = 0x82;
 	buf[4] = (pin_value >> 8) & 0xff;
 	buf[5] = (pin_direction >> 8) & 0xff;
 
@@ -256,7 +263,7 @@
 	 * avr has got the reset signal when we start sleeping.
 	 * (it may be stuck in the USB stack or some USB hub)
 	 */
-	E(ftdi_usb_purge_buffers(&ftdic));
+	avrftdi_flush();
 
 	return 0;
 	
@@ -348,7 +355,7 @@
 		buf[2] = (((buf_size - 1) >> 8) & 0xff);
 
 		memcpy(buf + 3, cmd, buf_size);
-		buf[buf_size + 3] = SEND_IMMEDIATE;
+		buf[buf_size + 3] = 0x87;
 
 #ifndef DRYRUN	
 		E(ftdi_write_data(&ftdic, buf, buf_size + 4) != buf_size + 4);
@@ -379,7 +386,7 @@
 	char serial[255], *foundsn;
 	struct ftdi_device_list* devlist;
 	struct ftdi_device_list* devlist_ptr;
-	struct libusb_device *found_dev;
+	struct usb_device *found_dev;
 	/* use vid/pid in following priority: config, defaults. cmd-line is currently not supported */
 	type=0;
 	snfound=0;
@@ -415,20 +422,20 @@
 		do {
 			ftdi_usb_get_strings(&ftdic, devlist_ptr->dev, NULL, 0, NULL, 0, serial, 255);
 			
-//			if(verbose)
-//				fprintf(stderr, "%s: device: %s, serial number: %s type 0x%04x found\n", 
-//			  progname,devlist_ptr->dev->filename, serial, devlist_ptr->dev->descriptor.bcdDevice);
+			if(verbose)
+				fprintf(stderr, "%s: device: %s, serial number: %s type 0x%04x found\n", 
+			  progname,devlist_ptr->dev->filename, serial, devlist_ptr->dev->descriptor.bcdDevice);
 			  
 			if(!snfound){
 				if(!strcmp(pgm->usbsn, serial)){
 					foundsn=strdup(serial);
 					snfound=1;
 					found_dev=devlist_ptr->dev;
-//					type=devlist_ptr->dev->descriptor.bcdDevice;
+					type=devlist_ptr->dev->descriptor.bcdDevice;
 				}
 			}else {
-//				if(0 == type)	/**we assume it will attach to first found.  */
-//					type=devlist_ptr->dev->descriptor.bcdDevice;
+				if(0 == type)	/**we assume it will attach to first found.  */
+					type=devlist_ptr->dev->descriptor.bcdDevice;
 				if(NULL == found_dev)
 					found_dev=devlist_ptr->dev;
 				if(NULL == foundsn)
@@ -463,8 +470,6 @@
 	E(ftdi_usb_open_dev(&ftdic,found_dev) <0);
 /*	E(ftdi_usb_open_desc(&ftdic, vid,pid,NULL,0==pgm->usbsn[0]?NULL:pgm->usbsn) < 0);  */
 	ftype=ftdic.type;
-	if(verbose)
-		fprintf(stderr, "Setting MPSSE Mode. Pindir %04x\n",pin_direction);
 	E(ftdi_set_bitmode(&ftdic, pin_direction & 0xff, BITMODE_MPSSE) < 0);	/*set SPI */
 #endif
 	
@@ -953,7 +958,7 @@
 
 static int avrftdi_noftdi_open (struct programmer_t *pgm, char * name)
 {
-	fprintf(stderr, "%s: error: no libftdi support. Please compile again with libftdi installed.\n",
+	fprintf(stderr, "%s: error: no libftdi support. please compile again with libftdi installed.\n",
 	  progname);
 
 	exit(1);
@@ -967,11 +972,11 @@
 
 #endif  /* HAVE_LIBFTDI */
 
-#else /*HAVE_LIBUSB_1_0*/
+#else /*HAVE_LIBUSB*/
 
 static int avrftdi_nousb_open (struct programmer_t *pgm, char * name)
 {
-	fprintf(stderr, "%s: error: no usb support. Please compile again with libsusb-1.0 installed.\n",
+	fprintf(stderr, "%s: error: no usb support. please compile again with libsusb installed.\n",
 	  progname);
 	
 	exit(1);
@@ -983,5 +988,5 @@
 	pgm->open = avrftdi_nousb_open;
 }
 
-#endif /*HAVE_LIBUSB_1_0*/
+#endif /*HAVE_LIBUSB*/
 
diff -x .svn -Nu avrdude/avrftdi.h avrdude-952-patched/avrftdi.h
--- avrdude/avrftdi.h	2011-07-27 20:30:20.381392100 +1000
+++ avrdude-952-patched/avrftdi.h	2011-07-25 23:32:36.500177600 +1000
@@ -5,9 +5,6 @@
 extern "C" {
 #endif
 
-#define SPICLK30MHZ 30000000
-#define SPICLK6MHZ 6000000
-
 #define SCK 0x01
 #define SDO 0x02
 #define SDI 0x04
Common subdirectories: avrdude/doc and avrdude-952-patched/doc
Common subdirectories: avrdude/tools and avrdude-952-patched/tools
diff -x .svn -Nu avrdude/usbasp.c avrdude-952-patched/usbasp.c
--- avrdude/usbasp.c	2011-07-26 00:50:12.511486200 +1000
+++ avrdude-952-patched/usbasp.c	2011-07-20 16:16:22.005462100 +1000
@@ -77,9 +77,9 @@
 	case LIBUSB_ERROR_BUSY:
 		return EBUSY;
 	case LIBUSB_ERROR_TIMEOUT:
-//		return ETIMEDOUT;
+		return ETIMEDOUT;
 	case LIBUSB_ERROR_OVERFLOW:
-//		return EOVERFLOW;
+		return EOVERFLOW;
 	case LIBUSB_ERROR_PIPE:
 		return EPIPE;
 	case LIBUSB_ERROR_INTERRUPTED:
Common subdirectories: avrdude/windows and avrdude-952-patched/windows
