Allow to search for all FTDI standard VID/PID
authorUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Tue, 28 Jun 2011 15:04:43 +0000 (17:04 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 4 Jul 2011 07:32:29 +0000 (09:32 +0200)
Allow to search for all FTDI standard VID/PID by passing VID:PID 0:0
to ftdi_usb_find_all

examples/find_all.c
src/ftdi.c

index 2f3b4e2..5ad40be 100644 (file)
@@ -23,7 +23,7 @@ int main(void)
         return EXIT_FAILURE;
     }
 
-    if ((ret = ftdi_usb_find_all(&ftdic, &devlist, 0x0403, 0x6010)) < 0)
+    if ((ret = ftdi_usb_find_all(&ftdic, &devlist, NULL, NULL)) < 0)
     {
         fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
         retval =  EXIT_FAILURE;
index 57730d9..4dc47bd 100644 (file)
@@ -257,8 +257,10 @@ void ftdi_set_usbdev (struct ftdi_context *ftdi, libusb_device_handle *usb)
 
 
 /**
-    Finds all ftdi devices on the usb bus. Creates a new ftdi_device_list which
-    needs to be deallocated by ftdi_list_free() after use.
+    Finds all ftdi devices with given VID:PID on the usb bus. Creates a new
+    ftdi_device_list which needs to be deallocated by ftdi_list_free() after
+    use.  With VID:PID 0:0, search for the default devices
+    (0x403:0x6001, 0x403:0x6010, 0x403:0x6011, 0x403:0x6014) 
 
     \param ftdi pointer to ftdi_context
     \param devlist Pointer where to store list of found devices
@@ -291,7 +293,9 @@ int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devli
         if (libusb_get_device_descriptor(dev, &desc) < 0)
             ftdi_error_return_free_device_list(-6, "libusb_get_device_descriptor() failed", devs);
 
-        if (desc.idVendor == vendor && desc.idProduct == product)
+        if ((vendor != 0 && product != 0 && desc.idVendor == vendor && desc.idProduct == product) ||
+            ((desc.idVendor == 0x403) && (desc.idProduct == 0x6001 || desc.idProduct == 0x6010
+                                          || desc.idProduct == 0x6011 || desc.idProduct == 0x6014)))
         {
             *curdev = (struct ftdi_device_list*)malloc(sizeof(struct ftdi_device_list));
             if (!*curdev)