]> sigrok.org Git - libsigrok.git/blobdiff - hardware/zeroplus-logic-cube/api.c
Replace 'probe' with 'channel' in most places.
[libsigrok.git] / hardware / zeroplus-logic-cube / api.c
index 84f830a6f96e4b5036729b524a1c692a213c5025..69e1441158ea4428934b27aad13e2a00e735e373 100644 (file)
@@ -57,14 +57,15 @@ static const int32_t hwcaps[] = {
        SR_CONF_LOGIC_ANALYZER,
        SR_CONF_SAMPLERATE,
        SR_CONF_CAPTURE_RATIO,
+       SR_CONF_VOLTAGE_THRESHOLD,
        SR_CONF_LIMIT_SAMPLES,
 };
 
 /*
- * ZEROPLUS LAP-C (16032) numbers the 16 probes A0-A7 and B0-B7.
+ * ZEROPLUS LAP-C (16032) numbers the 16 channels A0-A7 and B0-B7.
  * We currently ignore other untested/unsupported devices here.
  */
-static const char *probe_names[] = {
+static const char *channel_names[] = {
        "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7",
        "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7",
        "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7",
@@ -123,37 +124,37 @@ const uint64_t samplerates_200[] = {
 static int dev_close(struct sr_dev_inst *sdi);
 
 #if 0
-static int configure_probes(const struct sr_dev_inst *sdi)
+static int configure_channels(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
-       const struct sr_probe *probe;
+       const struct sr_channel *ch;
        const GSList *l;
-       int probe_bit, stage, i;
+       int channel_bit, stage, i;
        char *tc;
 
        /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */
        devc = sdi->priv;
 
-       devc->probe_mask = 0;
+       devc->channel_mask = 0;
        for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
                devc->trigger_mask[i] = 0;
                devc->trigger_value[i] = 0;
        }
 
        stage = -1;
-       for (l = sdi->probes; l; l = l->next) {
-               probe = (struct sr_probe *)l->data;
-               if (probe->enabled == FALSE)
+       for (l = sdi->channels; l; l = l->next) {
+               ch = (struct sr_channel *)l->data;
+               if (ch->enabled == FALSE)
                        continue;
-               probe_bit = 1 << (probe->index);
-               devc->probe_mask |= probe_bit;
+               channel_bit = 1 << (ch->index);
+               devc->channel_mask |= channel_bit;
 
-               if (probe->trigger) {
+               if (ch->trigger) {
                        stage = 0;
-                       for (tc = probe->trigger; *tc; tc++) {
-                               devc->trigger_mask[stage] |= probe_bit;
+                       for (tc = ch->trigger; *tc; tc++) {
+                               devc->trigger_mask[stage] |= channel_bit;
                                if (*tc == '1')
-                                       devc->trigger_value[stage] |= probe_bit;
+                                       devc->trigger_value[stage] |= channel_bit;
                                stage++;
                                if (stage > NUM_TRIGGER_STAGES)
                                        return SR_ERR;
@@ -165,23 +166,23 @@ static int configure_probes(const struct sr_dev_inst *sdi)
 }
 #endif
 
-static int configure_probes(const struct sr_dev_inst *sdi)
+static int configure_channels(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        const GSList *l;
-       const struct sr_probe *probe;
+       const struct sr_channel *ch;
        char *tc;
        int type;
 
        /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */
        devc = sdi->priv;
 
-       for (l = sdi->probes; l; l = l->next) {
-               probe = (struct sr_probe *)l->data;
-               if (probe->enabled == FALSE)
+       for (l = sdi->channels; l; l = l->next) {
+               ch = (struct sr_channel *)l->data;
+               if (ch->enabled == FALSE)
                        continue;
 
-               if ((tc = probe->trigger)) {
+               if ((tc = ch->trigger)) {
                        switch (*tc) {
                        case '1':
                                type = TRIGGER_HIGH;
@@ -203,7 +204,7 @@ static int configure_probes(const struct sr_dev_inst *sdi)
                        default:
                                return SR_ERR;
                        }
-                       analyzer_add_trigger(probe->index, type);
+                       analyzer_add_trigger(ch->index, type);
                        devc->trigger = 1;
                }
        }
@@ -238,11 +239,6 @@ SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate)
        return SR_OK;
 }
 
-static int dev_clear(void)
-{
-       return std_dev_clear(di, NULL);
-}
-
 static int init(struct sr_context *sr_ctx)
 {
        return std_init(sr_ctx, di, LOG_PREFIX);
@@ -251,7 +247,7 @@ static int init(struct sr_context *sr_ctx)
 static GSList *scan(GSList *options)
 {
        struct sr_dev_inst *sdi;
-       struct sr_probe *probe;
+       struct sr_channel *ch;
        struct drv_context *drvc;
        struct dev_context *devc;
        const struct zp_model *prof;
@@ -318,12 +314,12 @@ static GSList *scan(GSList *options)
                devc->memory_size = MEMORY_SIZE_8K;
                // memset(devc->trigger_buffer, 0, NUM_TRIGGER_STAGES);
 
-               /* Fill in probelist according to this device's profile. */
+               /* Fill in channellist according to this device's profile. */
                for (j = 0; j < devc->num_channels; j++) {
-                       if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE,
-                                       probe_names[j])))
+                       if (!(ch = sr_probe_new(j, SR_PROBE_LOGIC, TRUE,
+                                       channel_names[j])))
                                return NULL;
-                       sdi->probes = g_slist_append(sdi->probes, probe);
+                       sdi->channels = g_slist_append(sdi->channels, ch);
                }
 
                devices = g_slist_append(devices, sdi);
@@ -439,6 +435,9 @@ static int dev_open(struct sr_dev_inst *sdi)
                devc->cur_samplerate = SR_MHZ(1);
        }
 
+       if (devc->cur_threshold == 0)
+               set_voltage_threshold(devc, 1.5);
+
        return SR_OK;
 }
 
@@ -464,15 +463,15 @@ static int dev_close(struct sr_dev_inst *sdi)
 
 static int cleanup(void)
 {
-       return dev_clear();
+       return std_dev_clear(di, NULL);
 }
 
 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
-               const struct sr_probe_group *probe_group)
+               const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
 
-       (void)probe_group;
+       (void)cg;
 
        switch (id) {
        case SR_CONF_SAMPLERATE:
@@ -482,14 +481,24 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
                        sr_spew("Returning samplerate: %" PRIu64 "Hz.",
                                devc->cur_samplerate);
                } else
-                       return SR_ERR;
+                       return SR_ERR_ARG;
                break;
        case SR_CONF_CAPTURE_RATIO:
                if (sdi) {
                        devc = sdi->priv;
                        *data = g_variant_new_uint64(devc->capture_ratio);
                } else
-                       return SR_ERR;
+                       return SR_ERR_ARG;
+               break;
+       case SR_CONF_VOLTAGE_THRESHOLD:
+               if (sdi) {
+                       GVariant *range[2];
+                       devc = sdi->priv;
+                       range[0] = g_variant_new_double(devc->cur_threshold);
+                       range[1] = g_variant_new_double(devc->cur_threshold);
+                       *data = g_variant_new_tuple(range, 2);
+               } else
+                       return SR_ERR_ARG;
                break;
        default:
                return SR_ERR_NA;
@@ -499,11 +508,12 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
 }
 
 static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
-               const struct sr_probe_group *probe_group)
+               const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
+       gdouble low, high;
 
-       (void)probe_group;
+       (void)cg;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
@@ -520,6 +530,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
                return set_limit_samples(devc, g_variant_get_uint64(data));
        case SR_CONF_CAPTURE_RATIO:
                return set_capture_ratio(devc, g_variant_get_uint64(data));
+       case SR_CONF_VOLTAGE_THRESHOLD:
+               g_variant_get(data, "(dd)", &low, &high);
+               return set_voltage_threshold(devc, (low + high) / 2.0);
        default:
                return SR_ERR_NA;
        }
@@ -528,13 +541,15 @@ static int config_set(int id, 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)
+               const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
-       GVariant *gvar;
+       GVariant *gvar, *grange[2];
        GVariantBuilder gvb;
+       double v;
+       GVariant *range[2];
 
-       (void)probe_group;
+       (void)cg;
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
@@ -563,6 +578,24 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
        case SR_CONF_TRIGGER_TYPE:
                *data = g_variant_new_string(TRIGGER_TYPE);
                break;
+       case SR_CONF_VOLTAGE_THRESHOLD:
+               g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
+               for (v = -6.0; v <= 6.0; v += 0.1) {
+                       range[0] = g_variant_new_double(v);
+                       range[1] = g_variant_new_double(v);
+                       gvar = g_variant_new_tuple(range, 2);
+                       g_variant_builder_add_value(&gvb, gvar);
+               }
+               *data = g_variant_builder_end(&gvb);
+               break;
+       case SR_CONF_LIMIT_SAMPLES:
+               if (!sdi)
+                       return SR_ERR_ARG;
+               devc = sdi->priv;
+               grange[0] = g_variant_new_uint64(0);
+               grange[1] = g_variant_new_uint64(devc->max_sample_depth);
+               *data = g_variant_new_tuple(grange, 2);
+               break;
        default:
                return SR_ERR_NA;
        }
@@ -601,8 +634,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR_ARG;
        }
 
-       if (configure_probes(sdi) != SR_OK) {
-               sr_err("Failed to configure probes.");
+       if (configure_channels(sdi) != SR_OK) {
+               sr_err("Failed to configure channels.");
                return SR_ERR;
        }
 
@@ -789,7 +822,7 @@ SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = {
        .cleanup = cleanup,
        .scan = scan,
        .dev_list = dev_list,
-       .dev_clear = dev_clear,
+       .dev_clear = NULL,
        .config_get = config_get,
        .config_set = config_set,
        .config_list = config_list,