SR_CONF_TRIGGER_SOURCE,
SR_CONF_TRIGGER_SLOPE,
SR_CONF_HORIZ_TRIGGERPOS,
- SR_CONF_VDIV,
- SR_CONF_COUPLING,
SR_CONF_NUM_TIMEBASE,
+};
+
+static const int32_t analog_hwcaps[] = {
SR_CONF_NUM_VDIV,
+ SR_CONF_VDIV,
+ SR_CONF_COUPLING,
};
static const uint64_t timebases[][2] = {
static const char *supported_models[] = {
"DS1052E",
"DS1102E",
+ "DS1152E",
"DS1052D",
"DS1102D",
+ "DS1152D",
};
SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info;
static struct sr_dev_driver *di = &rigol_ds1xx2_driver_info;
-/* Properly close and free all devices. */
-static int clear_instances(void)
+static void clear_helper(void *priv)
{
- struct sr_dev_inst *sdi;
- struct drv_context *drvc;
struct dev_context *devc;
- GSList *l;
- if (!(drvc = di->priv))
- return SR_OK;
-
- for (l = drvc->instances; l; l = l->next) {
- if (!(sdi = l->data))
- continue;
-
- if (sdi->conn)
- sr_serial_dev_inst_free(sdi->conn);
-
- if ((devc = sdi->priv)) {
- g_free(devc->coupling[0]);
- g_free(devc->coupling[1]);
- g_free(devc->trigger_source);
- g_free(devc->trigger_slope);
- }
- sr_dev_inst_free(sdi);
- }
-
- g_slist_free(drvc->instances);
- drvc->instances = NULL;
+ devc = priv;
+ g_free(devc->coupling[0]);
+ g_free(devc->coupling[1]);
+ g_free(devc->trigger_source);
+ g_free(devc->trigger_slope);
+ g_slist_free(devc->analog_groups[0].probes);
+ g_slist_free(devc->analog_groups[1].probes);
+ g_slist_free(devc->digital_group.probes);
+}
- return SR_OK;
+static int dev_clear(void)
+{
+ return std_dev_clear(di, clear_helper);
}
static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
static int init(struct sr_context *sr_ctx)
{
- return std_hw_init(sr_ctx, di, LOG_PREFIX);
+ return std_init(sr_ctx, di, LOG_PREFIX);
}
static int probe_port(const char *port, GSList **devices)
if (!(sdi->conn = sr_serial_dev_inst_new(port, NULL)))
return SR_ERR_MALLOC;
sdi->driver = di;
+ sdi->inst_type = SR_INST_SERIAL;
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
return SR_ERR_MALLOC;
devc->has_digital = has_digital;
for (i = 0; i < 2; i++) {
- if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE,
- i == 0 ? "CH1" : "CH2")))
+ channel_name = (i == 0 ? "CH1" : "CH2");
+ if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, channel_name)))
return SR_ERR_MALLOC;
sdi->probes = g_slist_append(sdi->probes, probe);
+ devc->analog_groups[i].name = channel_name;
+ devc->analog_groups[i].probes = g_slist_append(NULL, probe);
+ sdi->probe_groups = g_slist_append(sdi->probe_groups,
+ &devc->analog_groups[i]);
}
if (devc->has_digital) {
if (!probe)
return SR_ERR_MALLOC;
sdi->probes = g_slist_append(sdi->probes, probe);
+ devc->digital_group.probes = g_slist_append(
+ devc->digital_group.probes, probe);
+ devc->digital_group.name = "LA";
+ sdi->probe_groups = g_slist_append(sdi->probe_groups,
+ &devc->digital_group);
}
}
sdi->priv = devc;
if (probe_port(port, &devices) == SR_ERR_MALLOC)
return NULL;
} else {
- if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL)))
- return NULL;
+ if (!(dir = g_dir_open("/sys/class/usbmisc/", 0, NULL)))
+ if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL)))
+ return NULL;
while ((dev_name = g_dir_read_name(dir))) {
if (strncmp(dev_name, "usbtmc", 6))
continue;
static int cleanup(void)
{
- clear_instances();
-
- return SR_OK;
+ return dev_clear();
}
-static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
+static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
+ const struct sr_probe_group *probe_group)
{
+ struct dev_context *devc;
+ unsigned int i;
- (void)sdi;
+ if (!sdi || !(devc = sdi->priv))
+ return SR_ERR_ARG;
+
+ /* If a probe group is specified, it must be a valid one. */
+ if (probe_group) {
+ if (probe_group != &devc->analog_groups[0]
+ && probe_group != &devc->analog_groups[1]) {
+ sr_err("Invalid probe group specified.");
+ return SR_ERR;
+ }
+ }
switch (id) {
case SR_CONF_NUM_TIMEBASE:
*data = g_variant_new_int32(NUM_TIMEBASE);
break;
case SR_CONF_NUM_VDIV:
- *data = g_variant_new_int32(NUM_VDIV);
- break;
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
+ }
+ for (i = 0; i < 2; i++) {
+ if (probe_group == &devc->analog_groups[i]) {
+ *data = g_variant_new_int32(NUM_VDIV);
+ return SR_OK;
+ }
+ }
+ return SR_ERR_NA;
default:
return SR_ERR_NA;
}
return SR_OK;
}
-static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
+static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
+ const struct sr_probe_group *probe_group)
{
struct dev_context *devc;
uint64_t tmp_u64, p, q;
double t_dbl;
- unsigned int i;
+ unsigned int i, j;
int ret;
const char *tmp_str;
- devc = sdi->priv;
+ if (!(devc = sdi->priv))
+ return SR_ERR_ARG;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
+ /* If a probe group is specified, it must be a valid one. */
+ if (probe_group) {
+ if (probe_group != &devc->analog_groups[0]
+ && probe_group != &devc->analog_groups[1]) {
+ sr_err("Invalid probe group specified.");
+ return SR_ERR;
+ }
+ }
+
ret = SR_OK;
switch (id) {
case SR_CONF_LIMIT_FRAMES:
ret = SR_ERR_ARG;
break;
case SR_CONF_VDIV:
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
+ }
g_variant_get(data, "(tt)", &p, &q);
- for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
- if (vdivs[i][0] != p || vdivs[i][1] != q)
- continue;
- devc->vdiv[0] = devc->vdiv[1] = (float)p / q;
- set_cfg(sdi, ":CHAN1:SCAL %.3f", devc->vdiv[0]);
- ret = set_cfg(sdi, ":CHAN2:SCAL %.3f", devc->vdiv[1]);
- break;
+ for (i = 0; i < 2; i++) {
+ if (probe_group == &devc->analog_groups[i]) {
+ for (j = 0; j < ARRAY_SIZE(vdivs); j++) {
+ if (vdivs[j][0] != p || vdivs[j][1] != q)
+ continue;
+ devc->vdiv[i] = (float)p / q;
+ return set_cfg(sdi, ":CHAN%d:SCAL %.3f", i + 1,
+ devc->vdiv[i]);
+ }
+ return SR_ERR_ARG;
+ }
}
- if (i == ARRAY_SIZE(vdivs))
- ret = SR_ERR_ARG;
- break;
+ return SR_ERR_NA;
case SR_CONF_COUPLING:
- /* TODO: Not supporting coupling per channel yet. */
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
+ }
tmp_str = g_variant_get_string(data, NULL);
- for (i = 0; i < ARRAY_SIZE(coupling); i++) {
- if (!strcmp(tmp_str, coupling[i])) {
- g_free(devc->coupling[0]);
- g_free(devc->coupling[1]);
- devc->coupling[0] = g_strdup(coupling[i]);
- devc->coupling[1] = g_strdup(coupling[i]);
- set_cfg(sdi, ":CHAN1:COUP %s", devc->coupling[0]);
- ret = set_cfg(sdi, ":CHAN2:COUP %s", devc->coupling[1]);
- break;
+ for (i = 0; i < 2; i++) {
+ if (probe_group == &devc->analog_groups[i]) {
+ for (j = 0; j < ARRAY_SIZE(coupling); j++) {
+ if (!strcmp(tmp_str, coupling[j])) {
+ g_free(devc->coupling[i]);
+ devc->coupling[i] = g_strdup(coupling[j]);
+ return set_cfg(sdi, ":CHAN%d:COUP %s", i + 1,
+ devc->coupling[i]);
+ }
+ }
+ return SR_ERR_ARG;
}
}
- if (i == ARRAY_SIZE(coupling))
- ret = SR_ERR_ARG;
- break;
+ return SR_ERR_NA;
default:
ret = SR_ERR_NA;
break;
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_probe_group *probe_group)
{
GVariant *tuple, *rational[2];
GVariantBuilder gvb;
unsigned int i;
struct dev_context *devc;
- switch (key) {
- case SR_CONF_SCAN_OPTIONS:
+ if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
+ return SR_OK;
+ } else if (key == SR_CONF_DEVICE_OPTIONS && probe_group == NULL) {
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+ hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
+ return SR_OK;
+ }
+
+ /* Every other option requires a valid device instance. */
+ if (!sdi || !(devc = sdi->priv))
+ return SR_ERR_ARG;
+
+ /* If a probe group is specified, it must be a valid one. */
+ if (probe_group) {
+ if (probe_group != &devc->analog_groups[0]
+ && probe_group != &devc->analog_groups[1]) {
+ sr_err("Invalid probe group specified.");
+ return SR_ERR;
+ }
+ }
+
+ switch (key) {
break;
case SR_CONF_DEVICE_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
- hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
+ }
+ if (probe_group == &devc->digital_group) {
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+ NULL, 0, sizeof(int32_t));
+ return SR_OK;
+ } else {
+ for (i = 0; i < 2; i++) {
+ if (probe_group == &devc->analog_groups[i]) {
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+ analog_hwcaps, ARRAY_SIZE(analog_hwcaps), sizeof(int32_t));
+ return SR_OK;
+ }
+ }
+ return SR_ERR_NA;
+ }
break;
case SR_CONF_COUPLING:
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
+ }
*data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
break;
case SR_CONF_VDIV:
+ if (!probe_group) {
+ sr_err("No probe group specified.");
+ return SR_ERR_PROBE_GROUP;
+ }
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
rational[0] = g_variant_new_uint64(vdivs[i][0]);
*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,
devc->has_digital ? ARRAY_SIZE(trigger_sources) : 4);
break;
.cleanup = cleanup,
.scan = scan,
.dev_list = dev_list,
- .dev_clear = clear_instances,
+ .dev_clear = dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,