hantek-dso: support SR_HWCAP_VDIV
This commit is contained in:
parent
bd8db307da
commit
313deed219
|
@ -49,6 +49,7 @@ static int capabilities[] = {
|
||||||
SR_HWCAP_TRIGGER_SLOPE,
|
SR_HWCAP_TRIGGER_SLOPE,
|
||||||
SR_HWCAP_HORIZ_TRIGGERPOS,
|
SR_HWCAP_HORIZ_TRIGGERPOS,
|
||||||
SR_HWCAP_FILTER,
|
SR_HWCAP_FILTER,
|
||||||
|
SR_HWCAP_VDIV,
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -95,6 +96,21 @@ static struct sr_rational timebases[] = {
|
||||||
{0,0}
|
{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[] = {
|
static char *trigger_sources[] = {
|
||||||
"CH1",
|
"CH1",
|
||||||
"CH2",
|
"CH2",
|
||||||
|
@ -365,6 +381,9 @@ static void *hw_get_device_info(int dev_index, int dev_info_id)
|
||||||
case SR_DI_FILTERS:
|
case SR_DI_FILTERS:
|
||||||
info = filter_targets;
|
info = filter_targets;
|
||||||
break;
|
break;
|
||||||
|
case SR_DI_VDIVS:
|
||||||
|
info = vdivs;
|
||||||
|
break;
|
||||||
/* TODO remove this */
|
/* TODO remove this */
|
||||||
case SR_DI_CUR_SAMPLERATE:
|
case SR_DI_CUR_SAMPLERATE:
|
||||||
info = &tmp;
|
info = &tmp;
|
||||||
|
@ -483,6 +502,20 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value)
|
||||||
}
|
}
|
||||||
g_strfreev(targets);
|
g_strfreev(targets);
|
||||||
break;
|
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:
|
default:
|
||||||
ret = SR_ERR_ARG;
|
ret = SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
|
@ -377,15 +377,52 @@ SR_PRIV int dso_set_voltage(struct context *ctx)
|
||||||
int ret, tmp;
|
int ret, tmp;
|
||||||
uint8_t cmdstring[8];
|
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));
|
memset(cmdstring, 0, sizeof(cmdstring));
|
||||||
cmdstring[0] = CMD_SET_VOLTAGE;
|
cmdstring[0] = CMD_SET_VOLTAGE;
|
||||||
cmdstring[1] = 0x0f;
|
cmdstring[1] = 0x0f;
|
||||||
cmdstring[2] = 0x03;
|
cmdstring[2] = 0x30;
|
||||||
cmdstring[2] |= ((2 - ctx->voltage_ch1 % 3) << 6);
|
|
||||||
cmdstring[2] |= ((2 - ctx->voltage_ch2 % 3) << 4);
|
/* CH1 volts/div is encoded in bits 0-1 */
|
||||||
cmdstring[2] = 0x30;
|
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)
|
if (send_begin(ctx) != SR_OK)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
@ -397,6 +434,7 @@ cmdstring[2] = 0x30;
|
||||||
sr_err("Failed to set voltage: %d", ret);
|
sr_err("Failed to set voltage: %d", ret);
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
sr_dbg("hantek-dso: sent CMD_SET_VOLTAGE");
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
@ -559,9 +597,6 @@ SR_PRIV int dso_init(struct context *ctx)
|
||||||
if (dso_enable_trigger(ctx) != SR_OK)
|
if (dso_enable_trigger(ctx) != SR_OK)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
if (dso_force_trigger(ctx) != SR_OK)
|
|
||||||
return SR_ERR;
|
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
#define MAX_CAPTURE_EMPTY 3
|
#define MAX_CAPTURE_EMPTY 3
|
||||||
|
|
||||||
#define DEFAULT_VOLTAGE VOLTAGE_2V
|
#define DEFAULT_VOLTAGE VDIV_500MV
|
||||||
#define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
|
#define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
|
||||||
#define DEFAULT_TIMEBASE TIME_100us
|
#define DEFAULT_TIMEBASE TIME_100us
|
||||||
#define DEFAULT_TRIGGER_SOURCE "CH1"
|
#define DEFAULT_TRIGGER_SOURCE "CH1"
|
||||||
|
@ -67,22 +67,11 @@ enum dso_commands {
|
||||||
CMD_GET_CHANNELDATA,
|
CMD_GET_CHANNELDATA,
|
||||||
CMD_GET_CAPTURESTATE,
|
CMD_GET_CAPTURESTATE,
|
||||||
CMD_SET_VOLTAGE,
|
CMD_SET_VOLTAGE,
|
||||||
|
/* unused */
|
||||||
cmdSetLogicalData,
|
cmdSetLogicalData,
|
||||||
cmdGetLogicalData
|
cmdGetLogicalData
|
||||||
};
|
};
|
||||||
|
|
||||||
enum voltages {
|
|
||||||
VOLTAGE_5V = 0,
|
|
||||||
VOLTAGE_2V,
|
|
||||||
VOLTAGE_1V,
|
|
||||||
VOLTAGE_500mV,
|
|
||||||
VOLTAGE_200mV,
|
|
||||||
VOLTAGE_100mV,
|
|
||||||
VOLTAGE_50mV,
|
|
||||||
VOLTAGE_20mV,
|
|
||||||
VOLTAGE_10mV
|
|
||||||
};
|
|
||||||
|
|
||||||
enum couplings {
|
enum couplings {
|
||||||
COUPLING_AC = 0,
|
COUPLING_AC = 0,
|
||||||
COUPLING_DC,
|
COUPLING_DC,
|
||||||
|
@ -107,6 +96,19 @@ enum time_bases {
|
||||||
TIME_400ms
|
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 {
|
enum trigger_slopes {
|
||||||
SLOPE_POSITIVE = 0,
|
SLOPE_POSITIVE = 0,
|
||||||
SLOPE_NEGATIVE
|
SLOPE_NEGATIVE
|
||||||
|
|
Loading…
Reference in New Issue