From: Russ Dill Date: Tue, 3 Dec 2013 07:29:04 +0000 (-0800) Subject: zeroplus: Add voltage threshold support X-Git-Tag: libsigrok-0.3.0~340 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7142d6b9d5d65749e0cedfcff9025dffe38c76c2;p=libsigrok.git zeroplus: Add voltage threshold support It doesn't currently mesh well with libsigrok, but at least the support is there. --- diff --git a/hardware/zeroplus-logic-cube/analyzer.c b/hardware/zeroplus-logic-cube/analyzer.c index 63116fc1..47dcfc8b 100644 --- a/hardware/zeroplus-logic-cube/analyzer.c +++ b/hardware/zeroplus-logic-cube/analyzer.c @@ -118,6 +118,7 @@ static int g_memory_size = MEMORY_SIZE_8K; static int g_ramsize_triggerbar_addr = 2 * 1024; static int g_triggerbar_addr = 0; static int g_compression = COMPRESSION_NONE; +static int g_thresh = 0x31; /* 1.5V */ /* Maybe unk specifies an "endpoint" or "register" of sorts. */ static int analyzer_write_status(libusb_device_handle *devh, unsigned char unk, @@ -465,10 +466,10 @@ SR_PRIV void analyzer_configure(libusb_device_handle *devh) __analyzer_set_trigger_count(devh, g_trigger_count); /* Set_Trigger_Level */ - gl_reg_write(devh, TRIGGER_LEVEL0, 0x31); - gl_reg_write(devh, TRIGGER_LEVEL1, 0x31); - gl_reg_write(devh, TRIGGER_LEVEL2, 0x31); - gl_reg_write(devh, TRIGGER_LEVEL3, 0x31); + gl_reg_write(devh, TRIGGER_LEVEL0, g_thresh); + gl_reg_write(devh, TRIGGER_LEVEL1, g_thresh); + gl_reg_write(devh, TRIGGER_LEVEL2, g_thresh); + gl_reg_write(devh, TRIGGER_LEVEL3, g_thresh); /* Size of actual memory >> 2 */ __analyzer_set_ramsize_trigger_address(devh, g_ramsize_triggerbar_addr); @@ -612,6 +613,11 @@ SR_PRIV void analyzer_set_compression(unsigned int type) g_compression = type; } +SR_PRIV void analyzer_set_voltage_threshold(int thresh) +{ + g_thresh = thresh; +} + SR_PRIV void analyzer_wait_button(libusb_device_handle *devh) { analyzer_wait(devh, STATUS_BUTTON_PRESSED, 0); diff --git a/hardware/zeroplus-logic-cube/analyzer.h b/hardware/zeroplus-logic-cube/analyzer.h index 94d1cc1a..f0bb7993 100644 --- a/hardware/zeroplus-logic-cube/analyzer.h +++ b/hardware/zeroplus-logic-cube/analyzer.h @@ -92,6 +92,7 @@ SR_PRIV void analyzer_set_memory_size(unsigned int size); SR_PRIV void analyzer_add_trigger(int channel, int type); SR_PRIV void analyzer_set_trigger_count(int count); SR_PRIV void analyzer_add_filter(int channel, int type); +SR_PRIV void analyzer_set_voltage_threshold(int thresh); SR_PRIV unsigned int analyzer_read_status(libusb_device_handle *devh); SR_PRIV unsigned int analyzer_read_id(libusb_device_handle *devh); diff --git a/hardware/zeroplus-logic-cube/api.c b/hardware/zeroplus-logic-cube/api.c index 84f830a6..25b4f78f 100644 --- a/hardware/zeroplus-logic-cube/api.c +++ b/hardware/zeroplus-logic-cube/api.c @@ -57,6 +57,7 @@ static const int32_t hwcaps[] = { SR_CONF_LOGIC_ANALYZER, SR_CONF_SAMPLERATE, SR_CONF_CAPTURE_RATIO, + SR_CONF_VOLTAGE_THRESHOLD, SR_CONF_LIMIT_SAMPLES, }; @@ -439,6 +440,9 @@ static int dev_open(struct sr_dev_inst *sdi) devc->cur_samplerate = SR_MHZ(1); } + if (devc->cur_threshold == 0) + set_voltage_threshold(devc, 1.5); + return SR_OK; } @@ -491,6 +495,16 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, } else return SR_ERR; break; + case SR_CONF_VOLTAGE_THRESHOLD: + if (sdi) { + GVariant *range[2]; + devc = sdi->priv; + range[0] = g_variant_new_double(devc->cur_threshold); + range[1] = g_variant_new_double(devc->cur_threshold); + *data = g_variant_new_tuple(range, 2); + } else + return SR_ERR; + break; default: return SR_ERR_NA; } @@ -502,6 +516,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_probe_group *probe_group) { struct dev_context *devc; + gdouble low, high; (void)probe_group; @@ -520,6 +535,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, return set_limit_samples(devc, g_variant_get_uint64(data)); case SR_CONF_CAPTURE_RATIO: return set_capture_ratio(devc, g_variant_get_uint64(data)); + case SR_CONF_VOLTAGE_THRESHOLD: + g_variant_get(data, "(dd)", &low, &high); + return set_voltage_threshold(devc, (low + high) / 2.0); default: return SR_ERR_NA; } @@ -533,6 +551,8 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, struct dev_context *devc; GVariant *gvar; GVariantBuilder gvb; + double v; + GVariant *range[2]; (void)probe_group; @@ -563,6 +583,16 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, case SR_CONF_TRIGGER_TYPE: *data = g_variant_new_string(TRIGGER_TYPE); break; + case SR_CONF_VOLTAGE_THRESHOLD: + g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); + for (v = -6.0; v <= 6.0; v += 0.1) { + range[0] = g_variant_new_double(v); + range[1] = g_variant_new_double(v); + gvar = g_variant_new_tuple(range, 2); + g_variant_builder_add_value(&gvb, gvar); + } + *data = g_variant_builder_end(&gvb); + break; default: return SR_ERR_NA; } diff --git a/hardware/zeroplus-logic-cube/protocol.c b/hardware/zeroplus-logic-cube/protocol.c index 205bf560..20adc389 100644 --- a/hardware/zeroplus-logic-cube/protocol.c +++ b/hardware/zeroplus-logic-cube/protocol.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include #include "protocol.h" SR_PRIV unsigned int get_memory_size(int type) @@ -91,6 +92,22 @@ SR_PRIV int set_capture_ratio(struct dev_context *devc, uint64_t ratio) return SR_OK; } +SR_PRIV int set_voltage_threshold(struct dev_context *devc, double thresh) +{ + if (thresh > 6.0) + thresh = 6.0; + if (thresh < -6.0) + thresh = -6.0; + + devc->cur_threshold = thresh; + + analyzer_set_voltage_threshold((int) round(-9.1*thresh + 62.6)); + + sr_info("Setting voltage threshold to %fV.", devc->cur_threshold); + + return SR_OK; +} + SR_PRIV void set_triggerbar(struct dev_context *devc) { unsigned int trigger_depth, triggerbar, ramsize_trigger; diff --git a/hardware/zeroplus-logic-cube/protocol.h b/hardware/zeroplus-logic-cube/protocol.h index 718dd217..09f82287 100644 --- a/hardware/zeroplus-logic-cube/protocol.h +++ b/hardware/zeroplus-logic-cube/protocol.h @@ -44,6 +44,7 @@ struct dev_context { // uint8_t trigger_buffer[NUM_TRIGGER_STAGES]; int trigger; unsigned int capture_ratio; + double cur_threshold; const struct zp_model *prof; }; @@ -51,6 +52,7 @@ SR_PRIV unsigned int get_memory_size(int type); SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate); SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples); SR_PRIV int set_capture_ratio(struct dev_context *devc, uint64_t ratio); +SR_PRIV int set_voltage_threshold(struct dev_context *devc, double thresh); SR_PRIV void set_triggerbar(struct dev_context *devc); #endif