]> sigrok.org Git - libsigrok.git/blobdiff - hardware/fx2lafw/fx2lafw.c
sr: remove obsolete SR_DI_INST
[libsigrok.git] / hardware / fx2lafw / fx2lafw.c
index 2cf9c0f5d4883edb89eb1b23bb5d28efe9ad8400..7a83b58ba53e1b89b846c7dc68f7bd5de4f99895 100644 (file)
@@ -143,9 +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_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(int dev_index, void *cb_data);
+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.
@@ -191,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)
@@ -229,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;
@@ -298,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;
@@ -333,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;
 
@@ -400,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);
        }
@@ -471,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. */
@@ -479,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);
                }
 
@@ -513,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;
 
        /*
@@ -535,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);
 
@@ -545,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) {
@@ -584,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;
 }
@@ -618,9 +600,6 @@ static int hw_info_get(int info_id, const void **data,
        struct context *ctx;
 
        switch (info_id) {
-       case SR_DI_INST:
-               *data = sdi;
-               break;
        case SR_DI_HWCAPS:
                *data = hwcaps;
                break;
@@ -656,17 +635,6 @@ static int hw_info_get(int 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 int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
                const void *value)
 {
@@ -947,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;
@@ -960,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;
 
@@ -1029,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;
@@ -1054,7 +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,
        .dev_config_set = hw_dev_config_set,
        .dev_acquisition_start = hw_dev_acquisition_start,
        .dev_acquisition_stop = hw_dev_acquisition_stop,