]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/beaglelogic/api.c
Simplify a few config_set() callbacks.
[libsigrok.git] / src / hardware / beaglelogic / api.c
index 098efa0627927cc3bb3453ff8d8a0b76d9207baa..74795caf42dee540e2be1d7606f3bbd1fa58861d 100644 (file)
@@ -21,7 +21,6 @@
 #include "beaglelogic.h"
 
 SR_PRIV struct sr_dev_driver beaglelogic_driver_info;
-static struct sr_dev_driver *di = &beaglelogic_driver_info;
 
 /* Scan options */
 static const uint32_t scanopts[] = {
@@ -49,7 +48,7 @@ static const int32_t soft_trigger_matches[] = {
 };
 
 /* Channels are numbered 0-13 */
-SR_PRIV const char *beaglelogic_channel_names[NUM_CHANNELS + 1] = {
+SR_PRIV const char *beaglelogic_channel_names[] = {
        "P8_45", "P8_46", "P8_43", "P8_44", "P8_41", "P8_42", "P8_39", "P8_40",
        "P8_27", "P8_29", "P8_28", "P8_30", "P8_21", "P8_20", NULL,
 };
@@ -61,7 +60,7 @@ static const uint64_t samplerates[] = {
        SR_HZ(1),
 };
 
-static int init(struct sr_context *sr_ctx)
+static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
 {
        return std_init(sr_ctx, di, LOG_PREFIX);
 }
@@ -79,14 +78,13 @@ static struct dev_context *beaglelogic_devc_alloc(void)
        return devc;
 }
 
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        struct drv_context *drvc;
        GSList *devices, *l;
        struct sr_config *src;
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
-       struct sr_channel *ch;
        int i, maxch;
 
        devices = NULL;
@@ -136,11 +134,9 @@ static GSList *scan(GSList *options)
        sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE);
 
        /* Fill the channels */
-       for (i = 0; i < maxch; i++) {
-               ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE,
+       for (i = 0; i < maxch; i++)
+               sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
                                beaglelogic_channel_names[i]);
-               sdi->channels = g_slist_append(sdi->channels, ch);
-       }
 
        sdi->priv = devc;
        drvc->instances = g_slist_append(drvc->instances, sdi);
@@ -149,12 +145,12 @@ static GSList *scan(GSList *options)
        return devices;
 }
 
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
 {
        return ((struct drv_context *)(di->priv))->instances;
 }
 
-static int dev_clear(void)
+static int dev_clear(const struct sr_dev_driver *di)
 {
        return std_dev_clear(di, NULL);
 }
@@ -203,7 +199,7 @@ static int dev_close(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
 {
        struct drv_context *drvc;
        struct sr_dev_inst *sdi;
@@ -223,8 +219,6 @@ static int cleanup(void)
        g_slist_free(drvc->instances);
        drvc->instances = NULL;
 
-       di->priv = NULL;
-
        return SR_OK;
 }
 
@@ -232,25 +226,22 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
                const struct sr_channel_group *cg)
 {
        struct dev_context *devc = sdi->priv;
+
        (void)cg;
 
        switch (key) {
        case SR_CONF_LIMIT_SAMPLES:
                *data = g_variant_new_uint64(devc->limit_samples);
                break;
-
        case SR_CONF_SAMPLERATE:
                *data = g_variant_new_uint64(devc->cur_samplerate);
                break;
-
        case SR_CONF_CAPTURE_RATIO:
                *data = g_variant_new_uint64(devc->capture_ratio);
                break;
-
        case SR_CONF_NUM_LOGIC_CHANNELS:
                *data = g_variant_new_uint32(g_slist_length(sdi->channels));
                break;
-
        default:
                return SR_ERR_NA;
        }
@@ -263,6 +254,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 {
        struct dev_context *devc = sdi->priv;
        uint64_t tmp_u64;
+
        (void)cg;
 
        if (sdi->status != SR_ST_ACTIVE)
@@ -272,7 +264,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        case SR_CONF_SAMPLERATE:
                devc->cur_samplerate = g_variant_get_uint64(data);
                return beaglelogic_set_samplerate(devc);
-
        case SR_CONF_LIMIT_SAMPLES:
                tmp_u64 = g_variant_get_uint64(data);
                devc->limit_samples = tmp_u64;
@@ -290,7 +281,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                                (SAMPLEUNIT_TO_BYTES(devc->sampleunit) * 1000000));
                }
                return beaglelogic_set_triggerflags(devc);
-
        case SR_CONF_CAPTURE_RATIO:
                devc->capture_ratio = g_variant_get_uint64(data);
                if (devc->capture_ratio > 100) {
@@ -298,7 +288,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                        return SR_ERR;
                }
                return SR_OK;
-
        default:
                return SR_ERR_NA;
        }
@@ -314,7 +303,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
 
        (void)sdi;
-       (void)data;
        (void)cg;
 
        ret = SR_OK;