From 707e6634c1c1a69f3906d4b0dc086875fa8cbcc6 Mon Sep 17 00:00:00 2001
From: rliebscher <rliebscher@81a1dc3b-b13d-400b-aceb-764788c761c2>
Date: Tue, 29 Jan 2013 18:33:34 +0000
Subject: [PATCH] patch #7932 Read USBtiny VID and PID from avrdude.conf if
 provided. 	* avrdude.conf.in: added usbpid, usbvid to usbtiny 	*
 usbtiny.[ch]: use usbpid, usbpid if provided in config file

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1134 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 ChangeLog       |  6 ++++++
 avrdude.conf.in |  2 ++
 usbtiny.c       | 18 +++++++++++++++---
 usbtiny.h       |  4 ++--
 4 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5de11b29..8588017e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-01-29  Rene Liebscher <R.Liebscher@gmx.de>
+
+	patch #7932 Read USBtiny VID and PID from avrdude.conf if provided.
+	* avrdude.conf.in: added usbpid, usbvid to usbtiny
+	* usbtiny.[ch]: use usbpid, usbpid if provided in config file
+
 2013-01-26  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	bug #38172: avrftdi: Incorrect information in avrdude.conf
diff --git a/avrdude.conf.in b/avrdude.conf.in
index 0eb79a9f..a7fe118b 100644
--- a/avrdude.conf.in
+++ b/avrdude.conf.in
@@ -714,6 +714,8 @@ programmer
   desc  = "USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/";
   type  = "usbtiny";
   connection_type = usb;
+  usbvid     = 0x1781;
+  usbpid     = 0x0c9f;
 ;
 
 programmer
diff --git a/usbtiny.c b/usbtiny.c
index 5a5c16a5..2825083e 100644
--- a/usbtiny.c
+++ b/usbtiny.c
@@ -204,6 +204,7 @@ static	int	usbtiny_open(PROGRAMMER* pgm, char* name)
   struct usb_device   *dev = 0;
   char *bus_name = NULL;
   char *dev_name = NULL;
+  int vid, pid;
 
   // if no -P was given or '-P usb' was given
   if(strcmp(name, "usb") == 0)
@@ -225,11 +226,22 @@ static	int	usbtiny_open(PROGRAMMER* pgm, char* name)
 
   PDATA(pgm)->usb_handle = NULL;
 
+  if (pgm->usbvid)
+    vid = pgm->usbvid;
+  else
+    vid = USBTINY_VENDOR_DEFAULT;
+  
+  if (pgm->usbpid)
+    pid = pgm->usbpid;
+  else
+    pid = USBTINY_PRODUCT_DEFAULT;
+  
+
   // now we iterate through all the busses and devices
   for ( bus = usb_busses; bus; bus = bus->next ) {
     for	( dev = bus->devices; dev; dev = dev->next ) {
-      if (dev->descriptor.idVendor == USBTINY_VENDOR
-	  && dev->descriptor.idProduct == USBTINY_PRODUCT ) {   // found match?
+      if (dev->descriptor.idVendor == vid
+	  && dev->descriptor.idProduct == pid ) {   // found match?
     if(verbose)
       fprintf(stderr,
 	      "%s: usbdev_open(): Found USBtinyISP, bus:device: %s:%s\n",
@@ -259,7 +271,7 @@ static	int	usbtiny_open(PROGRAMMER* pgm, char* name)
   }
   if (!PDATA(pgm)->usb_handle) {
     fprintf( stderr, "%s: Error: Could not find USBtiny device (0x%x/0x%x)\n",
-	     progname, USBTINY_VENDOR, USBTINY_PRODUCT );
+	     progname, vid, pid );
     return -1;
   }
 
diff --git a/usbtiny.h b/usbtiny.h
index 5bc5f827..1bf49fc2 100644
--- a/usbtiny.h
+++ b/usbtiny.h
@@ -25,8 +25,8 @@
 // these are specifically assigned to USBtiny,
 // if you need your own VID and PIDs you can get them for cheap from
 // www.mecanique.co.uk so please don't reuse these. Thanks!
-#define USBTINY_VENDOR  0x1781
-#define USBTINY_PRODUCT 0x0C9F
+#define USBTINY_VENDOR_DEFAULT  0x1781
+#define USBTINY_PRODUCT_DEFAULT 0x0C9F
 
 // Generic requests to the USBtiny
 #define	USBTINY_ECHO 	     0      // echo test