]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/sysclk-lwla/api.c
Pass driver struct pointer to driver callbacks.
[libsigrok.git] / src / hardware / sysclk-lwla / api.c
index 90b1b5c62b3ed3a977c78639d8ad6f02d96e623a..3fe9b2bd0b6f43fc8e8ca39744a13f117c613c79 100644 (file)
@@ -74,63 +74,42 @@ static const char *const signal_edge_names[] = { "r", "f" };
 SR_PRIV struct sr_dev_driver sysclk_lwla_driver_info;
 static struct sr_dev_driver *const di = &sysclk_lwla_driver_info;
 
-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 *gen_channel_list(int num_channels)
-{
-       GSList *list;
-       struct sr_channel *ch;
-       int i;
-       char name[8];
-
-       list = NULL;
-
-       for (i = num_channels; i > 0; --i) {
-               /* The LWLA series simply number channels from CH1 to CHxx. */
-               g_snprintf(name, sizeof(name), "CH%d", i);
-
-               ch = sr_channel_new(i - 1, SR_CHANNEL_LOGIC, TRUE, name);
-               list = g_slist_prepend(list, ch);
-       }
-
-       return list;
-}
-
-static struct sr_dev_inst *dev_inst_new()
+static struct sr_dev_inst *dev_inst_new(void)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
+       int i;
+       char name[8];
 
        /* Allocate memory for our private driver context. */
-       devc = g_try_new0(struct dev_context, 1);
-       if (!devc) {
-               sr_err("Device context malloc failed.");
-               return NULL;
-       }
+       devc = g_malloc0(sizeof(struct dev_context));
 
        /* Register the device with libsigrok. */
-       sdi = sr_dev_inst_new(SR_ST_INACTIVE,
-                             VENDOR_NAME, MODEL_NAME, NULL);
-       if (!sdi) {
-               sr_err("Failed to instantiate device.");
-               g_free(devc);
-               return NULL;
-       }
+       sdi = g_malloc0(sizeof(struct sr_dev_inst));
+       sdi->status = SR_ST_INACTIVE;
+       sdi->vendor = g_strdup(VENDOR_NAME);
+       sdi->model = g_strdup(MODEL_NAME);
 
        /* Enable all channels to match the default channel configuration. */
        devc->channel_mask = ALL_CHANNELS_MASK;
        devc->samplerate = DEFAULT_SAMPLERATE;
 
        sdi->priv = devc;
-       sdi->channels = gen_channel_list(NUM_CHANNELS);
+       for (i = NUM_CHANNELS; i > 0; --i) {
+               /* The LWLA series simply number channels from CH1 to CHxx. */
+               g_snprintf(name, sizeof(name), "CH%d", i);
+               sr_channel_new(sdi, i - 1, SR_CHANNEL_LOGIC, TRUE, name);
+       }
 
        return sdi;
 }
 
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        GSList *usb_devices, *devices, *node;
        struct drv_context *drvc;
@@ -138,7 +117,6 @@ static GSList *scan(GSList *options)
        struct sr_usb_dev_inst *usb;
        struct sr_config *src;
        const char *conn;
-       char connection_id[64];
 
        drvc = di->priv;
        conn = USB_VID_PID;
@@ -156,9 +134,6 @@ static GSList *scan(GSList *options)
        for (node = usb_devices; node != NULL; node = node->next) {
                usb = node->data;
 
-               usb_get_port_path(libusb_get_device(usb->devhdl),
-                               connection_id, sizeof(connection_id));
-
                /* Create sigrok device instance. */
                sdi = dev_inst_new();
                if (!sdi) {
@@ -168,7 +143,6 @@ static GSList *scan(GSList *options)
                sdi->driver = di;
                sdi->inst_type = SR_INST_USB;
                sdi->conn = usb;
-               sdi->connection_id = g_strdup(connection_id);
 
                /* Register device instance with driver. */
                drvc->instances = g_slist_append(drvc->instances, sdi);
@@ -180,7 +154,7 @@ static GSList *scan(GSList *options)
        return devices;
 }
 
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
 {
        struct drv_context *drvc;
 
@@ -201,7 +175,7 @@ static void clear_dev_context(void *priv)
        g_free(devc);
 }
 
-static int dev_clear(void)
+static int dev_clear(const struct sr_dev_driver *di)
 {
        return std_dev_clear(di, &clear_dev_context);
 }
@@ -269,9 +243,9 @@ static int dev_close(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-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,