]> sigrok.org Git - libsigrok.git/blobdiff - hardware/saleae-logic16/api.c
probe_groups: API changes required to implement probe groups.
[libsigrok.git] / hardware / saleae-logic16 / api.c
index baaf0e487b33313ae0d2ca2bbc7e79d50c770a1f..e399729e9b09d9d5a9dae883cc42ca744c0135f6 100644 (file)
@@ -30,7 +30,6 @@
 
 #define LOGIC16_VID            0x21a9
 #define LOGIC16_PID            0x1001
-#define NUM_PROBES             16
 
 #define USB_INTERFACE          0
 #define USB_CONFIGURATION      1
@@ -56,7 +55,7 @@ static const int32_t hwcaps[] = {
        SR_CONF_CONTINUOUS,
 };
 
-static const char *probe_names[NUM_PROBES + 1] = {
+static const char *probe_names[] = {
        "0", "1", "2", "3", "4", "5", "6", "7", "8",
        "9", "10", "11", "12", "13", "14", "15",
        NULL,
@@ -238,11 +237,7 @@ static GSList *scan(GSList *options)
 
 static GSList *dev_list(void)
 {
-       struct drv_context *drvc;
-
-       drvc = di->priv;
-
-       return drvc->instances;
+       return ((struct drv_context *)(di->priv))->instances;
 }
 
 static int dev_clear(void)
@@ -313,6 +308,20 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
                        break;
                }
 
+               ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
+               if (ret == LIBUSB_ERROR_BUSY) {
+                       sr_err("Unable to claim USB interface. Another "
+                              "program or driver has already claimed it.");
+                       break;
+               } else if (ret == LIBUSB_ERROR_NO_DEVICE) {
+                       sr_err("Device has been disconnected.");
+                       break;
+               } else if (ret != 0) {
+                       sr_err("Unable to claim interface: %s.",
+                              libusb_error_name(ret));
+                       break;
+               }
+
                if ((ret = logic16_init_device(sdi)) != SR_OK) {
                        sr_err("Failed to init device.");
                        break;
@@ -326,21 +335,25 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
        }
        libusb_free_device_list(devlist, 1);
 
-       if (sdi->status != SR_ST_ACTIVE)
+       if (sdi->status != SR_ST_ACTIVE) {
+               if (usb->devhdl) {
+                       libusb_release_interface(usb->devhdl, USB_INTERFACE);
+                       libusb_close(usb->devhdl);
+                       usb->devhdl = NULL;
+               }
                return SR_ERR;
+       }
 
        return SR_OK;
 }
 
 static int dev_open(struct sr_dev_inst *sdi)
 {
-       struct sr_usb_dev_inst *usb;
        struct dev_context *devc;
        int ret;
        int64_t timediff_us, timediff_ms;
 
        devc = sdi->priv;
-       usb = sdi->conn;
 
        /*
         * If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
@@ -376,25 +389,6 @@ static int dev_open(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
-       ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
-       if (ret != 0) {
-               switch (ret) {
-               case LIBUSB_ERROR_BUSY:
-                       sr_err("Unable to claim USB interface. Another "
-                              "program or driver has already claimed it.");
-                       break;
-               case LIBUSB_ERROR_NO_DEVICE:
-                       sr_err("Device has been disconnected.");
-                       break;
-               default:
-                       sr_err("Unable to claim interface: %s.",
-                              libusb_error_name(ret));
-                       break;
-               }
-
-               return SR_ERR;
-       }
-
        if (devc->cur_samplerate == 0) {
                /* Samplerate hasn't been set; default to the slowest one. */
                devc->cur_samplerate = samplerates[0];
@@ -437,7 +431,8 @@ static int cleanup(void)
        return ret;
 }
 
-static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
+static int config_get(int key, 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;
@@ -446,6 +441,8 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
        int ret;
        unsigned int i;
 
+       (void)probe_group;
+
        ret = SR_OK;
        switch (key) {
        case SR_CONF_CONN:
@@ -488,13 +485,16 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
        return ret;
 }
 
-static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
+static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
+               const struct sr_probe_group *probe_group)
 {
        struct dev_context *devc;
        gdouble low, high;
        int ret;
        unsigned int i;
 
+       (void)probe_group;
+
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
@@ -528,7 +528,8 @@ static int config_set(int key, 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)
 {
        GVariant *gvar, *range[2];
        GVariantBuilder gvb;
@@ -536,6 +537,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
        unsigned int i;
 
        (void)sdi;
+       (void)probe_group;
 
        ret = SR_OK;
        switch (key) {