]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/pipistrello-ols/api.c
Change type of SR_CONF keys to uint32_t.
[libsigrok.git] / src / hardware / pipistrello-ols / api.c
index 8a1fa5dca59a813ec547d432eb9055656fe931be..892821793bca73c15ae2aff28d145749ba409ca7 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "protocol.h"
 
-static const int32_t hwcaps[] = {
+static const uint32_t hwcaps[] = {
        SR_CONF_LOGIC_ANALYZER,
        SR_CONF_SAMPLERATE,
        SR_CONF_TRIGGER_MATCH,
@@ -236,7 +236,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 +247,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 +278,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 +294,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 +375,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 +387,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,
+                               hwcaps, ARRAY_SIZE(hwcaps), sizeof(uint32_t));
                break;
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
@@ -519,6 +519,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 +612,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. */