]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hantek-6xxx/protocol.c
Introduce standard cleanup helper
[libsigrok.git] / src / hardware / hantek-6xxx / protocol.c
index 4c2b8cdaf76dbd817835f52572ef436b25e9bde6..12a56ab9d09970589aa0fd1e25c46ed29ebc5cc2 100644 (file)
@@ -123,7 +123,7 @@ SR_PRIV int hantek_6xxx_get_channeldata(const struct sr_dev_inst *sdi,
        transfer = libusb_alloc_transfer(0);
        libusb_fill_bulk_transfer(transfer, usb->devhdl, HANTEK_EP_IN, buf,
                        data_amount, cb, (void *)sdi, 4000);
-       if ((ret = libusb_submit_transfer(transfer)) != 0) {
+       if ((ret = libusb_submit_transfer(transfer)) < 0) {
                sr_err("Failed to submit transfer: %s.",
                        libusb_error_name(ret));
                /* TODO: Free them all. */
@@ -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;