SR_HWCAP_OSCILLOSCOPE,
SR_HWCAP_LIMIT_SAMPLES,
SR_HWCAP_CONTINUOUS,
+ SR_HWCAP_TIMEBASE,
+ SR_HWCAP_BUFFERSIZE,
+ SR_HWCAP_TRIGGER_SOURCE,
+ SR_HWCAP_TRIGGER_SLOPE,
+ SR_HWCAP_HORIZ_TRIGGERPOS,
0,
};
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
+static uint64_t buffersizes[] = {
+ 10240,
+ 32768,
+ /* TODO: 65535 */
+ 0
+};
+
+static struct sr_rational timebases[] = {
+ /* microseconds */
+ { 10, 1000000 },
+ { 20, 1000000 },
+ { 40, 1000000 },
+ { 100, 1000000 },
+ { 200, 1000000 },
+ { 400, 1000000 },
+ /* milliseconds */
+ { 1, 1000 },
+ { 2, 1000 },
+ { 4, 1000 },
+ { 10, 1000 },
+ { 20, 1000 },
+ { 40, 1000 },
+ { 100, 1000 },
+ { 200, 1000 },
+ { 400, 1000 },
+ {0,0}
+};
+
+static char *trigger_sources[] = {
+ "CH1",
+ "CH2",
+ "EXT",
+ NULL
+};
SR_PRIV libusb_context *usb_context = NULL;
SR_PRIV GSList *dev_insts = NULL;
ctx->voffset_trigger = DEFAULT_VERT_TRIGGERPOS;
ctx->framesize = DEFAULT_FRAMESIZE;
ctx->triggerslope = SLOPE_POSITIVE;
- ctx->triggersource = DEFAULT_TRIGGER_SOURCE;
+ ctx->triggersource = g_strdup(DEFAULT_TRIGGER_SOURCE);
ctx->triggerposition = DEFAULT_HORIZ_TRIGGERPOS;
sdi->priv = ctx;
dev_insts = g_slist_append(dev_insts, sdi);
}
dso_close(sdi);
sr_usb_dev_inst_free(ctx->usb);
+ g_free(ctx->triggersource);
+
sr_dev_inst_free(sdi);
}
case SR_DI_PROBE_NAMES:
info = probe_names;
break;
+ case SR_DI_BUFFERSIZES:
+ info = buffersizes;
+ break;
+ case SR_DI_TIMEBASES:
+ info = timebases;
+ break;
+ case SR_DI_TRIGGER_SOURCES:
+ info = trigger_sources;
+ break;
/* TODO remove this */
case SR_DI_CUR_SAMPLERATE:
info = &tmp;
{
struct sr_dev_inst *sdi;
struct context *ctx;
- int tmp, ret;
+ struct sr_rational tmp_rat;
+ float tmp_float;
+ uint64_t tmp_u64;
+ int ret, i;
+ char *tmp_str;
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
return SR_ERR;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR;
+ ret = SR_OK;
ctx = sdi->priv;
switch (hwcap) {
case SR_HWCAP_LIMIT_FRAMES:
case SR_HWCAP_PROBECONFIG:
ret = configure_probes(ctx, (GSList *) value);
break;
- case SR_HWCAP_TRIGGERSLOPE:
- tmp = *(int *)value;
- if (tmp != SLOPE_NEGATIVE && tmp != SLOPE_POSITIVE)
+ case SR_HWCAP_TRIGGER_SLOPE:
+ tmp_u64 = *(int *)value;
+ if (tmp_u64 != SLOPE_NEGATIVE && tmp_u64 != SLOPE_POSITIVE)
+ ret = SR_ERR_ARG;
+ ctx->triggerslope = tmp_u64;
+ break;
+ case SR_HWCAP_HORIZ_TRIGGERPOS:
+ tmp_float = *(float *)value;
+ if (tmp_float < 0.0 || tmp_float > 1.0) {
+ sr_err("hantek-dso: trigger position should be between 0.0 and 1.0");
ret = SR_ERR_ARG;
- ctx->triggerslope = tmp;
+ } else
+ ctx->triggerposition = tmp_float;
+ break;
+ case SR_HWCAP_BUFFERSIZE:
+ tmp_u64 = *(int *)value;
+ for (i = 0; buffersizes[i]; i++) {
+ if (buffersizes[i] == tmp_u64) {
+ ctx->framesize = tmp_u64;
+ break;
+ }
+ }
+ if (buffersizes[i] == 0)
+ ret = SR_ERR_ARG;
+ break;
+ case SR_HWCAP_TIMEBASE:
+ tmp_rat = *(struct sr_rational *)value;
+ for (i = 0; timebases[i].p && timebases[i].q; i++) {
+ if (timebases[i].p == tmp_rat.p
+ && timebases[i].q == tmp_rat.q) {
+ ctx->timebase = i;
+ break;
+ }
+ }
+ if (timebases[i].p == 0 && timebases[i].q == 0)
+ 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);
+ break;
+ }
+ }
+ if (trigger_sources[i] == 0)
+ ret = SR_ERR_ARG;
+ break;
default:
ret = SR_ERR_ARG;
}
return TRUE;
if (dso_enable_trigger(ctx) != SR_OK)
return TRUE;
- if (dso_force_trigger(ctx) != SR_OK)
- return TRUE;
+// if (dso_force_trigger(ctx) != SR_OK)
+// return TRUE;
sr_dbg("hantek-dso: successfully requested next chunk");
ctx->dev_state = CAPTURE;
return TRUE;
break;
if (dso_enable_trigger(ctx) != SR_OK)
break;
- if (dso_force_trigger(ctx) != SR_OK)
- break;
+// if (dso_force_trigger(ctx) != SR_OK)
+// break;
sr_dbg("hantek-dso: successfully requested next chunk");
}
break;
uint16_t timebase_large[] = { 0xffff, 0x0000, 0xfffc, 0xfff7, 0xffe8,
0xffce, 0xff9d, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79 };
- sr_dbg("hantek-dso: sending CMD_SET_TRIGGER_SAMPLERATE");
+ sr_dbg("hantek-dso: preparing CMD_SET_TRIGGER_SAMPLERATE");
memset(cmdstring, 0, sizeof(cmdstring));
/* Command */
cmdstring[0] = CMD_SET_TRIGGER_SAMPLERATE;
/* Trigger source */
- cmdstring[2] = (ctx->triggersource & 0x03);
+ sr_dbg("hantek-dso: trigger source %s", ctx->triggersource);
+ if (!strcmp("CH2", ctx->triggersource))
+ tmp = 0;
+ else if (!strcmp("CH1", ctx->triggersource))
+ tmp = 1;
+ else if (!strcmp("EXT", ctx->triggersource))
+ tmp = 2;
+ else {
+ sr_err("hantek-dso: invalid trigger source %s", ctx->triggersource);
+ return SR_ERR_ARG;
+ }
+ cmdstring[2] = tmp;
/* Frame size */
+ sr_dbg("hantek-dso: frame size %d", ctx->framesize);
cmdstring[2] |= (ctx->framesize == FRAMESIZE_SMALL ? 0x01 : 0x02) << 2;
/* Timebase fast */
+ sr_dbg("hantek-dso: time base index %d", ctx->timebase);
switch (ctx->framesize) {
case FRAMESIZE_SMALL:
if (ctx->timebase < TIME_20us)
cmdstring[2] |= (tmp & 0x07) << 5;
/* Enabled channels: 00=CH1 01=CH2 10=both */
+ sr_dbg("hantek-dso: channels CH1=%d CH2=%d", ctx->ch1_enabled, ctx->ch2_enabled);
tmp = (((ctx->ch2_enabled ? 1 : 0) << 1) + (ctx->ch1_enabled ? 1 : 0)) - 1;
cmdstring[3] = tmp;
cmdstring[3] |= tmp << 2;
/* Trigger slope: 0=positive 1=negative */
+ /* TODO: does this work? */
+ sr_dbg("hantek-dso: trigger slope %d", ctx->triggerslope);
cmdstring[3] |= (ctx->triggerslope == SLOPE_NEGATIVE ? 1 : 0) << 3;
- /* Timebase */
+ /* Timebase slow */
if (ctx->timebase < TIME_100us)
tmp = 0;
else if (ctx->timebase > TIME_400ms)
cmdstring[5] = (tmp >> 8) & 0xff;
/* Horizontal trigger position */
+ sr_dbg("hantek-dso: trigger position %3.2f", ctx->triggerposition);
tmp = 0x77fff + 0x8000 * ctx->triggerposition;
cmdstring[6] = tmp & 0xff;
cmdstring[7] = (tmp >> 8) & 0xff;
sr_err("Failed to set trigger/samplerate: %d", ret);
return SR_ERR;
}
+ sr_dbg("hantek-dso: sent CMD_SET_TRIGGER_SAMPLERATE");
return SR_OK;
}
if (ctx->coupling_ch2 != COUPLING_AC)
relays[6] = ~relays[6];
- if (ctx->triggersource == TRIGGER_EXT)
+ if (!strcmp(ctx->triggersource, "EXT"))
relays[7] = ~relays[7];
if ((ret = libusb_control_transfer(ctx->usb->devhdl,