SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info;
static struct sr_dev_driver *zdi = &zeroplus_logic_cube_driver_info;
-static libusb_context *usb_context = NULL;
-
/*
* The hardware supports more samplerates than these, but these are the
* options hardcoded into the vendor's Windows GUI.
* API callbacks
*/
-static int hw_init(void)
+static int hw_init(struct sr_context *sr_ctx)
{
struct drv_context *drvc;
sr_err("zeroplus: driver context malloc failed.");
return SR_ERR_MALLOC;
}
+ drvc->sr_ctx = sr_ctx;
zdi->priv = drvc;
- if (libusb_init(&usb_context) != 0) {
- sr_err("zp: Failed to initialize USB.");
- return 0;
- }
-
return SR_OK;
}
int ret, devcnt, i, j;
(void)options;
+
drvc = zdi->priv;
devices = NULL;
/* Find all ZEROPLUS analyzers and add them to device list. */
devcnt = 0;
- libusb_get_device_list(usb_context, &devlist); /* TODO: Errors. */
+ libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); /* TODO: Errors. */
for (i = 0; devlist[i]; i++) {
ret = libusb_get_device_descriptor(devlist[i], &des);
if (ret != 0) {
- sr_err("zp: failed to get device descriptor: %d", ret);
+ sr_err("zp: failed to get device descriptor: %s",
+ libusb_error_name(ret));
continue;
}
static int hw_dev_open(struct sr_dev_inst *sdi)
{
struct dev_context *devc;
+ struct drv_context *drvc = zdi->priv;
libusb_device **devlist, *dev;
struct libusb_device_descriptor des;
int device_count, ret, i;
return SR_ERR_ARG;
}
- device_count = libusb_get_device_list(usb_context, &devlist);
+ device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx,
+ &devlist);
if (device_count < 0) {
sr_err("zp: Failed to retrieve device list");
return SR_ERR;
dev = NULL;
for (i = 0; i < device_count; i++) {
if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
- sr_err("fx2lafw: Failed to get device descriptor: %d.",
- ret);
+ sr_err("zp: Failed to get device descriptor: %s.",
+ libusb_error_name(ret));
continue;
}
if (libusb_get_bus_number(devlist[i]) == devc->usb->bus
sdi->index, devc->usb->bus,
devc->usb->address, USB_INTERFACE);
} else {
- sr_err("zp: failed to open device: %d", ret);
+ sr_err("zp: failed to open device: %s", libusb_error_name(ret));
return SR_ERR;
}
ret = libusb_set_configuration(devc->usb->devhdl, USB_CONFIGURATION);
if (ret < 0) {
- sr_err("zp: Unable to set USB configuration %d: %d",
- USB_CONFIGURATION, ret);
+ sr_err("zp: Unable to set USB configuration %d: %s",
+ USB_CONFIGURATION, libusb_error_name(ret));
return SR_ERR;
}
ret = libusb_claim_interface(devc->usb->devhdl, USB_INTERFACE);
if (ret != 0) {
- sr_err("zp: Unable to claim interface: %d", ret);
+ sr_err("zp: Unable to claim interface: %s",
+ libusb_error_name(ret));
return SR_ERR;
}
clear_instances();
- if (usb_context)
- libusb_exit(usb_context);
- usb_context = NULL;
-
return SR_OK;
}