X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Fhardware%2Fsaleae-logic16%2Fapi.c;h=af421d3c96733ec83a5b0456e9c0e879171f085d;hp=f33894ea0e0a8f294c4aa5beeaa5c8d191dba14c;hb=c1aae90038456a61d0f9313d34e6107c3440d3e7;hpb=5a971f66a37df7c4dbe7799b3c7fc7eb30055a61 diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index f33894ea..af421d3c 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -24,7 +24,7 @@ #include #include #include -#include "libsigrok.h" +#include #include "libsigrok-internal.h" #include "protocol.h" @@ -39,7 +39,6 @@ #define NUM_SIMUL_TRANSFERS 32 SR_PRIV struct sr_dev_driver saleae_logic16_driver_info; -static struct sr_dev_driver *di = &saleae_logic16_driver_info; static const uint32_t scanopts[] = { SR_CONF_CONN, @@ -67,7 +66,6 @@ static const int32_t soft_trigger_matches[] = { static const char *channel_names[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", - NULL, }; static const struct { @@ -96,7 +94,7 @@ static const uint64_t samplerates[] = { SR_MHZ(100), }; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } @@ -139,22 +137,22 @@ static gboolean check_conf_profile(libusb_device *dev) return ret; } -static GSList *scan(GSList *options) +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_channel *ch; struct sr_config *src; GSList *l, *devices, *conn_devices; struct libusb_device_descriptor des; libusb_device **devlist; - int ret, i, j; + int ret; + unsigned int i, j; const char *conn; char connection_id[64]; - drvc = di->priv; + drvc = di->context; conn = NULL; for (l = options; l; l = l->next) { @@ -206,11 +204,9 @@ static GSList *scan(GSList *options) sdi->driver = di; sdi->connection_id = g_strdup(connection_id); - for (j = 0; channel_names[j]; j++) { - ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, + for (j = 0; j < ARRAY_SIZE(channel_names); j++) + sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE, channel_names[j]); - sdi->channels = g_slist_append(sdi->channels, ch); - } devc = g_malloc0(sizeof(struct dev_context)); devc->selected_voltage_range = VOLTAGE_RANGE_18_33_V; @@ -244,13 +240,14 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { - return ((struct drv_context *)(di->priv))->instances; + return ((struct drv_context *)(di->context))->instances; } static int logic16_dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di; libusb_device **devlist; struct sr_usb_dev_inst *usb; struct libusb_device_descriptor des; @@ -258,7 +255,8 @@ static int logic16_dev_open(struct sr_dev_inst *sdi) int ret, i, device_count; char connection_id[64]; - drvc = di->priv; + di = sdi->driver; + drvc = di->context; usb = sdi->conn; if (sdi->status == SR_ST_ACTIVE) @@ -400,7 +398,7 @@ static int dev_close(struct sr_dev_inst *sdi) struct sr_usb_dev_inst *usb; usb = sdi->conn; - if (usb->devhdl == NULL) + if (!usb->devhdl) return SR_ERR; sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.", @@ -413,18 +411,17 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { int ret; struct drv_context *drvc; - if (!(drvc = di->priv)) + if (!(drvc = di->context)) /* Can get called on an unused driver, doesn't matter. */ return SR_OK; ret = std_dev_clear(di, NULL); g_free(drvc); - di->priv = NULL; return ret; } @@ -683,12 +680,14 @@ static int receive_data(int fd, int revents, void *cb_data) struct dev_context *devc; struct drv_context *drvc; const struct sr_dev_inst *sdi; + struct sr_dev_driver *di; (void)fd; (void)revents; sdi = cb_data; - drvc = di->priv; + di = sdi->driver; + drvc = di->context; devc = sdi->priv; tv.tv_sec = tv.tv_usec = 0; @@ -704,6 +703,7 @@ static int receive_data(int fd, int revents, void *cb_data) static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; struct drv_context *drvc; struct sr_usb_dev_inst *usb; @@ -717,7 +717,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - drvc = di->priv; + drvc = di->context; devc = sdi->priv; usb = sdi->conn; @@ -738,7 +738,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if (devc->limit_samples > 0) pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); - if (devc->stl == NULL) + if (!devc->stl) return SR_ERR_MALLOC; devc->trigger_fired = FALSE; } else @@ -845,5 +845,5 @@ SR_PRIV struct sr_dev_driver saleae_logic16_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, };