SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
};
-static const char *channel_names[] = {
- "0", "1", "2", "3", "4", "5", "6", "7",
- "8", "9", "10", "11", "12", "13", "14", "15",
-};
-
-static const char *ax_channel_names[] = {
- "A0",
-};
-
static const int32_t soft_trigger_matches[] = {
SR_TRIGGER_ZERO,
SR_TRIGGER_ONE,
struct dev_context *devc;
struct sr_dev_inst *sdi;
struct sr_usb_dev_inst *usb;
+ struct sr_channel *ch;
+ struct sr_channel_group *cg;
struct sr_config *src;
const struct fx2lafw_profile *prof;
GSList *l, *devices, *conn_devices;
int num_logic_channels = 0, num_analog_channels = 0;
const char *conn;
char manufacturer[64], product[64], serial_num[64], connection_id[64];
+ char channel_name[16];
drvc = di->context;
num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8;
num_analog_channels = prof->dev_caps & DEV_CAPS_AX_ANALOG ? 1 : 0;
- for (j = 0; j < num_logic_channels; j++)
- sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE,
- channel_names[j]);
-
- for (j = 0; j < num_analog_channels; j++)
- sr_channel_new(sdi, j, SR_CHANNEL_ANALOG, TRUE,
- ax_channel_names[j]);
+ /* Logic channels, all in one channel group. */
+ cg = g_malloc0(sizeof(struct sr_channel_group));
+ cg->name = g_strdup("Logic");
+ for (j = 0; j < num_logic_channels; j++) {
+ sprintf(channel_name, "D%d", j);
+ ch = sr_channel_new(sdi, j, SR_CHANNEL_LOGIC,
+ TRUE, channel_name);
+ cg->channels = g_slist_append(cg->channels, ch);
+ }
+ sdi->channel_groups = g_slist_append(NULL, cg);
+
+ for (j = 0; j < num_analog_channels; j++) {
+ snprintf(channel_name, 16, "A%d", j);
+ ch = sr_channel_new(sdi, j + num_logic_channels,
+ SR_CHANNEL_ANALOG, TRUE, channel_name);
+
+ /* Every analog channel gets its own channel group. */
+ cg = g_malloc0(sizeof(struct sr_channel_group));
+ cg->name = g_strdup(channel_name);
+ cg->channels = g_slist_append(NULL, ch);
+ sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
+ }
devc = fx2lafw_dev_new();
devc->profile = prof;
- devc->sample_wide = (prof->dev_caps & DEV_CAPS_16BIT) != 0;
+ if ((prof->dev_caps & DEV_CAPS_16BIT) || (prof->dev_caps & DEV_CAPS_AX_ANALOG))
+ devc->sample_wide = TRUE;
sdi->priv = devc;
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
return devices;
}
+static void clear_dev_context(void *priv)
+{
+ 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);
+}
+
static GSList *dev_list(const struct sr_dev_driver *di)
{
return ((struct drv_context *)(di->context))->instances;
return ret;
}
+static int configure_channels(const struct sr_dev_inst *sdi)
+{
+ struct dev_context *devc;
+ const GSList *l;
+ int p;
+ struct sr_channel *ch;
+
+ devc = sdi->priv;
+
+ g_slist_free(devc->enabled_analog_channels);
+ devc->enabled_analog_channels = NULL;
+ memset(devc->ch_enabled, 0, sizeof(devc->ch_enabled));
+
+ for (l = sdi->channels, p = 0; l; l = l->next, p++) {
+ ch = l->data;
+ if ((p <= NUM_CHANNELS) && (ch->type == SR_CHANNEL_ANALOG)) {
+ devc->ch_enabled[p] = ch->enabled;
+ devc->enabled_analog_channels =
+ g_slist_append(devc->enabled_analog_channels, ch);
+ }
+ }
+
+ return SR_OK;
+}
+
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
{
struct sr_dev_driver *di;
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);
.cleanup = cleanup,
.scan = scan,
.dev_list = dev_list,
- .dev_clear = NULL,
+ .dev_clear = dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,
/* Select the sampling width. */
cmd.flags |= devc->sample_wide ? CMD_START_FLAGS_SAMPLE_16BIT :
CMD_START_FLAGS_SAMPLE_8BIT;
+ /* Enable CTL2 clock. */
+ cmd.flags |= (devc->profile->dev_caps & DEV_CAPS_AX_ANALOG) ? CMD_START_FLAGS_CLK_CTL2 : 0;
/* Send the control message. */
ret = libusb_control_transfer(usb->devhdl, LIBUSB_REQUEST_TYPE_VENDOR |
sample_width = sample_width;
length /= 2;
- sr_dbg("mso_send_data_proc length = %d", length);
-
/* Send the logic */
for(i = 0; i < length; i++) {
devc->logic_buffer[i] = data[i * 2];
- devc->analog_buffer[i] = data[i * 2 + 1] - 128.0f;
+ /* Rescale to -10V - +10V from 0-255. */
+ devc->analog_buffer[i] = data[i * 2 + 1] - 128.0f / 12.8f;
};
const struct sr_datafeed_logic logic = {
sr_session_send(devc->cb_data, &logic_packet);
const struct sr_datafeed_analog_old analog = {
+ .channels = devc->enabled_analog_channels,
.num_samples = length,
.mq = SR_MQ_VOLTAGE,
.unit = SR_UNIT_VOLT,
- .mqflags = SR_MQFLAG_DC,
+ .mqflags = 0 /*SR_MQFLAG_DC*/,
.data = devc->analog_buffer
};
.type = SR_DF_ANALOG_OLD,
.payload = &analog
};
-
- sr_dbg("mso_send_data_proc length = %d", length);
sr_session_send(devc->cb_data, &analog_packet);
}