hantek-dso: proper protocol implementation of trigger/samplerate setting
This commit is contained in:
parent
6e71ef3b6f
commit
bc79e906a0
|
@ -221,8 +221,6 @@ SR_PRIV int dso_set_trigger_samplerate(struct context *ctx)
|
||||||
{
|
{
|
||||||
int ret, tmp;
|
int ret, tmp;
|
||||||
uint8_t cmdstring[12];
|
uint8_t cmdstring[12];
|
||||||
uint8_t timebasefast_small[] = {1, 2, 3, 4};
|
|
||||||
uint8_t timebasefast_large[] = {0, 0, 2, 3};
|
|
||||||
uint16_t timebase_small[] = { 0xffff, 0xfffc, 0xfff7, 0xffe8, 0xffce,
|
uint16_t timebase_small[] = { 0xffff, 0xfffc, 0xfff7, 0xffe8, 0xffce,
|
||||||
0xff9c, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79, 0xd8f1 };
|
0xff9c, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79, 0xd8f1 };
|
||||||
uint16_t timebase_large[] = { 0xffff, 0x0000, 0xfffc, 0xfff7, 0xffe8,
|
uint16_t timebase_large[] = { 0xffff, 0x0000, 0xfffc, 0xfff7, 0xffe8,
|
||||||
|
@ -235,33 +233,53 @@ SR_PRIV int dso_set_trigger_samplerate(struct context *ctx)
|
||||||
cmdstring[0] = CMD_SET_TRIGGER_SAMPLERATE;
|
cmdstring[0] = CMD_SET_TRIGGER_SAMPLERATE;
|
||||||
|
|
||||||
/* Trigger source */
|
/* Trigger source */
|
||||||
cmdstring[2] = (ctx->triggersource & 0x03) << 6;
|
cmdstring[2] = (ctx->triggersource & 0x03);
|
||||||
|
|
||||||
/* Frame size */
|
/* Frame size */
|
||||||
cmdstring[2] |= (ctx->framesize == FRAMESIZE_SMALL ? 0x01 : 0x02) << 3;
|
cmdstring[2] |= (ctx->framesize == FRAMESIZE_SMALL ? 0x01 : 0x02) << 2;
|
||||||
|
|
||||||
/* Timebase fast (no idea what this means) */
|
/* Timebase fast */
|
||||||
if (ctx->timebase < TIME_20us)
|
switch (ctx->framesize) {
|
||||||
tmp = 0;
|
case FRAMESIZE_SMALL:
|
||||||
else if (ctx->timebase > TIME_200us)
|
if (ctx->timebase < TIME_20us)
|
||||||
tmp = 4;
|
tmp = 0;
|
||||||
else {
|
else if (ctx->timebase == TIME_20us)
|
||||||
if (ctx->framesize == FRAMESIZE_SMALL)
|
tmp = 1;
|
||||||
tmp = timebasefast_small[ctx->timebase - 1];
|
else if (ctx->timebase == TIME_40us)
|
||||||
else
|
tmp = 2;
|
||||||
tmp = timebasefast_large[ctx->timebase - 1];
|
else if (ctx->timebase == TIME_100us)
|
||||||
|
tmp = 3;
|
||||||
|
else if (ctx->timebase >= TIME_200us)
|
||||||
|
tmp = 4;
|
||||||
|
break;
|
||||||
|
case FRAMESIZE_LARGE:
|
||||||
|
if (ctx->timebase < TIME_40us) {
|
||||||
|
sr_err("hantek-dso: timebase < 40us only supported with 10K buffer");
|
||||||
|
return SR_ERR_ARG;
|
||||||
|
}
|
||||||
|
else if (ctx->timebase == TIME_40us)
|
||||||
|
tmp = 0;
|
||||||
|
else if (ctx->timebase == TIME_100us)
|
||||||
|
tmp = 2;
|
||||||
|
else if (ctx->timebase == TIME_200us)
|
||||||
|
tmp = 3;
|
||||||
|
else if (ctx->timebase >= TIME_400us)
|
||||||
|
tmp = 4;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
cmdstring[2] |= tmp & 0x07;
|
cmdstring[2] |= (tmp & 0x07) << 5;
|
||||||
cmdstring[2] = 0x45;
|
|
||||||
/* Enabled channels */
|
/* Enabled channels: 00=CH1 01=CH2 10=both */
|
||||||
tmp = (((ctx->ch2_enabled ? 1 : 0) << 1) + (ctx->ch1_enabled ? 1 : 0)) - 1;
|
tmp = (((ctx->ch2_enabled ? 1 : 0) << 1) + (ctx->ch1_enabled ? 1 : 0)) - 1;
|
||||||
cmdstring[3] = tmp;
|
cmdstring[3] = tmp;
|
||||||
|
|
||||||
/* TODO: Fast rates channel */
|
/* Fast rates channel */
|
||||||
cmdstring[3] |= 0 << 5;
|
/* TODO: is this right? */
|
||||||
|
tmp = ctx->timebase < TIME_10us ? 1 : 0;
|
||||||
|
cmdstring[3] |= tmp << 2;
|
||||||
|
|
||||||
/* Trigger slope */
|
/* Trigger slope: 0=positive 1=negative */
|
||||||
cmdstring[3] |= (ctx->triggerslope ? 1 : 0) << 4;
|
cmdstring[3] |= (ctx->triggerslope == SLOPE_NEGATIVE ? 1 : 0) << 3;
|
||||||
|
|
||||||
/* Timebase */
|
/* Timebase */
|
||||||
if (ctx->timebase < TIME_100us)
|
if (ctx->timebase < TIME_100us)
|
||||||
|
@ -274,15 +292,13 @@ cmdstring[2] = 0x45;
|
||||||
else
|
else
|
||||||
tmp = timebase_large[ctx->timebase - 3];
|
tmp = timebase_large[ctx->timebase - 3];
|
||||||
}
|
}
|
||||||
tmp = 0xebff;
|
cmdstring[4] = tmp & 0xff;
|
||||||
|
cmdstring[5] = (tmp >> 8) & 0xff;
|
||||||
|
|
||||||
|
/* Horizontal trigger position */
|
||||||
|
tmp = 0x77fff + 0x8000 * ctx->triggerposition;
|
||||||
cmdstring[6] = tmp & 0xff;
|
cmdstring[6] = tmp & 0xff;
|
||||||
cmdstring[7] = (tmp >> 8) & 0xff;
|
cmdstring[7] = (tmp >> 8) & 0xff;
|
||||||
|
|
||||||
/* Trigger position (time) */
|
|
||||||
tmp = 0x77660 + ctx->triggerposition;
|
|
||||||
tmp = 0x7006f;
|
|
||||||
cmdstring[8] = tmp & 0xff;
|
|
||||||
cmdstring[9] = (tmp >> 8) & 0xff;
|
|
||||||
cmdstring[10] = (tmp >> 16) & 0xff;
|
cmdstring[10] = (tmp >> 16) & 0xff;
|
||||||
|
|
||||||
if (send_begin(ctx) != SR_OK)
|
if (send_begin(ctx) != SR_OK)
|
||||||
|
@ -388,7 +404,7 @@ relays[0] = 0x01;
|
||||||
if (ctx->coupling_ch2 != COUPLING_AC)
|
if (ctx->coupling_ch2 != COUPLING_AC)
|
||||||
relays[6] = ~relays[6];
|
relays[6] = ~relays[6];
|
||||||
|
|
||||||
if (ctx->triggersource == TRIGGER_EXT || ctx->triggersource == TRIGGER_EXT10)
|
if (ctx->triggersource == TRIGGER_EXT)
|
||||||
relays[7] = ~relays[7];
|
relays[7] = ~relays[7];
|
||||||
|
|
||||||
if ((ret = libusb_control_transfer(ctx->usb->devhdl,
|
if ((ret = libusb_control_transfer(ctx->usb->devhdl,
|
||||||
|
|
|
@ -34,12 +34,10 @@
|
||||||
|
|
||||||
#define DEFAULT_VOLTAGE VOLTAGE_2V
|
#define DEFAULT_VOLTAGE VOLTAGE_2V
|
||||||
#define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
|
#define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
|
||||||
#define DEFAULT_TIMEBASE TIME_1ms
|
#define DEFAULT_TIMEBASE TIME_400us
|
||||||
#define DEFAULT_TRIGGER_SOURCE TRIGGER_CH1
|
#define DEFAULT_TRIGGER_SOURCE TRIGGER_CH1
|
||||||
#define DEFAULT_COUPLING COUPLING_AC
|
#define DEFAULT_COUPLING COUPLING_AC
|
||||||
/* Halfway between min and max = 0V */
|
#define DEFAULT_HORIZ_TRIGGERPOS 0.5
|
||||||
#define DEFAULT_HORIZ_TRIGGERPOS 0x1400
|
|
||||||
|
|
||||||
#define DEFAULT_VERT_OFFSET 0.5
|
#define DEFAULT_VERT_OFFSET 0.5
|
||||||
#define DEFAULT_VERT_TRIGGERPOS 0.0
|
#define DEFAULT_VERT_TRIGGERPOS 0.0
|
||||||
|
|
||||||
|
@ -117,9 +115,7 @@ enum trigger_slopes {
|
||||||
enum trigger_sources {
|
enum trigger_sources {
|
||||||
TRIGGER_CH2 = 0,
|
TRIGGER_CH2 = 0,
|
||||||
TRIGGER_CH1,
|
TRIGGER_CH1,
|
||||||
TRIGGER_ALT,
|
|
||||||
TRIGGER_EXT,
|
TRIGGER_EXT,
|
||||||
TRIGGER_EXT10
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum capturestates {
|
enum capturestates {
|
||||||
|
@ -193,7 +189,7 @@ struct context {
|
||||||
gboolean filter_trigger;
|
gboolean filter_trigger;
|
||||||
int triggerslope;
|
int triggerslope;
|
||||||
int triggersource;
|
int triggersource;
|
||||||
int triggerposition;
|
float triggerposition;
|
||||||
int triggermode;
|
int triggermode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue