]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/kingst-la2016/api.c
kingst-la2016: complete hardware setup in probe, set features in open
[libsigrok.git] / src / hardware / kingst-la2016 / api.c
index d89d25618ef81d0af2dd5404d54455ababa8b949..8f8afef8728f4c1468d6ee798018ccad4994f4cb 100644 (file)
 #include "libsigrok-internal.h"
 #include "protocol.h"
 
-/*
- * Default device configuration. Must be applicable to any of the
- * supported devices (no model specific default values yet). Specific
- * firmware implementation details unfortunately won't let us detect
- * and keep using previously configured values.
- */
-#define LA2016_DFLT_SAMPLERATE SR_MHZ(100)
-#define LA2016_DFLT_SAMPLEDEPTH        (5 * 1000 * 1000)
-#define LA2016_DFLT_CAPT_RATIO 5 /* Capture ratio, in percent. */
-
 static const uint32_t scanopts[] = {
        SR_CONF_CONN,
 };
@@ -259,7 +249,17 @@ static int la2016_identify_read(struct sr_dev_inst *sdi,
                        sr_err("Cannot communicate to MCU firmware.");
                return ret;
        }
+
+       /*
+        * Also complete the hardware configuration (FPGA bitstream)
+        * when MCU firmware communication became operational. Either
+        * failure is considered fatal when probing for the device.
+        */
        ret = la2016_identify_device(sdi, show_message);
+       if (ret == SR_OK) {
+               ret = la2016_init_hardware(sdi);
+       }
+
        la2016_close_usb(usb);
 
        return ret;
@@ -568,9 +568,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                }
 
                sr_sw_limits_init(&devc->sw_limits);
-               devc->sw_limits.limit_samples = LA2016_DFLT_SAMPLEDEPTH;
-               devc->capture_ratio = LA2016_DFLT_CAPT_RATIO;
-               devc->cur_samplerate = LA2016_DFLT_SAMPLERATE;
+               devc->sw_limits.limit_samples = 0;
+               devc->capture_ratio = 50;
+               devc->cur_samplerate = devc->model->samplerate;
                devc->threshold_voltage_idx = 0;
                devc->threshold_voltage = logic_threshold_value[devc->threshold_voltage_idx];
 
@@ -592,6 +592,16 @@ static int dev_open(struct sr_dev_inst *sdi)
                return ret;
        }
 
+       /*
+        * Setup a default configuration of device features. This
+        * affects the logic threshold, PWM channels, and similar.
+        */
+       ret = la2016_init_params(sdi);
+       if (ret != SR_OK) {
+               sr_err("Cannot initialize device's hardware.");
+               return ret;
+       }
+
        return SR_OK;
 }
 
@@ -604,7 +614,7 @@ static int dev_close(struct sr_dev_inst *sdi)
        if (!usb->devhdl)
                return SR_ERR_BUG;
 
-       la2016_deinit_device(sdi);
+       la2016_deinit_hardware(sdi);
 
        sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
                usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
@@ -738,8 +748,7 @@ static int config_list(uint32_t key, GVariant **data,
                        *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_100mhz));
                break;
        case SR_CONF_LIMIT_SAMPLES:
-               *data = std_gvar_tuple_u64(LA2016_NUM_SAMPLES_MIN,
-                       LA2016_NUM_SAMPLES_MAX);
+               *data = std_gvar_tuple_u64(0, LA2016_NUM_SAMPLES_MAX);
                break;
        case SR_CONF_VOLTAGE_THRESHOLD:
                *data = std_gvar_min_max_step_thresholds(