]> sigrok.org Git - libsigrok.git/commitdiff
hantek-4032l: Get FGPA version.
authorAndrej Valek <redacted>
Sun, 29 Apr 2018 20:15:12 +0000 (22:15 +0200)
committerUwe Hermann <redacted>
Tue, 5 Jun 2018 14:57:48 +0000 (16:57 +0200)
- 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 <redacted>
src/hardware/hantek-4032l/api.c
src/hardware/hantek-4032l/protocol.c
src/hardware/hantek-4032l/protocol.h

index 55b764e1e60eedf4b9ba3cd45624afa621d4816b..77a2beded8a307b36b1c7ff636bf06c534ae54c2 100644 (file)
@@ -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;
 }
 
index 84a5608a9784bbbb422d38cd4d990b23fd0b07c9..c41dc8b00201d40589fba903c761421d365b12f7 100644 (file)
@@ -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;
+}
index b95b711f84e27bba7aecdd9c25770e92b88d0b8d..f7fbdbda062968f8c3e07d6a92f1e63d0e1e6078 100644 (file)
@@ -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