X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Flascar-el-usb%2Fapi.c;h=74fd1e71ef6f61b1670e04282ad7f978fd06fb2c;hb=2588e50c63d08245547e9947e67b4247f9102b19;hp=7553e6cf2c2be4b44ee9fa3b89c277c0625fffca;hpb=6078d2c99619233173d4536b74258c15e6be73ba;p=libsigrok.git diff --git a/hardware/lascar-el-usb/api.c b/hardware/lascar-el-usb/api.c index 7553e6cf..74fd1e71 100644 --- a/hardware/lascar-el-usb/api.c +++ b/hardware/lascar-el-usb/api.c @@ -26,7 +26,6 @@ SR_PRIV struct sr_dev_inst *lascar_scan(int bus, int address); SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info; static struct sr_dev_driver *di = &lascar_el_usb_driver_info; -static int dev_close(struct sr_dev_inst *sdi); static const int32_t hwopts[] = { SR_CONF_CONN, @@ -39,37 +38,14 @@ static const int32_t hwcaps[] = { SR_CONF_LIMIT_SAMPLES, }; -/* Properly close and free all devices. */ -static int clear_instances(void) +static int dev_clear(void) { - struct sr_dev_inst *sdi; - struct drv_context *drvc; - struct dev_context *devc; - GSList *l; - - if (!(drvc = di->priv)) - return SR_OK; - - for (l = drvc->instances; l; l = l->next) { - if (!(sdi = l->data)) - continue; - if (!(devc = sdi->priv)) - continue; - - dev_close(sdi); - sr_usb_dev_inst_free(sdi->conn); - sr_dev_inst_free(sdi); - } - - g_slist_free(drvc->instances); - drvc->instances = NULL; - - return SR_OK; + return std_dev_clear(di, NULL); } static int init(struct sr_context *sr_ctx) { - return std_hw_init(sr_ctx, di, LOG_PREFIX); + return std_init(sr_ctx, di, LOG_PREFIX); } static GSList *scan(GSList *options) @@ -173,26 +149,30 @@ static int dev_close(struct sr_dev_inst *sdi) static int cleanup(void) { + int ret; struct drv_context *drvc; if (!(drvc = di->priv)) /* Can get called on an unused driver, doesn't matter. */ return SR_OK; - clear_instances(); + ret = dev_clear(); g_free(drvc); di->priv = NULL; - return SR_OK; + return ret; } -static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) +static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, + const struct sr_probe_group *probe_group) { struct dev_context *devc; struct sr_usb_dev_inst *usb; int ret; char str[128]; + (void)probe_group; + devc = sdi->priv; switch (id) { case SR_CONF_CONN: @@ -219,11 +199,14 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) return SR_OK; } -static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) +static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, + const struct sr_probe_group *probe_group) { struct dev_context *devc; int ret; + (void)probe_group; + if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; @@ -256,10 +239,11 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) return ret; } -static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) +static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, + const struct sr_probe_group *probe_group) { - (void)sdi; + (void)probe_group; switch (key) { case SR_CONF_SCAN_OPTIONS: @@ -356,10 +340,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) struct drv_context *drvc; struct sr_usb_dev_inst *usb; struct libusb_transfer *xfer_in, *xfer_out; - const struct libusb_pollfd **pfd; struct timeval tv; uint64_t interval; - int ret, i; + int ret; unsigned char cmd[3], resp[4], *buf; if (sdi->status != SR_ST_ACTIVE) @@ -456,15 +439,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->log_size = xfer_in->buffer[1] + (xfer_in->buffer[2] << 8); libusb_free_transfer(xfer_out); - pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; pfd[i]; i++) { - /* Handle USB events every 100ms, for decent latency. */ - sr_source_add(pfd[i]->fd, pfd[i]->events, 100, - lascar_el_usb_handle_events, (void *)sdi); - /* We'll need to remove this fd later. */ - devc->usbfd[i] = pfd[i]->fd; - } - devc->usbfd[i] = -1; + usb_source_add(drvc->sr_ctx, 100, lascar_el_usb_handle_events, (void *)sdi); buf = g_try_malloc(4096); libusb_fill_bulk_transfer(xfer_in, usb->devhdl, LASCAR_EP_IN, @@ -507,7 +482,7 @@ SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info = { .cleanup = cleanup, .scan = scan, .dev_list = dev_list, - .dev_clear = clear_instances, + .dev_clear = dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list,