X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Ffx2lafw%2Ffx2lafw.c;h=648b13f48cb0361712a59b8bf032f778b1503280;hb=d4928d7102c6b2f9f7aa51a1b98669bf148fff80;hp=c19400414beef8a1c219cf188c26289af9e23937;hpb=1ebe4b4e6926eb1288ce77b179a92bc670eb9eca;p=libsigrok.git diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index c1940041..648b13f4 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -194,6 +194,7 @@ static int fx2lafw_dev_open(struct sr_dev_inst *sdi) libusb_device **devlist; struct libusb_device_descriptor des; struct dev_context *devc; + struct drv_context *drvc = fdi->priv; struct version_info vi; int ret, skip, i; uint8_t revid; @@ -205,7 +206,8 @@ static int fx2lafw_dev_open(struct sr_dev_inst *sdi) return SR_ERR; skip = 0; - const int device_count = libusb_get_device_list(NULL, &devlist); + const int device_count = libusb_get_device_list( + drvc->sr_ctx->libusb_ctx, &devlist); if (device_count < 0) { sr_err("fx2lafw: Failed to retrieve device list (%d)", device_count); @@ -214,8 +216,8 @@ static int fx2lafw_dev_open(struct sr_dev_inst *sdi) for (i = 0; i < device_count; i++) { if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { - sr_err("fx2lafw: Failed to get device descriptor: %d.", - ret); + sr_err("fx2lafw: Failed to get device descriptor: %s.", + libusb_error_name(ret)); continue; } @@ -248,7 +250,8 @@ static int fx2lafw_dev_open(struct sr_dev_inst *sdi) */ devc->usb->address = libusb_get_device_address(devlist[i]); } else { - sr_err("fx2lafw: Failed to open device: %d.", ret); + sr_err("fx2lafw: Failed to open device: %s.", + libusb_error_name(ret)); break; } @@ -408,12 +411,6 @@ static int hw_init(struct sr_context *sr_ctx) return SR_ERR_MALLOC; } - if (libusb_init(NULL) != 0) { - g_free(drvc); - sr_warn("fx2lafw: Failed to initialize libusb."); - return SR_ERR; - } - drvc->sr_ctx = sr_ctx; fdi->priv = drvc; @@ -441,12 +438,13 @@ static GSList *hw_scan(GSList *options) /* Find all fx2lafw compatible devices and upload firmware to them. */ devices = NULL; - 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)) != 0) { - sr_warn("fx2lafw: Failed to get device descriptor: %d.", ret); + sr_warn("fx2lafw: Failed to get device descriptor: %s.", + libusb_error_name(ret)); continue; } @@ -568,7 +566,8 @@ static int hw_dev_open(struct sr_dev_inst *sdi) break; default: - sr_err("fx2lafw: Unable to claim interface: %d.", ret); + sr_err("fx2lafw: Unable to claim interface: %s.", + libusb_error_name(ret)); break; } @@ -613,8 +612,6 @@ static int hw_cleanup(void) ret = clear_instances(); - libusb_exit(NULL); - g_free(drvc); fdi->priv = NULL; @@ -686,13 +683,14 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, static int receive_data(int fd, int revents, void *cb_data) { struct timeval tv; + struct drv_context *drvc = fdi->priv; (void)fd; (void)revents; (void)cb_data; tv.tv_sec = tv.tv_usec = 0; - libusb_handle_events_timeout(NULL, &tv); + libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); return TRUE; } @@ -712,6 +710,7 @@ static void abort_acquisition(struct dev_context *devc) static void finish_acquisition(struct dev_context *devc) { struct sr_datafeed_packet packet; + struct drv_context *drvc = fdi->priv; int i; @@ -721,7 +720,7 @@ static void finish_acquisition(struct dev_context *devc) /* Remove fds from polling */ const struct libusb_pollfd **const lupfd = - libusb_get_pollfds(NULL); + libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); for (i = 0; lupfd[i]; i++) sr_source_remove(lupfd[i]->fd); free(lupfd); /* NOT g_free()! */ @@ -754,12 +753,15 @@ static void free_transfer(struct libusb_transfer *transfer) static void resubmit_transfer(struct libusb_transfer *transfer) { - if (libusb_submit_transfer(transfer) != 0) { - free_transfer(transfer); - /* TODO: Stop session? */ - /* TODO: Better error message. */ - sr_err("fx2lafw: %s: libusb_submit_transfer error.", __func__); - } + int ret = libusb_submit_transfer(transfer); + + if (LIBUSB_SUCCESS == ret) + return; + + free_transfer(transfer); + /* TODO: Stop session? */ + + sr_err("fx2lafw: %s: %s", __func__, libusb_error_name(ret)); } static void receive_transfer(struct libusb_transfer *transfer) @@ -947,6 +949,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, struct sr_datafeed_header header; struct sr_datafeed_meta_logic meta; struct dev_context *devc; + struct drv_context *drvc = fdi->priv; struct libusb_transfer *transfer; const struct libusb_pollfd **lupfd; unsigned int i; @@ -987,7 +990,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, libusb_fill_bulk_transfer(transfer, devc->usb->devhdl, 2 | LIBUSB_ENDPOINT_IN, buf, size, receive_transfer, devc, timeout); - if (libusb_submit_transfer(transfer) != 0) { + if ((ret = libusb_submit_transfer(transfer)) != 0) { + sr_err("fx2lafw: %s: libusb_submit_transfer: %s.", + __func__, libusb_error_name(ret)); libusb_free_transfer(transfer); g_free(buf); abort_acquisition(devc); @@ -997,7 +1002,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, devc->submitted_transfers++; } - 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, timeout, receive_data, NULL);