return SR_OK;
}
-static int hw_init(void)
+static int hw_init(struct sr_context *sr_ctx)
{
struct drv_context *drvc;
return SR_ERR_MALLOC;
}
- if (libusb_init(NULL) != 0) {
- g_free(drvc);
- sr_err("Failed to initialize USB.");
- return SR_ERR;
- }
-
+ drvc->sr_ctx = sr_ctx;
hdi->priv = drvc;
return SR_OK;
clear_instances();
/* Find all Hantek DSO devices and upload firmware to all of them. */
- libusb_get_device_list(NULL, &devlist);
+ libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
for (i = 0; devlist[i]; i++) {
if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
- sr_err("Failed to get device descriptor: %d.", ret);
+ sr_err("Failed to get device descriptor: %s.",
+ libusb_error_name(ret));
continue;
}
err = libusb_claim_interface(devc->usb->devhdl, USB_INTERFACE);
if (err != 0) {
- sr_err("Unable to claim interface: %d.", err);
+ sr_err("Unable to claim interface: %s.",
+ libusb_error_name(err));
return SR_ERR;
}
clear_instances();
- libusb_exit(NULL);
-
return SR_OK;
}
struct sr_datafeed_packet packet;
struct timeval tv;
struct dev_context *devc;
+ struct drv_context *drvc = hdi->priv;
const struct libusb_pollfd **lupfd;
int num_probes, i;
uint32_t trigger_offset;
* TODO: Doesn't really cancel pending transfers so they might
* come in after SR_DF_END is sent.
*/
- lupfd = libusb_get_pollfds(NULL);
+ lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
for (i = 0; lupfd[i]; i++)
sr_source_remove(lupfd[i]->fd);
free(lupfd);
/* Always handle pending libusb events. */
tv.tv_sec = tv.tv_usec = 0;
- libusb_handle_events_timeout(NULL, &tv);
+ libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
/* TODO: ugh */
if (devc->dev_state == NEW_CAPTURE) {
struct sr_datafeed_header header;
struct sr_datafeed_meta_analog meta;
struct dev_context *devc;
+ struct drv_context *drvc = hdi->priv;
int i;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR;
devc->dev_state = CAPTURE;
- lupfd = libusb_get_pollfds(NULL);
+ lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
for (i = 0; lupfd[i]; i++)
sr_source_add(lupfd[i]->fd, lupfd[i]->events, TICK,
handle_event, (void *)sdi);