]> git.sur5r.net Git - openocd/commitdiff
arm-jtag-ew: use jtag_usb_open
authorZachary T Welch <zw@superlucidity.net>
Thu, 19 Nov 2009 20:06:05 +0000 (12:06 -0800)
committerZachary T Welch <zw@superlucidity.net>
Tue, 24 Nov 2009 15:30:19 +0000 (07:30 -0800)
Rewrite armjtagwe_usb_open to use jtag_usb_open.

src/jtag/arm-jtag-ew.c

index 46dacc6dccd25373897373a1d0f2e6b8b12f25de..01c5559fb560cc830730d398ad86d8ac9b65d9b0 100644 (file)
@@ -25,6 +25,7 @@
 #include "interface.h"
 #include "commands.h"
 #include <usb.h>
+#include "usb_common.h"
 
 
 #define USB_VID                                                0x15ba
@@ -714,50 +715,30 @@ static int armjtagew_tap_execute(void)
 
 static struct armjtagew* armjtagew_usb_open()
 {
-       struct usb_bus *busses;
-       struct usb_bus *bus;
-       struct usb_device *dev;
-
-       struct armjtagew *result;
-
-       result = (struct armjtagew*) malloc(sizeof(struct armjtagew));
-
        usb_init();
-       usb_find_busses();
-       usb_find_devices();
-
-       busses = usb_get_busses();
 
-       /* find armjtagew device in usb bus */
+       const uint16_t vids[] = { USB_VID, 0 };
+       const uint16_t pids[] = { USB_PID, 0 };
+       struct usb_dev_handle *dev;
+       if (jtag_usb_open(vids, pids, &dev) != ERROR_OK)
+               return NULL;
 
-       for (bus = busses; bus; bus = bus->next)
-       {
-               for (dev = bus->devices; dev; dev = dev->next)
-               {
-                       if ((dev->descriptor.idVendor == USB_VID) && (dev->descriptor.idProduct == USB_PID))
-                       {
-                               result->usb_handle = usb_open(dev);
+       struct armjtagew *result = malloc(sizeof(struct armjtagew));
+       result->usb_handle = dev;
 
 #if 0
-                               /* usb_set_configuration required under win32 */
-                               usb_set_configuration(result->usb_handle, dev->config[0].bConfigurationValue);
+       /* usb_set_configuration required under win32 */
+       usb_set_configuration(dev, dev->config[0].bConfigurationValue);
 #endif
-                               usb_claim_interface(result->usb_handle, 0);
-
+       usb_claim_interface(dev, 0);
 #if 0
-                               /*
-                                * This makes problems under Mac OS X. And is not needed
-                                * under Windows. Hopefully this will not break a linux build
-                                */
-                               usb_set_altinterface(result->usb_handle, 0);
+       /*
+        * This makes problems under Mac OS X. And is not needed
+        * under Windows. Hopefully this will not break a linux build
+        */
+       usb_set_altinterface(dev, 0);
 #endif
-                               return result;
-                       }
-               }
-       }
-
-       free(result);
-       return NULL;
+       return result;
 }
 
 static void armjtagew_usb_close(struct armjtagew *armjtagew)