]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/fx2lafw/api.c
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / hardware / fx2lafw / api.c
index a2de010a27defc3464fb7f0188093fe2aaa9d48f..255788bfdd0731233ca75e0a9454bb7021ce5de2 100644 (file)
@@ -105,11 +105,19 @@ static const struct fx2lafw_profile supported_fx2[] = {
                "fx2lafw-sigrok-fx2-16ch.fw",
                DEV_CAPS_16BIT, NULL, NULL },
 
+       /*
+        * usb-c-grok
+        */
+       { 0x1d50, 0x608f, "sigrok", "usb-c-grok", NULL,
+               "fx2lafw-usb-c-grok.fw",
+               0, NULL, NULL},
+
        ALL_ZERO
 };
 
 static const uint32_t scanopts[] = {
        SR_CONF_CONN,
+       SR_CONF_PROBE_NAMES,
 };
 
 static const uint32_t drvopts[] = {
@@ -118,6 +126,7 @@ static const uint32_t drvopts[] = {
 
 static const uint32_t devopts[] = {
        SR_CONF_CONTINUOUS,
+       SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_CONN | SR_CONF_GET,
        SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
@@ -150,6 +159,16 @@ static const uint64_t samplerates[] = {
        SR_MHZ(12),
        SR_MHZ(16),
        SR_MHZ(24),
+       SR_MHZ(48),
+};
+
+static const char *channel_names_logic[] = {
+       "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
+       "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
+};
+
+static const char *channel_names_analog[] = {
+       "A0", "A1", "A2", "A3",
 };
 
 static gboolean is_plausible(const struct libusb_device_descriptor *des)
@@ -181,21 +200,27 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        struct libusb_device_descriptor des;
        libusb_device **devlist;
        struct libusb_device_handle *hdl;
-       int ret, i, j;
-       int num_logic_channels = 0, num_analog_channels = 0;
+       int ret, i;
+       size_t j, num_logic_channels, num_analog_channels;
        const char *conn;
+       const char *probe_names;
        char manufacturer[64], product[64], serial_num[64], connection_id[64];
-       char channel_name[16];
+       size_t ch_max, ch_idx;
+       const char *channel_name;
 
        drvc = di->context;
 
        conn = NULL;
+       probe_names = 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;
+               case SR_CONF_PROBE_NAMES:
+                       probe_names = g_variant_get_string(src->data, NULL);
+                       break;
                }
        }
        if (conn)
@@ -263,10 +288,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                        continue;
                }
 
-               usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
-
                libusb_close(hdl);
 
+               if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0)
+                       continue;
+
                prof = NULL;
                for (j = 0; supported_fx2[j].vid; j++) {
                        if (des.idVendor == supported_fx2[j].vid &&
@@ -291,38 +317,56 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                sdi->serial_num = g_strdup(serial_num);
                sdi->connection_id = g_strdup(connection_id);
 
+               devc = fx2lafw_dev_new();
+               devc->profile = prof;
+               sdi->priv = devc;
+               devices = g_slist_append(devices, sdi);
+
                /* Fill in channellist according to this device's profile. */
                num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8;
+               if (num_logic_channels > ARRAY_SIZE(channel_names_logic))
+                       num_logic_channels = ARRAY_SIZE(channel_names_logic);
                num_analog_channels = prof->dev_caps & DEV_CAPS_AX_ANALOG ? 1 : 0;
+               if (num_analog_channels > ARRAY_SIZE(channel_names_analog))
+                       num_analog_channels = ARRAY_SIZE(channel_names_analog);
+
+               /*
+                * Allow user specs to override the builtin probe names.
+                *
+                * Implementor's note: Because the device's number of
+                * logic channels is not known at compile time, and thus
+                * the location of the analog channel names is not known
+                * at compile time, and the construction of a list with
+                * default names at runtime is not done here, and we
+                * don't want to keep several default lists around, this
+                * implementation only supports to override the names of
+                * logic probes. The use case which motivated the config
+                * key is protocol decoders, which are logic only.
+                */
+               ch_max = num_logic_channels;
+               devc->channel_names = sr_parse_probe_names(probe_names,
+                       channel_names_logic, ch_max, ch_max, &ch_max);
+               ch_idx = 0;
 
                /* Logic channels, all in one channel group. */
-               cg = g_malloc0(sizeof(struct sr_channel_group));
-               cg->name = g_strdup("Logic");
+               cg = sr_channel_group_new(sdi, "Logic", NULL);
                for (j = 0; j < num_logic_channels; j++) {
-                       sprintf(channel_name, "D%d", j);
-                       ch = sr_channel_new(sdi, j, SR_CHANNEL_LOGIC,
-                                               TRUE, channel_name);
+                       channel_name = devc->channel_names[j];
+                       ch = sr_channel_new(sdi, ch_idx++, SR_CHANNEL_LOGIC,
+                               TRUE, channel_name);
                        cg->channels = g_slist_append(cg->channels, ch);
                }
-               sdi->channel_groups = g_slist_append(NULL, cg);
 
                for (j = 0; j < num_analog_channels; j++) {
-                       snprintf(channel_name, 16, "A%d", j);
-                       ch = sr_channel_new(sdi, j + num_logic_channels,
-                                       SR_CHANNEL_ANALOG, TRUE, channel_name);
+                       channel_name = channel_names_analog[j];
+                       ch = sr_channel_new(sdi, ch_idx++, SR_CHANNEL_ANALOG,
+                               TRUE, channel_name);
 
                        /* Every analog channel gets its own channel group. */
-                       cg = g_malloc0(sizeof(struct sr_channel_group));
-                       cg->name = g_strdup(channel_name);
+                       cg = sr_channel_group_new(sdi, channel_name, NULL);
                        cg->channels = g_slist_append(NULL, ch);
-                       sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
                }
 
-               devc = fx2lafw_dev_new();
-               devc->profile = prof;
-               sdi->priv = devc;
-               devices = g_slist_append(devices, sdi);
-
                devc->samplerates = samplerates;
                devc->num_samplerates = ARRAY_SIZE(samplerates);
                has_firmware = usb_match_manuf_prod(devlist[i],
@@ -337,14 +381,16 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                                        libusb_get_device_address(devlist[i]), NULL);
                } else {
                        if (ezusb_upload_firmware(drvc->sr_ctx, devlist[i],
-                                       USB_CONFIGURATION, prof->firmware) == SR_OK)
+                                       USB_CONFIGURATION, prof->firmware) == SR_OK) {
                                /* Store when this device's FW was updated. */
                                devc->fw_updated = g_get_monotonic_time();
-                       else
+                       } else {
                                sr_err("Firmware upload failed for "
-                                      "device %d.%d (logical).",
+                                      "device %d.%d (logical), name %s.",
                                       libusb_get_bus_number(devlist[i]),
-                                      libusb_get_device_address(devlist[i]));
+                                      libusb_get_device_address(devlist[i]),
+                                      prof->firmware);
+                       }
                        sdi->inst_type = SR_INST_USB;
                        sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
                                        0xff, NULL);
@@ -480,6 +526,9 @@ static int config_get(uint32_t key, GVariant **data,
                        return SR_ERR;
                *data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
                break;
+       case SR_CONF_LIMIT_FRAMES:
+               *data = g_variant_new_uint64(devc->limit_frames);
+               break;
        case SR_CONF_LIMIT_SAMPLES:
                *data = g_variant_new_uint64(devc->limit_samples);
                break;
@@ -515,6 +564,9 @@ static int config_set(uint32_t key, GVariant *data,
                        return SR_ERR_ARG;
                devc->cur_samplerate = devc->samplerates[idx];
                break;
+       case SR_CONF_LIMIT_FRAMES:
+               devc->limit_frames = g_variant_get_uint64(data);
+               break;
        case SR_CONF_LIMIT_SAMPLES:
                devc->limit_samples = g_variant_get_uint64(data);
                break;
@@ -538,8 +590,12 @@ static int config_list(uint32_t key, GVariant **data,
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
        case SR_CONF_DEVICE_OPTIONS:
+               if (cg)
+                       return SR_ERR_NA;
                return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
+               if (!devc)
+                       return SR_ERR_NA;
                *data = std_gvar_samplerates(devc->samplerates, devc->num_samplerates);
                break;
        case SR_CONF_TRIGGER_MATCH: