]> sigrok.org Git - libsigrok.git/blobdiff - hardware/fx2lafw/fx2lafw.c
Don't automatically clear known instances from USB drivers on scan
[libsigrok.git] / hardware / fx2lafw / fx2lafw.c
index 270601e9f7a27fc80f80cc557076a8a6c6a9db6b..9647c4b0e903cf92b439d73f1f7175fd1b1e450e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
  * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
  * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
@@ -81,6 +81,10 @@ static const struct fx2lafw_profile supported_fx2[] = {
        { 0, 0, 0, 0, 0, 0, 0 }
 };
 
+static const int32_t hwopts[] = {
+       SR_CONF_CONN,
+};
+
 static const int32_t hwcaps[] = {
        SR_CONF_LOGIC_ANALYZER,
        SR_CONF_TRIGGER_TYPE,
@@ -365,13 +369,8 @@ static GSList *hw_scan(GSList *options)
        int devcnt, num_logic_probes, ret, i, j;
        const char *conn;
 
-       (void)options;
-
        drvc = di->priv;
 
-       /* This scan always invalidates any previous scans. */
-       clear_instances();
-
        conn = NULL;
        for (l = options; l; l = l->next) {
                src = l->data;
@@ -582,14 +581,26 @@ static int hw_cleanup(void)
 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
+       struct sr_usb_dev_inst *usb;
+       char str[128];
 
        switch (id) {
+       case SR_CONF_CONN:
+               if (!sdi || !sdi->conn)
+                       return SR_ERR_ARG;
+               usb = sdi->conn;
+               if (usb->address == 255)
+                       /* Device still needs to re-enumerate after firmware
+                        * upload, so we don't know its (future) address. */
+                       return SR_ERR;
+               snprintf(str, 128, "%d.%d", usb->bus, usb->address);
+               *data = g_variant_new_string(str);
+               break;
        case SR_CONF_SAMPLERATE:
-               if (sdi) {
-                       devc = sdi->priv;
-                       *data = g_variant_new_uint64(devc->cur_samplerate);
-               } else
+               if (!sdi)
                        return SR_ERR;
+               devc = sdi->priv;
+               *data = g_variant_new_uint64(devc->cur_samplerate);
                break;
        default:
                return SR_ERR_NA;
@@ -603,6 +614,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        int ret;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR;
+
        devc = sdi->priv;
 
        if (id == SR_CONF_SAMPLERATE) {
@@ -626,6 +640,10 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
        (void)sdi;
 
        switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+                               hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
+               break;
        case SR_CONF_DEVICE_OPTIONS:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
                                hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
@@ -930,6 +948,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        unsigned char *buf;
        size_t size;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        drvc = di->priv;
        devc = sdi->priv;
        usb = sdi->conn;