Пример #1
0
int hw_init(char *deviceinfo)
{
	struct usb_device_instance *udi;
	struct libusb_device_descriptor des;
	libusb_device **devlist;
	int err, devcnt, i;

	if(libusb_init(&usb_context) != 0)
	{
		g_warning("Failed to initialize USB.");
		return 0;
	}
	libusb_set_debug(usb_context, 3);

	/* find all Saleae Logic devices and upload firmware to all of them */
	devcnt = 0;
	libusb_get_device_list(usb_context, &devlist);
	for(i = 0; devlist[i]; i++)
	{
		err = libusb_get_device_descriptor(devlist[i], &des);
		if(err != 0)
		{
			g_warning("failed to get device descriptor: %d", err);
			continue;
		}
		if(des.idVendor == USB_VENDOR && des.idProduct == USB_PRODUCT)
		{
			/* definitely a Saleae Logic */
			if(check_conf_profile(devlist[i]) == 0)
			{
				if(upload_firmware(devlist[i]) > 0)
					g_warning("firmware upload failed for device %d", devcnt);
				udi = usb_device_instance_new(devcnt, ST_INITIALIZING,
						libusb_get_bus_number(devlist[i]), 0, NULL);
				usb_devices = g_slist_append(usb_devices, udi);
			}
			else
			{
				/* already has the firmware on it, so fix the address */
				udi = usb_device_instance_new(devcnt, ST_INACTIVE,
						libusb_get_bus_number(devlist[i]),
						libusb_get_device_address(devlist[i]), NULL);
				usb_devices = g_slist_append(usb_devices, udi);
			}
			devcnt++;
		}
	}
	libusb_free_device_list(devlist, 1);

	return devcnt;
}
Пример #2
0
static int hw_init(const char *deviceinfo)
{
	struct sr_device_instance *sdi;
	struct libusb_device_descriptor des;
	struct fx2_profile *fx2_prof;
	struct fx2_device *fx2;
	libusb_device **devlist;
	int err, devcnt, i, j;

	/* Avoid compiler warnings. */
	(void)deviceinfo;

	if (libusb_init(&usb_context) != 0) {
		sr_warn("Failed to initialize USB.");
		return 0;
	}

	/* Find all Saleae Logic devices and upload firmware to all of them. */
	devcnt = 0;
	libusb_get_device_list(usb_context, &devlist);
	for (i = 0; devlist[i]; i++) {
		fx2_prof = NULL;
		err = libusb_get_device_descriptor(devlist[i], &des);
		if (err != 0) {
			sr_warn("failed to get device descriptor: %d", err);
			continue;
		}

		for (j = 0; supported_fx2[j].orig_vid; j++) {
			if (des.idVendor == supported_fx2[j].orig_vid
				&& des.idProduct == supported_fx2[j].orig_pid) {
				fx2_prof = &supported_fx2[j];
				break;
			}
		}
		if (!fx2_prof)
			/* not a supported VID/PID */
			continue;

		sdi = sr_device_instance_new(devcnt, SR_ST_INITIALIZING,
			fx2_prof->vendor, fx2_prof->model, fx2_prof->model_version);
		if (!sdi)
			return 0;
		fx2 = fx2_device_new();
		fx2->profile = fx2_prof;
		sdi->priv = fx2;
		device_instances = g_slist_append(device_instances, sdi);

		if (check_conf_profile(devlist[i])) {
			/* Already has the firmware, so fix the new address. */
			sdi->status = SR_ST_INACTIVE;
			sdi->usb = sr_usb_device_instance_new
			    (libusb_get_bus_number(devlist[i]),
			     libusb_get_device_address(devlist[i]), NULL);
		} else {
			if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION, FIRMWARE) == SR_OK)
				/* Remember when the firmware on this device was updated */
				g_get_current_time(&fx2->fw_updated);
			else
				sr_warn("firmware upload failed for device %d", devcnt);
			sdi->usb = sr_usb_device_instance_new
				(libusb_get_bus_number(devlist[i]), 0xff, NULL);
		}
		devcnt++;
	}
	libusb_free_device_list(devlist, 1);

	return devcnt;
}
Пример #3
0
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
	struct drv_context *drvc;
	struct dev_context *devc;
	struct sr_dev_inst *sdi;
	struct sr_usb_dev_inst *usb;
	struct sr_config *src;
	GSList *l, *devices, *conn_devices;
	struct libusb_device_descriptor des;
	libusb_device **devlist;
	int ret;
	unsigned int i, j;
	const char *conn;
	char connection_id[64];

	drvc = di->priv;

	conn = NULL;
	for (l = options; l; l = l->next) {
		src = l->data;
		switch (src->key) {
		case SR_CONF_CONN:
			conn = g_variant_get_string(src->data, NULL);
			break;
		}
	}
	if (conn)
		conn_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn);
	else
		conn_devices = NULL;

	/* Find all Logic16 devices and upload firmware to them. */
	devices = NULL;
	libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
	for (i = 0; devlist[i]; i++) {
		if (conn) {
			usb = NULL;
			for (l = conn_devices; l; l = l->next) {
				usb = l->data;
				if (usb->bus == libusb_get_bus_number(devlist[i])
				    && usb->address == libusb_get_device_address(devlist[i]))
					break;
			}
			if (!l)
				/* This device matched none of the ones that
				 * matched the conn specification. */
				continue;
		}

		if ((ret = libusb_get_device_descriptor(devlist[i], &des)) != 0) {
			sr_warn("Failed to get device descriptor: %s.",
				libusb_error_name(ret));
			continue;
		}

		usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));

		if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID)
			continue;

		sdi = g_malloc0(sizeof(struct sr_dev_inst));
		sdi->status = SR_ST_INITIALIZING;
		sdi->vendor = g_strdup("Saleae");
		sdi->model = g_strdup("Logic16");
		sdi->driver = di;
		sdi->connection_id = g_strdup(connection_id);

		for (j = 0; j < ARRAY_SIZE(channel_names); j++)
			sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE,
					    channel_names[j]);

		devc = g_malloc0(sizeof(struct dev_context));
		devc->selected_voltage_range = VOLTAGE_RANGE_18_33_V;
		sdi->priv = devc;
		drvc->instances = g_slist_append(drvc->instances, sdi);
		devices = g_slist_append(devices, sdi);

		if (check_conf_profile(devlist[i])) {
			/* Already has the firmware, so fix the new address. */
			sr_dbg("Found a Logic16 device.");
			sdi->status = SR_ST_INACTIVE;
			sdi->inst_type = SR_INST_USB;
			sdi->conn = sr_usb_dev_inst_new(
				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)
				/* Store when this device's FW was updated. */
				devc->fw_updated = g_get_monotonic_time();
			else
				sr_err("Firmware upload failed.");
			sdi->inst_type = SR_INST_USB;
			sdi->conn = sr_usb_dev_inst_new(
				libusb_get_bus_number(devlist[i]), 0xff, NULL);
		}
	}
	libusb_free_device_list(devlist, 1);
	g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);

	return devices;
}