libusb_device **devlist;
struct libusb_device_descriptor des;
struct dev_context *devc;
+ struct drv_context *drvc = fdi->priv;
struct version_info vi;
int ret, skip, i;
uint8_t revid;
return SR_ERR;
skip = 0;
- const int device_count = libusb_get_device_list(NULL, &devlist);
+ const int device_count = libusb_get_device_list(
+ drvc->sr_ctx->libusb_ctx, &devlist);
if (device_count < 0) {
sr_err("fx2lafw: Failed to retrieve device list (%d)",
device_count);
return SR_ERR_MALLOC;
}
- if (libusb_init(NULL) != 0) {
- g_free(drvc);
- sr_warn("fx2lafw: Failed to initialize libusb.");
- return SR_ERR;
- }
-
drvc->sr_ctx = sr_ctx;
fdi->priv = drvc;
/* Find all fx2lafw compatible devices and upload firmware to them. */
devices = NULL;
- 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(
ret = clear_instances();
- libusb_exit(NULL);
-
g_free(drvc);
fdi->priv = NULL;
static int receive_data(int fd, int revents, void *cb_data)
{
struct timeval tv;
+ struct drv_context *drvc = fdi->priv;
(void)fd;
(void)revents;
(void)cb_data;
tv.tv_sec = tv.tv_usec = 0;
- libusb_handle_events_timeout(NULL, &tv);
+ libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
return TRUE;
}
static void finish_acquisition(struct dev_context *devc)
{
struct sr_datafeed_packet packet;
+ struct drv_context *drvc = fdi->priv;
int i;
/* Remove fds from polling */
const struct libusb_pollfd **const lupfd =
- libusb_get_pollfds(NULL);
+ libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
for (i = 0; lupfd[i]; i++)
sr_source_remove(lupfd[i]->fd);
free(lupfd); /* NOT g_free()! */
struct sr_datafeed_header header;
struct sr_datafeed_meta_logic meta;
struct dev_context *devc;
+ struct drv_context *drvc = fdi->priv;
struct libusb_transfer *transfer;
const struct libusb_pollfd **lupfd;
unsigned int i;
devc->submitted_transfers++;
}
- 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,
timeout, receive_data, NULL);
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;
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);
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);
libusb_device **devlist;
struct libusb_device_descriptor des;
struct dev_context *devc;
+ struct drv_context *drvc = hantek_dso_driver_info.priv;
int err, skip, i;
devc = sdi->priv;
return SR_ERR;
skip = 0;
- libusb_get_device_list(NULL, &devlist);
+ libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
for (i = 0; devlist[i]; i++) {
if ((err = libusb_get_device_descriptor(devlist[i], &des))) {
sr_err("Failed to get device descriptor: %d.", err);
static int hw_init(struct sr_context *sr_ctx, int dmm)
{
- int ret;
struct drv_context *drvc;
if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
return SR_ERR_MALLOC;
}
- if ((ret = libusb_init(NULL)) < 0) {
- sr_err("Failed to initialize libusb: %s.",
- libusb_error_name(ret));
- return SR_ERR;
- }
-
if (dmm == UNI_T_UT61D)
di = di_ut61d;
else if (dmm == VOLTCRAFT_VC820)
devices = NULL;
- if (!(l = sr_usb_connect(NULL, "1a86.e008")))
+ if (!(l = sr_usb_connect(drvc->sr_ctx->libusb_ctx, "1a86.e008")))
return NULL;
for (i = 0; i < (int)g_slist_length(l); i++) {
{
clear_instances();
- // libusb_exit(NULL);
-
return SR_OK;
}
clear_instances();
devices = NULL;
- 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)) != 0) {
sr_warn("Failed to get device descriptor: %s",
static int hw_dev_open(struct sr_dev_inst *sdi)
{
struct dev_context *devc;
+ struct drv_context *drvc = di->priv;
libusb_device **devlist;
int ret, i;
}
devc = sdi->priv;
- libusb_get_device_list(NULL, &devlist);
+ libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
for (i = 0; devlist[i]; i++) {
if (libusb_get_bus_number(devlist[i]) != devc->usb->bus
|| libusb_get_device_address(devlist[i]) != devc->usb->address)
static int handle_events(int fd, int revents, void *cb_data)
{
struct dev_context *devc;
+ struct drv_context *drvc = di->priv;
struct sr_datafeed_packet packet;
struct sr_dev_inst *sdi;
struct timeval tv;
}
memset(&tv, 0, sizeof(struct timeval));
- libusb_handle_events_timeout_completed(NULL, &tv, NULL);
+ libusb_handle_events_timeout_completed(drvc->sr_ctx->libusb_ctx, &tv,
+ NULL);
return TRUE;
}
struct sr_datafeed_header header;
struct sr_datafeed_meta_analog meta;
struct dev_context *devc;
+ struct drv_context *drvc = di->priv;
const struct libusb_pollfd **pfd;
struct libusb_transfer *transfer;
int ret, i;
meta.num_probes = 1;
sr_session_send(devc->cb_data, &packet);
- pfd = libusb_get_pollfds(NULL);
+ pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
for (i = 0; pfd[i]; i++) {
/* Handle USB events every 100ms, for decent latency. */
sr_source_add(pfd[i]->fd, pfd[i]->events, 100,
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.
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;
}
/* 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);
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;
clear_instances();
- if (usb_context)
- libusb_exit(usb_context);
- usb_context = NULL;
-
return SR_OK;
}