]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/saleae-logic16/api.c
ols: add feature to support >256K memory
[libsigrok.git] / src / hardware / saleae-logic16 / api.c
index 3ee4ea65802df47465b2f25db57c96c84a39e909..99916e44e1343cbfedaffc961dba3250178b80bc 100644 (file)
@@ -72,12 +72,12 @@ static const char *channel_names[] = {
 
 static const struct {
        enum voltage_range range;
-} volt_thresholds_ranges[] = {
+} thresholds_ranges[] = {
        { VOLTAGE_RANGE_18_33_V, },
        { VOLTAGE_RANGE_5_V, },
 };
 
-static const double volt_thresholds[][2] = {
+static const double thresholds[][2] = {
        { 0.7, 1.4 },
        { 1.4, 3.6 },
 };
@@ -188,7 +188,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                libusb_get_device_descriptor(devlist[i], &des);
 
-               usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
+               if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0)
+                       continue;
 
                if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID)
                        continue;
@@ -218,11 +219,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                                libusb_get_device_address(devlist[i]), NULL);
                } else {
                        if (ezusb_upload_firmware(drvc->sr_ctx, devlist[i],
-                                       USB_CONFIGURATION, FX2_FIRMWARE) == SR_OK)
+                                       USB_CONFIGURATION, FX2_FIRMWARE) == SR_OK) {
                                /* Store when this device's FW was updated. */
                                devc->fw_updated = g_get_monotonic_time();
-                       else
-                               sr_err("Firmware upload failed.");
+                       } else {
+                               sr_err("Firmware upload failed, name %s.", FX2_FIRMWARE);
+                       }
                        sdi->inst_type = SR_INST_USB;
                        sdi->conn = sr_usb_dev_inst_new(
                                libusb_get_bus_number(devlist[i]), 0xff, NULL);
@@ -266,7 +268,9 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
                        /*
                         * Check device by its physical USB bus/port address.
                         */
-                       usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
+                       if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0)
+                               continue;
+
                        if (strcmp(sdi->connection_id, connection_id))
                                /* This is not the one. */
                                continue;
@@ -434,11 +438,10 @@ static int config_get(uint32_t key, GVariant **data,
                if (!sdi)
                        return SR_ERR;
                devc = sdi->priv;
-               for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++) {
-                       if (devc->selected_voltage_range !=
-                           volt_thresholds_ranges[i].range)
+               for (i = 0; i < ARRAY_SIZE(thresholds); i++) {
+                       if (devc->selected_voltage_range != thresholds_ranges[i].range)
                                continue;
-                       *data = std_gvar_tuple_double(volt_thresholds[i][0], volt_thresholds[i][1]);
+                       *data = std_gvar_tuple_double(thresholds[i][0], thresholds[i][1]);
                        return SR_OK;
                }
                return SR_ERR;
@@ -468,11 +471,11 @@ static int config_set(uint32_t key, GVariant *data,
                break;
        case SR_CONF_CAPTURE_RATIO:
                devc->capture_ratio = g_variant_get_uint64(data);
-               return (devc->capture_ratio > 100) ? SR_ERR : SR_OK;
+               break;
        case SR_CONF_VOLTAGE_THRESHOLD:
-               if ((idx = std_double_tuple_idx(data, ARRAY_AND_SIZE(volt_thresholds))) < 0)
+               if ((idx = std_double_tuple_idx(data, ARRAY_AND_SIZE(thresholds))) < 0)
                        return SR_ERR_ARG;
-               devc->selected_voltage_range = volt_thresholds_ranges[idx].range;
+               devc->selected_voltage_range = thresholds_ranges[idx].range;
                break;
        default:
                return SR_ERR_NA;
@@ -492,7 +495,7 @@ static int config_list(uint32_t key, GVariant **data,
                *data = std_gvar_samplerates(ARRAY_AND_SIZE(samplerates));
                break;
        case SR_CONF_VOLTAGE_THRESHOLD:
-               *data = std_gvar_thresholds(ARRAY_AND_SIZE(volt_thresholds));
+               *data = std_gvar_thresholds(ARRAY_AND_SIZE(thresholds));
                break;
        case SR_CONF_TRIGGER_MATCH:
                *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
@@ -649,7 +652,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        if ((trigger = sr_session_trigger_get(sdi->session))) {
                int pre_trigger_samples = 0;
                if (devc->limit_samples > 0)
-                       pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
+                       pre_trigger_samples = (devc->capture_ratio * devc->limit_samples) / 100;
                devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
                if (!devc->stl)
                        return SR_ERR_MALLOC;