From: Gerhard Sittig Date: Thu, 25 May 2017 17:47:31 +0000 (+0200) Subject: asix-sigma: Only download firmware when necessary X-Git-Tag: libsigrok-0.5.0~42 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a9016883f800c40a1866c3f0d011cdb0c256888b;p=libsigrok.git asix-sigma: Only download firmware when necessary The Asix Sigma driver is aware of three firmware images, which are required for acquisition with up to 50MHz, 100MHz, and 200MHz. The previous implementation always downloaded the corresponding firmware image whenever the sample rate has changed, which was redundant. Skip the download when the new samplerate uses the same firmware as the previously selected samplerate did. This results in faster responses in the GUI when the samplerate selection changes. Move assignments out of the variable declaration block for improved readability while we are here. --- diff --git a/src/hardware/asix-sigma/protocol.c b/src/hardware/asix-sigma/protocol.c index 98cfce7a..253e98a0 100644 --- a/src/hardware/asix-sigma/protocol.c +++ b/src/hardware/asix-sigma/protocol.c @@ -442,10 +442,18 @@ static int upload_firmware(struct sr_context *ctx, unsigned char *buf; unsigned char pins; size_t buf_size; - const char *firmware = sigma_firmware_files[firmware_idx]; - struct ftdi_context *ftdic = &devc->ftdic; + const char *firmware; + struct ftdi_context *ftdic; + + /* Avoid downloading the same firmware multiple times. */ + firmware = sigma_firmware_files[firmware_idx]; + if (devc->cur_firmware == firmware_idx) { + sr_info("Not uploading firmware file '%s' again.", firmware); + return SR_OK; + } /* Make sure it's an ASIX SIGMA. */ + ftdic = &devc->ftdic; ret = ftdi_usb_open_desc(ftdic, USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL); if (ret < 0) {