]> sigrok.org Git - libsigrok.git/commitdiff
zeroplus: Add voltage threshold support
authorRuss Dill <redacted>
Tue, 3 Dec 2013 07:29:04 +0000 (23:29 -0800)
committerBert Vermeulen <redacted>
Fri, 3 Jan 2014 14:09:11 +0000 (15:09 +0100)
It doesn't currently mesh well with libsigrok, but at least the support is there.

hardware/zeroplus-logic-cube/analyzer.c
hardware/zeroplus-logic-cube/analyzer.h
hardware/zeroplus-logic-cube/api.c
hardware/zeroplus-logic-cube/protocol.c
hardware/zeroplus-logic-cube/protocol.h

index 63116fc1fa85c91e8741ef7adf52132c6aec9f33..47dcfc8b2574200b0b9069edc96384532c9bc9d2 100644 (file)
@@ -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);
index 94d1cc1a3c0baae5d396ec31a414a092d155f141..f0bb79932009c503f2e6d8ccd0a7626e28c88661 100644 (file)
@@ -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);
index 84f830a6f96e4b5036729b524a1c692a213c5025..25b4f78f80aa278a5a30cc996a2d88d203db85da 100644 (file)
@@ -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;
        }
index 205bf560e168f45f043f11385cadf0e149222203..20adc389eea6679e2e46db4bff457772d98f645b 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <math.h>
 #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;
index 718dd217ad83f3378b3c8675dc800e415ee213cd..09f82287bd87db9eddbed913611ce480b5b61460 100644 (file)
@@ -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