]> sigrok.org Git - libsigrok.git/commitdiff
saleae-logic16: Add voltage threshold conf.
authorMarcus Comstedt <redacted>
Sun, 4 Aug 2013 14:20:07 +0000 (16:20 +0200)
committerUwe Hermann <redacted>
Tue, 20 Aug 2013 17:55:57 +0000 (19:55 +0200)
hardware/saleae-logic16/api.c
hardware/saleae-logic16/protocol.c
hardware/saleae-logic16/protocol.h
hwdriver.c
libsigrok.h

index 1d5bb3820190690072c8f22a3d2efecb26a66eda..2192b12e4a7ebc6c49b30ae60678612e6d4d4bf8 100644 (file)
@@ -21,6 +21,7 @@
 #include <libusb.h>
 #include <stdlib.h>
 #include <string.h>
+#include <math.h>
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 #include "protocol.h"
@@ -47,6 +48,7 @@ static const int32_t hwopts[] = {
 static const int32_t hwcaps[] = {
        SR_CONF_LOGIC_ANALYZER,
        SR_CONF_SAMPLERATE,
+       SR_CONF_VOLTAGE_THRESHOLD,
 
        /* These are really implemented in the driver, not the hardware. */
        SR_CONF_LIMIT_SAMPLES,
@@ -59,6 +61,15 @@ static const char *probe_names[NUM_PROBES + 1] = {
        NULL,
 };
 
+static const struct {
+       enum voltage_range range;
+       gdouble low;
+       gdouble high;
+} volt_thresholds[] = {
+       { VOLTAGE_RANGE_18_33_V, 0.7, 1.4 },
+       { VOLTAGE_RANGE_5_V,     1.4, 3.6 },
+};
+
 static const uint64_t samplerates[] = {
        SR_KHZ(500),
        SR_MHZ(1),
@@ -192,6 +203,7 @@ static GSList *scan(GSList *options)
 
                if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
                        return NULL;
+               devc->selected_voltage_range = VOLTAGE_RANGE_18_33_V;
                sdi->priv = devc;
                drvc->instances = g_slist_append(drvc->instances, sdi);
                devices = g_slist_append(devices, sdi);
@@ -430,8 +442,10 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct sr_usb_dev_inst *usb;
+       GVariant *range[2];
        char str[128];
        int ret;
+       unsigned i;
 
        ret = SR_OK;
        switch (key) {
@@ -452,6 +466,21 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
                devc = sdi->priv;
                *data = g_variant_new_uint64(devc->cur_samplerate);
                break;
+       case SR_CONF_VOLTAGE_THRESHOLD:
+               if (!sdi)
+                       return SR_ERR;
+               devc = sdi->priv;
+               ret = SR_ERR;
+               for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++)
+                       if (devc->selected_voltage_range ==
+                           volt_thresholds[i].range) {
+                               range[0] = g_variant_new_double(volt_thresholds[i].low);
+                               range[1] = g_variant_new_double(volt_thresholds[i].high);
+                               *data = g_variant_new_tuple(range, 2);
+                               ret = SR_OK;
+                               break;
+                       }
+               break;
        default:
                return SR_ERR_NA;
        }
@@ -462,7 +491,9 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
 static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
+       gdouble low, high;
        int ret;
+       unsigned i;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
@@ -477,6 +508,19 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
        case SR_CONF_LIMIT_SAMPLES:
                devc->limit_samples = g_variant_get_uint64(data);
                break;
+       case SR_CONF_VOLTAGE_THRESHOLD:
+               g_variant_get(data, "(dd)", &low, &high);
+               ret = SR_ERR_ARG;
+               for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++) {
+                       if (fabs(volt_thresholds[i].low - low) < 0.1 &&
+                           fabs(volt_thresholds[i].high - high) < 0.1) {
+                               devc->selected_voltage_range =
+                                       volt_thresholds[i].range;
+                               ret = SR_OK;
+                               break;
+                       }
+               }
+               break;
        default:
                ret = SR_ERR_NA;
        }
@@ -486,9 +530,10 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
 
 static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
 {
-       GVariant *gvar;
+       GVariant *gvar, *range[2];
        GVariantBuilder gvb;
        int ret;
+       unsigned i;
 
        (void)sdi;
 
@@ -509,6 +554,16 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
                g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
                *data = g_variant_builder_end(&gvb);
                break;
+       case SR_CONF_VOLTAGE_THRESHOLD:
+               g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
+               for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++) {
+                       range[0] = g_variant_new_double(volt_thresholds[i].low);
+                       range[1] = g_variant_new_double(volt_thresholds[i].high);
+                       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 03808874c97da793d895644397ee5bd411f817f4..29be871b7f1aaa6909425481e43e0f607e2320ab 100644 (file)
@@ -429,6 +429,9 @@ SR_PRIV int saleae_logic16_setup_acquisition(const struct sr_dev_inst *sdi,
        uint8_t clock_select, reg1, reg10;
        uint64_t div;
        int i, ret, nchan = 0;
+       struct dev_context *devc;
+
+       devc = sdi->priv;
 
        if (samplerate == 0 || samplerate > MAX_SAMPLE_RATE) {
                sr_err("Unable to sample at %" PRIu64 "Hz.", samplerate);
@@ -460,6 +463,9 @@ SR_PRIV int saleae_logic16_setup_acquisition(const struct sr_dev_inst *sdi,
                return SR_ERR;
        }
 
+       if ((ret = upload_fpga_bitstream(sdi, devc->selected_voltage_range)) != SR_OK)
+               return ret;
+
        if ((ret = read_fpga_register(sdi, 1, &reg1)) != SR_OK)
                return ret;
 
@@ -568,7 +574,7 @@ SR_PRIV int saleae_logic16_init_device(const struct sr_dev_inst *sdi)
        if ((ret = read_eeprom(sdi, 8, 8, devc->eeprom_data)) != SR_OK)
                return ret;
 
-       if ((ret = upload_fpga_bitstream(sdi, VOLTAGE_RANGE_18_33_V)) != SR_OK)
+       if ((ret = upload_fpga_bitstream(sdi, devc->selected_voltage_range)) != SR_OK)
                return ret;
 
        return SR_OK;
index 80b20f95643ad14fa0d7fd232b3ac4fcd11eafe0..eeb9781ee3685ebf283612dc84a2c19d7f3bd1e8 100644 (file)
@@ -59,6 +59,9 @@ struct dev_context {
        /** The currently configured input voltage of the device */
        enum voltage_range cur_voltage_range;
 
+       /** The input voltage selected by the user */
+       enum voltage_range selected_voltage_range;
+
        /** Channels to use */
        uint16_t cur_channels;
 
index ccd46e8ab0469a65f1c1be44ecaaa42cdfa36f5a..65c8c2583b4bb6c540f3ffb7fe3f6f12be21f5d2 100644 (file)
@@ -93,6 +93,8 @@ static struct sr_config_info sr_config_info_data[] = {
                "Hold min", NULL},
        {SR_CONF_SPL_MEASUREMENT_RANGE, SR_T_UINT64_RANGE, "spl_meas_range",
                "Sound pressure level measurement range", NULL},
+       {SR_CONF_VOLTAGE_THRESHOLD, SR_T_DOUBLE_RANGE, "voltage_threshold",
+               "Voltage threshold", NULL },
        {SR_CONF_POWER_OFF, SR_T_BOOL, "power_off",
                "Power off", NULL},
        {SR_CONF_DATA_SOURCE, SR_T_CHAR, "data_source",
index 2f7047a426119ef1a4a909792c8244e138e46cce..a93a07ea3a4745218ce74c167117f254d3df75a8 100644 (file)
@@ -142,6 +142,7 @@ enum {
        SR_T_RATIONAL_VOLT,
        SR_T_KEYVALUE,
        SR_T_UINT64_RANGE,
+       SR_T_DOUBLE_RANGE,
 };
 
 /** Value for sr_datafeed_packet.type. */
@@ -681,6 +682,9 @@ enum {
        /** Min hold mode. */
        SR_CONF_HOLD_MIN,
 
+       /** Logic low-high threshold range. */
+       SR_CONF_VOLTAGE_THRESHOLD,
+
        /*--- Special stuff -------------------------------------------------*/
 
        /** Scan options supported by the driver. */