From: Bert Vermeulen Date: Tue, 15 May 2012 20:41:00 +0000 (+0200) Subject: hantek-dso: support for SR_HWCAP_FILTER X-Git-Tag: dsupstream~943 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ebb781a69f1128fab5a9eedd39a548cba8ceccbb;p=libsigrok.git hantek-dso: support for SR_HWCAP_FILTER --- diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index ba55e868..898bccec 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -48,6 +48,7 @@ static int capabilities[] = { SR_HWCAP_TRIGGER_SOURCE, SR_HWCAP_TRIGGER_SLOPE, SR_HWCAP_HORIZ_TRIGGERPOS, + SR_HWCAP_FILTER, 0, }; @@ -101,6 +102,13 @@ static char *trigger_sources[] = { NULL }; +static char *filter_targets[] = { + "CH1", + "CH2", + /* TODO: "TRIGGER", */ + NULL +}; + SR_PRIV libusb_context *usb_context = NULL; SR_PRIV GSList *dev_insts = NULL; @@ -354,6 +362,9 @@ static void *hw_get_device_info(int dev_index, int dev_info_id) case SR_DI_TRIGGER_SOURCES: info = trigger_sources; break; + case SR_DI_FILTERS: + info = filter_targets; + break; /* TODO remove this */ case SR_DI_CUR_SAMPLERATE: info = &tmp; @@ -387,7 +398,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) float tmp_float; uint64_t tmp_u64; int ret, i; - char *tmp_str; + char *tmp_str, **targets; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; @@ -452,6 +463,26 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) if (trigger_sources[i] == 0) ret = SR_ERR_ARG; break; + case SR_HWCAP_FILTER: + ctx->filter_ch1 = ctx->filter_ch2 = ctx->filter_trigger = 0; + targets = g_strsplit(value, ",", 0); + for (i = 0; targets[i]; i++) { + if (targets[i] == '\0') + /* Empty filter string can be used to clear them all. */ + ; + else if (!strcmp(targets[i], "CH1")) + ctx->filter_ch1 = TRUE; + else if (!strcmp(targets[i], "CH2")) + ctx->filter_ch2 = TRUE; + else if (!strcmp(targets[i], "TRIGGER")) + ctx->filter_trigger = TRUE; + else { + sr_err("invalid filter target %s", targets[i]); + ret = SR_ERR_ARG; + } + } + g_strfreev(targets); + break; default: ret = SR_ERR_ARG; } diff --git a/hardware/hantek-dso/dso.c b/hardware/hantek-dso/dso.c index aa5fe239..3f65eed9 100644 --- a/hardware/hantek-dso/dso.c +++ b/hardware/hantek-dso/dso.c @@ -338,17 +338,24 @@ SR_PRIV int dso_set_filters(struct context *ctx) int ret, tmp; uint8_t cmdstring[8]; - sr_dbg("hantek-dso: sending CMD_SET_FILTERS"); + sr_dbg("hantek-dso: preparing CMD_SET_FILTERS"); memset(cmdstring, 0, sizeof(cmdstring)); cmdstring[0] = CMD_SET_FILTERS; cmdstring[1] = 0x0f; - if (ctx->filter_ch1) + if (ctx->filter_ch1) { + sr_dbg("hantek-dso: turning on CH1 filter"); cmdstring[2] |= 0x80; - if (ctx->filter_ch2) + } + if (ctx->filter_ch2) { + sr_dbg("hantek-dso: turning on CH2 filter"); cmdstring[2] |= 0x40; - if (ctx->filter_trigger) + } + if (ctx->filter_trigger) { + /* TODO: supported on the DSO-2090? */ + sr_dbg("hantek-dso: turning on trigger filter"); cmdstring[2] |= 0x20; + } if (send_begin(ctx) != SR_OK) return SR_ERR; @@ -360,6 +367,7 @@ SR_PRIV int dso_set_filters(struct context *ctx) sr_err("Failed to set filters: %d", ret); return SR_ERR; } + sr_dbg("hantek-dso: sent CMD_SET_FILTERS"); return SR_OK; }