X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Ffx2lafw%2Ffx2lafw.c;h=e74312fb77b8a745d770bd007f7fafed4c7e03d6;hb=538ac9a91e5efb65e3c28d5a9af16c6fcfd63872;hp=44cc9aef802adc336f34db745a4da8e1c922638f;hpb=014359e3293ef0cdc61fbde4f63dc0a9da98179d;p=libsigrok.git diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index 44cc9aef..e74312fb 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -23,7 +23,6 @@ #include #include #include -#include "config.h" #include "libsigrok.h" #include "libsigrok-internal.h" #include "fx2lafw.h" @@ -195,13 +194,11 @@ static int fx2lafw_dev_open(struct sr_dev_inst *sdi) { libusb_device **devlist; struct libusb_device_descriptor des; - struct drv_context *drvc; struct dev_context *devc; struct version_info vi; int ret, skip, i; uint8_t revid; - drvc = fdi->priv; devc = sdi->priv; if (sdi->status == SR_ST_ACTIVE) @@ -209,7 +206,7 @@ static int fx2lafw_dev_open(struct sr_dev_inst *sdi) return SR_ERR; skip = 0; - const int device_count = libusb_get_device_list(drvc->usb_context, &devlist); + const int device_count = libusb_get_device_list(NULL, &devlist); if (device_count < 0) { sr_err("fx2lafw: Failed to retrieve device list (%d)", device_count); @@ -409,10 +406,10 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("fx2lafw: driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } - if (libusb_init(&drvc->usb_context) != 0) { + if (libusb_init(NULL) != 0) { g_free(drvc); sr_warn("fx2lafw: Failed to initialize libusb."); return SR_ERR; @@ -444,7 +441,7 @@ static GSList *hw_scan(GSList *options) /* Find all fx2lafw compatible devices and upload firmware to them. */ devices = NULL; - libusb_get_device_list(drvc->usb_context, &devlist); + libusb_get_device_list(NULL, &devlist); for (i = 0; devlist[i]; i++) { if ((ret = libusb_get_device_descriptor( @@ -511,6 +508,15 @@ static GSList *hw_scan(GSList *options) return devices; } +static GSList *hw_dev_list(void) +{ + struct drv_context *drvc; + + drvc = fdi->priv; + + return drvc->instances; +} + static int hw_dev_open(struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -607,9 +613,7 @@ static int hw_cleanup(void) ret = clear_instances(); - if (drvc->usb_context) - libusb_exit(drvc->usb_context); - drvc->usb_context = NULL; + libusb_exit(NULL); g_free(drvc); fdi->priv = NULL; @@ -681,7 +685,6 @@ 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 drv_context *drvc; struct timeval tv; /* Avoid compiler warnings. */ @@ -689,9 +692,8 @@ static int receive_data(int fd, int revents, void *cb_data) (void)revents; (void)cb_data; - drvc = fdi->priv; tv.tv_sec = tv.tv_usec = 0; - libusb_handle_events_timeout(drvc->usb_context, &tv); + libusb_handle_events_timeout(NULL, &tv); return TRUE; } @@ -710,11 +712,9 @@ static void abort_acquisition(struct dev_context *devc) static void finish_acquisition(struct dev_context *devc) { - struct drv_context *drvc; struct sr_datafeed_packet packet; int i; - drvc = fdi->priv; /* Terminate session */ packet.type = SR_DF_END; @@ -722,7 +722,7 @@ static void finish_acquisition(struct dev_context *devc) /* Remove fds from polling */ const struct libusb_pollfd **const lupfd = - libusb_get_pollfds(drvc->usb_context); + libusb_get_pollfds(NULL); for (i = 0; lupfd[i]; i++) sr_source_remove(lupfd[i]->fd); free(lupfd); /* NOT g_free()! */ @@ -947,7 +947,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, struct sr_datafeed_packet packet; struct sr_datafeed_header header; struct sr_datafeed_meta_logic meta; - struct drv_context *drvc; struct dev_context *devc; struct libusb_transfer *transfer; const struct libusb_pollfd **lupfd; @@ -955,7 +954,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, int ret; unsigned char *buf; - drvc = fdi->priv; devc = sdi->priv; if (devc->submitted_transfers != 0) return SR_ERR; @@ -974,8 +972,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, const size_t size = get_buffer_size(devc); devc->transfers = g_try_malloc0(sizeof(*devc->transfers) * num_transfers); - if (!devc->transfers) - return SR_ERR; + if (!devc->transfers) { + sr_err("fx2lafw: USB transfers malloc failed."); + return SR_ERR_MALLOC; + } devc->num_transfers = num_transfers; @@ -998,7 +998,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, devc->submitted_transfers++; } - lupfd = libusb_get_pollfds(drvc->usb_context); + lupfd = libusb_get_pollfds(NULL); for (i = 0; lupfd[i]; i++) sr_source_add(lupfd[i]->fd, lupfd[i]->events, timeout, receive_data, NULL); @@ -1046,6 +1046,8 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info = { .init = hw_init, .cleanup = hw_cleanup, .scan = hw_scan, + .dev_list = hw_dev_list, + .dev_clear = clear_instances, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .info_get = hw_info_get,