]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/fx2lafw/api.c
fx2lafw: Only sample/send analog data if analog channels are enabled.
[libsigrok.git] / src / hardware / fx2lafw / api.c
index e1eb3ee13ce3e600b3bc212b4048324885b482e1..1ad9bedc56b3b18e83096d7b646c24510f3fc497 100644 (file)
@@ -47,6 +47,13 @@ static const struct fx2lafw_profile supported_fx2[] = {
                "fx2lafw-cwav-usbeesx.fw",
                0, NULL, NULL},
 
+       /*
+        * CWAV USBee ZX
+        */
+       { 0x08a9, 0x0005, "CWAV", "USBee ZX", NULL,
+               "fx2lafw-cwav-usbeezx.fw",
+               0, NULL, NULL},
+
        /* DreamSourceLab DSLogic (before FW upload) */
        { 0x2a0e, 0x0001, "DreamSourceLab", "DSLogic", NULL,
                "dreamsourcelab-dslogic-fx2.fw",
@@ -207,6 +214,20 @@ static const uint64_t dslogic_samplerates[] = {
        SR_MHZ(400),
 };
 
+static gboolean is_plausible(const struct libusb_device_descriptor *des)
+{
+       int i;
+
+       for (i = 0; supported_fx2[i].vid; i++) {
+               if (des->idVendor != supported_fx2[i].vid)
+                       continue;
+               if (des->idProduct == supported_fx2[i].pid)
+                       return TRUE;
+       }
+
+       return FALSE;
+}
+
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        struct drv_context *drvc;
@@ -264,8 +285,15 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                libusb_get_device_descriptor( devlist[i], &des);
 
-               if ((ret = libusb_open(devlist[i], &hdl)) < 0)
+               if (!is_plausible(&des))
+                       continue;
+
+               if ((ret = libusb_open(devlist[i], &hdl)) < 0) {
+                       sr_warn("Failed to open potential device with "
+                               "VID:PID %04x:%04x: %s.", des.idVendor,
+                               des.idProduct, libusb_error_name(ret));
                        continue;
+               }
 
                if (des.iManufacturer == 0) {
                        manufacturer[0] = '\0';
@@ -307,7 +335,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                                        des.idProduct == supported_fx2[j].pid &&
                                        (!supported_fx2[j].usb_manufacturer ||
                                         !strcmp(manufacturer, supported_fx2[j].usb_manufacturer)) &&
-                                       (!supported_fx2[j].usb_manufacturer ||
+                                       (!supported_fx2[j].usb_product ||
                                         !strcmp(product, supported_fx2[j].usb_product))) {
                                prof = &supported_fx2[j];
                                break;
@@ -355,8 +383,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                devc = fx2lafw_dev_new();
                devc->profile = prof;
-               if ((prof->dev_caps & DEV_CAPS_16BIT) || (prof->dev_caps & DEV_CAPS_AX_ANALOG))
-                       devc->sample_wide = TRUE;
                sdi->priv = devc;
                devices = g_slist_append(devices, sdi);
 
@@ -852,7 +878,12 @@ static int start_transfers(const struct sr_dev_inst *sdi)
                devc->submitted_transfers++;
        }
 
-       if (devc->profile->dev_caps & DEV_CAPS_AX_ANALOG)
+       /*
+        * If this device has analog channels and at least one of them is
+        * enabled, use mso_send_data_proc() to properly handle the analog
+        * data. Otherwise use la_send_data_proc().
+        */
+       if (g_slist_length(devc->enabled_analog_channels) > 0)
                devc->send_data_proc = mso_send_data_proc;
        else
                devc->send_data_proc = la_send_data_proc;
@@ -953,22 +984,31 @@ static int configure_channels(const struct sr_dev_inst *sdi)
        const GSList *l;
        int p;
        struct sr_channel *ch;
+       uint32_t channel_mask = 0, num_analog = 0;
 
        devc = sdi->priv;
 
        g_slist_free(devc->enabled_analog_channels);
        devc->enabled_analog_channels = NULL;
-       memset(devc->ch_enabled, 0, sizeof(devc->ch_enabled));
 
        for (l = sdi->channels, p = 0; l; l = l->next, p++) {
                ch = l->data;
-               if ((p <= NUM_CHANNELS) && (ch->type == SR_CHANNEL_ANALOG)) {
-                       devc->ch_enabled[p] = ch->enabled;
+               if ((p <= NUM_CHANNELS) && (ch->type == SR_CHANNEL_ANALOG)
+                               && (ch->enabled)) {
+                       num_analog++;
                        devc->enabled_analog_channels =
                            g_slist_append(devc->enabled_analog_channels, ch);
+               } else {
+                       channel_mask |= ch->enabled << p;
                }
        }
 
+       /*
+        * Use wide sampling if either any of the LA channels 8..15 is enabled
+        * and/or at least one analog channel is enabled.
+        */
+       devc->sample_wide = (channel_mask > 0xff || num_analog > 0);
+
        return SR_OK;
 }
 
@@ -1005,7 +1045,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        } else {
                size = fx2lafw_get_buffer_size(devc);
                /* Prepare for analog sampling. */
-               if (devc->profile->dev_caps & DEV_CAPS_AX_ANALOG) {
+               if (g_slist_length(devc->enabled_analog_channels) > 0) {
                        /* We need a buffer half the size of a transfer. */
                        devc->logic_buffer = g_try_malloc(size / 2);
                        devc->analog_buffer = g_try_malloc(