X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fhantek-6xxx%2Fprotocol.c;h=8e406ffe03f04db5220cfccc18653ac10b72d024;hb=7e463623382e1f574fde150b3fc88a65eaebb578;hp=37380490a80d25bcc1c25c7c0f372d61735ec378;hpb=f2a66a8ee669df5afa1b7bdade6e25ac0857fe4b;p=libsigrok.git diff --git a/src/hardware/hantek-6xxx/protocol.c b/src/hardware/hantek-6xxx/protocol.c index 37380490..8e406ffe 100644 --- a/src/hardware/hantek-6xxx/protocol.c +++ b/src/hardware/hantek-6xxx/protocol.c @@ -27,23 +27,15 @@ SR_PRIV int hantek_6xxx_open(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; struct libusb_device_descriptor des; libusb_device **devlist; - int err, i; + int err = SR_ERR, i; char connection_id[64]; devc = sdi->priv; usb = sdi->conn; - if (sdi->status == SR_ST_ACTIVE) - /* Already in use. */ - return SR_ERR; - libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); for (i = 0; devlist[i]; i++) { - if ((err = libusb_get_device_descriptor(devlist[i], &des))) { - sr_err("Failed to get device descriptor: %s.", - libusb_error_name(err)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); if (des.idVendor != devc->profile->fw_vid || des.idProduct != devc->profile->fw_pid) @@ -69,14 +61,16 @@ SR_PRIV int hantek_6xxx_open(struct sr_dev_inst *sdi) usb->address = libusb_get_device_address(devlist[i]); } - sdi->status = SR_ST_ACTIVE; sr_info("Opened device on %d.%d (logical) / " "%s (physical) interface %d.", usb->bus, usb->address, sdi->connection_id, USB_INTERFACE); + + err = SR_OK; } else { sr_err("Failed to open device: %s.", libusb_error_name(err)); + err = SR_ERR; } /* If we made it here, we handled the device (somehow). */ @@ -85,10 +79,7 @@ SR_PRIV int hantek_6xxx_open(struct sr_dev_inst *sdi) libusb_free_device_list(devlist, 1); - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; - - return SR_OK; + return err; } SR_PRIV void hantek_6xxx_close(struct sr_dev_inst *sdi) @@ -127,7 +118,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. */ @@ -219,6 +210,20 @@ 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]); + + if (devc->has_coupling) { + sr_dbg("update coupling 0x%x", coupling); + return write_control(sdi, COUPLING_REG, coupling); + } else { + sr_dbg("coupling not supported"); + return SR_OK; + } +} + SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi) { struct dev_context *devc = sdi->priv; @@ -234,6 +239,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;