X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fsaleae-logic16%2Fapi.c;h=bf41b759a3dda3c94c11399791999ecd95799183;hb=1c47e0da8f2571bc34dbdc368c3c1f55318c3aa0;hp=ae77bd8671952f15186ac6dc386283e7b91404f6;hpb=dcd438ee3523098201c7937e75e55775da3b506f;p=libsigrok.git diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index ae77bd86..bf41b759 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -19,12 +19,13 @@ * along with this program. If not, see . */ +#include #include #include #include #include #include -#include "libsigrok.h" +#include #include "libsigrok-internal.h" #include "protocol.h" @@ -33,7 +34,7 @@ #define USB_INTERFACE 0 #define USB_CONFIGURATION 1 -#define FX2_FIRMWARE FIRMWARE_DIR "/saleae-logic16-fx2.fw" +#define FX2_FIRMWARE "saleae-logic16-fx2.fw" #define MAX_RENUM_DELAY_MS 3000 #define NUM_SIMUL_TRANSFERS 32 @@ -66,7 +67,6 @@ static const int32_t soft_trigger_matches[] = { static const char *channel_names[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", - NULL, }; static const struct { @@ -111,8 +111,7 @@ static gboolean check_conf_profile(libusb_device *dev) ret = FALSE; while (!ret) { /* Assume the FW has not been loaded, unless proven wrong. */ - if (libusb_get_device_descriptor(dev, &des) != 0) - break; + libusb_get_device_descriptor(dev, &des); if (libusb_open(dev, &hdl) != 0) break; @@ -148,12 +147,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) GSList *l, *devices, *conn_devices; struct libusb_device_descriptor des; libusb_device **devlist; - int ret, j; - unsigned int i; + unsigned int i, j; const char *conn; char connection_id[64]; - drvc = di->priv; + drvc = di->context; conn = NULL; for (l = options; l; l = l->next) { @@ -187,11 +185,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) continue; } - if ((ret = libusb_get_device_descriptor(devlist[i], &des)) != 0) { - sr_warn("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)); @@ -205,7 +199,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->driver = di; sdi->connection_id = g_strdup(connection_id); - for (j = 0; channel_names[j]; j++) + for (j = 0; j < ARRAY_SIZE(channel_names); j++) sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE, channel_names[j]); @@ -224,8 +218,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) libusb_get_bus_number(devlist[i]), libusb_get_device_address(devlist[i]), NULL); } else { - if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION, - FX2_FIRMWARE) == SR_OK) + if (ezusb_upload_firmware(drvc->sr_ctx, devlist[i], + USB_CONFIGURATION, FX2_FIRMWARE) == SR_OK) /* Store when this device's FW was updated. */ devc->fw_updated = g_get_monotonic_time(); else @@ -243,7 +237,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) static GSList *dev_list(const struct sr_dev_driver *di) { - return ((struct drv_context *)(di->priv))->instances; + return ((struct drv_context *)(di->context))->instances; } static int logic16_dev_open(struct sr_dev_inst *sdi) @@ -257,7 +251,7 @@ static int logic16_dev_open(struct sr_dev_inst *sdi) char connection_id[64]; di = sdi->driver; - drvc = di->priv; + drvc = di->context; usb = sdi->conn; if (sdi->status == SR_ST_ACTIVE) @@ -272,11 +266,7 @@ static int logic16_dev_open(struct sr_dev_inst *sdi) } for (i = 0; i < device_count; i++) { - if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { - sr_err("Failed to get device descriptor: %s.", - libusb_error_name(ret)); - continue; - } + libusb_get_device_descriptor(devlist[i], &des); if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID) continue; @@ -399,7 +389,7 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; usb = sdi->conn; - if (usb->devhdl == NULL) + if (!usb->devhdl) return SR_ERR; sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.", @@ -417,7 +407,7 @@ static int cleanup(const struct sr_dev_driver *di) int ret; struct drv_context *drvc; - if (!(drvc = di->priv)) + if (!(drvc = di->context)) /* Can get called on an unused driver, doesn't matter. */ return SR_OK; @@ -512,11 +502,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio > 100) { - devc->capture_ratio = 0; - ret = SR_ERR; - } else - ret = SR_OK; + ret = (devc->capture_ratio > 100) ? SR_ERR : SR_OK; break; case SR_CONF_VOLTAGE_THRESHOLD: g_variant_get(data, "(dd)", &low, &high); @@ -688,7 +674,7 @@ static int receive_data(int fd, int revents, void *cb_data) sdi = cb_data; di = sdi->driver; - drvc = di->priv; + drvc = di->context; devc = sdi->priv; tv.tv_sec = tv.tv_usec = 0; @@ -718,7 +704,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - drvc = di->priv; + drvc = di->context; devc = sdi->priv; usb = sdi->conn; @@ -739,7 +725,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if (devc->limit_samples > 0) pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); - if (devc->stl == NULL) + if (!devc->stl) return SR_ERR_MALLOC; devc->trigger_fired = FALSE; } else @@ -803,7 +789,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) usb_source_add(sdi->session, devc->ctx, timeout, receive_data, (void *)sdi); - /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); if ((ret = logic16_start_acquisition(sdi)) != SR_OK) { @@ -846,5 +831,5 @@ SR_PRIV struct sr_dev_driver saleae_logic16_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, };