#define SERIALCOMM "115200/8n1"
-static const int hwopts[] = {
+static const int32_t hwopts[] = {
SR_CONF_CONN,
SR_CONF_SERIALCOMM,
- 0,
};
-static const int hwcaps[] = {
+static const int32_t hwcaps[] = {
SR_CONF_LOGIC_ANALYZER,
SR_CONF_SAMPLERATE,
SR_CONF_CAPTURE_RATIO,
SR_CONF_LIMIT_SAMPLES,
SR_CONF_RLE,
- 0,
};
/* Probes are numbered 0-31 (on the PCB silkscreen). */
};
/* Default supported samplerates, can be overridden by device metadata. */
-static const struct sr_samplerates samplerates = {
- .low = SR_HZ(10),
- .high = SR_MHZ(200),
- .step = SR_HZ(1),
- .list = NULL,
+static const uint64_t samplerates[] = {
+ SR_HZ(10),
+ SR_MHZ(200),
+ SR_HZ(1),
};
SR_PRIV struct sr_dev_driver ols_driver_info;
src = l->data;
switch (src->key) {
case SR_CONF_CONN:
- conn = src->value;
+ conn = g_variant_get_string(src->data, NULL);
break;
case SR_CONF_SERIALCOMM:
- serialcomm = src->value;
+ serialcomm = g_variant_get_string(src->data, NULL);
break;
}
}
return ret;
}
-static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
+static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
case SR_CONF_SAMPLERATE:
if (sdi) {
devc = sdi->priv;
- *data = &devc->cur_samplerate;
+ *data = g_variant_new_uint64(devc->cur_samplerate);
} else
return SR_ERR;
break;
return SR_OK;
}
-static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
+static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
int ret;
- const uint64_t *tmp_u64;
+ uint64_t tmp_u64;
devc = sdi->priv;
switch (id) {
case SR_CONF_SAMPLERATE:
- ret = ols_set_samplerate(sdi, *(const uint64_t *)value,
- &samplerates);
+ tmp_u64 = g_variant_get_uint64(data);
+ if (tmp_u64 < samplerates[0] || tmp_u64 > samplerates[1])
+ return SR_ERR_SAMPLERATE;
+ ret = ols_set_samplerate(sdi, g_variant_get_uint64(data));
break;
case SR_CONF_LIMIT_SAMPLES:
- tmp_u64 = value;
- if (*tmp_u64 < MIN_NUM_SAMPLES)
+ tmp_u64 = g_variant_get_uint64(data);
+ if (tmp_u64 < MIN_NUM_SAMPLES)
return SR_ERR;
- if (*tmp_u64 > devc->max_samples)
+ if (tmp_u64 > devc->max_samples)
sr_err("Sample limit exceeds hardware maximum.");
- devc->limit_samples = *tmp_u64;
+ devc->limit_samples = tmp_u64;
sr_info("Sample limit is %" PRIu64 ".", devc->limit_samples);
ret = SR_OK;
break;
case SR_CONF_CAPTURE_RATIO:
- devc->capture_ratio = *(const uint64_t *)value;
+ devc->capture_ratio = g_variant_get_uint64(data);
if (devc->capture_ratio < 0 || devc->capture_ratio > 100) {
devc->capture_ratio = 0;
ret = SR_ERR;
ret = SR_OK;
break;
case SR_CONF_RLE:
- if (*(int *)value) {
+ if (g_variant_get_boolean(data)) {
sr_info("Enabling RLE.");
devc->flag_reg |= FLAG_RLE;
}
return ret;
}
-static int config_list(int key, const void **data, const struct sr_dev_inst *sdi)
+static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
{
+ GVariant *gvar;
+ GVariantBuilder gvb;
(void)sdi;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
- *data = hwopts;
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+ hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
- *data = hwcaps;
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+ hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
break;
case SR_CONF_SAMPLERATE:
- *data = &samplerates;
+ g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
+ gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
+ ARRAY_SIZE(samplerates), sizeof(uint64_t));
+ g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
+ *data = g_variant_builder_end(&gvb);
break;
case SR_CONF_TRIGGER_TYPE:
- *data = (char *)TRIGGER_TYPE;
+ *data = g_variant_new_string(TRIGGER_TYPE);
break;
default:
return SR_ERR_ARG;
}
SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi,
- uint64_t samplerate,
- const struct sr_samplerates *samplerates)
+ const uint64_t samplerate)
{
struct dev_context *devc;
devc = sdi->priv;
- if (devc->max_samplerate) {
- if (samplerate > devc->max_samplerate)
- return SR_ERR_SAMPLERATE;
- } else if (samplerate < samplerates->low || samplerate > samplerates->high)
+ if (devc->max_samplerate && samplerate > devc->max_samplerate)
return SR_ERR_SAMPLERATE;
if (samplerate > CLOCK_RATE) {
if (devc->flag_reg & FLAG_DEMUX)
devc->cur_samplerate *= 2;
if (devc->cur_samplerate != samplerate)
- sr_err("Can't match samplerate %" PRIu64 ", using %"
+ sr_info("Can't match samplerate %" PRIu64 ", using %"
PRIu64 ".", samplerate, devc->cur_samplerate);
return SR_OK;