]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/beaglelogic/api.c
drivers: Factor out std_gvar_samplerates{,_steps}().
[libsigrok.git] / src / hardware / beaglelogic / api.c
index 34b09f211fb26f2b54e464a7f973c2ce0a51ee3e..e904833da69d3095e4131b8e30bbdae697862692 100644 (file)
 #include "protocol.h"
 #include "beaglelogic.h"
 
-/* Scan options */
 static const uint32_t scanopts[] = {
        SR_CONF_NUM_LOGIC_CHANNELS,
 };
 
-/* Hardware capabilities */
-static const uint32_t devopts[] = {
+static const uint32_t drvopts[] = {
        SR_CONF_LOGIC_ANALYZER,
+};
+
+static const uint32_t devopts[] = {
        SR_CONF_CONTINUOUS,
        SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET,
@@ -37,7 +38,6 @@ static const uint32_t devopts[] = {
        SR_CONF_NUM_LOGIC_CHANNELS | SR_CONF_GET,
 };
 
-/* Trigger matching capabilities */
 static const int32_t soft_trigger_matches[] = {
        SR_TRIGGER_ZERO,
        SR_TRIGGER_ONE,
@@ -117,10 +117,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        beaglelogic_set_sampleunit(devc);
        beaglelogic_close(devc);
 
-       /* Signal */
        sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE);
 
-       /* Fill the channels */
        for (i = 0; i < maxch; i++)
                sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
                                channel_names[i]);
@@ -157,8 +155,6 @@ static int dev_open(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
-       /* We're good to go now */
-       sdi->status = SR_ST_ACTIVE;
        return SR_OK;
 }
 
@@ -166,12 +162,10 @@ static int dev_close(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc = sdi->priv;
 
-       if (sdi->status == SR_ST_ACTIVE) {
-               /* Close the memory mapping and the file */
-               beaglelogic_munmap(devc);
-               beaglelogic_close(devc);
-       }
-       sdi->status = SR_ST_INACTIVE;
+       /* Close the memory mapping and the file */
+       beaglelogic_munmap(devc);
+       beaglelogic_close(devc);
+
        return SR_OK;
 }
 
@@ -210,9 +204,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 
        (void)cg;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        switch (key) {
        case SR_CONF_SAMPLERATE:
                devc->cur_samplerate = g_variant_get_uint64(data);
@@ -249,29 +240,12 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       int ret;
-       GVariant *gvar;
-       GVariantBuilder gvb;
-
-       (void)sdi;
-       (void)cg;
-
-       ret = SR_OK;
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
-               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);
+               *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates));
                break;
        case SR_CONF_TRIGGER_MATCH:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
@@ -282,7 +256,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                return SR_ERR_NA;
        }
 
-       return ret;
+       return SR_OK;
 }
 
 /* get a sane timeout for poll() */
@@ -294,9 +268,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        struct dev_context *devc = sdi->priv;
        struct sr_trigger *trigger;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        /* Clear capture state */
        devc->bytes_read = 0;
        devc->offset = 0;
@@ -332,9 +303,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc = sdi->priv;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        /* Execute a stop on BeagleLogic */
        beaglelogic_stop(devc);
 
@@ -356,6 +324,7 @@ static struct sr_dev_driver beaglelogic_driver_info = {
        .cleanup = std_cleanup,
        .scan = scan,
        .dev_list = std_dev_list,
+       .dev_clear = std_dev_clear,
        .config_get = config_get,
        .config_set = config_set,
        .config_list = config_list,