hantek-6xxx: add coupling support
Sainsmart DDS-120 supports AC or DC coupling. Add driver support to control that feature.
This commit is contained in:
parent
10e0d374cb
commit
cc5ebc8a3d
|
@ -43,12 +43,17 @@ static const uint32_t devopts[] = {
|
||||||
|
|
||||||
static const uint32_t devopts_cg[] = {
|
static const uint32_t devopts_cg[] = {
|
||||||
SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
|
SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
|
||||||
|
SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *channel_names[] = {
|
static const char *channel_names[] = {
|
||||||
"CH1", "CH2",
|
"CH1", "CH2",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char *coupling[] = {
|
||||||
|
"AC", "DC",
|
||||||
|
};
|
||||||
|
|
||||||
static const struct hantek_6xxx_profile dev_profiles[] = {
|
static const struct hantek_6xxx_profile dev_profiles[] = {
|
||||||
{
|
{
|
||||||
0x04b4, 0x6022, 0x04b5, 0x6022,
|
0x04b4, 0x6022, 0x04b5, 0x6022,
|
||||||
|
@ -103,6 +108,7 @@ static struct sr_dev_inst *hantek_6xxx_dev_new(const struct hantek_6xxx_profile
|
||||||
for (i = 0; i < NUM_CHANNELS; i++) {
|
for (i = 0; i < NUM_CHANNELS; i++) {
|
||||||
devc->ch_enabled[i] = TRUE;
|
devc->ch_enabled[i] = TRUE;
|
||||||
devc->voltage[i] = DEFAULT_VOLTAGE;
|
devc->voltage[i] = DEFAULT_VOLTAGE;
|
||||||
|
devc->coupling[i] = DEFAULT_COUPLING;
|
||||||
}
|
}
|
||||||
|
|
||||||
devc->sample_buf = NULL;
|
devc->sample_buf = NULL;
|
||||||
|
@ -382,6 +388,9 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
||||||
vdiv = vdivs[devc->voltage[ch_idx]];
|
vdiv = vdivs[devc->voltage[ch_idx]];
|
||||||
*data = g_variant_new("(tt)", vdiv[0], vdiv[1]);
|
*data = g_variant_new("(tt)", vdiv[0], vdiv[1]);
|
||||||
break;
|
break;
|
||||||
|
case SR_CONF_COUPLING:
|
||||||
|
*data = g_variant_new_string(coupling[devc->coupling[ch_idx]]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,6 +404,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
||||||
uint64_t p, q;
|
uint64_t p, q;
|
||||||
int tmp_int, ch_idx, ret;
|
int tmp_int, ch_idx, ret;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
const char *tmp_str;
|
||||||
|
|
||||||
if (sdi->status != SR_ST_ACTIVE)
|
if (sdi->status != SR_ST_ACTIVE)
|
||||||
return SR_ERR_DEV_CLOSED;
|
return SR_ERR_DEV_CLOSED;
|
||||||
|
@ -440,6 +450,17 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
||||||
} else
|
} else
|
||||||
ret = SR_ERR_ARG;
|
ret = SR_ERR_ARG;
|
||||||
break;
|
break;
|
||||||
|
case SR_CONF_COUPLING:
|
||||||
|
tmp_str = g_variant_get_string(data, NULL);
|
||||||
|
for (i = 0; coupling[i]; i++) {
|
||||||
|
if (!strcmp(tmp_str, coupling[i])) {
|
||||||
|
devc->coupling[ch_idx] = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (coupling[i] == 0)
|
||||||
|
ret = SR_ERR_ARG;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ret = SR_ERR_NA;
|
ret = SR_ERR_NA;
|
||||||
break;
|
break;
|
||||||
|
@ -493,6 +514,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
||||||
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
|
||||||
devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
|
devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
|
||||||
break;
|
break;
|
||||||
|
case SR_CONF_COUPLING:
|
||||||
|
*data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
|
||||||
|
break;
|
||||||
case SR_CONF_VDIV:
|
case SR_CONF_VDIV:
|
||||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||||
for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
|
for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
|
||||||
|
|
|
@ -215,6 +215,16 @@ SR_PRIV int hantek_6xxx_update_vdiv(const struct sr_dev_inst *sdi)
|
||||||
return MIN(ret1, ret2);
|
return MIN(ret1, ret2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SR_PRIV int hantek_6xxx_update_coupling(const struct sr_dev_inst *sdi)
|
||||||
|
{
|
||||||
|
struct dev_context *devc = sdi->priv;
|
||||||
|
uint8_t coupling = 0xFF & ((devc->coupling[1] << 4) | devc->coupling[0]);
|
||||||
|
|
||||||
|
sr_dbg("update coupling 0x%x", coupling);
|
||||||
|
|
||||||
|
return write_control(sdi, COUPLING_REG, coupling);
|
||||||
|
}
|
||||||
|
|
||||||
SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi)
|
SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct dev_context *devc = sdi->priv;
|
struct dev_context *devc = sdi->priv;
|
||||||
|
@ -230,6 +240,7 @@ SR_PRIV int hantek_6xxx_init(const struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
hantek_6xxx_update_samplerate(sdi);
|
hantek_6xxx_update_samplerate(sdi);
|
||||||
hantek_6xxx_update_vdiv(sdi);
|
hantek_6xxx_update_vdiv(sdi);
|
||||||
|
hantek_6xxx_update_coupling(sdi);
|
||||||
// hantek_6xxx_update_channels(sdi); /* Only 2 channel mode supported. */
|
// hantek_6xxx_update_channels(sdi); /* Only 2 channel mode supported. */
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#define MAX_RENUM_DELAY_MS 3000
|
#define MAX_RENUM_DELAY_MS 3000
|
||||||
|
|
||||||
#define DEFAULT_VOLTAGE 2
|
#define DEFAULT_VOLTAGE 2
|
||||||
|
#define DEFAULT_COUPLING COUPLING_DC
|
||||||
#define DEFAULT_SAMPLERATE SR_MHZ(8)
|
#define DEFAULT_SAMPLERATE SR_MHZ(8)
|
||||||
|
|
||||||
#define NUM_CHANNELS 2
|
#define NUM_CHANNELS 2
|
||||||
|
@ -71,6 +72,7 @@ enum control_requests {
|
||||||
SAMPLERATE_REG = 0xe2,
|
SAMPLERATE_REG = 0xe2,
|
||||||
TRIGGER_REG = 0xe3,
|
TRIGGER_REG = 0xe3,
|
||||||
CHANNELS_REG = 0xe4,
|
CHANNELS_REG = 0xe4,
|
||||||
|
COUPLING_REG = 0xe5,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum states {
|
enum states {
|
||||||
|
@ -80,6 +82,11 @@ enum states {
|
||||||
STOPPING,
|
STOPPING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum couplings {
|
||||||
|
COUPLING_AC = 0,
|
||||||
|
COUPLING_DC,
|
||||||
|
};
|
||||||
|
|
||||||
struct hantek_6xxx_profile {
|
struct hantek_6xxx_profile {
|
||||||
/* VID/PID after cold boot */
|
/* VID/PID after cold boot */
|
||||||
uint16_t orig_vid;
|
uint16_t orig_vid;
|
||||||
|
@ -116,6 +123,7 @@ struct dev_context {
|
||||||
|
|
||||||
gboolean ch_enabled[NUM_CHANNELS];
|
gboolean ch_enabled[NUM_CHANNELS];
|
||||||
int voltage[NUM_CHANNELS];
|
int voltage[NUM_CHANNELS];
|
||||||
|
int coupling[NUM_CHANNELS];
|
||||||
uint64_t samplerate;
|
uint64_t samplerate;
|
||||||
|
|
||||||
uint64_t limit_msec;
|
uint64_t limit_msec;
|
||||||
|
@ -130,6 +138,7 @@ SR_PRIV int hantek_6xxx_get_channeldata(const struct sr_dev_inst *sdi,
|
||||||
SR_PRIV int hantek_6xxx_start_data_collecting(const struct sr_dev_inst *sdi);
|
SR_PRIV int hantek_6xxx_start_data_collecting(const struct sr_dev_inst *sdi);
|
||||||
SR_PRIV int hantek_6xxx_stop_data_collecting(const struct sr_dev_inst *sdi);
|
SR_PRIV int hantek_6xxx_stop_data_collecting(const struct sr_dev_inst *sdi);
|
||||||
|
|
||||||
|
SR_PRIV int hantek_6xxx_update_coupling(const struct sr_dev_inst *sdi);
|
||||||
SR_PRIV int hantek_6xxx_update_samplerate(const struct sr_dev_inst *sdi);
|
SR_PRIV int hantek_6xxx_update_samplerate(const struct sr_dev_inst *sdi);
|
||||||
SR_PRIV int hantek_6xxx_update_vdiv(const struct sr_dev_inst *sdi);
|
SR_PRIV int hantek_6xxx_update_vdiv(const struct sr_dev_inst *sdi);
|
||||||
SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi);
|
SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi);
|
||||||
|
|
Loading…
Reference in New Issue