X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Ffx2lafw%2Ffx2lafw.c;h=7a83b58ba53e1b89b846c7dc68f7bd5de4f99895;hb=aee878fa2efb8483bf93fa3bb03508357fc713a8;hp=bdc6b42366f5e887ae006a1575a6061ee20e2924;hpb=c5e82ca5e3ba7cd154c0e8afc19859564fc36dab;p=libsigrok.git diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index bdc6b423..7a83b58b 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -143,8 +143,11 @@ static libusb_context *usb_context = NULL; SR_PRIV struct sr_dev_driver fx2lafw_driver_info; static struct sr_dev_driver *fdi = &fx2lafw_driver_info; -static int hw_dev_config_set(int dev_index, int hwcap, const void *value); -static int hw_dev_acquisition_stop(int dev_index, void *cb_data); +static int hw_dev_close(struct sr_dev_inst *sdi); +static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, + const void *value); +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data); /** * Check the USB configuration to determine if this is an fx2lafw device. @@ -190,18 +193,15 @@ static gboolean check_conf_profile(libusb_device *dev) return ret; } -static int fx2lafw_dev_open(int dev_index) +static int fx2lafw_dev_open(struct sr_dev_inst *sdi) { libusb_device **devlist; struct libusb_device_descriptor des; - struct sr_dev_inst *sdi; struct context *ctx; struct version_info vi; int ret, skip, i; uint8_t revid; - if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) - return SR_ERR; ctx = sdi->priv; if (sdi->status == SR_ST_ACTIVE) @@ -228,7 +228,7 @@ static int fx2lafw_dev_open(int dev_index) continue; if (sdi->status == SR_ST_INITIALIZING) { - if (skip != dev_index) { + if (skip != sdi->index) { /* Skip devices of this type that aren't the one we want. */ skip += 1; continue; @@ -297,23 +297,6 @@ static int fx2lafw_dev_open(int dev_index) return SR_OK; } -static void close_dev(struct sr_dev_inst *sdi) -{ - struct context *ctx; - - ctx = sdi->priv; - - if (ctx->usb->devhdl == NULL) - return; - - sr_info("fx2lafw: Closing device %d on %d.%d interface %d.", - sdi->index, ctx->usb->bus, ctx->usb->address, USB_INTERFACE); - libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE); - libusb_close(ctx->usb->devhdl); - ctx->usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; -} - static int configure_probes(struct context *ctx, GSList *probes) { struct sr_probe *probe; @@ -332,10 +315,10 @@ static int configure_probes(struct context *ctx, GSList *probes) if (probe->enabled == FALSE) continue; - if (probe->index > 8) + if (probe->index > 7) ctx->sample_wide = TRUE; - probe_bit = 1 << (probe->index - 1); + probe_bit = 1 << (probe->index); if (!(probe->trigger)) continue; @@ -399,7 +382,7 @@ static int clear_instances(void) ret = SR_ERR_BUG; continue; } - close_dev(sdi); + hw_dev_close(sdi); sdi = l->data; sr_dev_inst_free(sdi); } @@ -470,7 +453,7 @@ static GSList *hw_scan(GSList *options) sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING, prof->vendor, prof->model, prof->model_version); if (!sdi) - return 0; + return NULL; sdi->driver = fdi; /* Fill in probelist according to this device's profile. */ @@ -478,7 +461,7 @@ static GSList *hw_scan(GSList *options) for (j = 0; j < num_logic_probes; j++) { if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE, probe_names[j]))) - return 0; + return NULL; sdi->probes = g_slist_append(sdi->probes, probe); } @@ -512,15 +495,12 @@ static GSList *hw_scan(GSList *options) return devices; } -static int hw_dev_open(int dev_index) +static int hw_dev_open(struct sr_dev_inst *sdi) { - struct sr_dev_inst *sdi; struct context *ctx; int ret; int64_t timediff_us, timediff_ms; - if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) - return SR_ERR; ctx = sdi->priv; /* @@ -534,7 +514,7 @@ static int hw_dev_open(int dev_index) g_usleep(300 * 1000); timediff_ms = 0; while (timediff_ms < MAX_RENUM_DELAY_MS) { - if ((ret = fx2lafw_dev_open(dev_index)) == SR_OK) + if ((ret = fx2lafw_dev_open(sdi)) == SR_OK) break; g_usleep(100 * 1000); @@ -544,7 +524,7 @@ static int hw_dev_open(int dev_index) } sr_info("fx2lafw: Device came back after %d ms.", timediff_ms); } else { - ret = fx2lafw_dev_open(dev_index); + ret = fx2lafw_dev_open(sdi); } if (ret != SR_OK) { @@ -575,7 +555,7 @@ static int hw_dev_open(int dev_index) if (ctx->cur_samplerate == 0) { /* Samplerate hasn't been set; default to the slowest one. */ - if (hw_dev_config_set(dev_index, SR_HWCAP_SAMPLERATE, + if (hw_dev_config_set(sdi, SR_HWCAP_SAMPLERATE, &supported_samplerates[0]) == SR_ERR) return SR_ERR; } @@ -583,17 +563,20 @@ static int hw_dev_open(int dev_index) return SR_OK; } -static int hw_dev_close(int dev_index) +static int hw_dev_close(struct sr_dev_inst *sdi) { - struct sr_dev_inst *sdi; + struct context *ctx; - if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) { - sr_err("fx2lafw: %s: sdi was NULL.", __func__); - return SR_ERR_BUG; - } + ctx = sdi->priv; + if (ctx->usb->devhdl == NULL) + return SR_ERR; - /* TODO */ - close_dev(sdi); + sr_info("fx2lafw: Closing device %d on %d.%d interface %d.", + sdi->index, ctx->usb->bus, ctx->usb->address, USB_INTERFACE); + libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE); + libusb_close(ctx->usb->devhdl); + ctx->usb->devhdl = NULL; + sdi->status = SR_ST_INACTIVE; return SR_OK; } @@ -611,14 +594,15 @@ static int hw_cleanup(void) return ret; } -static int hw_info_get(int dev_info_id, const void **data, +static int hw_info_get(int info_id, const void **data, const struct sr_dev_inst *sdi) { struct context *ctx; - switch (dev_info_id) { - case SR_DI_INST: - return sdi; + switch (info_id) { + case SR_DI_HWCAPS: + *data = hwcaps; + break; case SR_DI_NUM_PROBES: if (sdi) { ctx = sdi->priv; @@ -651,30 +635,12 @@ static int hw_info_get(int dev_info_id, const void **data, return SR_OK; } -static int hw_dev_status_get(int dev_index) -{ - const struct sr_dev_inst *const sdi = - sr_dev_inst_get(fdi->instances, dev_index); - - if (!sdi) - return SR_ST_NOT_FOUND; - - return sdi->status; -} - -static const int *hw_hwcap_get_all(void) -{ - return hwcaps; -} - -static int hw_dev_config_set(int dev_index, int hwcap, const void *value) +static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, + const void *value) { - struct sr_dev_inst *sdi; struct context *ctx; int ret; - if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) - return SR_ERR; ctx = sdi->priv; if (hwcap == SR_HWCAP_SAMPLERATE) { @@ -949,9 +915,9 @@ static unsigned int get_timeout(struct context *ctx) return timeout + timeout / 4; /* Leave a headroom of 25% percent */ } -static int hw_dev_acquisition_start(int dev_index, void *cb_data) +static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, + void *cb_data) { - struct sr_dev_inst *sdi; struct sr_datafeed_packet packet; struct sr_datafeed_header header; struct sr_datafeed_meta_logic meta; @@ -962,10 +928,7 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) int ret; unsigned char *buf; - if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) - return SR_ERR; ctx = sdi->priv; - if (ctx->submitted_transfers != 0) return SR_ERR; @@ -1031,16 +994,13 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data) } /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ -static int hw_dev_acquisition_stop(int dev_index, void *cb_data) +static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, + void *cb_data) { - struct sr_dev_inst *sdi; /* Avoid compiler warnings. */ (void)cb_data; - if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) - return SR_ERR; - abort_acquisition(sdi->priv); return SR_OK; @@ -1056,8 +1016,6 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info = { .dev_open = hw_dev_open, .dev_close = hw_dev_close, .info_get = hw_info_get, - .dev_status_get = hw_dev_status_get, - .hwcap_get_all = hw_hwcap_get_all, .dev_config_set = hw_dev_config_set, .dev_acquisition_start = hw_dev_acquisition_start, .dev_acquisition_stop = hw_dev_acquisition_stop,