X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fhantek-dso%2Fapi.c;h=0847da558aabbacb361a4b6db3538514a199aecf;hb=47f4f073e0a7fe68a55001180c3c9092551f2108;hp=64dc0f98080af1b7f776337625d8cdd5b3c79a10;hpb=811deee4af9f600ae0c457a74d3877c4f68f2f37;p=libsigrok.git diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index 64dc0f98..0847da55 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -31,7 +31,6 @@ #include #include "libsigrok.h" #include "libsigrok-internal.h" -#include "config.h" #include "dso.h" @@ -146,8 +145,7 @@ static const char *coupling[] = { SR_PRIV struct sr_dev_driver hantek_dso_driver_info; static struct sr_dev_driver *hdi = &hantek_dso_driver_info; -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data); +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static struct sr_dev_inst *dso_dev_new(int index, const struct dso_profile *prof) { @@ -259,10 +257,10 @@ static int hw_init(void) if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { sr_err("hantek-dso: driver context malloc failed."); - return SR_ERR; + return SR_ERR_MALLOC; } - if (libusb_init(&drvc->usb_context) != 0) { + if (libusb_init(NULL) != 0) { g_free(drvc); sr_err("hantek-dso: Failed to initialize USB."); return SR_ERR; @@ -293,7 +291,7 @@ static GSList *hw_scan(GSList *options) clear_instances(); /* Find all Hantek DSO devices and upload firmware to all of them. */ - libusb_get_device_list(drvc->usb_context, &devlist); + libusb_get_device_list(NULL, &devlist); for (i = 0; devlist[i]; i++) { if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { sr_err("hantek-dso: failed to get device descriptor: %d", ret); @@ -418,9 +416,7 @@ static int hw_cleanup(void) clear_instances(); - if (drvc->usb_context) - libusb_exit(drvc->usb_context); - drvc->usb_context = NULL; + libusb_exit(NULL); return SR_OK; } @@ -605,6 +601,7 @@ static void send_chunk(struct dev_context *devc, unsigned char *buf, analog.num_samples = num_samples; analog.mq = SR_MQ_VOLTAGE; analog.unit = SR_UNIT_VOLT; + /* TODO: Check malloc return value. */ analog.data = g_try_malloc(analog.num_samples * sizeof(float) * num_probes); data_offset = 0; for (i = 0; i < analog.num_samples; i++) { @@ -732,7 +729,6 @@ static int handle_event(int fd, int revents, void *cb_data) const struct sr_dev_inst *sdi; struct sr_datafeed_packet packet; struct timeval tv; - struct drv_context *drvc; struct dev_context *devc; const struct libusb_pollfd **lupfd; int num_probes, i; @@ -743,7 +739,6 @@ static int handle_event(int fd, int revents, void *cb_data) (void)fd; (void)revents; - drvc = hdi->priv; sdi = cb_data; devc = sdi->priv; if (devc->dev_state == STOPPING) { @@ -751,7 +746,7 @@ static int handle_event(int fd, int revents, void *cb_data) sr_dbg("hantek-dso: stopping acquisition"); /* TODO: doesn't really cancel pending transfers so they might * come in after SR_DF_END is sent. */ - lupfd = libusb_get_pollfds(drvc->usb_context); + lupfd = libusb_get_pollfds(NULL); for (i = 0; lupfd[i]; i++) sr_source_remove(lupfd[i]->fd); free(lupfd); @@ -766,7 +761,7 @@ static int handle_event(int fd, int revents, void *cb_data) /* Always handle pending libusb events. */ tv.tv_sec = tv.tv_usec = 0; - libusb_handle_events_timeout(drvc->usb_context, &tv); + libusb_handle_events_timeout(NULL, &tv); /* TODO: ugh */ if (devc->dev_state == NEW_CAPTURE) { @@ -809,6 +804,7 @@ static int handle_event(int fd, int revents, void *cb_data) devc->trigger_offset = trigger_offset; num_probes = (devc->ch1_enabled && devc->ch2_enabled) ? 2 : 1; + /* TODO: Check malloc return value. */ devc->framebuf = g_try_malloc(devc->framesize * num_probes * 2); devc->samp_buffered = devc->samp_received = 0; @@ -846,11 +842,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, struct sr_datafeed_packet packet; struct sr_datafeed_header header; struct sr_datafeed_meta_analog meta; - struct drv_context *drvc; struct dev_context *devc; int i; - drvc = hdi->priv; if (sdi->status != SR_ST_ACTIVE) return SR_ERR; @@ -869,7 +863,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_ERR; devc->dev_state = CAPTURE; - lupfd = libusb_get_pollfds(drvc->usb_context); + lupfd = libusb_get_pollfds(NULL); for (i = 0; lupfd[i]; i++) sr_source_add(lupfd[i]->fd, lupfd[i]->events, TICK, handle_event, (void *)sdi); @@ -891,8 +885,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc;