]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/manson-hcs-3xxx/api.c
Pass driver struct pointer to driver callbacks.
[libsigrok.git] / src / hardware / manson-hcs-3xxx / api.c
index 6be41b9fd9b67460d98fffbe78c5ef20b3fcd6f5..b9e6524b482b139d4a840abcb57205b1fcbad09a 100644 (file)
 
 #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,
@@ -68,26 +73,24 @@ static struct hcs_model models[] = {
 };
 
 SR_PRIV struct sr_dev_driver manson_hcs_3xxx_driver_info;
-static struct sr_dev_driver *di = &manson_hcs_3xxx_driver_info;
 
-static int dev_clear(void)
+static int dev_clear(const struct sr_dev_driver *di)
 {
        return std_dev_clear(di, NULL);
 }
 
-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);
 }
 
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        int i, model_id;
        struct drv_context *drvc;
        struct dev_context *devc;
        struct sr_dev_inst *sdi;
        struct sr_config *src;
-       struct sr_channel *ch;
        GSList *devices, *l;
        const char *conn, *serialcomm;
        struct sr_serial_dev_inst *serial;
@@ -120,8 +123,7 @@ static GSList *scan(GSList *options)
        if (!serialcomm)
                serialcomm = "9600/8n1";
 
-       if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
-               return NULL;
+       serial = sr_serial_dev_inst_new(conn, serialcomm);
 
        if (serial_open(serial, SERIAL_RDWR) != SR_OK)
                return NULL;
@@ -150,7 +152,7 @@ static GSList *scan(GSList *options)
        }
 
        /* Init device instance, etc. */
-       sdi = sr_dev_inst_new();
+       sdi = g_malloc0(sizeof(struct sr_dev_inst));
        sdi->status = SR_ST_INACTIVE;
        sdi->vendor = g_strdup("Manson");
        sdi->model = g_strdup(models[model_id].name);
@@ -158,11 +160,7 @@ static GSList *scan(GSList *options)
        sdi->conn = serial;
        sdi->driver = di;
 
-       if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"))) {
-               sr_err("Failed to create channel.");
-               goto exit_err;
-       }
-       sdi->channels = g_slist_append(sdi->channels, ch);
+       sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
 
        devc = g_malloc0(sizeof(struct dev_context));
        devc->model = &models[model_id];
@@ -204,14 +202,14 @@ exit_err:
        return NULL;
 }
 
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
 {
        return ((struct drv_context *)(di->priv))->instances;
 }
 
-static int cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
 {
-       return dev_clear();
+       return dev_clear(di);
 }
 
 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
@@ -329,15 +327,26 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
 
        (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;
 
        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));