From: Benjamin Larsson Date: Mon, 4 Apr 2016 19:44:00 +0000 (+0200) Subject: hantek-6xxx: add coupling support X-Git-Tag: libsigrok-0.5.0~500 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cc5ebc8a3d66e15ade82475ae890e0dafe9b4586;p=libsigrok.git hantek-6xxx: add coupling support Sainsmart DDS-120 supports AC or DC coupling. Add driver support to control that feature. --- diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index 461c08a5..beace1da 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -43,12 +43,17 @@ static const uint32_t devopts[] = { static const uint32_t devopts_cg[] = { 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[] = { "CH1", "CH2", }; +static const char *coupling[] = { + "AC", "DC", +}; + static const struct hantek_6xxx_profile dev_profiles[] = { { 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++) { devc->ch_enabled[i] = TRUE; devc->voltage[i] = DEFAULT_VOLTAGE; + devc->coupling[i] = DEFAULT_COUPLING; } 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]]; *data = g_variant_new("(tt)", vdiv[0], vdiv[1]); 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; int tmp_int, ch_idx, ret; unsigned int i; + const char *tmp_str; if (sdi->status != SR_ST_ACTIVE) 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 ret = SR_ERR_ARG; 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: ret = SR_ERR_NA; 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, devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t)); break; + case SR_CONF_COUPLING: + *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling)); + break; case SR_CONF_VDIV: g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); for (i = 0; i < ARRAY_SIZE(vdivs); i++) { diff --git a/src/hardware/hantek-6xxx/protocol.c b/src/hardware/hantek-6xxx/protocol.c index c02aa174..12a56ab9 100644 --- a/src/hardware/hantek-6xxx/protocol.c +++ b/src/hardware/hantek-6xxx/protocol.c @@ -215,6 +215,16 @@ SR_PRIV int hantek_6xxx_update_vdiv(const struct sr_dev_inst *sdi) 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) { 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_vdiv(sdi); + hantek_6xxx_update_coupling(sdi); // hantek_6xxx_update_channels(sdi); /* Only 2 channel mode supported. */ return SR_OK; diff --git a/src/hardware/hantek-6xxx/protocol.h b/src/hardware/hantek-6xxx/protocol.h index 7c8de938..6e87079c 100644 --- a/src/hardware/hantek-6xxx/protocol.h +++ b/src/hardware/hantek-6xxx/protocol.h @@ -31,6 +31,7 @@ #define MAX_RENUM_DELAY_MS 3000 #define DEFAULT_VOLTAGE 2 +#define DEFAULT_COUPLING COUPLING_DC #define DEFAULT_SAMPLERATE SR_MHZ(8) #define NUM_CHANNELS 2 @@ -71,6 +72,7 @@ enum control_requests { SAMPLERATE_REG = 0xe2, TRIGGER_REG = 0xe3, CHANNELS_REG = 0xe4, + COUPLING_REG = 0xe5, }; enum states { @@ -80,6 +82,11 @@ enum states { STOPPING, }; +enum couplings { + COUPLING_AC = 0, + COUPLING_DC, +}; + struct hantek_6xxx_profile { /* VID/PID after cold boot */ uint16_t orig_vid; @@ -116,6 +123,7 @@ struct dev_context { gboolean ch_enabled[NUM_CHANNELS]; int voltage[NUM_CHANNELS]; + int coupling[NUM_CHANNELS]; uint64_t samplerate; 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_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_vdiv(const struct sr_dev_inst *sdi); SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi);