]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/ipdbg-la/api.c
ipdbg-la: Simplify config_get/_set/_list.
[libsigrok.git] / src / hardware / ipdbg-la / api.c
index ac7d8d84d83bb7fd2c57c7e4d0c5b776db236024..62d0616e35077fdc95a31aacedbca821d2c0235b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the libsigrok project.
  *
- * Copyright (C) 2016 danselmi <da@da>
+ * Copyright (C) 2016 Eva Kissling <eva.kissling@bluewin.ch>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <config.h>
 #include "protocol.h"
 
-static const uint32_t ipdbg_la_drvopts[] = {
+static const uint32_t drvopts[] = {
        SR_CONF_LOGIC_ANALYZER,
 };
 
-static const uint32_t ipdbg_la_scanopts[] = {
+static const uint32_t scanopts[] = {
        SR_CONF_CONN,
 };
 
-static const uint32_t ipdbg_la_devopts[] = {
-       SR_CONF_TRIGGER_MATCH | SR_CONF_LIST | SR_CONF_SET,
+static const uint32_t devopts[] = {
+       SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
        SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
-       SR_CONF_LIMIT_SAMPLES | SR_CONF_GET,
+       SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
 };
 
-static const int32_t ipdbg_la_trigger_matches[] = {
+static const int32_t trigger_matches[] = {
        SR_TRIGGER_ZERO,
        SR_TRIGGER_ONE,
        SR_TRIGGER_RISING,
@@ -108,7 +108,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        sdi->version = g_strdup("v1.0");
        sdi->driver = di;
 
-       struct ipdbg_la_dev_context *devc = ipdbg_la_dev_new();
+       struct dev_context *devc = ipdbg_la_dev_new();
        sdi->priv = devc;
 
        ipdbg_la_get_addrwidth_and_datawidth(tcp, devc);
@@ -190,12 +190,10 @@ static int dev_close(struct sr_dev_inst *sdi)
 static int config_get(uint32_t key, GVariant **data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
-       int ret = SR_OK;
+       struct dev_context *devc = sdi->priv;
 
        (void)cg;
 
-       struct ipdbg_la_dev_context *devc = sdi->priv;
-
        switch (key) {
        case SR_CONF_CAPTURE_RATIO:
                *data = g_variant_new_uint64(devc->capture_ratio);
@@ -204,80 +202,45 @@ static int config_get(uint32_t key, GVariant **data,
                *data = g_variant_new_uint64(devc->limit_samples);
                break;
        default:
-               ret = SR_ERR_NA;
+               return SR_ERR_NA;
        }
 
-       return ret;
+       return SR_OK;
 }
 
 static int config_set(uint32_t key, GVariant *data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
-       int ret = SR_OK;
-       uint64_t value;
+       struct dev_context *devc = sdi->priv;
 
        (void)cg;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
-       struct ipdbg_la_dev_context *devc = sdi->priv;
-
        switch (key) {
        case SR_CONF_CAPTURE_RATIO:
-               value = g_variant_get_uint64(data);
-               if (value <= 100)
-                       devc->capture_ratio = value;
-               else
-                       ret = SR_ERR;
+               devc->capture_ratio = g_variant_get_uint64(data);
                break;
        case SR_CONF_LIMIT_SAMPLES:
-               value = g_variant_get_uint64(data);
-               if (value <= devc->limit_samples_max)
-                       devc->limit_samples = value;
-               else
-                       ret = SR_ERR;
+               devc->limit_samples = g_variant_get_uint64(data);
                break;
        default:
-               ret = SR_ERR_NA;
+               return SR_ERR_NA;
        }
 
-       return ret;
+       return SR_OK;
 }
 
 static int config_list(uint32_t key, GVariant **data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
-       (void)cg;
-
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       ipdbg_la_scanopts,
-                       ARRAY_SIZE
-                       (ipdbg_la_scanopts),
-                       sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi)
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               ipdbg_la_drvopts,
-                               ARRAY_SIZE
-                               (ipdbg_la_drvopts),
-                               sizeof(uint32_t));
-               else
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               ipdbg_la_devopts,
-                               ARRAY_SIZE
-                               (ipdbg_la_devopts),
-                               sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_TRIGGER_MATCH:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
-                       ipdbg_la_trigger_matches,
-                       ARRAY_SIZE
-                       (ipdbg_la_trigger_matches),
-                       sizeof(int32_t));
+               *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
                break;
        default:
                return SR_ERR_NA;
@@ -302,7 +265,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                return SR_ERR_DEV_CLOSED;
 
        struct ipdbg_la_tcp *tcp = sdi->conn;
-       struct ipdbg_la_dev_context *devc = sdi->priv;
+       struct dev_context *devc = sdi->priv;
 
        ipdbg_la_convert_trigger(sdi);
        ipdbg_la_send_trigger(devc, tcp);
@@ -322,7 +285,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
        struct ipdbg_la_tcp *tcp = sdi->conn;
-       struct ipdbg_la_dev_context *devc = sdi->priv;
+       struct dev_context *devc = sdi->priv;
 
        uint8_t byte;