#define LOGIC16_VID 0x21a9
#define LOGIC16_PID 0x1001
-#define NUM_PROBES 16
#define USB_INTERFACE 0
#define USB_CONFIGURATION 1
SR_CONF_CONTINUOUS,
};
-static const char *probe_names[NUM_PROBES + 1] = {
+static const char *channel_names[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "13", "14", "15",
NULL,
struct dev_context *devc;
struct sr_dev_inst *sdi;
struct sr_usb_dev_inst *usb;
- struct sr_probe *probe;
+ struct sr_channel *ch;
struct sr_config *src;
GSList *l, *devices, *conn_devices;
struct libusb_device_descriptor des;
return NULL;
sdi->driver = di;
- for (j = 0; probe_names[j]; j++) {
- if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE,
- probe_names[j])))
+ for (j = 0; channel_names[j]; j++) {
+ if (!(ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE,
+ channel_names[j])))
return NULL;
- sdi->probes = g_slist_append(sdi->probes, probe);
+ sdi->channels = g_slist_append(sdi->channels, ch);
}
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
static GSList *dev_list(void)
{
- struct drv_context *drvc;
-
- drvc = di->priv;
-
- return drvc->instances;
-}
-
-static int dev_clear(void)
-{
- return std_dev_clear(di, NULL);
+ return ((struct drv_context *)(di->priv))->instances;
}
static int logic16_dev_open(struct sr_dev_inst *sdi)
break;
}
+ ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
+ if (ret == LIBUSB_ERROR_BUSY) {
+ sr_err("Unable to claim USB interface. Another "
+ "program or driver has already claimed it.");
+ break;
+ } else if (ret == LIBUSB_ERROR_NO_DEVICE) {
+ sr_err("Device has been disconnected.");
+ break;
+ } else if (ret != 0) {
+ sr_err("Unable to claim interface: %s.",
+ libusb_error_name(ret));
+ break;
+ }
+
if ((ret = logic16_init_device(sdi)) != SR_OK) {
sr_err("Failed to init device.");
break;
}
libusb_free_device_list(devlist, 1);
- if (sdi->status != SR_ST_ACTIVE)
+ if (sdi->status != SR_ST_ACTIVE) {
+ if (usb->devhdl) {
+ libusb_release_interface(usb->devhdl, USB_INTERFACE);
+ libusb_close(usb->devhdl);
+ usb->devhdl = NULL;
+ }
return SR_ERR;
+ }
return SR_OK;
}
static int dev_open(struct sr_dev_inst *sdi)
{
- struct sr_usb_dev_inst *usb;
struct dev_context *devc;
int ret;
int64_t timediff_us, timediff_ms;
devc = sdi->priv;
- usb = sdi->conn;
/*
* If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
return SR_ERR;
}
- ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
- if (ret != 0) {
- switch (ret) {
- case LIBUSB_ERROR_BUSY:
- sr_err("Unable to claim USB interface. Another "
- "program or driver has already claimed it.");
- break;
- case LIBUSB_ERROR_NO_DEVICE:
- sr_err("Device has been disconnected.");
- break;
- default:
- sr_err("Unable to claim interface: %s.",
- libusb_error_name(ret));
- break;
- }
-
- return SR_ERR;
- }
-
if (devc->cur_samplerate == 0) {
/* Samplerate hasn't been set; default to the slowest one. */
devc->cur_samplerate = samplerates[0];
/* Can get called on an unused driver, doesn't matter. */
return SR_OK;
- ret = dev_clear();
+
+ ret = std_dev_clear(di, NULL);
g_free(drvc);
di->priv = NULL;
return ret;
}
-static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
+static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
+ const struct sr_channel_group *cg)
{
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
int ret;
unsigned int i;
+ (void)cg;
+
ret = SR_OK;
switch (key) {
case SR_CONF_CONN:
return ret;
}
-static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
+static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
+ const struct sr_channel_group *cg)
{
struct dev_context *devc;
gdouble low, high;
int ret;
unsigned int i;
+ (void)cg;
+
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
return ret;
}
-static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
+static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
+ const struct sr_channel_group *cg)
{
GVariant *gvar, *range[2];
GVariantBuilder gvb;
unsigned int i;
(void)sdi;
+ (void)cg;
ret = SR_OK;
switch (key) {
return timeout + timeout / 4; /* Leave a headroom of 25% percent. */
}
-static int configure_probes(const struct sr_dev_inst *sdi)
+static int configure_channels(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
- struct sr_probe *probe;
+ struct sr_channel *ch;
GSList *l;
- uint16_t probe_bit;
+ uint16_t channel_bit;
devc = sdi->priv;
devc->cur_channels = 0;
devc->num_channels = 0;
- for (l = sdi->probes; l; l = l->next) {
- probe = (struct sr_probe *)l->data;
- if (probe->enabled == FALSE)
+ for (l = sdi->channels; l; l = l->next) {
+ ch = (struct sr_channel *)l->data;
+ if (ch->enabled == FALSE)
continue;
- probe_bit = 1 << (probe->index);
+ channel_bit = 1 << (ch->index);
- devc->cur_channels |= probe_bit;
+ devc->cur_channels |= channel_bit;
#ifdef WORDS_BIGENDIAN
/*
* To speed things up during conversion, do the switcharoo
* here instead.
*/
- probe_bit = 1 << (probe->index ^ 8);
+ channel_bit = 1 << (ch->index ^ 8);
#endif
- devc->channel_masks[devc->num_channels++] = probe_bit;
+ devc->channel_masks[devc->num_channels++] = channel_bit;
+ }
+
+ if (devc->cur_channels & ~0xff) {
+ devc->unitsize = 2;
+ } else {
+#ifdef WORDS_BIGENDIAN
+ int i;
+ for (i=0; i<devc->num_channels; i++)
+ devc->channel_masks[i] >>= 8;
+#endif
+ devc->unitsize = 1;
}
return SR_OK;
struct drv_context *drvc;
struct sr_usb_dev_inst *usb;
struct libusb_transfer *transfer;
- const struct libusb_pollfd **lupfd;
unsigned int i, timeout, num_transfers;
int ret;
unsigned char *buf;
usb = sdi->conn;
/* Configures devc->cur_channels. */
- if (configure_probes(sdi) != SR_OK) {
- sr_err("Failed to configure probes.");
+ if (configure_channels(sdi) != SR_OK) {
+ sr_err("Failed to configure channels.");
return SR_ERR;
}
size = get_buffer_size(devc);
convsize = (size / devc->num_channels + 2) * 16;
devc->submitted_transfers = 0;
- devc->usbfd = NULL;
devc->convbuffer_size = convsize;
if (!(devc->convbuffer = g_try_malloc(convsize))) {
devc->submitted_transfers++;
}
- lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
- for (i = 0; lupfd[i]; i++);
- devc->usbfd = g_try_malloc(sizeof(struct libusb_pollfd) * (i + 1));
- if (!devc->usbfd) {
- abort_acquisition(devc);
- free(lupfd);
- return SR_ERR;
- }
- for (i = 0; lupfd[i]; i++) {
- sr_source_add(lupfd[i]->fd, lupfd[i]->events,
- timeout, receive_data, (void *)sdi);
- devc->usbfd[i] = lupfd[i]->fd;
- }
- devc->usbfd[i] = -1;
- free(lupfd);
+ devc->ctx = drvc->sr_ctx;
+
+ usb_source_add(devc->ctx, timeout, receive_data, (void *)sdi);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
.cleanup = cleanup,
.scan = scan,
.dev_list = dev_list,
- .dev_clear = dev_clear,
+ .dev_clear = NULL,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,