]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/lecroy-xstream/api.c
lecroy-xstream: Fix sample rate
[libsigrok.git] / src / hardware / lecroy-xstream / api.c
index 2bcf2cd00567443e0c2f7ef4cd4bc8a8fe548365..533275a28882deeb7f2fd43e24def96a6a37ac6a 100644 (file)
@@ -204,7 +204,6 @@ static int config_set(uint32_t key, GVariant *data,
        const struct scope_config *model;
        struct scope_state *state;
        double tmp_d;
-       gboolean update_sample_rate;
 
        if (!sdi)
                return SR_ERR_ARG;
@@ -213,7 +212,6 @@ static int config_set(uint32_t key, GVariant *data,
 
        model = devc->model_config;
        state = devc->model_state;
-       update_sample_rate = FALSE;
 
        ret = SR_ERR_NA;
 
@@ -227,7 +225,7 @@ static int config_set(uint32_t key, GVariant *data,
                        return SR_ERR_ARG;
                state->trigger_source = idx;
                g_snprintf(command, sizeof(command),
-                               "SET TRIGGER SOURCE %s", (*model->trigger_sources)[idx]);
+                               "TRIG_SELECT EDGE,SR,%s", (*model->trigger_sources)[idx]);
                ret = sr_scpi_send(sdi->conn, command);
                break;
        case SR_CONF_VDIV:
@@ -249,7 +247,6 @@ static int config_set(uint32_t key, GVariant *data,
                g_snprintf(command, sizeof(command),
                                "TIME_DIV %E", (float) (*model->timebases)[idx][0] / (*model->timebases)[idx][1]);
                ret = sr_scpi_send(sdi->conn, command);
-               update_sample_rate = TRUE;
                break;
        case SR_CONF_HORIZ_TRIGGERPOS:
                tmp_d = g_variant_get_double(data);
@@ -272,7 +269,8 @@ static int config_set(uint32_t key, GVariant *data,
                        return SR_ERR_ARG;
                state->trigger_slope = idx;
                g_snprintf(command, sizeof(command),
-                               "SET TRIGGER SLOPE %s", (*model->trigger_slopes)[idx]);
+                               "%s:TRIG_SLOPE %s", (*model->trigger_sources)[state->trigger_source],
+                               (*model->trigger_slopes)[idx]);
                ret = sr_scpi_send(sdi->conn, command);
                break;
        case SR_CONF_COUPLING:
@@ -295,12 +293,19 @@ static int config_set(uint32_t key, GVariant *data,
        if (ret == SR_OK)
                ret = sr_scpi_get_opc(sdi->conn);
 
-       if (ret == SR_OK && update_sample_rate)
-               ret = lecroy_xstream_update_sample_rate(sdi);
-
        return ret;
 }
 
+static int config_channel_set(const struct sr_dev_inst *sdi,
+       struct sr_channel *ch, unsigned int changes)
+{
+       /* Currently we only handle SR_CHANNEL_SET_ENABLED. */
+       if (changes != SR_CHANNEL_SET_ENABLED)
+               return SR_ERR_NA;
+
+       return lecroy_xstream_channel_state_set(sdi, ch->index, ch->enabled);
+}
+
 static int config_list(uint32_t key, GVariant **data,
                const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
@@ -367,7 +372,6 @@ SR_PRIV int lecroy_xstream_request_data(const struct sr_dev_inst *sdi)
 static int setup_channels(const struct sr_dev_inst *sdi)
 {
        GSList *l;
-       gboolean setup_changed;
        char command[MAX_COMMAND_SIZE];
        struct scope_state *state;
        struct sr_channel *ch;
@@ -377,7 +381,6 @@ static int setup_channels(const struct sr_dev_inst *sdi)
        devc = sdi->priv;
        scpi = sdi->conn;
        state = devc->model_state;
-       setup_changed = FALSE;
 
        for (l = sdi->channels; l; l = l->next) {
                ch = l->data;
@@ -392,16 +395,12 @@ static int setup_channels(const struct sr_dev_inst *sdi)
                                return SR_ERR;
 
                        state->analog_channels[ch->index].state = ch->enabled;
-                       setup_changed = TRUE;
                        break;
                default:
                        return SR_ERR;
                }
        }
 
-       if (setup_changed && lecroy_xstream_update_sample_rate(sdi) != SR_OK)
-               return SR_ERR;
-
        return SR_OK;
 }
 
@@ -410,6 +409,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        GSList *l;
        struct sr_channel *ch;
        struct dev_context *devc;
+       struct scope_state *state;
        int ret;
        struct sr_scpi_dev_inst *scpi;
 
@@ -419,28 +419,22 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        /* Preset empty results. */
        g_slist_free(devc->enabled_channels);
        devc->enabled_channels = NULL;
+       state = devc->model_state;
+       state->sample_rate = 0;
 
-       /*
-        * Contruct the list of enabled channels. Determine the highest
-        * number of digital pods involved in the acquisition.
-        */
-
+       /* Contruct the list of enabled channels. */
        for (l = sdi->channels; l; l = l->next) {
                ch = l->data;
                if (!ch->enabled)
                        continue;
-               /* Only add a single digital channel per group (pod). */
-               devc->enabled_channels = g_slist_append(
-                       devc->enabled_channels, ch);
+
+               devc->enabled_channels = g_slist_append(devc->enabled_channels, ch);
        }
 
        if (!devc->enabled_channels)
                return SR_ERR;
 
-       /*
-        * Configure the analog channels and the
-        * corresponding digital pods.
-        */
+       /* Configure the analog channels. */
        if (setup_channels(sdi) != SR_OK) {
                sr_err("Failed to setup channel configuration!");
                ret = SR_ERR;
@@ -496,6 +490,7 @@ static struct sr_dev_driver lecroy_xstream_driver_info = {
        .dev_clear = dev_clear,
        .config_get = config_get,
        .config_set = config_set,
+       .config_channel_set = config_channel_set,
        .config_list = config_list,
        .dev_open = dev_open,
        .dev_close = dev_close,