#include <unistd.h>
#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include <glib.h>
#include "libsigrok.h"
#include "libsigrok-internal.h"
static const int32_t hwcaps[] = {
SR_CONF_OSCILLOSCOPE,
- SR_CONF_LIMIT_SAMPLES,
SR_CONF_TIMEBASE,
SR_CONF_TRIGGER_SOURCE,
SR_CONF_TRIGGER_SLOPE,
"CH2",
"EXT",
"AC Line",
+ "D0",
+ "D1",
+ "D2",
+ "D3",
+ "D4",
+ "D5",
+ "D6",
+ "D7",
+ "D8",
+ "D9",
+ "D10",
+ "D11",
+ "D12",
+ "D13",
+ "D14",
+ "D15",
};
static const char *coupling[] = {
static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
{
struct dev_context *devc;
- struct timespec delay;
va_list args;
char buf[256];
/* When setting a bunch of parameters in a row, the DS1052E scrambles
* some of them unless there is at least 100ms delay in between. */
- delay.tv_sec = 0;
- delay.tv_nsec = 100000000L;
- sr_spew("delay %dms", delay.tv_nsec / 1000000);
- nanosleep(&delay, NULL);
+ sr_spew("delay %dms", 100);
+ g_usleep(100000);
return SR_OK;
}
gchar **tokens;
const char *manufacturer, *model, *version;
gboolean matched = FALSE;
+ gboolean has_digital = FALSE;
char buf[256];
+ gchar *channel_name;
(void)options;
close(fd);
if (len == 0) {
g_free(device);
- return NULL;
+ continue;
}
buf[len] = 0;
if (num_tokens < 4) {
g_strfreev(tokens);
g_free(device);
- return NULL;
+ continue;
}
manufacturer = tokens[0];
if (strcmp(manufacturer, "Rigol Technologies")) {
g_strfreev(tokens);
g_free(device);
- return NULL;
+ continue;
}
for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
if (!strcmp(model, supported_models[i])) {
matched = 1;
+ has_digital = g_str_has_suffix(model, "D");
break;
}
}
manufacturer, model, version))) {
g_strfreev(tokens);
g_free(device);
- return NULL;
+ continue;
}
g_strfreev(tokens);
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
g_free(device);
- return NULL;
+ goto hw_scan_abort;
}
+
devc->limit_frames = 0;
devc->device = device;
+ devc->has_digital = has_digital;
sdi->priv = devc;
sdi->driver = di;
+ drvc->instances = g_slist_append(drvc->instances, sdi);
+ devices = g_slist_append(devices, sdi);
for (i = 0; i < 2; i++) {
- if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE,
- i == 0 ? "CH1" : "CH2")))
- return NULL;
+ if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE,
+ i == 0 ? "CH1" : "CH2")))
+ goto hw_scan_abort;
sdi->probes = g_slist_append(sdi->probes, probe);
}
- drvc->instances = g_slist_append(drvc->instances, sdi);
- devices = g_slist_append(devices, sdi);
+ if (devc->has_digital) {
+ for (i = 0; i < 16; i++) {
+ if (!(channel_name = g_strdup_printf("D%d", i)))
+ goto hw_scan_abort;
+ probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, channel_name);
+ g_free(channel_name);
+ if (!probe)
+ goto hw_scan_abort;
+ sdi->probes = g_slist_append(sdi->probes, probe);
+ }
+ }
}
g_dir_close(dir);
return devices;
+
+hw_scan_abort:
+ g_dir_close(dir);
+ g_slist_free(devices);
+ clear_instances();
+ return NULL;
}
static GSList *hw_dev_list(void)
*data = g_variant_new_int32(NUM_VDIV);
break;
default:
- return SR_ERR_ARG;
+ return SR_ERR_NA;
}
return SR_OK;
ret = SR_ERR_ARG;
break;
default:
- sr_err("Unknown hardware capability: %d.", id);
- ret = SR_ERR_ARG;
+ ret = SR_ERR_NA;
break;
}
GVariant *tuple, *rational[2];
GVariantBuilder gvb;
unsigned int i;
-
- (void)sdi;
+ struct dev_context *devc;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_builder_end(&gvb);
break;
case SR_CONF_TRIGGER_SOURCE:
+ if (!sdi || !sdi->priv)
+ /* Can't know this until we have the exact model. */
+ return SR_ERR_ARG;
+ devc = sdi->priv;
*data = g_variant_new_strv(trigger_sources,
- ARRAY_SIZE(trigger_sources));
+ devc->has_digital ? ARRAY_SIZE(trigger_sources) : 4);
break;
default:
- return SR_ERR_ARG;
+ return SR_ERR_NA;
}
return SR_OK;
struct dev_context *devc;
struct sr_probe *probe;
GSList *l;
- int probenum;
char cmd[256];
(void)cb_data;
for (l = sdi->probes; l; l = l->next) {
probe = l->data;
- probenum = probe->name[2] == '1' ? 0 : 1;
- if (probe->enabled)
- devc->enabled_probes = g_slist_append(devc->enabled_probes, probe);
-
- if (probe->enabled != devc->channels[probenum]) {
- /* Enabled channel is currently disabled, or vice versa. */
- sprintf(cmd, ":CHAN%d:DISP %s", probenum + 1,
- probe->enabled ? "ON" : "OFF");
- if (rigol_ds1xx2_send(devc, cmd) != SR_OK)
- return SR_ERR;
+ sr_dbg("handling probe %s", probe->name);
+ if (probe->type == SR_PROBE_ANALOG) {
+ if (probe->enabled)
+ devc->enabled_analog_probes = g_slist_append(
+ devc->enabled_analog_probes, probe);
+ if (probe->enabled != devc->analog_channels[probe->index]) {
+ /* Enabled channel is currently disabled, or vice versa. */
+ sprintf(cmd, ":CHAN%d:DISP %s", probe->index + 1,
+ probe->enabled ? "ON" : "OFF");
+ if (rigol_ds1xx2_send(devc, cmd) != SR_OK)
+ return SR_ERR;
+ }
+ } else if (probe->type == SR_PROBE_LOGIC) {
+ if (probe->enabled)
+ devc->enabled_digital_probes = g_slist_append(
+ devc->enabled_digital_probes, probe);
+ if (probe->enabled != devc->digital_channels[probe->index]) {
+ /* Enabled channel is currently disabled, or vice versa. */
+ sprintf(cmd, ":DIG%d:TURN %s", probe->index,
+ probe->enabled ? "ON" : "OFF");
+ if (rigol_ds1xx2_send(devc, cmd) != SR_OK)
+ return SR_ERR;
+ }
}
}
- if (!devc->enabled_probes)
+ if (!devc->enabled_analog_probes && !devc->enabled_digital_probes)
return SR_ERR;
sr_source_add(devc->fd, G_IO_IN, 50, rigol_ds1xx2_receive, (void *)sdi);
std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
/* Fetch the first frame. */
- devc->channel_frame = devc->enabled_probes->data;
- if (rigol_ds1xx2_send(devc, ":WAV:DATA? CHAN%c",
- devc->channel_frame->name[2]) != SR_OK)
- return SR_ERR;
+ if (devc->enabled_analog_probes) {
+ devc->channel_frame = devc->enabled_analog_probes->data;
+ if (rigol_ds1xx2_send(devc, ":WAV:DATA? CHAN%d",
+ devc->channel_frame->index + 1) != SR_OK)
+ return SR_ERR;
+ } else {
+ devc->channel_frame = devc->enabled_digital_probes->data;
+ if (rigol_ds1xx2_send(devc, ":WAV:DATA? DIG") != SR_OK)
+ return SR_ERR;
+ }
+
+ devc->num_frame_bytes = 0;
return SR_OK;
}
return SR_ERR;
}
- g_slist_free(devc->enabled_probes);
- devc->enabled_probes = NULL;
+ g_slist_free(devc->enabled_analog_probes);
+ g_slist_free(devc->enabled_digital_probes);
+ devc->enabled_analog_probes = NULL;
+ devc->enabled_digital_probes = NULL;
sr_source_remove(devc->fd);
return SR_OK;