X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fpipistrello-ols%2Fapi.c;h=2db23fd042eaea1ea39a1de1c194576b5d1d0d78;hb=a258204e00715c44b0d013ee3141ce890c8ea71c;hp=8a1fa5dca59a813ec547d432eb9055656fe931be;hpb=acc885c7553d12ce18d45fc603ebf7d0c188db09;p=libsigrok.git diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 8a1fa5dc..2db23fd0 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -19,16 +19,16 @@ #include "protocol.h" -static const int32_t hwcaps[] = { +static const uint32_t devopts[] = { SR_CONF_LOGIC_ANALYZER, - SR_CONF_SAMPLERATE, - SR_CONF_TRIGGER_MATCH, - SR_CONF_CAPTURE_RATIO, - SR_CONF_LIMIT_SAMPLES, - SR_CONF_PATTERN_MODE, - SR_CONF_EXTERNAL_CLOCK, - SR_CONF_SWAP, - SR_CONF_RLE, + SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_TRIGGER_MATCH | SR_CONF_LIST, + SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET, + SR_CONF_PATTERN_MODE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, + SR_CONF_EXTERNAL_CLOCK | SR_CONF_GET | SR_CONF_SET, + SR_CONF_SWAP | SR_CONF_SET, + SR_CONF_RLE | SR_CONF_GET | SR_CONF_SET, }; static const int32_t trigger_matches[] = { @@ -185,7 +185,6 @@ static GSList *scan(GSList *options) /* Parse the metadata. */ sdi = p_ols_get_metadata((uint8_t *)buf, bytes_read, devc); - sdi->index = 0; /* Configure samplerate and divider. */ if (p_ols_set_samplerate(sdi, DEFAULT_SAMPLERATE) != SR_OK) @@ -236,7 +235,7 @@ static int cleanup(void) } -static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, +static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; @@ -247,7 +246,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, return SR_ERR_ARG; devc = sdi->priv; - switch (id) { + switch (key) { case SR_CONF_SAMPLERATE: *data = g_variant_new_uint64(devc->cur_samplerate); break; @@ -278,7 +277,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, return SR_OK; } -static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, +static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; @@ -294,7 +293,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, devc = sdi->priv; - switch (id) { + switch (key) { case SR_CONF_SAMPLERATE: tmp_u64 = g_variant_get_uint64(data); if (tmp_u64 < samplerates[0] || tmp_u64 > samplerates[1]) @@ -375,7 +374,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, return ret; } -static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, +static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; @@ -387,8 +386,8 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); break; case SR_CONF_SAMPLERATE: g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); @@ -519,6 +518,35 @@ static int set_trigger(const struct sr_dev_inst *sdi, int stage) return SR_OK; } +static int disable_trigger(const struct sr_dev_inst *sdi, int stage) +{ + struct dev_context *devc; + uint8_t cmd, arg[4]; + + devc = sdi->priv; + + cmd = CMD_SET_TRIGGER_MASK + stage * 4; + arg[0] = arg[1] = arg[2] = arg[3] = 0x00; + if (write_longcommand(devc, cmd, arg) != SR_OK) + return SR_ERR; + + cmd = CMD_SET_TRIGGER_VALUE + stage * 4; + if (write_longcommand(devc, cmd, arg) != SR_OK) + return SR_ERR; + + cmd = CMD_SET_TRIGGER_CONFIG + stage * 4; + arg[2] = 0x03; + if (write_longcommand(devc, cmd, arg) != SR_OK) + return SR_ERR; + + cmd = CMD_SET_TRIGGER_EDGE + stage * 4; + arg[2] = 0x00; + if (write_longcommand(devc, cmd, arg) != SR_OK) + return SR_ERR; + + return SR_OK; +} + static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { @@ -583,13 +611,21 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, sr_err("Failed to configure channels."); return SR_ERR; } + if (devc->num_stages > 0) { delaycount = readcount * (1 - devc->capture_ratio / 100.0); devc->trigger_at = (readcount - delaycount) * samplespercount - devc->num_stages; - for (i = 0; i <= devc->num_stages; i++) { - sr_dbg("Setting p-ols stage %d trigger.", i); - if ((ret = set_trigger(sdi, i)) != SR_OK) - return ret; + for (i = 0; i < NUM_TRIGGER_STAGES; i++) { + if (i <= devc->num_stages) { + sr_dbg("Setting p-ols stage %d trigger.", i); + if ((ret = set_trigger(sdi, i)) != SR_OK) + return ret; + } + else { + sr_dbg("Disabling p-ols stage %d trigger.", i); + if ((ret = disable_trigger(sdi, i)) != SR_OK) + return ret; + } } } else { /* No triggers configured, force trigger on first stage. */