]> 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 5f51b82cd86d177d3bcadeaab3fdc075597e95d0..b9e6524b482b139d4a840abcb57205b1fcbad09a 100644 (file)
@@ -73,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;
@@ -162,8 +160,7 @@ static GSList *scan(GSList *options)
        sdi->conn = serial;
        sdi->driver = di;
 
-       ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1");
-       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];
@@ -205,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,
@@ -330,21 +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));