From 0f544f4310dcd9e056f668f5ddceaad5d7725801 Mon Sep 17 00:00:00 2001 From: Zachary T Welch Date: Thu, 19 Nov 2009 12:09:11 -0800 Subject: [PATCH] usbprog: use jtag_usb_open Rewrite usbprob_jtag_open to use jtag_usb_open helper. --- src/jtag/usbprog.c | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/src/jtag/usbprog.c b/src/jtag/usbprog.c index e8c0eadf..204d0e2e 100644 --- a/src/jtag/usbprog.c +++ b/src/jtag/usbprog.c @@ -36,8 +36,7 @@ #include "interface.h" #include "commands.h" - -#include +#include "usb_common.h" #define VID 0x1781 @@ -383,39 +382,23 @@ struct usb_bus *busses; struct usbprog_jtag* usbprog_jtag_open(void) { - struct usb_bus *bus; - struct usb_device *dev; - - struct usbprog_jtag *tmp; - - tmp = (struct usbprog_jtag*)malloc(sizeof(struct usbprog_jtag)); - usb_set_debug(10); usb_init(); - usb_find_busses(); - usb_find_devices(); - busses = usb_get_busses(); + const uint16_t vids[] = { VID, 0 }; + const uint16_t pids[] = { PID, 0 }; + struct usb_dev_handle *dev; + if (jtag_usb_open(vids, pids, &dev) != ERROR_OK) + return NULL; - /* find usbprog_jtag device in usb bus */ + struct usbprog_jtag *tmp = malloc(sizeof(struct usbprog_jtag)); + tmp->usb_handle = dev; - for (bus = busses; bus; bus = bus->next) - { - for (dev = bus->devices; dev; dev = dev->next) - { - /* condition for sucessfully hit (too bad, I only check the vendor id)*/ - if (dev->descriptor.idVendor == VID && dev->descriptor.idProduct == PID) - { - tmp->usb_handle = usb_open(dev); - usb_set_configuration(tmp->usb_handle, 1); - usb_claim_interface(tmp->usb_handle, 0); - usb_set_altinterface(tmp->usb_handle, 0); - return tmp; - } - } - } - free(tmp); - return 0; + usb_set_configuration(dev, 1); + usb_claim_interface(dev, 0); + usb_set_altinterface(dev, 0); + + return tmp; } #if 0 -- 2.39.5