]> sigrok.org Git - libsigrok.git/commitdiff
chronovu-la8: Adjust to GVariant-based sr_config_* functions
authorBert Vermeulen <redacted>
Sun, 31 Mar 2013 19:31:49 +0000 (21:31 +0200)
committerBert Vermeulen <redacted>
Thu, 11 Apr 2013 16:32:07 +0000 (18:32 +0200)
hardware/chronovu-la8/api.c
hardware/chronovu-la8/protocol.c
hardware/chronovu-la8/protocol.h

index 2dd12e3bf05411900c121ca760e7d25ccca35417..b0dccfeac918a7c46ea2104e824484fb4090766a 100644 (file)
 SR_PRIV struct sr_dev_driver chronovu_la8_driver_info;
 static struct sr_dev_driver *di = &chronovu_la8_driver_info;
 
+/* This will be initialized via config_list()/SR_CONF_SAMPLERATE.
+ *
+ * Min: 1 sample per 0.01us -> sample time is 0.084s, samplerate 100MHz
+ * Max: 1 sample per 2.55us -> sample time is 21.391s, samplerate 392.15kHz
+ */
+SR_PRIV uint64_t chronovu_la8_samplerates[255 + 1] = { 0 };
+
+/* Note: Continuous sampling is not supported by the hardware. */
+SR_PRIV const int32_t chronovu_la8_hwcaps[] = {
+       SR_CONF_LOGIC_ANALYZER,
+       SR_CONF_SAMPLERATE,
+       SR_CONF_LIMIT_MSEC, /* TODO: Not yet implemented. */
+       SR_CONF_LIMIT_SAMPLES, /* TODO: Not yet implemented. */
+};
+
 /*
  * The ChronoVu LA8 can have multiple PIDs. Older versions shipped with
  * a standard FTDI USB VID/PID of 0403:6001, newer ones have 0403:8867.
@@ -150,9 +165,9 @@ static GSList *hw_scan(GSList *options)
        sdi->driver = di;
        sdi->priv = devc;
 
-       for (i = 0; probe_names[i]; i++) {
+       for (i = 0; chronovu_la8_probe_names[i]; i++) {
                if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE,
-                                          probe_names[i])))
+                                          chronovu_la8_probe_names[i])))
                        return NULL;
                sdi->probes = g_slist_append(sdi->probes, probe);
        }
@@ -267,7 +282,7 @@ static int hw_cleanup(void)
        return SR_OK;
 }
 
-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;
 
@@ -275,7 +290,7 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
        case SR_CONF_SAMPLERATE:
                if (sdi) {
                        devc = sdi->priv;
-                       *data = &devc->cur_samplerate;
+                       *data = g_variant_new_uint64(devc->cur_samplerate);
                        sr_spew("%s: Returning samplerate: %" PRIu64 "Hz.",
                                __func__, devc->cur_samplerate);
                } else
@@ -288,7 +303,7 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
        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;
 
@@ -299,26 +314,26 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
 
        switch (id) {
        case SR_CONF_SAMPLERATE:
-               if (set_samplerate(sdi, *(const uint64_t *)value) == SR_ERR) {
+               if (set_samplerate(sdi, g_variant_get_uint64(data)) == SR_ERR) {
                        sr_err("%s: setting samplerate failed.", __func__);
                        return SR_ERR;
                }
                sr_dbg("SAMPLERATE = %" PRIu64, devc->cur_samplerate);
                break;
        case SR_CONF_LIMIT_MSEC:
-               if (*(const uint64_t *)value == 0) {
+               if (g_variant_get_uint64(data) == 0) {
                        sr_err("%s: LIMIT_MSEC can't be 0.", __func__);
                        return SR_ERR;
                }
-               devc->limit_msec = *(const uint64_t *)value;
+               devc->limit_msec = g_variant_get_uint64(data);
                sr_dbg("LIMIT_MSEC = %" PRIu64, devc->limit_msec);
                break;
        case SR_CONF_LIMIT_SAMPLES:
-               if (*(const uint64_t *)value < MIN_NUM_SAMPLES) {
+               if (g_variant_get_uint64(data) < MIN_NUM_SAMPLES) {
                        sr_err("%s: LIMIT_SAMPLES too small.", __func__);
                        return SR_ERR;
                }
-               devc->limit_samples = *(const uint64_t *)value;
+               devc->limit_samples = g_variant_get_uint64(data);
                sr_dbg("LIMIT_SAMPLES = %" PRIu64, devc->limit_samples);
                break;
        default:
@@ -331,21 +346,30 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-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_DEVICE_OPTIONS:
-               *data = hwcaps;
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+                               chronovu_la8_hwcaps, ARRAY_SIZE(chronovu_la8_hwcaps),
+                               sizeof(int32_t));
                break;
        case SR_CONF_SAMPLERATE:
                fill_supported_samplerates_if_needed();
-               *data = &samplerates;
+               g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
+               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
+                               chronovu_la8_samplerates, ARRAY_SIZE(chronovu_la8_samplerates),
+                               sizeof(uint64_t));
+               g_variant_builder_add(&gvb, "{sv}", "samplerates", 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;
index 5de7cf1761c5a1b7a1df0d58ff7e580c557bad38..d106b3361653720ecc26c491d8cdb0ca4059f81b 100644 (file)
 #include "protocol.h"
 
 /* Probes are numbered 0-7. */
-SR_PRIV const char *probe_names[NUM_PROBES + 1] = {
+SR_PRIV const char *chronovu_la8_probe_names[NUM_PROBES + 1] = {
        "0", "1", "2", "3", "4", "5", "6", "7",
        NULL,
 };
 
-/* This will be initialized via config_list()/SR_CONF_SAMPLERATE. */
-SR_PRIV uint64_t supported_samplerates[255 + 1] = { 0 };
-
-/*
- * Min: 1 sample per 0.01us -> sample time is 0.084s, samplerate 100MHz
- * Max: 1 sample per 2.55us -> sample time is 21.391s, samplerate 392.15kHz
- */
-const struct sr_samplerates samplerates = {
-       .low  = 0,
-       .high = 0,
-       .step = 0,
-       .list = supported_samplerates,
-};
-
-/* Note: Continuous sampling is not supported by the hardware. */
-SR_PRIV const int hwcaps[] = {
-       SR_CONF_LOGIC_ANALYZER,
-       SR_CONF_SAMPLERATE,
-       SR_CONF_LIMIT_MSEC, /* TODO: Not yet implemented. */
-       SR_CONF_LIMIT_SAMPLES, /* TODO: Not yet implemented. */
-       0,
-};
-
 SR_PRIV void fill_supported_samplerates_if_needed(void)
 {
        int i;
 
-       /* Do nothing if supported_samplerates[] is already filled. */
-       if (supported_samplerates[0] != 0)
+       if (chronovu_la8_samplerates[0] != 0)
                return;
 
-       /* Fill supported_samplerates[] with the proper values. */
        for (i = 0; i < 255; i++)
-               supported_samplerates[254 - i] = SR_MHZ(100) / (i + 1);
-       supported_samplerates[255] = 0;
+               chronovu_la8_samplerates[254 - i] = SR_MHZ(100) / (i + 1);
+       chronovu_la8_samplerates[255] = 0;
 }
 
 /**
@@ -80,7 +55,7 @@ SR_PRIV int is_valid_samplerate(uint64_t samplerate)
        fill_supported_samplerates_if_needed();
 
        for (i = 0; i < 255; i++) {
-               if (supported_samplerates[i] == samplerate)
+               if (chronovu_la8_samplerates[i] == samplerate)
                        return 1;
        }
 
index 8c78ef077bd94705b537b1b45bad22b6ac7643f7..771760ade609c8a7e2c2a556965c90401a3e1545 100644 (file)
@@ -111,10 +111,9 @@ struct dev_context {
 };
 
 /* protocol.c */
-extern SR_PRIV uint64_t supported_samplerates[];
-extern SR_PRIV const int hwcaps[];
-extern SR_PRIV const char *probe_names[];
-extern const struct sr_samplerates samplerates;
+extern const int32_t chronovu_la8_hwcaps[];
+extern uint64_t chronovu_la8_samplerates[];
+extern SR_PRIV const char *chronovu_la8_probe_names[];
 SR_PRIV void fill_supported_samplerates_if_needed(void);
 SR_PRIV int is_valid_samplerate(uint64_t samplerate);
 SR_PRIV uint8_t samplerate_to_divcount(uint64_t samplerate);