diff options
author | Zachary T Welch <zw@superlucidity.net> | 2009-11-19 12:09:11 -0800 |
---|---|---|
committer | Zachary T Welch <zw@superlucidity.net> | 2009-11-24 07:30:19 -0800 |
commit | 0f544f4310dcd9e056f668f5ddceaad5d7725801 (patch) | |
tree | 0ed8167f404b80d49edfe354cc29cf4dfdff1402 | |
parent | d836b079b413e8cbd30267a741f09b6c6f44f378 (diff) | |
download | openocd_libswd-0f544f4310dcd9e056f668f5ddceaad5d7725801.tar.gz openocd_libswd-0f544f4310dcd9e056f668f5ddceaad5d7725801.tar.bz2 openocd_libswd-0f544f4310dcd9e056f668f5ddceaad5d7725801.tar.xz openocd_libswd-0f544f4310dcd9e056f668f5ddceaad5d7725801.zip |
usbprog: use jtag_usb_open
Rewrite usbprob_jtag_open to use jtag_usb_open helper.
-rw-r--r-- | src/jtag/usbprog.c | 43 |
1 files 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 <usb.h> +#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 |