]> sigrok.org Git - libsigrok.git/blobdiff - hardware/zeroplus-logic-cube/api.c
zeroplus-logic-cube: Use new trigger API.
[libsigrok.git] / hardware / zeroplus-logic-cube / api.c
index 63b2efd9a9edd3b7ef3f3d0ed5dd183284ba9599..a49f07481c0469a1adcede4fa25cda98c227a0c0 100644 (file)
@@ -23,7 +23,6 @@
 #define USB_INTERFACE                  0
 #define USB_CONFIGURATION              1
 #define NUM_TRIGGER_STAGES             4
-#define TRIGGER_TYPE                   "01"
 #define PACKET_SIZE                    2048    /* ?? */
 
 //#define ZP_EXPERIMENTAL
@@ -56,16 +55,22 @@ static const struct zp_model zeroplus_models[] = {
 static const int32_t hwcaps[] = {
        SR_CONF_LOGIC_ANALYZER,
        SR_CONF_SAMPLERATE,
+       SR_CONF_TRIGGER_MATCH,
        SR_CONF_CAPTURE_RATIO,
        SR_CONF_VOLTAGE_THRESHOLD,
        SR_CONF_LIMIT_SAMPLES,
 };
 
+static const int32_t trigger_matches[] = {
+       SR_TRIGGER_ZERO,
+       SR_TRIGGER_ONE,
+};
+
 /*
- * 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,95 +128,6 @@ 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)
-{
-       struct dev_context *devc;
-       const struct sr_probe *probe;
-       const GSList *l;
-       int probe_bit, stage, i;
-       char *tc;
-
-       /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */
-       devc = sdi->priv;
-
-       devc->probe_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)
-                       continue;
-               probe_bit = 1 << (probe->index);
-               devc->probe_mask |= probe_bit;
-
-               if (probe->trigger) {
-                       stage = 0;
-                       for (tc = probe->trigger; *tc; tc++) {
-                               devc->trigger_mask[stage] |= probe_bit;
-                               if (*tc == '1')
-                                       devc->trigger_value[stage] |= probe_bit;
-                               stage++;
-                               if (stage > NUM_TRIGGER_STAGES)
-                                       return SR_ERR;
-                       }
-               }
-       }
-
-       return SR_OK;
-}
-#endif
-
-static int configure_probes(const struct sr_dev_inst *sdi)
-{
-       struct dev_context *devc;
-       const GSList *l;
-       const struct sr_probe *probe;
-       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)
-                       continue;
-
-               if ((tc = probe->trigger)) {
-                       switch (*tc) {
-                       case '1':
-                               type = TRIGGER_HIGH;
-                               break;
-                       case '0':
-                               type = TRIGGER_LOW;
-                               break;
-#if 0
-                       case 'r':
-                               type = TRIGGER_POSEDGE;
-                               break;
-                       case 'f':
-                               type = TRIGGER_NEGEDGE;
-                               break;
-                       case 'c':
-                               type = TRIGGER_ANYEDGE;
-                               break;
-#endif
-                       default:
-                               return SR_ERR;
-                       }
-                       analyzer_add_trigger(probe->index, type);
-                       devc->trigger = 1;
-               }
-       }
-
-       return SR_OK;
-}
-
 SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate)
 {
        int i;
@@ -247,7 +163,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;
@@ -314,12 +230,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_channel_new(j, SR_CHANNEL_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);
@@ -575,8 +491,10 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
                g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
                *data = g_variant_builder_end(&gvb);
                break;
-       case SR_CONF_TRIGGER_TYPE:
-               *data = g_variant_new_string(TRIGGER_TYPE);
+       case SR_CONF_TRIGGER_MATCH:
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+                               trigger_matches, ARRAY_SIZE(trigger_matches),
+                               sizeof(int32_t));
                break;
        case SR_CONF_VOLTAGE_THRESHOLD:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
@@ -634,8 +552,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 (analyzer_add_triggers(sdi) != SR_OK) {
+               sr_err("Failed to configure triggers.");
                return SR_ERR;
        }