]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/korad-kaxxxxp/api.c
drivers: Provide proper drvopts.
[libsigrok.git] / src / hardware / korad-kaxxxxp / api.c
index bd80b6e1b5e22e0db693f6222b9105586de625bc..04a26834114efbfe865216b5fa362042651f2b67 100644 (file)
 #include <config.h>
 #include "protocol.h"
 
-static const uint32_t drvopts[] = {
-       /* Device class */
-       SR_CONF_POWER_SUPPLY,
-};
-
 static const uint32_t scanopts[] = {
        SR_CONF_CONN,
        SR_CONF_SERIALCOMM,
 };
 
-static const uint32_t devopts[] = {
+static const uint32_t drvopts[] = {
        /* Device class */
        SR_CONF_POWER_SUPPLY,
+};
+
+static const uint32_t devopts[] = {
+       /* Device class */
        /* Acquisition modes. */
        SR_CONF_CONTINUOUS,
        SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
@@ -64,9 +63,8 @@ static const struct korad_kaxxxxp_model models[] = {
 
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
-       struct drv_context *drvc;
        struct dev_context *devc;
-       GSList *devices, *l;
+       GSList *l;
        struct sr_dev_inst *sdi;
        struct sr_config *src;
        const char *conn, *serialcomm;
@@ -75,10 +73,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        int i, model_id;
        unsigned int len;
 
-       devices = NULL;
        conn = NULL;
        serialcomm = NULL;
-       drvc = di->context;
 
        for (l = options; l; l = l->next) {
                src = l->data;
@@ -140,7 +136,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        sdi->model = g_strdup(models[model_id].name);
        sdi->inst_type = SR_INST_SERIAL;
        sdi->conn = serial;
-       sdi->driver = di;
 
        sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
 
@@ -154,14 +149,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        /* Get current status of device. */
        if (korad_kaxxxxp_get_all_values(serial, devc) < 0)
                goto exit_err;
-       drvc->instances = g_slist_append(drvc->instances, sdi);
-       devices = g_slist_append(devices, sdi);
 
        serial_close(serial);
-       if (!devices)
-               sr_serial_dev_inst_free(serial);
 
-       return devices;
+       return std_scan_complete(di, g_slist_append(NULL, sdi));
 
 exit_err:
        sr_dev_inst_free(sdi);
@@ -184,6 +175,8 @@ static int config_get(uint32_t key, GVariant **data,
        devc = sdi->priv;
 
        switch (key) {
+       case SR_CONF_LIMIT_SAMPLES:
+       case SR_CONF_LIMIT_MSEC:
                return sr_sw_limits_config_get(&devc->limits, key, data);
        case SR_CONF_VOLTAGE:
                *data = g_variant_new_double(devc->voltage);
@@ -226,9 +219,6 @@ static int config_set(uint32_t key, GVariant *data,
 
        (void)cg;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        switch (key) {
@@ -291,33 +281,12 @@ static int config_list(uint32_t key, GVariant **data,
        double dval;
        int idx;
 
-       (void)cg;
-
-       /* Always available (with or without sdi). */
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       /* Return drvopts without sdi (and devopts with sdi, see below). */
-       if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       /* Every other key needs an sdi. */
-       if (!sdi)
-               return SR_ERR_ARG;
-
-       devc = sdi->priv;
+       devc = (sdi) ? sdi->priv : NULL;
 
        switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
        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_VOLTAGE_TARGET:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                /* Min, max, step. */
@@ -350,13 +319,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        sr_sw_limits_acquisition_start(&devc->limits);
-       std_session_send_df_header(sdi, LOG_PREFIX);
+       std_session_send_df_header(sdi);
 
        devc->reply_pending = FALSE;
        devc->req_sent_at = 0;
@@ -368,15 +334,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int dev_acquisition_stop(struct sr_dev_inst *sdi)
-{
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
-       return std_serial_dev_acquisition_stop(sdi,
-               std_serial_dev_close, sdi->conn, LOG_PREFIX);
-}
-
 static struct sr_dev_driver korad_kaxxxxp_driver_info = {
        .name = "korad-kaxxxxp",
        .longname = "Korad KAxxxxP",
@@ -385,13 +342,14 @@ static struct sr_dev_driver korad_kaxxxxp_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,
        .dev_open = std_serial_dev_open,
        .dev_close = std_serial_dev_close,
        .dev_acquisition_start = dev_acquisition_start,
-       .dev_acquisition_stop = dev_acquisition_stop,
+       .dev_acquisition_stop = std_serial_dev_acquisition_stop,
        .context = NULL,
 };
 SR_REGISTER_DEV_DRIVER(korad_kaxxxxp_driver_info);