]> sigrok.org Git - libsigrok.git/blobdiff - hardware/fx2lafw/fx2lafw.c
Add driver helper std_dev_clear()
[libsigrok.git] / hardware / fx2lafw / fx2lafw.c
index f4e0360fecccfe6ca85e914edb79c784a985df7b..25d47d8552561bc67771f91feabaaf3a8517086a 100644 (file)
@@ -380,15 +380,18 @@ static int hw_init(struct sr_context *sr_ctx)
 
 static GSList *hw_scan(GSList *options)
 {
-       GSList *devices;
-       struct libusb_device_descriptor des;
-       struct sr_dev_inst *sdi;
-       const struct fx2lafw_profile *prof;
        struct drv_context *drvc;
        struct dev_context *devc;
+       struct sr_dev_inst *sdi;
+       struct sr_usb_dev_inst *usb;
        struct sr_probe *probe;
+       struct sr_config *src;
+       const struct fx2lafw_profile *prof;
+       GSList *l, *devices, *conn_devices;
+       struct libusb_device_descriptor des;
        libusb_device **devlist;
        int devcnt, num_logic_probes, ret, i, j;
+       const char *conn;
 
        (void)options;
 
@@ -397,13 +400,39 @@ static GSList *hw_scan(GSList *options)
        /* This scan always invalidates any previous scans. */
        clear_instances();
 
+       conn = NULL;
+       for (l = options; l; l = l->next) {
+               src = l->data;
+               switch (src->key) {
+               case SR_CONF_CONN:
+                       conn = g_variant_get_string(src->data, NULL);
+                       break;
+               }
+       }
+       if (conn)
+               conn_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn);
+       else
+               conn_devices = NULL;
+
        /* Find all fx2lafw compatible devices and upload firmware to them. */
        devices = NULL;
        libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
        for (i = 0; devlist[i]; i++) {
+               if (conn) {
+                       usb = NULL;
+                       for (l = conn_devices; l; l = l->next) {
+                               usb = l->data;
+                               if (usb->bus == libusb_get_bus_number(devlist[i])
+                                       && usb->address == libusb_get_device_address(devlist[i]))
+                                       break;
+                       }
+                       if (!l)
+                               /* This device matched none of the ones that
+                                * matched the conn specification. */
+                               continue;
+               }
 
-               if ((ret = libusb_get_device_descriptor(
-                    devlist[i], &des)) != 0) {
+               if ((ret = libusb_get_device_descriptor( devlist[i], &des)) != 0) {
                        sr_warn("Failed to get device descriptor: %s.",
                                libusb_error_name(ret));
                        continue;
@@ -591,7 +620,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
                        return SR_ERR;
                break;
        default:
-               return SR_ERR_ARG;
+               return SR_ERR_NA;
        }
 
        return SR_OK;
@@ -611,7 +640,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
                devc->limit_samples = g_variant_get_uint64(data);
                ret = SR_OK;
        } else {
-               ret = SR_ERR;
+               ret = SR_ERR_NA;
        }
 
        return ret;
@@ -640,7 +669,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
                *data = g_variant_new_string(TRIGGER_TYPE);
                break;
        default:
-               return SR_ERR_ARG;
+               return SR_ERR_NA;
        }
 
        return SR_OK;