]> sigrok.org Git - libsigrok.git/commitdiff
hantek-dso: support SR_HWCAP_VDIV
authorBert Vermeulen <redacted>
Thu, 17 May 2012 00:03:12 +0000 (02:03 +0200)
committerBert Vermeulen <redacted>
Wed, 30 May 2012 21:56:12 +0000 (23:56 +0200)
hardware/hantek-dso/api.c
hardware/hantek-dso/dso.c
hardware/hantek-dso/dso.h

index 898bccec597ff3648174874a0922a02dcdc679de..6c1042ffca439250f89a550d4df137786cb9a7eb 100644 (file)
@@ -49,6 +49,7 @@ static int capabilities[] = {
        SR_HWCAP_TRIGGER_SLOPE,
        SR_HWCAP_HORIZ_TRIGGERPOS,
        SR_HWCAP_FILTER,
+       SR_HWCAP_VDIV,
        0,
 };
 
@@ -95,6 +96,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",
@@ -365,6 +381,9 @@ static void *hw_get_device_info(int dev_index, int dev_info_id)
        case SR_DI_FILTERS:
                info = filter_targets;
                break;
+       case SR_DI_VDIVS:
+               info = vdivs;
+               break;
        /* TODO remove this */
        case SR_DI_CUR_SAMPLERATE:
                info = &tmp;
@@ -483,6 +502,20 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value)
                }
                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;
        default:
                ret = SR_ERR_ARG;
        }
index 3f65eed9c7d3ba85cbdf7120d7c05cd2fcf38cf7..00dde6da1f14693aa68c554ad8881a7772a5317a 100644 (file)
@@ -377,15 +377,52 @@ SR_PRIV int dso_set_voltage(struct context *ctx)
        int ret, tmp;
        uint8_t cmdstring[8];
 
-       sr_dbg("hantek-dso: sending CMD_SET_VOLTAGE");
+       sr_dbg("hantek-dso: preparing CMD_SET_VOLTAGE");
 
        memset(cmdstring, 0, sizeof(cmdstring));
        cmdstring[0] = CMD_SET_VOLTAGE;
        cmdstring[1] = 0x0f;
-       cmdstring[2] = 0x03;
-       cmdstring[2] |= ((2 - ctx->voltage_ch1 % 3) << 6);
-       cmdstring[2] |= ((2 - ctx->voltage_ch2 % 3) << 4);
-cmdstring[2] = 0x30;
+       cmdstring[2] = 0x30;
+
+       /* CH1 volts/div is encoded in bits 0-1 */
+       sr_dbg("hantek-dso: CH1 vdiv index %d", ctx->voltage_ch1);
+       switch (ctx->voltage_ch1) {
+       case VDIV_1V:
+       case VDIV_100MV:
+       case VDIV_10MV:
+               cmdstring[2] |= 0x00;
+               break;
+       case VDIV_2V:
+       case VDIV_200MV:
+       case VDIV_20MV:
+               cmdstring[2] |= 0x01;
+               break;
+       case VDIV_5V:
+       case VDIV_500MV:
+       case VDIV_50MV:
+               cmdstring[2] |= 0x02;
+               break;
+       }
+
+       /* CH2 volts/div is encoded in bits 2-3 */
+       sr_dbg("hantek-dso: CH2 vdiv index %d", ctx->voltage_ch2);
+       switch (ctx->voltage_ch2) {
+       case VDIV_1V:
+       case VDIV_100MV:
+       case VDIV_10MV:
+               cmdstring[2] |= 0x00;
+               break;
+       case VDIV_2V:
+       case VDIV_200MV:
+       case VDIV_20MV:
+               cmdstring[2] |= 0x08;
+               break;
+       case VDIV_5V:
+       case VDIV_500MV:
+       case VDIV_50MV:
+               cmdstring[2] |= 0x04;
+               break;
+       }
 
        if (send_begin(ctx) != SR_OK)
                return SR_ERR;
@@ -397,6 +434,7 @@ cmdstring[2] = 0x30;
                sr_err("Failed to set voltage: %d", ret);
                return SR_ERR;
        }
+       sr_dbg("hantek-dso: sent CMD_SET_VOLTAGE");
 
        return SR_OK;
 }
@@ -559,9 +597,6 @@ SR_PRIV int dso_init(struct context *ctx)
        if (dso_enable_trigger(ctx) != SR_OK)
                return SR_ERR;
 
-       if (dso_force_trigger(ctx) != SR_OK)
-               return SR_ERR;
-
        return SR_OK;
 }
 
index 42077c0ab51a1404e02c089b9212c13f06b7a504..53d953e12fa4f024576532ee6722f3351d06df3e 100644 (file)
@@ -32,7 +32,7 @@
 
 #define MAX_CAPTURE_EMPTY      3
 
-#define DEFAULT_VOLTAGE            VOLTAGE_2V
+#define DEFAULT_VOLTAGE            VDIV_500MV
 #define DEFAULT_FRAMESIZE          FRAMESIZE_SMALL
 #define DEFAULT_TIMEBASE           TIME_100us
 #define DEFAULT_TRIGGER_SOURCE     "CH1"
@@ -67,22 +67,11 @@ enum dso_commands {
        CMD_GET_CHANNELDATA,
        CMD_GET_CAPTURESTATE,
        CMD_SET_VOLTAGE,
+       /* unused */
        cmdSetLogicalData,
        cmdGetLogicalData
 };
 
-enum voltages {
-       VOLTAGE_5V = 0,
-       VOLTAGE_2V,
-       VOLTAGE_1V,
-       VOLTAGE_500mV,
-       VOLTAGE_200mV,
-       VOLTAGE_100mV,
-       VOLTAGE_50mV,
-       VOLTAGE_20mV,
-       VOLTAGE_10mV
-};
-
 enum couplings {
        COUPLING_AC = 0,
        COUPLING_DC,
@@ -107,6 +96,19 @@ enum time_bases {
        TIME_400ms
 };
 
+/* Must match the vdivs table, these are just handy indexes into it. */
+enum {
+       VDIV_10MV,
+       VDIV_20MV,
+       VDIV_50MV,
+       VDIV_100MV,
+       VDIV_200MV,
+       VDIV_500MV,
+       VDIV_1V,
+       VDIV_2V,
+       VDIV_5V,
+};
+
 enum trigger_slopes {
        SLOPE_POSITIVE = 0,
        SLOPE_NEGATIVE