]> sigrok.org Git - libsigrok.git/blobdiff - hardware/sysclk-lwla/api.c
sysclk-lwla: Advertise SR_CONF_CONN option.
[libsigrok.git] / hardware / sysclk-lwla / api.c
index e20564a56232cee28ceb13e590f6bf67a56dc4cb..5bae5d5499225e9b1d39c60641ba7b3e66a353a1 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
+static const int32_t hwopts[] = {
+       SR_CONF_CONN,
+};
+
 static const int32_t hwcaps[] = {
        SR_CONF_LOGIC_ANALYZER,
        SR_CONF_SAMPLERATE,
        SR_CONF_EXTERNAL_CLOCK,
        SR_CONF_TRIGGER_TYPE,
+       SR_CONF_LIMIT_MSEC,
        SR_CONF_LIMIT_SAMPLES,
 };
 
@@ -65,7 +70,7 @@ static GSList *gen_probe_list(int num_probes)
 
        for (i = num_probes; i > 0; --i) {
                /* The LWLA series simply number probes from CH1 to CHxx. */
-               g_ascii_formatd(name, sizeof name, "CH%.0f", i);
+               g_snprintf(name, sizeof(name), "CH%d", i);
 
                probe = sr_probe_new(i - 1, SR_PROBE_LOGIC, TRUE, name);
                list = g_slist_prepend(list, probe);
@@ -254,6 +259,9 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
        case SR_CONF_SAMPLERATE:
                *data = g_variant_new_uint64(devc->samplerate);
                break;
+       case SR_CONF_LIMIT_MSEC:
+               *data = g_variant_new_uint64(devc->limit_msec);
+               break;
        case SR_CONF_LIMIT_SAMPLES:
                *data = g_variant_new_uint64(devc->limit_samples);
                break;
@@ -271,8 +279,8 @@ static int config_get(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)
 {
+       uint64_t value;
        struct dev_context *devc;
-       uint64_t rate;
 
        (void)probe_group;
 
@@ -282,15 +290,23 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
 
        switch (key) {
        case SR_CONF_SAMPLERATE:
-               rate = g_variant_get_uint64(data);
-               sr_info("Setting samplerate %" G_GUINT64_FORMAT, rate);
-               if (rate > samplerates[0]
-                   || rate < samplerates[G_N_ELEMENTS(samplerates) - 1])
+               value = g_variant_get_uint64(data);
+               if (value < samplerates[G_N_ELEMENTS(samplerates) - 1]
+                               || value > samplerates[0])
                        return SR_ERR_SAMPLERATE;
-               devc->samplerate = rate;
+               devc->samplerate = value;
+               break;
+       case SR_CONF_LIMIT_MSEC:
+               value = g_variant_get_uint64(data);
+               if (value > MAX_LIMIT_MSEC)
+                       return SR_ERR_ARG;
+               devc->limit_msec = value;
                break;
        case SR_CONF_LIMIT_SAMPLES:
-               devc->limit_samples = g_variant_get_uint64(data);
+               value = g_variant_get_uint64(data);
+               if (value > MAX_LIMIT_SAMPLES)
+                       return SR_ERR_ARG;
+               devc->limit_samples = value;
                break;
        case SR_CONF_EXTERNAL_CLOCK:
                if (g_variant_get_boolean(data)) {
@@ -321,14 +337,18 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
        (void)probe_group;
 
        switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+                               hwopts, G_N_ELEMENTS(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));
+                               hwcaps, G_N_ELEMENTS(hwcaps), sizeof(int32_t));
                break;
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
-                               samplerates, ARRAY_SIZE(samplerates),
+                               samplerates, G_N_ELEMENTS(samplerates),
                                sizeof(uint64_t));
                g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
                *data = g_variant_builder_end(&gvb);
@@ -357,18 +377,17 @@ static int configure_probes(const struct sr_dev_inst *sdi)
        devc->trigger_edge_mask = 0;
        devc->trigger_values = 0;
 
-       for (node = sdi->probes, probe_bit = 1;
-                       node != NULL;
-                       node = node->next, probe_bit <<= 1) {
-
-               if (probe_bit >= ((uint64_t)1 << NUM_PROBES)) {
-                       sr_err("Channels over the limit of %d.", NUM_PROBES);
-                       return SR_ERR;
-               }
+       for (node = sdi->probes; node != NULL; node = node->next) {
                probe = node->data;
                if (!probe || !probe->enabled)
                        continue;
 
+               if (probe->index >= NUM_PROBES) {
+                       sr_err("Channel index %d out of range.", probe->index);
+                       return SR_ERR_BUG;
+               }
+               probe_bit = (uint64_t)1 << probe->index;
+
                /* Enable input channel for this probe. */
                devc->channel_mask |= probe_bit;