]> sigrok.org Git - libsigrok.git/blobdiff - hardware/hantek-dso/api.c
hantek-dso: Update to constified libsigrok API.
[libsigrok.git] / hardware / hantek-dso / api.c
index ba55e86805be572c80f1aa4fb95902a02614d9ef..211d782e6c47d2687e2bb01551a8552e82b6d6bb 100644 (file)
@@ -35,6 +35,8 @@
 #include "config.h"
 #include "dso.h"
 
+/* FIXME: Temporary build fix, this will be removed later. */
+#define GTV_TO_MSEC(gtv)       (gtv.tv_sec * 1000 + gtv.tv_usec / 1000)
 
 /* Max time in ms before we want to check on events */
 #define TICK    1
@@ -48,6 +50,9 @@ static int capabilities[] = {
        SR_HWCAP_TRIGGER_SOURCE,
        SR_HWCAP_TRIGGER_SLOPE,
        SR_HWCAP_HORIZ_TRIGGERPOS,
+       SR_HWCAP_FILTER,
+       SR_HWCAP_VDIV,
+       SR_HWCAP_COUPLING,
        0,
 };
 
@@ -94,6 +99,21 @@ static struct sr_rational timebases[] = {
        {0,0}
 };
 
+static struct sr_rational vdivs[] = {
+       /* millivolts */
+       { 10, 1000 },
+       { 20, 1000 },
+       { 50, 1000 },
+       { 100, 1000 },
+       { 200, 1000 },
+       { 500, 1000 },
+       /* volts */
+       { 1, 1 },
+       { 2, 1 },
+       { 5, 1 },
+       {0,0}
+};
+
 static char *trigger_sources[] = {
        "CH1",
        "CH2",
@@ -101,6 +121,20 @@ static char *trigger_sources[] = {
        NULL
 };
 
+static char *filter_targets[] = {
+       "CH1",
+       "CH2",
+       /* TODO: "TRIGGER", */
+       NULL
+};
+
+static char *coupling[] = {
+       "AC",
+       "DC",
+       "GND",
+       NULL
+};
+
 SR_PRIV libusb_context *usb_context = NULL;
 SR_PRIV GSList *dev_insts = NULL;
 
@@ -323,7 +357,7 @@ static int hw_cleanup(void)
        return SR_OK;
 }
 
-static void *hw_get_device_info(int dev_index, int dev_info_id)
+static const void *hw_get_device_info(int dev_index, int dev_info_id)
 {
        struct sr_dev_inst *sdi;
        struct context *ctx;
@@ -354,6 +388,15 @@ 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;
+       case SR_DI_VDIVS:
+               info = vdivs;
+               break;
+       case SR_DI_COUPLING:
+               info = coupling;
+               break;
        /* TODO remove this */
        case SR_DI_CUR_SAMPLERATE:
                info = &tmp;
@@ -373,13 +416,12 @@ static int hw_get_status(int device_index)
        return sdi->status;
 }
 
-static int *hwcap_get_all(void)
+static const int *hwcap_get_all(void)
 {
-
        return capabilities;
 }
 
-static int hw_dev_config_set(int dev_index, int hwcap, void *value)
+static int hw_dev_config_set(int dev_index, int hwcap, const void *value)
 {
        struct sr_dev_inst *sdi;
        struct context *ctx;
@@ -387,7 +429,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 **targets;
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
                return SR_ERR;
@@ -442,16 +484,61 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value)
                        ret = SR_ERR_ARG;
                break;
        case SR_HWCAP_TRIGGER_SOURCE:
-               tmp_str = value;
                for (i = 0; trigger_sources[i]; i++) {
-                       if (!strcmp(tmp_str, trigger_sources[i])) {
-                               ctx->triggersource = g_strdup(tmp_str);
+                       if (!strcmp(value, trigger_sources[i])) {
+                               ctx->triggersource = g_strdup(value);
                                break;
                        }
                }
                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;
+       case SR_HWCAP_VDIV:
+               /* TODO not supporting vdiv per channel yet */
+               tmp_rat = *(struct sr_rational *)value;
+               for (i = 0; vdivs[i].p && vdivs[i].q; i++) {
+                       if (vdivs[i].p == tmp_rat.p
+                                       && vdivs[i].q == tmp_rat.q) {
+                               ctx->voltage_ch1 = i;
+                               ctx->voltage_ch2 = i;
+                               break;
+                       }
+               }
+               if (vdivs[i].p == 0 && vdivs[i].q == 0)
+                       ret = SR_ERR_ARG;
+               break;
+       case SR_HWCAP_COUPLING:
+               /* TODO not supporting coupling per channel yet */
+               for (i = 0; coupling[i]; i++) {
+                       if (!strcmp(value, coupling[i])) {
+                               ctx->coupling_ch1 = i;
+                               ctx->coupling_ch2 = i;
+                               break;
+                       }
+               }
+               if (coupling[i] == 0)
+                       ret = SR_ERR_ARG;
+               break;
        default:
                ret = SR_ERR_ARG;
        }