From: Andrej Valek Date: Sun, 29 Apr 2018 20:15:12 +0000 (+0200) Subject: hantek-4032l: Get FGPA version. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7a7afc008670cb23b4e179b2fea91a7d5459913d;p=libsigrok.git hantek-4032l: Get FGPA version. - get FPGA version in dev_open - enable some features only for newer FPGA - decrease printing number of message of FPGA version Signed-off-by: Andrej Valek --- diff --git a/src/hardware/hantek-4032l/api.c b/src/hardware/hantek-4032l/api.c index 55b764e1..77a2bede 100644 --- a/src/hardware/hantek-4032l/api.c +++ b/src/hardware/hantek-4032l/api.c @@ -267,6 +267,10 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_ERR; } + /* Get FPGA version. */ + if ((ret = h4032l_get_fpga_version(sdi)) != SR_OK) + return ret; + return SR_OK; } diff --git a/src/hardware/hantek-4032l/protocol.c b/src/hardware/hantek-4032l/protocol.c index 84a5608a..c41dc8b0 100644 --- a/src/hardware/hantek-4032l/protocol.c +++ b/src/hardware/hantek-4032l/protocol.c @@ -124,7 +124,6 @@ void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer) * First Transfer as next. */ status = (struct h4032l_status_packet *)transfer->buffer; - sr_dbg("FPGA version: 0x%x.", status->fpga_version); if (status->magic != H4032L_STATUS_PACKET_MAGIC) devc->status = H4032L_STATUS_RESPONSE_STATUS; else if (status->status == 2) @@ -333,3 +332,46 @@ SR_PRIV int h4032l_dev_open(struct sr_dev_inst *sdi) libusb_free_device_list(devlist, 1); return ret; } + +SR_PRIV int h4032l_get_fpga_version(const struct sr_dev_inst *sdi) +{ + struct dev_context *devc = sdi->priv; + struct sr_usb_dev_inst *usb = sdi->conn; + struct h4032l_status_packet *status; + int transferred; + int i, ret; + + /* Set command to status. */ + devc->cmd_pkt.magic = H4032L_CMD_PKT_MAGIC; + devc->cmd_pkt.cmd = CMD_STATUS; + + /* Send status request. */ + if ((ret = libusb_bulk_transfer(usb->devhdl, + 2 | LIBUSB_ENDPOINT_OUT, (unsigned char *)&devc->cmd_pkt, + sizeof(struct h4032l_cmd_pkt), &transferred, H4032L_USB_TIMEOUT)) < 0) { + sr_err("Unable to send FPGA version request: %s.", + libusb_error_name(ret)); + return SR_ERR; + } + + /* Attempt to get FGPA version. */ + for (i = 0; i < 10; i++) { + if ((ret = libusb_bulk_transfer(usb->devhdl, + 6 | LIBUSB_ENDPOINT_IN, devc->buffer, + ARRAY_SIZE(devc->buffer), &transferred, H4032L_USB_TIMEOUT)) < 0) { + sr_err("Unable to receive FPGA version: %s.", + libusb_error_name(ret)); + return SR_ERR; + } + status = (struct h4032l_status_packet *)devc->buffer; + if (status->magic == H4032L_STATUS_PACKET_MAGIC) { + sr_dbg("FPGA version: 0x%x.", status->fpga_version); + devc->fpga_version = status->fpga_version; + return SR_OK; + } + } + + sr_err("Unable to get FPGA version."); + + return SR_ERR; +} diff --git a/src/hardware/hantek-4032l/protocol.h b/src/hardware/hantek-4032l/protocol.h index b95b711f..f7fbdbda 100644 --- a/src/hardware/hantek-4032l/protocol.h +++ b/src/hardware/hantek-4032l/protocol.h @@ -126,6 +126,7 @@ struct dev_context { struct libusb_transfer *usb_transfer; uint8_t buffer[512]; uint64_t capture_ratio; + uint32_t fpga_version; }; SR_PRIV int h4032l_receive_data(int fd, int revents, void *cb_data); @@ -133,5 +134,6 @@ SR_PRIV uint16_t h4032l_voltage2pwm(double voltage); SR_PRIV void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer); SR_PRIV int h4032l_start(const struct sr_dev_inst *sdi); SR_PRIV int h4032l_dev_open(struct sr_dev_inst *sdi); +SR_PRIV int h4032l_get_fpga_version(const struct sr_dev_inst *sdi); #endif