diff --git a/include/libsigrok/libsigrok.h b/include/libsigrok/libsigrok.h index ed6fd424..63dc483b 100644 --- a/include/libsigrok/libsigrok.h +++ b/include/libsigrok/libsigrok.h @@ -767,12 +767,21 @@ enum sr_configkey { /** The device supports run-length encoding (RLE). */ SR_CONF_RLE, + /** Trigger source. */ + SR_CONF_TRIGGER_SOURCE, + /** The device supports setting trigger slope. */ SR_CONF_TRIGGER_SLOPE, /** The device supports setting a pattern for the logic trigger. */ SR_CONF_TRIGGER_PATTERN, + /** High resolution mode. */ + SR_CONF_HIGH_RESOLUTION, + + /** Peak detection. */ + SR_CONF_PEAK_DETECTION, + /** The device supports averaging. */ SR_CONF_AVERAGING, @@ -782,9 +791,6 @@ enum sr_configkey { */ SR_CONF_AVG_SAMPLES, - /** Trigger source. */ - SR_CONF_TRIGGER_SOURCE, - /** Horizontal trigger position. */ SR_CONF_HORIZ_TRIGGERPOS, diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index e5808fb3..bbbaaaa7 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -204,6 +204,12 @@ static int config_get(uint32_t key, GVariant **data, case SR_CONF_TRIGGER_PATTERN: *data = g_variant_new_string(state->trigger_pattern); break; + case SR_CONF_HIGH_RESOLUTION: + *data = g_variant_new_boolean(state->high_resolution); + break; + case SR_CONF_PEAK_DETECTION: + *data = g_variant_new_boolean(state->peak_detection); + break; case SR_CONF_HORIZ_TRIGGERPOS: *data = g_variant_new_double(state->horiz_triggerpos); break; @@ -270,7 +276,7 @@ static int config_set(uint32_t key, GVariant *data, const struct scope_config *model; struct scope_state *state; double tmp_d, tmp_d2; - gboolean update_sample_rate; + gboolean update_sample_rate, tmp_bool; if (!sdi) return SR_ERR_ARG; @@ -293,18 +299,6 @@ static int config_set(uint32_t key, GVariant *data, devc->frame_limit = g_variant_get_uint64(data); ret = SR_OK; break; - case SR_CONF_TRIGGER_SOURCE: - if ((idx = std_str_idx(data, *model->trigger_sources, model->num_trigger_sources)) < 0) - return SR_ERR_ARG; - g_snprintf(command, sizeof(command), - (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE], - (*model->trigger_sources)[idx]); - if (sr_scpi_send(sdi->conn, command) != SR_OK || - sr_scpi_get_opc(sdi->conn) != SR_OK) - return SR_ERR; - state->trigger_source = idx; - ret = SR_OK; - break; case SR_CONF_VDIV: if (!cg) return SR_ERR_CHANNEL_GROUP; @@ -356,6 +350,18 @@ static int config_set(uint32_t key, GVariant *data, state->horiz_triggerpos = tmp_d; ret = SR_OK; break; + case SR_CONF_TRIGGER_SOURCE: + if ((idx = std_str_idx(data, *model->trigger_sources, model->num_trigger_sources)) < 0) + return SR_ERR_ARG; + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE], + (*model->trigger_sources)[idx]); + if (sr_scpi_send(sdi->conn, command) != SR_OK || + sr_scpi_get_opc(sdi->conn) != SR_OK) + return SR_ERR; + state->trigger_source = idx; + ret = SR_OK; + break; case SR_CONF_TRIGGER_SLOPE: if ((idx = std_str_idx(data, *model->trigger_slopes, model->num_trigger_slopes)) < 0) return SR_ERR_ARG; @@ -384,6 +390,48 @@ static int config_set(uint32_t key, GVariant *data, MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT); ret = SR_OK; break; + case SR_CONF_HIGH_RESOLUTION: + tmp_bool = g_variant_get_boolean(data); + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_HIGH_RESOLUTION], + tmp_bool ? "AUTO" : "OFF"); + if (sr_scpi_send(sdi->conn, command) != SR_OK || + sr_scpi_get_opc(sdi->conn) != SR_OK) + return SR_ERR; + /* High Resolution mode automatically switches off Peak Detection. */ + if (tmp_bool) { + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_PEAK_DETECTION], + "OFF"); + if (sr_scpi_send(sdi->conn, command) != SR_OK || + sr_scpi_get_opc(sdi->conn) != SR_OK) + return SR_ERR; + state->peak_detection = FALSE; + } + state->high_resolution = tmp_bool; + ret = SR_OK; + break; + case SR_CONF_PEAK_DETECTION: + tmp_bool = g_variant_get_boolean(data); + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_PEAK_DETECTION], + tmp_bool ? "AUTO" : "OFF"); + if (sr_scpi_send(sdi->conn, command) != SR_OK || + sr_scpi_get_opc(sdi->conn) != SR_OK) + return SR_ERR; + /* Peak Detection automatically switches off High Resolution mode. */ + if (tmp_bool) { + g_snprintf(command, sizeof(command), + (*model->scpi_dialect)[SCPI_CMD_SET_HIGH_RESOLUTION], + "OFF"); + if (sr_scpi_send(sdi->conn, command) != SR_OK || + sr_scpi_get_opc(sdi->conn) != SR_OK) + return SR_ERR; + state->high_resolution = FALSE; + } + state->peak_detection = tmp_bool; + ret = SR_OK; + break; case SR_CONF_COUPLING: if (!cg) return SR_ERR_CHANNEL_GROUP; diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index 167c1a4f..b0875eb5 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -44,6 +44,8 @@ static const char *hameg_scpi_dialect[] = { [SCPI_CMD_SET_VERTICAL_SCALE] = ":CHAN%d:SCAL %s", [SCPI_CMD_GET_DIG_POD_STATE] = ":POD%d:STAT?", [SCPI_CMD_SET_DIG_POD_STATE] = ":POD%d:STAT %d", + [SCPI_CMD_GET_TRIGGER_SOURCE] = ":TRIG:A:SOUR?", + [SCPI_CMD_SET_TRIGGER_SOURCE] = ":TRIG:A:SOUR %s", [SCPI_CMD_GET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP?", [SCPI_CMD_SET_TRIGGER_SLOPE] = ":TRIG:A:TYPE EDGE;:TRIG:A:EDGE:SLOP %s", [SCPI_CMD_GET_TRIGGER_PATTERN] = ":TRIG:A:PATT:SOUR?", @@ -52,8 +54,10 @@ static const char *hameg_scpi_dialect[] = { ":TRIG:A:PATT:COND \"TRUE\";" \ ":TRIG:A:PATT:MODE OFF;" \ ":TRIG:A:PATT:SOUR \"%s\"", - [SCPI_CMD_GET_TRIGGER_SOURCE] = ":TRIG:A:SOUR?", - [SCPI_CMD_SET_TRIGGER_SOURCE] = ":TRIG:A:SOUR %s", + [SCPI_CMD_GET_HIGH_RESOLUTION] = ":ACQ:HRES?", + [SCPI_CMD_SET_HIGH_RESOLUTION] = ":ACQ:HRES %s", + [SCPI_CMD_GET_PEAK_DETECTION] = ":ACQ:PEAK?", + [SCPI_CMD_SET_PEAK_DETECTION] = ":ACQ:PEAK %s", [SCPI_CMD_GET_DIG_CHAN_STATE] = ":LOG%d:STAT?", [SCPI_CMD_SET_DIG_CHAN_STATE] = ":LOG%d:STAT %d", [SCPI_CMD_GET_VERTICAL_OFFSET] = ":CHAN%d:POS?", @@ -82,6 +86,8 @@ static const char *rohde_schwarz_log_not_pod_scpi_dialect[] = { [SCPI_CMD_SET_VERTICAL_SCALE] = ":CHAN%d:SCAL %s", [SCPI_CMD_GET_DIG_POD_STATE] = ":LOG%d:STAT?", [SCPI_CMD_SET_DIG_POD_STATE] = ":LOG%d:STAT %d", + [SCPI_CMD_GET_TRIGGER_SOURCE] = ":TRIG:A:SOUR?", + [SCPI_CMD_SET_TRIGGER_SOURCE] = ":TRIG:A:SOUR %s", [SCPI_CMD_GET_TRIGGER_SLOPE] = ":TRIG:A:EDGE:SLOP?", [SCPI_CMD_SET_TRIGGER_SLOPE] = ":TRIG:A:TYPE EDGE;:TRIG:A:EDGE:SLOP %s", [SCPI_CMD_GET_TRIGGER_PATTERN] = ":TRIG:A:PATT:SOUR?", @@ -90,8 +96,10 @@ static const char *rohde_schwarz_log_not_pod_scpi_dialect[] = { ":TRIG:A:PATT:COND \"TRUE\";" \ ":TRIG:A:PATT:MODE OFF;" \ ":TRIG:A:PATT:SOUR \"%s\"", - [SCPI_CMD_GET_TRIGGER_SOURCE] = ":TRIG:A:SOUR?", - [SCPI_CMD_SET_TRIGGER_SOURCE] = ":TRIG:A:SOUR %s", + [SCPI_CMD_GET_HIGH_RESOLUTION] = ":ACQ:HRES?", + [SCPI_CMD_SET_HIGH_RESOLUTION] = ":ACQ:HRES %s", + [SCPI_CMD_GET_PEAK_DETECTION] = ":ACQ:PEAK?", + [SCPI_CMD_SET_PEAK_DETECTION] = ":ACQ:PEAK %s", [SCPI_CMD_GET_DIG_CHAN_STATE] = ":LOG%d:STAT?", [SCPI_CMD_SET_DIG_CHAN_STATE] = ":LOG%d:STAT %d", [SCPI_CMD_GET_VERTICAL_OFFSET] = ":CHAN%d:POS?", /* Might not be supported on RTB200x... */ @@ -117,6 +125,8 @@ static const uint32_t devopts[] = { SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_TRIGGER_PATTERN | SR_CONF_GET | SR_CONF_SET, + SR_CONF_HIGH_RESOLUTION | SR_CONF_GET | SR_CONF_SET, + SR_CONF_PEAK_DETECTION | SR_CONF_GET | SR_CONF_SET, }; static const uint32_t devopts_cg_analog[] = { @@ -1120,6 +1130,26 @@ SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi) MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT); g_free(tmp_str); + if (sr_scpi_get_string(sdi->conn, + (*config->scpi_dialect)[SCPI_CMD_GET_HIGH_RESOLUTION], + &tmp_str) != SR_OK) + return SR_ERR; + if (!strcmp("OFF", tmp_str)) + state->high_resolution = FALSE; + else + state->high_resolution = TRUE; + g_free(tmp_str); + + if (sr_scpi_get_string(sdi->conn, + (*config->scpi_dialect)[SCPI_CMD_GET_PEAK_DETECTION], + &tmp_str) != SR_OK) + return SR_ERR; + if (!strcmp("OFF", tmp_str)) + state->peak_detection = FALSE; + else + state->peak_detection = TRUE; + g_free(tmp_str); + if (hmo_update_sample_rate(sdi) != SR_OK) return SR_ERR; diff --git a/src/hardware/hameg-hmo/protocol.h b/src/hardware/hameg-hmo/protocol.h index 975ea7e3..2749fb8e 100644 --- a/src/hardware/hameg-hmo/protocol.h +++ b/src/hardware/hameg-hmo/protocol.h @@ -108,6 +108,9 @@ struct scope_state { int trigger_slope; char trigger_pattern[MAX_ANALOG_CHANNEL_COUNT + MAX_DIGITAL_CHANNEL_COUNT]; + gboolean high_resolution; + gboolean peak_detection; + uint64_t sample_rate; }; diff --git a/src/hwdriver.c b/src/hwdriver.c index 27ca060d..342abeb9 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -81,16 +81,20 @@ static struct sr_key_info sr_key_info_config[] = { "Pattern", NULL}, {SR_CONF_RLE, SR_T_BOOL, "rle", "Run length encoding", NULL}, + {SR_CONF_TRIGGER_SOURCE, SR_T_STRING, "triggersource", + "Trigger source", NULL}, {SR_CONF_TRIGGER_SLOPE, SR_T_STRING, "triggerslope", "Trigger slope", NULL}, {SR_CONF_TRIGGER_PATTERN, SR_T_STRING, "triggerpattern", "Trigger pattern", NULL}, + {SR_CONF_HIGH_RESOLUTION, SR_T_BOOL, "highresolution", + "High resolution", NULL}, + {SR_CONF_PEAK_DETECTION, SR_T_BOOL, "peakdetection", + "Peak detection", NULL}, {SR_CONF_AVERAGING, SR_T_BOOL, "averaging", "Averaging", NULL}, {SR_CONF_AVG_SAMPLES, SR_T_UINT64, "avg_samples", "Number of samples to average over", NULL}, - {SR_CONF_TRIGGER_SOURCE, SR_T_STRING, "triggersource", - "Trigger source", NULL}, {SR_CONF_HORIZ_TRIGGERPOS, SR_T_FLOAT, "horiz_triggerpos", "Horizontal trigger position", NULL}, {SR_CONF_BUFFERSIZE, SR_T_UINT64, "buffersize", diff --git a/src/scpi.h b/src/scpi.h index 7d9a39bb..e8bb33f4 100644 --- a/src/scpi.h +++ b/src/scpi.h @@ -38,12 +38,16 @@ enum { SCPI_CMD_GET_HORIZONTAL_DIV, SCPI_CMD_GET_VERTICAL_SCALE, SCPI_CMD_SET_VERTICAL_SCALE, + SCPI_CMD_GET_TRIGGER_SOURCE, + SCPI_CMD_SET_TRIGGER_SOURCE, SCPI_CMD_GET_TRIGGER_SLOPE, SCPI_CMD_SET_TRIGGER_SLOPE, SCPI_CMD_GET_TRIGGER_PATTERN, SCPI_CMD_SET_TRIGGER_PATTERN, - SCPI_CMD_GET_TRIGGER_SOURCE, - SCPI_CMD_SET_TRIGGER_SOURCE, + SCPI_CMD_GET_HIGH_RESOLUTION, + SCPI_CMD_SET_HIGH_RESOLUTION, + SCPI_CMD_GET_PEAK_DETECTION, + SCPI_CMD_SET_PEAK_DETECTION, SCPI_CMD_GET_COUPLING, SCPI_CMD_SET_COUPLING, SCPI_CMD_GET_HORIZ_TRIGGERPOS,