X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fhantek-dso%2Fapi.c;h=01a080017e2eae8339a828e0c295e97adf3467d1;hb=123d97b17715204c58b795b8e6cbecc55725e5d3;hp=08c1164293c2f299949e2c3c51dd12cd30122604;hpb=1ebe4b4e6926eb1288ce77b179a92bc670eb9eca;p=libsigrok.git diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index 08c11642..01a08001 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -262,12 +262,6 @@ static int hw_init(struct sr_context *sr_ctx) return SR_ERR_MALLOC; } - if (libusb_init(NULL) != 0) { - g_free(drvc); - sr_err("Failed to initialize USB."); - return SR_ERR; - } - drvc->sr_ctx = sr_ctx; hdi->priv = drvc; @@ -295,10 +289,11 @@ static GSList *hw_scan(GSList *options) clear_instances(); /* Find all Hantek DSO devices and upload firmware to all of them. */ - libusb_get_device_list(NULL, &devlist); + libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); for (i = 0; devlist[i]; i++) { if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { - sr_err("Failed to get device descriptor: %d.", ret); + sr_err("Failed to get device descriptor: %s.", + libusb_error_name(ret)); continue; } @@ -396,7 +391,8 @@ static int hw_dev_open(struct sr_dev_inst *sdi) err = libusb_claim_interface(devc->usb->devhdl, USB_INTERFACE); if (err != 0) { - sr_err("Unable to claim interface: %d.", err); + sr_err("Unable to claim interface: %s.", + libusb_error_name(err)); return SR_ERR; } @@ -419,8 +415,6 @@ static int hw_cleanup(void) clear_instances(); - libusb_exit(NULL); - return SR_OK; } @@ -740,6 +734,7 @@ static int handle_event(int fd, int revents, void *cb_data) struct sr_datafeed_packet packet; struct timeval tv; struct dev_context *devc; + struct drv_context *drvc = hdi->priv; const struct libusb_pollfd **lupfd; int num_probes, i; uint32_t trigger_offset; @@ -757,7 +752,7 @@ static int handle_event(int fd, int revents, void *cb_data) * TODO: Doesn't really cancel pending transfers so they might * come in after SR_DF_END is sent. */ - lupfd = libusb_get_pollfds(NULL); + lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); for (i = 0; lupfd[i]; i++) sr_source_remove(lupfd[i]->fd); free(lupfd); @@ -772,7 +767,7 @@ static int handle_event(int fd, int revents, void *cb_data) /* Always handle pending libusb events. */ tv.tv_sec = tv.tv_usec = 0; - libusb_handle_events_timeout(NULL, &tv); + libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); /* TODO: ugh */ if (devc->dev_state == NEW_CAPTURE) { @@ -856,6 +851,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, struct sr_datafeed_header header; struct sr_datafeed_meta_analog meta; struct dev_context *devc; + struct drv_context *drvc = hdi->priv; int i; if (sdi->status != SR_ST_ACTIVE) @@ -876,7 +872,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_ERR; devc->dev_state = CAPTURE; - lupfd = libusb_get_pollfds(NULL); + lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); for (i = 0; lupfd[i]; i++) sr_source_add(lupfd[i]->fd, lupfd[i]->events, TICK, handle_event, (void *)sdi);