X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Flecroy-xstream%2Fapi.c;h=504dde3bd469b5c3d0e43cf25de8db7c6bf6a3bc;hb=6e9606dbae378c5f37d7be3fe3aa4b06c5d142ed;hp=62cb967b560ad8530ad96bf034df43c387d68018;hpb=bd633efa3215c1bb8600a5728e5b3a692940c679;p=libsigrok.git diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index 62cb967b..504dde3b 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -83,7 +83,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) hw_info = NULL; devc = g_malloc0(sizeof(struct dev_context)); - sdi->priv = devc; if (lecroy_xstream_init_device(sdi) != SR_OK) @@ -132,9 +131,9 @@ static int dev_close(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) + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - unsigned int i; + int idx; struct dev_context *devc; const struct scope_config *model; struct scope_state *state; @@ -158,20 +157,16 @@ static int config_get(uint32_t key, GVariant **data, (*model->timebases)[state->timebase][1]); break; case SR_CONF_NUM_VDIV: - for (i = 0; i < model->analog_channels; i++) { - if (cg != devc->analog_groups[i]) - continue; - *data = g_variant_new_int32(model->num_ydivs); - } + if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0) + return SR_ERR_ARG; + *data = g_variant_new_int32(model->num_ydivs); break; case SR_CONF_VDIV: - for (i = 0; i < model->analog_channels; i++) { - if (cg != devc->analog_groups[i]) - continue; - *data = g_variant_new("(tt)", - (*model->vdivs)[state->analog_channels[i].vdiv][0], - (*model->vdivs)[state->analog_channels[i].vdiv][1]); - } + if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) + return SR_ERR_ARG; + *data = g_variant_new("(tt)", + (*model->vdivs)[state->analog_channels[idx].vdiv][0], + (*model->vdivs)[state->analog_channels[idx].vdiv][1]); break; case SR_CONF_TRIGGER_SOURCE: *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]); @@ -183,11 +178,9 @@ static int config_get(uint32_t key, GVariant **data, *data = g_variant_new_double(state->horiz_triggerpos); break; case SR_CONF_COUPLING: - for (i = 0; i < model->analog_channels; i++) { - if (cg != devc->analog_groups[i]) - continue; - *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[i].coupling]); - } + if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) + return SR_ERR_ARG; + *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]); break; case SR_CONF_SAMPLERATE: *data = g_variant_new_uint64(state->sample_rate); @@ -203,10 +196,9 @@ static int config_get(uint32_t key, GVariant **data, } static int config_set(uint32_t key, GVariant *data, - const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - int ret, idx; - unsigned int j; + int ret, idx, j; char command[MAX_COMMAND_SIZE]; struct dev_context *devc; const struct scope_config *model; @@ -235,23 +227,19 @@ 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: if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0) return SR_ERR_ARG; - for (j = 1; j <= model->analog_channels; j++) { - if (cg != devc->analog_groups[j - 1]) - continue; - state->analog_channels[j - 1].vdiv = idx; - g_snprintf(command, sizeof(command), - "C%d:VDIV %E", j, (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]); - if (sr_scpi_send(sdi->conn, command) != SR_OK || - sr_scpi_get_opc(sdi->conn) != SR_OK) - return SR_ERR; - break; - } + if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) + return SR_ERR_ARG; + state->analog_channels[j].vdiv = idx; + g_snprintf(command, sizeof(command), + "C%d:VDIV %E", j + 1, (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]); + if (sr_scpi_send(sdi->conn, command) != SR_OK || sr_scpi_get_opc(sdi->conn) != SR_OK) + return SR_ERR; ret = SR_OK; break; case SR_CONF_TIMEBASE: @@ -259,7 +247,7 @@ static int config_set(uint32_t key, GVariant *data, return SR_ERR_ARG; state->timebase = idx; g_snprintf(command, sizeof(command), - "TIME_DIV %E", (float) (*model->timebases)[idx][0] / (*model->timebases)[idx][1]); + "TIME_DIV %E", (float) (*model->timebases)[idx][0] / (*model->timebases)[idx][1]); ret = sr_scpi_send(sdi->conn, command); update_sample_rate = TRUE; break; @@ -271,9 +259,9 @@ static int config_set(uint32_t key, GVariant *data, state->horiz_triggerpos = tmp_d; tmp_d = -(tmp_d - 0.5) * - ((double)(*model->timebases)[state->timebase][0] / - (*model->timebases)[state->timebase][1]) - * model->num_xdivs; + ((double)(*model->timebases)[state->timebase][0] / + (*model->timebases)[state->timebase][1]) + * model->num_xdivs; g_snprintf(command, sizeof(command), "TRIG POS %e S", tmp_d); @@ -284,23 +272,20 @@ 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: if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) return SR_ERR_ARG; - for (j = 1; j <= model->analog_channels; j++) { - if (cg != devc->analog_groups[j - 1]) - continue; - state->analog_channels[j - 1].coupling = idx; - g_snprintf(command, sizeof(command), "C%d:COUPLING %s", - j, (*model->coupling_options)[idx]); - if (sr_scpi_send(sdi->conn, command) != SR_OK || - sr_scpi_get_opc(sdi->conn) != SR_OK) - return SR_ERR; - break; - } + if ((j = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0) + return SR_ERR_ARG; + state->analog_channels[j].coupling = idx; + g_snprintf(command, sizeof(command), "C%d:COUPLING %s", + j + 1, (*model->coupling_options)[idx]); + if (sr_scpi_send(sdi->conn, command) != SR_OK || sr_scpi_get_opc(sdi->conn) != SR_OK) + return SR_ERR; ret = SR_OK; break; default: @@ -317,8 +302,18 @@ static int config_set(uint32_t key, GVariant *data, 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) + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; const struct scope_config *model; @@ -371,14 +366,12 @@ SR_PRIV int lecroy_xstream_request_data(const struct sr_dev_inst *sdi) struct dev_context *devc; devc = sdi->priv; - ch = devc->current_channel->data; if (ch->type != SR_CHANNEL_ANALOG) return SR_ERR; - g_snprintf(command, sizeof(command), - "COMM_FORMAT DEF9,WORD,BIN;C%d:WAVEFORM?", ch->index + 1); + g_snprintf(command, sizeof(command), "C%d:WAVEFORM?", ch->index + 1); return sr_scpi_send(sdi->conn, command); } @@ -404,10 +397,11 @@ static int setup_channels(const struct sr_dev_inst *sdi) if (ch->enabled == state->analog_channels[ch->index].state) break; g_snprintf(command, sizeof(command), "C%d:TRACE %s", - ch->index + 1, ch->enabled ? "ON" : "OFF"); + ch->index + 1, ch->enabled ? "ON" : "OFF"); if (sr_scpi_send(scpi, command) != SR_OK) return SR_ERR; + state->analog_channels[ch->index].state = ch->enabled; setup_changed = TRUE; break; @@ -437,27 +431,19 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) g_slist_free(devc->enabled_channels); devc->enabled_channels = NULL; - /* - * 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; @@ -513,6 +499,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,