From: Uwe Hermann Date: Thu, 2 Feb 2012 20:08:33 +0000 (+0100) Subject: sr: zeroplus: Remove unused gl_open()/gl_close(). X-Git-Tag: libsigrok-0.1.0~155 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=185ae2c5c9ada0353b43e3736e838bbc8e370cb4;p=libsigrok.git sr: zeroplus: Remove unused gl_open()/gl_close(). Merge the missing function calls into zeroplus.c's init functions. --- diff --git a/hardware/zeroplus-logic-cube/gl_usb.c b/hardware/zeroplus-logic-cube/gl_usb.c index 7353f65d..613028ed 100644 --- a/hardware/zeroplus-logic-cube/gl_usb.c +++ b/hardware/zeroplus-logic-cube/gl_usb.c @@ -140,69 +140,3 @@ int gl_reg_read(libusb_device_handle *devh, unsigned int reg) ret = gl_read_data(devh); return ret; } - -int gl_open(int vid) -{ - int ret; - struct libusb_device **devs; - struct libusb_device *dev; - size_t i = 0; - struct libusb_device_descriptor desc; - - ret = libusb_init(NULL); - if (ret < 0) - return GL_ELIBUSB; - - if (libusb_get_device_list(NULL, &devs) < 0) { - ret = GL_EOPEN; - goto gl_open_error; - } - - while ((dev = devs[i++]) != NULL) { - if (libusb_get_device_descriptor(dev, &desc) < 0) - break; - - if (desc.idVendor == vid) { - if (libusb_open(dev, &g_devh) < 0) - g_devh = NULL; - break; - } - } - - libusb_free_device_list(devs, 1); - - if (!g_devh) { - ret = GL_EOPEN; - goto gl_open_error; - } - - ret = libusb_set_configuration(g_devh, 1); - if (ret < 0) { - ret = GL_ESETCONFIG; - goto gl_open_error; - } - - ret = libusb_claim_interface(g_devh, 0); - if (ret < 0) { - ret = GL_ECLAIM; - goto gl_open_error; - } - - return GL_OK; - -gl_open_error: - gl_close(); - return ret; -} - -int gl_close(void) -{ - if (g_devh) { - libusb_release_interface(g_devh, 0); - libusb_reset_device(g_devh); - libusb_close(g_devh); - } - libusb_exit(NULL); - - return 0; -} diff --git a/hardware/zeroplus-logic-cube/gl_usb.h b/hardware/zeroplus-logic-cube/gl_usb.h index 921dae8e..2bc1d938 100644 --- a/hardware/zeroplus-logic-cube/gl_usb.h +++ b/hardware/zeroplus-logic-cube/gl_usb.h @@ -47,7 +47,5 @@ int gl_read_bulk(libusb_device_handle *devh, void *buffer, unsigned int size); int gl_reg_write(libusb_device_handle *devh, unsigned int reg, unsigned int val); int gl_reg_read(libusb_device_handle *devh, unsigned int reg); -int gl_open(int vid); -int gl_close(void); #endif diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index 1632c877..cd50c45d 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -283,8 +283,10 @@ static void close_device(struct sr_device_instance *sdi) sr_info("closing device %d on %d.%d interface %d", sdi->index, zp->usb->bus, zp->usb->address, USB_INTERFACE); libusb_release_interface(zp->usb->devhdl, USB_INTERFACE); + libusb_reset_device(zp->usb->devhdl); libusb_close(zp->usb->devhdl); zp->usb->devhdl = NULL; + /* TODO: Call libusb_exit() here or only in hw_cleanup()? */ sdi->status = SR_ST_INACTIVE; } @@ -367,7 +369,7 @@ static int hw_init(const char *deviceinfo) /* Find all ZeroPlus analyzers and add them to device list. */ devcnt = 0; - libusb_get_device_list(usb_context, &devlist); + libusb_get_device_list(usb_context, &devlist); /* TODO: Errors. */ for (i = 0; devlist[i]; i++) { err = libusb_get_device_descriptor(devlist[i], &des); @@ -425,11 +427,19 @@ static int hw_opendev(int device_index) return SR_ERR_ARG; } + err = libusb_set_configuration(zp->usb->devhdl, USB_CONFIGURATION); + if (err < 0) { + sr_warn("zp: Unable to set USB configuration %d: %d", + USB_CONFIGURATION, err); + return SR_ERR; + } + err = libusb_claim_interface(zp->usb->devhdl, USB_INTERFACE); if (err != 0) { sr_warn("Unable to claim interface: %d", err); return SR_ERR; } + analyzer_reset(zp->usb->devhdl); analyzer_initialize(zp->usb->devhdl);