ols: Adjust to GVariant-based sr_config_* functions

This commit is contained in:
Bert Vermeulen 2013-03-25 20:40:15 +01:00
parent d6836bf129
commit e46aa4f611
3 changed files with 39 additions and 37 deletions

View File

@ -21,19 +21,17 @@
#define SERIALCOMM "115200/8n1" #define SERIALCOMM "115200/8n1"
static const int hwopts[] = { static const int32_t hwopts[] = {
SR_CONF_CONN, SR_CONF_CONN,
SR_CONF_SERIALCOMM, SR_CONF_SERIALCOMM,
0,
}; };
static const int hwcaps[] = { static const int32_t hwcaps[] = {
SR_CONF_LOGIC_ANALYZER, SR_CONF_LOGIC_ANALYZER,
SR_CONF_SAMPLERATE, SR_CONF_SAMPLERATE,
SR_CONF_CAPTURE_RATIO, SR_CONF_CAPTURE_RATIO,
SR_CONF_LIMIT_SAMPLES, SR_CONF_LIMIT_SAMPLES,
SR_CONF_RLE, SR_CONF_RLE,
0,
}; };
/* Probes are numbered 0-31 (on the PCB silkscreen). */ /* Probes are numbered 0-31 (on the PCB silkscreen). */
@ -45,11 +43,10 @@ SR_PRIV const char *ols_probe_names[NUM_PROBES + 1] = {
}; };
/* Default supported samplerates, can be overridden by device metadata. */ /* Default supported samplerates, can be overridden by device metadata. */
static const struct sr_samplerates samplerates = { static const uint64_t samplerates[] = {
.low = SR_HZ(10), SR_HZ(10),
.high = SR_MHZ(200), SR_MHZ(200),
.step = SR_HZ(1), SR_HZ(1),
.list = NULL,
}; };
SR_PRIV struct sr_dev_driver ols_driver_info; SR_PRIV struct sr_dev_driver ols_driver_info;
@ -85,10 +82,10 @@ static GSList *hw_scan(GSList *options)
src = l->data; src = l->data;
switch (src->key) { switch (src->key) {
case SR_CONF_CONN: case SR_CONF_CONN:
conn = src->value; conn = g_variant_get_string(src->data, NULL);
break; break;
case SR_CONF_SERIALCOMM: case SR_CONF_SERIALCOMM:
serialcomm = src->value; serialcomm = g_variant_get_string(src->data, NULL);
break; break;
} }
} }
@ -239,7 +236,7 @@ static int hw_cleanup(void)
return ret; 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; struct dev_context *devc;
@ -247,7 +244,7 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
case SR_CONF_SAMPLERATE: case SR_CONF_SAMPLERATE:
if (sdi) { if (sdi) {
devc = sdi->priv; devc = sdi->priv;
*data = &devc->cur_samplerate; *data = g_variant_new_uint64(devc->cur_samplerate);
} else } else
return SR_ERR; return SR_ERR;
break; break;
@ -258,11 +255,11 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
return SR_OK; 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; struct dev_context *devc;
int ret; int ret;
const uint64_t *tmp_u64; uint64_t tmp_u64;
devc = sdi->priv; devc = sdi->priv;
@ -271,21 +268,23 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
switch (id) { switch (id) {
case SR_CONF_SAMPLERATE: case SR_CONF_SAMPLERATE:
ret = ols_set_samplerate(sdi, *(const uint64_t *)value, tmp_u64 = g_variant_get_uint64(data);
&samplerates); if (tmp_u64 < samplerates[0] || tmp_u64 > samplerates[1])
return SR_ERR_SAMPLERATE;
ret = ols_set_samplerate(sdi, g_variant_get_uint64(data));
break; break;
case SR_CONF_LIMIT_SAMPLES: case SR_CONF_LIMIT_SAMPLES:
tmp_u64 = value; tmp_u64 = g_variant_get_uint64(data);
if (*tmp_u64 < MIN_NUM_SAMPLES) if (tmp_u64 < MIN_NUM_SAMPLES)
return SR_ERR; return SR_ERR;
if (*tmp_u64 > devc->max_samples) if (tmp_u64 > devc->max_samples)
sr_err("Sample limit exceeds hardware maximum."); 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); sr_info("Sample limit is %" PRIu64 ".", devc->limit_samples);
ret = SR_OK; ret = SR_OK;
break; break;
case SR_CONF_CAPTURE_RATIO: 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) { if (devc->capture_ratio < 0 || devc->capture_ratio > 100) {
devc->capture_ratio = 0; devc->capture_ratio = 0;
ret = SR_ERR; ret = SR_ERR;
@ -293,7 +292,7 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
ret = SR_OK; ret = SR_OK;
break; break;
case SR_CONF_RLE: case SR_CONF_RLE:
if (*(int *)value) { if (g_variant_get_boolean(data)) {
sr_info("Enabling RLE."); sr_info("Enabling RLE.");
devc->flag_reg |= FLAG_RLE; devc->flag_reg |= FLAG_RLE;
} }
@ -306,23 +305,31 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
return ret; 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; (void)sdi;
switch (key) { switch (key) {
case SR_CONF_SCAN_OPTIONS: 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; break;
case SR_CONF_DEVICE_OPTIONS: 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; break;
case SR_CONF_SAMPLERATE: 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; break;
case SR_CONF_TRIGGER_TYPE: case SR_CONF_TRIGGER_TYPE:
*data = (char *)TRIGGER_TYPE; *data = g_variant_new_string(TRIGGER_TYPE);
break; break;
default: default:
return SR_ERR_ARG; return SR_ERR_ARG;

View File

@ -284,16 +284,12 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
} }
SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi, SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi,
uint64_t samplerate, const uint64_t samplerate)
const struct sr_samplerates *samplerates)
{ {
struct dev_context *devc; struct dev_context *devc;
devc = sdi->priv; devc = sdi->priv;
if (devc->max_samplerate) { if (devc->max_samplerate && samplerate > devc->max_samplerate)
if (samplerate > devc->max_samplerate)
return SR_ERR_SAMPLERATE;
} else if (samplerate < samplerates->low || samplerate > samplerates->high)
return SR_ERR_SAMPLERATE; return SR_ERR_SAMPLERATE;
if (samplerate > CLOCK_RATE) { if (samplerate > CLOCK_RATE) {
@ -311,7 +307,7 @@ SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi,
if (devc->flag_reg & FLAG_DEMUX) if (devc->flag_reg & FLAG_DEMUX)
devc->cur_samplerate *= 2; devc->cur_samplerate *= 2;
if (devc->cur_samplerate != samplerate) 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); PRIu64 ".", samplerate, devc->cur_samplerate);
return SR_OK; return SR_OK;

View File

@ -119,8 +119,7 @@ SR_PRIV uint32_t reverse32(uint32_t in);
SR_PRIV struct dev_context *ols_dev_new(void); SR_PRIV struct dev_context *ols_dev_new(void);
SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial); SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial);
SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi, SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi,
uint64_t samplerate, uint64_t samplerate);
const struct sr_samplerates *samplerates);
SR_PRIV void abort_acquisition(const struct sr_dev_inst *sdi); SR_PRIV void abort_acquisition(const struct sr_dev_inst *sdi);
SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data); SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data);