From: Bert Vermeulen Date: Tue, 27 May 2014 22:21:23 +0000 (+0200) Subject: ikalogic-scanalogic2: Use new trigger API. X-Git-Tag: libsigrok-0.4.0~1303 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=02d5c0d8ea5b398962b51952928d31e75c4a8f8d;p=libsigrok.git ikalogic-scanalogic2: Use new trigger API. --- diff --git a/hardware/ikalogic-scanalogic2/api.c b/hardware/ikalogic-scanalogic2/api.c index e586011e..fd0f2176 100644 --- a/hardware/ikalogic-scanalogic2/api.c +++ b/hardware/ikalogic-scanalogic2/api.c @@ -23,10 +23,16 @@ static const int hwcaps[] = { SR_CONF_LOGIC_ANALYZER, SR_CONF_SAMPLERATE, SR_CONF_LIMIT_SAMPLES, - SR_CONF_TRIGGER_TYPE, + SR_CONF_TRIGGER_MATCH, SR_CONF_CAPTURE_RATIO, }; +static const int32_t trigger_matches[] = { + SR_TRIGGER_RISING, + SR_TRIGGER_FALLING, + SR_TRIGGER_EDGE, +}; + SR_PRIV const uint64_t sl2_samplerates[NUM_SAMPLERATES] = { SR_KHZ(1.25), SR_KHZ(10), @@ -390,8 +396,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_LIMIT_SAMPLES: grange[0] = g_variant_new_uint64(0); @@ -431,7 +439,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) * The trigger must be configured first because the calculation of the * pre and post trigger samples depends on a configured trigger. */ - sl2_configure_trigger(sdi); + sl2_convert_trigger(sdi); sl2_calculate_trigger_samples(sdi); trigger_bytes = devc->pre_trigger_bytes + devc->post_trigger_bytes; diff --git a/hardware/ikalogic-scanalogic2/protocol.c b/hardware/ikalogic-scanalogic2/protocol.c index b99709c6..abd3952e 100644 --- a/hardware/ikalogic-scanalogic2/protocol.c +++ b/hardware/ikalogic-scanalogic2/protocol.c @@ -479,14 +479,14 @@ SR_PRIV int sl2_set_limit_samples(const struct sr_dev_inst *sdi, return SR_OK; } -SR_PRIV void sl2_configure_trigger(const struct sr_dev_inst *sdi) +SR_PRIV int sl2_convert_trigger(const struct sr_dev_inst *sdi) { struct dev_context *devc; - struct sr_channel *ch; - uint8_t trigger_type; - int channel_index, num_triggers_anyedge; - char *trigger; - GSList *l; + struct sr_trigger *trigger; + struct sr_trigger_stage *stage; + struct sr_trigger_match *match; + const GSList *l, *m; + int num_triggers_anyedge; devc = sdi->priv; @@ -494,32 +494,36 @@ SR_PRIV void sl2_configure_trigger(const struct sr_dev_inst *sdi) devc->trigger_channel = TRIGGER_CHANNEL_0; devc->trigger_type = TRIGGER_TYPE_NONE; - num_triggers_anyedge = 0; - - for (l = sdi->channels, channel_index = 0; l; l = l->next, channel_index++) { - ch = l->data; - trigger = ch->trigger; + if (!(trigger = sr_session_trigger_get())) + return SR_OK; - if (!trigger || !ch->enabled) - continue; + if (g_slist_length(trigger->stages) > 1) { + sr_err("This device only supports 1 trigger stage."); + return SR_ERR; + } - switch (*trigger) { - case 'r': - trigger_type = TRIGGER_TYPE_POSEDGE; - break; - case 'f': - trigger_type = TRIGGER_TYPE_NEGEDGE; - break; - case 'c': - trigger_type = TRIGGER_TYPE_ANYEDGE; - num_triggers_anyedge++; - break; - default: - continue; + num_triggers_anyedge = 0; + for (l = trigger->stages; l; l = l->next) { + stage = l->data; + for (m = stage->matches; m; m = m->next) { + match = m->data; + if (!match->channel->enabled) + /* Ignore disabled channels with a trigger. */ + continue; + devc->trigger_channel = match->channel->index + 1; + switch (match->match) { + case SR_TRIGGER_RISING: + devc->trigger_type = TRIGGER_TYPE_POSEDGE; + break; + case SR_TRIGGER_FALLING: + devc->trigger_type = TRIGGER_TYPE_NEGEDGE; + break; + case SR_TRIGGER_EDGE: + devc->trigger_type = TRIGGER_TYPE_ANYEDGE; + num_triggers_anyedge++; + break; + } } - - devc->trigger_channel = channel_index + 1; - devc->trigger_type = trigger_type; } /* @@ -533,6 +537,8 @@ SR_PRIV void sl2_configure_trigger(const struct sr_dev_inst *sdi) sr_dbg("Trigger set to channel 0x%02x and type 0x%02x.", devc->trigger_channel, devc->trigger_type); + + return SR_OK; } SR_PRIV int sl2_set_capture_ratio(const struct sr_dev_inst *sdi, diff --git a/hardware/ikalogic-scanalogic2/protocol.h b/hardware/ikalogic-scanalogic2/protocol.h index 3b411e69..5e7c7b3b 100644 --- a/hardware/ikalogic-scanalogic2/protocol.h +++ b/hardware/ikalogic-scanalogic2/protocol.h @@ -49,8 +49,6 @@ #define NUM_SAMPLERATES 11 #define NUM_CHANNELS 4 -#define TRIGGER_TYPES "rfc" - /* * Number of sample bytes and samples the device can acquire. Note that the * vendor software can acquire 32736 sample bytes only but the device is capable @@ -225,7 +223,7 @@ SR_PRIV int sl2_set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate); SR_PRIV int sl2_set_limit_samples(const struct sr_dev_inst *sdi, uint64_t limit_samples); -SR_PRIV void sl2_configure_trigger(const struct sr_dev_inst *sdi); +SR_PRIV int sl2_convert_trigger(const struct sr_dev_inst *sdi); SR_PRIV int sl2_set_capture_ratio(const struct sr_dev_inst *sdi, uint64_t capture_ratio); SR_PRIV int sl2_set_after_trigger_delay(const struct sr_dev_inst *sdi,