static const struct fx2lafw_profile supported_fx2[] = {
/*
* CWAV USBee AX
- * EE Electronics ESLA201A
- * ARMFLY AX-Pro
+ * ARMFLY AX-Pro (clone of the CWAV USBee AX)
+ * ARMFLY Mini-Logic (clone of the CWAV USBee AX)
+ * EE Electronics ESLA201A (clone of the CWAV USBee AX)
+ * HT USBee-AxPro (clone of the CWAV USBee AX)
+ * MCU123 USBee AX Pro clone (clone of the CWAV USBee AX)
+ * Noname LHT00SU1 (clone of the CWAV USBee AX)
+ * XZL_Studio AX (clone of the CWAV USBee AX)
*/
{ 0x08a9, 0x0014, "CWAV", "USBee AX", NULL,
"fx2lafw-cwav-usbeeax.fw",
DEV_CAPS_AX_ANALOG, NULL, NULL},
+
/*
* CWAV USBee DX
- * XZL-Studio DX
+ * HT USBee-DxPro (clone of the CWAV USBee DX), not yet supported!
+ * XZL-Studio DX (clone of the CWAV USBee DX)
*/
{ 0x08a9, 0x0015, "CWAV", "USBee DX", NULL,
"fx2lafw-cwav-usbeedx.fw",
/*
* Saleae Logic
- * EE Electronics ESLA100
- * Robomotic MiniLogic
- * Robomotic BugLogic 3
+ * EE Electronics ESLA100 (clone of the Saleae Logic)
+ * Hantek 6022BL in LA mode (clone of the Saleae Logic)
+ * Instrustar ISDS205X in LA mode (clone of the Saleae Logic)
+ * Robomotic MiniLogic (clone of the Saleae Logic)
+ * Robomotic BugLogic 3 (clone of the Saleae Logic)
+ * MCU123 Saleae Logic clone (clone of the Saleae Logic)
*/
{ 0x0925, 0x3881, "Saleae", "Logic", NULL,
"fx2lafw-saleae-logic.fw",
* Default Cypress FX2 without EEPROM, e.g.:
* Lcsoft Mini Board
* Braintechnology USB Interface V2.x
+ * fx2grok-tiny
*/
{ 0x04B4, 0x8613, "Cypress", "FX2", NULL,
"fx2lafw-cypress-fx2.fw",
/*
* sigrok FX2 based 8-channel logic analyzer
+ * fx2grok-flat (before and after renumeration)
*/
{ 0x1d50, 0x608c, "sigrok", "FX2 LA (8ch)", NULL,
"fx2lafw-sigrok-fx2-8ch.fw",
ALL_ZERO
};
-static const uint32_t drvopts[] = {
- SR_CONF_LOGIC_ANALYZER,
-};
-
static const uint32_t scanopts[] = {
SR_CONF_CONN,
};
+static const uint32_t drvopts[] = {
+ SR_CONF_LOGIC_ANALYZER,
+};
+
static const uint32_t devopts[] = {
SR_CONF_CONTINUOUS,
SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
};
-static const int32_t soft_trigger_matches[] = {
+static const int32_t trigger_matches[] = {
SR_TRIGGER_ZERO,
SR_TRIGGER_ONE,
SR_TRIGGER_RISING,
continue;
}
- usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
-
libusb_close(hdl);
+ if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0)
+ continue;
+
prof = NULL;
for (j = 0; supported_fx2[j].vid; j++) {
if (des.idVendor == supported_fx2[j].vid &&
}
}
- /* Skip if the device was not found. */
if (!prof)
continue;
return std_scan_complete(di, devices);
}
-static void clear_dev_context(void *priv)
+static void clear_helper(struct dev_context *devc)
{
- struct dev_context *devc;
-
- devc = priv;
g_slist_free(devc->enabled_analog_channels);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
{
- return std_dev_clear(di, clear_dev_context);
+ return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
}
static int dev_open(struct sr_dev_inst *sdi)
usb = sdi->conn;
if (!usb->devhdl)
- return SR_ERR;
+ return SR_ERR_BUG;
- sr_info("fx2lafw: Closing device on %d.%d (logical) / %s (physical) interface %d.",
+ sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
libusb_release_interface(usb->devhdl, USB_INTERFACE);
libusb_close(usb->devhdl);
usb->devhdl = NULL;
- sdi->status = SR_ST_INACTIVE;
return SR_OK;
}
{
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
- char str[128];
(void)cg;
/* Device still needs to re-enumerate after firmware
* upload, so we don't know its (future) address. */
return SR_ERR;
- snprintf(str, 128, "%d.%d", usb->bus, usb->address);
- *data = g_variant_new_string(str);
+ *data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
break;
case SR_CONF_LIMIT_SAMPLES:
*data = g_variant_new_uint64(devc->limit_samples);
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
- uint64_t arg;
- int i, ret;
+ int idx;
(void)cg;
if (!sdi)
return SR_ERR_ARG;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR;
-
devc = sdi->priv;
- ret = SR_OK;
-
switch (key) {
case SR_CONF_SAMPLERATE:
- arg = g_variant_get_uint64(data);
- for (i = 0; i < devc->num_samplerates; i++) {
- if (devc->samplerates[i] == arg) {
- devc->cur_samplerate = arg;
- break;
- }
- }
- if (i == devc->num_samplerates)
- ret = SR_ERR_ARG;
+ if ((idx = std_u64_idx(data, devc->samplerates, devc->num_samplerates)) < 0)
+ return SR_ERR_ARG;
+ devc->cur_samplerate = devc->samplerates[idx];
break;
case SR_CONF_LIMIT_SAMPLES:
devc->limit_samples = g_variant_get_uint64(data);
break;
case SR_CONF_CAPTURE_RATIO:
devc->capture_ratio = g_variant_get_uint64(data);
- ret = (devc->capture_ratio > 100) ? SR_ERR : SR_OK;
break;
default:
- ret = SR_ERR_NA;
+ return SR_ERR_NA;
}
- return ret;
+ return SR_OK;
}
static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
- GVariant *gvar;
- GVariantBuilder gvb;
- (void)cg;
+ devc = (sdi) ? sdi->priv : NULL;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
- break;
case SR_CONF_DEVICE_OPTIONS:
- if (!sdi) {
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
- } else {
- devc = sdi->priv;
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
- }
- break;
+ return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_SAMPLERATE:
- devc = sdi->priv;
- g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
- gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), devc->samplerates,
- devc->num_samplerates, sizeof(uint64_t));
- g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
- *data = g_variant_builder_end(&gvb);
+ if (!devc)
+ return SR_ERR_NA;
+ *data = std_gvar_samplerates(devc->samplerates, devc->num_samplerates);
break;
case SR_CONF_TRIGGER_MATCH:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
- soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches),
- sizeof(int32_t));
+ *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
break;
default:
return SR_ERR_NA;
return SR_OK;
}
-static int receive_data(int fd, int revents, void *cb_data)
-{
- struct timeval tv;
- struct drv_context *drvc;
-
- (void)fd;
- (void)revents;
-
- drvc = (struct drv_context *)cb_data;
-
- tv.tv_sec = tv.tv_usec = 0;
- libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
-
- return TRUE;
-}
-
-static int start_transfers(const struct sr_dev_inst *sdi)
-{
- struct dev_context *devc;
- struct sr_usb_dev_inst *usb;
- struct sr_trigger *trigger;
- struct libusb_transfer *transfer;
- unsigned int i, num_transfers;
- int timeout, ret;
- unsigned char *buf;
- size_t size;
-
- devc = sdi->priv;
- usb = sdi->conn;
-
- devc->sent_samples = 0;
- devc->acq_aborted = FALSE;
- devc->empty_transfer_count = 0;
-
- if ((trigger = sr_session_trigger_get(sdi->session))) {
- int pre_trigger_samples = 0;
- 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)
- return SR_ERR_MALLOC;
- devc->trigger_fired = FALSE;
- } else
- devc->trigger_fired = TRUE;
-
- num_transfers = fx2lafw_get_number_of_transfers(devc);
-
- size = fx2lafw_get_buffer_size(devc);
- devc->submitted_transfers = 0;
-
- devc->transfers = g_try_malloc0(sizeof(*devc->transfers) * num_transfers);
- if (!devc->transfers) {
- sr_err("USB transfers malloc failed.");
- return SR_ERR_MALLOC;
- }
-
- timeout = fx2lafw_get_timeout(devc);
- devc->num_transfers = num_transfers;
- for (i = 0; i < num_transfers; i++) {
- if (!(buf = g_try_malloc(size))) {
- sr_err("USB transfer buffer malloc failed.");
- return SR_ERR_MALLOC;
- }
- transfer = libusb_alloc_transfer(0);
- libusb_fill_bulk_transfer(transfer, usb->devhdl,
- 2 | LIBUSB_ENDPOINT_IN, buf, size,
- fx2lafw_receive_transfer, (void *)sdi, timeout);
- sr_info("submitting transfer: %d", i);
- if ((ret = libusb_submit_transfer(transfer)) != 0) {
- sr_err("Failed to submit transfer: %s.",
- libusb_error_name(ret));
- libusb_free_transfer(transfer);
- g_free(buf);
- fx2lafw_abort_acquisition(devc);
- return SR_ERR;
- }
- devc->transfers[i] = transfer;
- devc->submitted_transfers++;
- }
-
- /*
- * If this device has analog channels and at least one of them is
- * enabled, use mso_send_data_proc() to properly handle the analog
- * data. Otherwise use la_send_data_proc().
- */
- if (g_slist_length(devc->enabled_analog_channels) > 0)
- devc->send_data_proc = mso_send_data_proc;
- else
- devc->send_data_proc = la_send_data_proc;
-
- std_session_send_df_header(sdi);
-
- return SR_OK;
-}
-
-static int configure_channels(const struct sr_dev_inst *sdi)
-{
- struct dev_context *devc;
- const GSList *l;
- int p;
- struct sr_channel *ch;
- uint32_t channel_mask = 0, num_analog = 0;
-
- devc = sdi->priv;
-
- g_slist_free(devc->enabled_analog_channels);
- devc->enabled_analog_channels = NULL;
-
- for (l = sdi->channels, p = 0; l; l = l->next, p++) {
- ch = l->data;
- if ((p <= NUM_CHANNELS) && (ch->type == SR_CHANNEL_ANALOG)
- && (ch->enabled)) {
- num_analog++;
- devc->enabled_analog_channels =
- g_slist_append(devc->enabled_analog_channels, ch);
- } else {
- channel_mask |= ch->enabled << p;
- }
- }
-
- /*
- * Use wide sampling if either any of the LA channels 8..15 is enabled,
- * and/or at least one analog channel is enabled.
- */
- devc->sample_wide = channel_mask > 0xff || num_analog > 0;
-
- return SR_OK;
-}
-
-static int dev_acquisition_start(const struct sr_dev_inst *sdi)
-{
- struct sr_dev_driver *di;
- struct drv_context *drvc;
- struct dev_context *devc;
- int timeout, ret;
- size_t size;
-
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
- di = sdi->driver;
- drvc = di->context;
- devc = sdi->priv;
-
- devc->ctx = drvc->sr_ctx;
- devc->sent_samples = 0;
- devc->empty_transfer_count = 0;
- devc->acq_aborted = FALSE;
-
- if (configure_channels(sdi) != SR_OK) {
- sr_err("Failed to configure channels.");
- return SR_ERR;
- }
-
- timeout = fx2lafw_get_timeout(devc);
- usb_source_add(sdi->session, devc->ctx, timeout, receive_data, drvc);
-
- size = fx2lafw_get_buffer_size(devc);
- /* Prepare for analog sampling. */
- if (g_slist_length(devc->enabled_analog_channels) > 0) {
- /* We need a buffer half the size of a transfer. */
- devc->logic_buffer = g_try_malloc(size / 2);
- devc->analog_buffer = g_try_malloc(
- sizeof(float) * size / 2);
- }
- start_transfers(sdi);
- if ((ret = fx2lafw_command_start_acquisition(sdi)) != SR_OK) {
- fx2lafw_abort_acquisition(devc);
- return ret;
- }
-
- return SR_OK;
-}
-
static int dev_acquisition_stop(struct sr_dev_inst *sdi)
{
fx2lafw_abort_acquisition(sdi->priv);
.config_list = config_list,
.dev_open = dev_open,
.dev_close = dev_close,
- .dev_acquisition_start = dev_acquisition_start,
+ .dev_acquisition_start = fx2lafw_start_acquisition,
.dev_acquisition_stop = dev_acquisition_stop,
.context = NULL,
};