X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fsysclk-lwla%2Fapi.c;h=a4346a012329c083349fd40a80831c1e504f02c9;hb=43cd4637285833706f8a404ca027bcf0ee75b9ae;hp=1ff49bf4b7f97d884298da91b395dc705c21b868;hpb=660e398fe9f5fc608787f8fd75a9df8aac61026f;p=libsigrok.git diff --git a/hardware/sysclk-lwla/api.c b/hardware/sysclk-lwla/api.c index 1ff49bf4..a4346a01 100644 --- a/hardware/sysclk-lwla/api.c +++ b/hardware/sysclk-lwla/api.c @@ -34,13 +34,20 @@ static const int32_t hwcaps[] = { SR_CONF_SAMPLERATE, SR_CONF_EXTERNAL_CLOCK, SR_CONF_CLOCK_EDGE, - SR_CONF_TRIGGER_TYPE, + SR_CONF_TRIGGER_MATCH, SR_CONF_TRIGGER_SOURCE, SR_CONF_TRIGGER_SLOPE, SR_CONF_LIMIT_MSEC, SR_CONF_LIMIT_SAMPLES, }; +static const int32_t trigger_matches[] = { + SR_TRIGGER_ZERO, + SR_TRIGGER_ONE, + SR_TRIGGER_RISING, + SR_TRIGGER_FALLING, +}; + /* The hardware supports more samplerates than these, but these are the * options hardcoded into the vendor's Windows GUI. */ @@ -72,21 +79,21 @@ static int init(struct sr_context *sr_ctx) return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *gen_probe_list(int num_probes) +static GSList *gen_channel_list(int num_channels) { GSList *list; - struct sr_probe *probe; + struct sr_channel *ch; int i; char name[8]; list = NULL; - for (i = num_probes; i > 0; --i) { - /* The LWLA series simply number probes from CH1 to CHxx. */ + for (i = num_channels; i > 0; --i) { + /* The LWLA series simply number channels from CH1 to CHxx. */ 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); + ch = sr_channel_new(i - 1, SR_CHANNEL_LOGIC, TRUE, name); + list = g_slist_prepend(list, ch); } return list; @@ -113,12 +120,12 @@ static struct sr_dev_inst *dev_inst_new(int device_index) return NULL; } - /* Enable all channels to match the default probe configuration. */ + /* Enable all channels to match the default channel configuration. */ devc->channel_mask = ALL_CHANNELS_MASK; devc->samplerate = DEFAULT_SAMPLERATE; sdi->priv = devc; - sdi->probes = gen_probe_list(NUM_PROBES); + sdi->channels = gen_channel_list(NUM_CHANNELS); return sdi; } @@ -265,12 +272,12 @@ static int cleanup(void) } static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *channel_group) + const struct sr_channel_group *cg) { struct dev_context *devc; size_t idx; - (void)channel_group; + (void)cg; if (!sdi) return SR_ERR_ARG; @@ -337,13 +344,13 @@ static int lookup_index(GVariant *value, const char *const *table, int len) } static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *channel_group) + const struct sr_channel_group *cg) { uint64_t value; struct dev_context *devc; int idx; - (void)channel_group; + (void)cg; devc = sdi->priv; if (!devc) @@ -401,66 +408,28 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, return SR_OK; } -static int config_probe_set(const struct sr_dev_inst *sdi, - struct sr_probe *probe, unsigned int changes) +static int config_channel_set(const struct sr_dev_inst *sdi, + struct sr_channel *ch, unsigned int changes) { - uint64_t probe_bit; - uint64_t trigger_mask; - uint64_t trigger_values; - uint64_t trigger_edge_mask; + uint64_t channel_bit; struct dev_context *devc; devc = sdi->priv; if (!devc) return SR_ERR_DEV_CLOSED; - if (probe->index < 0 || probe->index >= NUM_PROBES) { - sr_err("Probe index %d out of range.", probe->index); + if (ch->index < 0 || ch->index >= NUM_CHANNELS) { + sr_err("Channel index %d out of range.", ch->index); return SR_ERR_BUG; } - probe_bit = (uint64_t)1 << probe->index; + channel_bit = (uint64_t)1 << ch->index; - if ((changes & SR_PROBE_SET_ENABLED) != 0) { - /* Enable or disable input channel for this probe. */ - if (probe->enabled) - devc->channel_mask |= probe_bit; + if ((changes & SR_CHANNEL_SET_ENABLED) != 0) { + /* Enable or disable input channel for this channel. */ + if (ch->enabled) + devc->channel_mask |= channel_bit; else - devc->channel_mask &= ~probe_bit; - } - - if ((changes & SR_PROBE_SET_TRIGGER) != 0) { - trigger_mask = devc->trigger_mask & ~probe_bit; - trigger_values = devc->trigger_values & ~probe_bit; - trigger_edge_mask = devc->trigger_edge_mask & ~probe_bit; - - if (probe->trigger && probe->trigger[0] != '\0') { - if (probe->trigger[1] != '\0') { - sr_warn("Trigger configuration \"%s\" with " - "multiple stages is not supported.", - probe->trigger); - return SR_ERR_ARG; - } - /* Enable trigger for this probe. */ - trigger_mask |= probe_bit; - - /* Configure edge mask and trigger value. */ - switch (probe->trigger[0]) { - case '1': trigger_values |= probe_bit; - case '0': break; - - case 'r': trigger_values |= probe_bit; - case 'f': trigger_edge_mask |= probe_bit; - break; - default: - sr_warn("Trigger type '%c' is not supported.", - probe->trigger[0]); - return SR_ERR_ARG; - } - } - /* Store validated trigger setup. */ - devc->trigger_mask = trigger_mask; - devc->trigger_values = trigger_values; - devc->trigger_edge_mask = trigger_edge_mask; + devc->channel_mask &= ~channel_bit; } return SR_OK; @@ -477,13 +446,13 @@ static int config_commit(const struct sr_dev_inst *sdi) } static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *channel_group) + const struct sr_channel_group *cg) { GVariant *gvar; GVariantBuilder gvb; (void)sdi; - (void)channel_group; + (void)cg; switch (key) { case SR_CONF_SCAN_OPTIONS: @@ -502,8 +471,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_TYPES); + 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_TRIGGER_SOURCE: *data = g_variant_new_strv(trigger_source_names, @@ -550,6 +521,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) sr_info("Starting acquisition."); devc->acquisition = acq; + lwla_convert_trigger(sdi); ret = lwla_setup_acquisition(sdi); if (ret != SR_OK) { sr_err("Failed to set up acquisition."); @@ -565,7 +537,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) lwla_free_acquisition_state(acq); return ret; } - usb_source_add(drvc->sr_ctx, 100, &lwla_receive_data, + usb_source_add(sdi->session, drvc->sr_ctx, 100, &lwla_receive_data, (struct sr_dev_inst *)sdi); sr_info("Waiting for data."); @@ -601,7 +573,7 @@ SR_PRIV struct sr_dev_driver sysclk_lwla_driver_info = { .dev_clear = dev_clear, .config_get = config_get, .config_set = config_set, - .config_probe_set = config_probe_set, + .config_channel_set = config_channel_set, .config_commit = config_commit, .config_list = config_list, .dev_open = dev_open,