]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/zeroplus-logic-cube/api.c
Pass driver struct pointer to driver callbacks.
[libsigrok.git] / src / hardware / zeroplus-logic-cube / api.c
index b2e7b7f38ce47409bf2ac30bff537d59c6c4480c..5d8c534f27eb56c7f8c86b3462649886f84ef848 100644 (file)
@@ -80,7 +80,6 @@ static const char *channel_names[] = {
 };
 
 SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info;
-static struct sr_dev_driver *di = &zeroplus_logic_cube_driver_info;
 
 /*
  * The hardware supports more samplerates than these, but these are the
@@ -156,15 +155,14 @@ SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate)
        return SR_OK;
 }
 
-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)
 {
        struct sr_dev_inst *sdi;
-       struct sr_channel *ch;
        struct drv_context *drvc;
        struct dev_context *devc;
        const struct zp_model *prof;
@@ -231,11 +229,7 @@ static GSList *scan(GSList *options)
                sdi->connection_id = g_strdup(connection_id);
 
                /* Allocate memory for our private driver context. */
-               if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
-                       sr_err("Device context malloc failed.");
-                       return NULL;
-               }
-
+               devc = g_malloc0(sizeof(struct dev_context));
                sdi->priv = devc;
                devc->prof = prof;
                devc->num_channels = prof->channels;
@@ -251,12 +245,9 @@ static GSList *scan(GSList *options)
                // memset(devc->trigger_buffer, 0, NUM_TRIGGER_STAGES);
 
                /* Fill in channellist according to this device's profile. */
-               for (j = 0; j < devc->num_channels; j++) {
-                       if (!(ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE,
-                                       channel_names[j])))
-                               return NULL;
-                       sdi->channels = g_slist_append(sdi->channels, ch);
-               }
+               for (j = 0; j < devc->num_channels; j++)
+                       sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE,
+                                       channel_names[j]);
 
                devices = g_slist_append(devices, sdi);
                drvc->instances = g_slist_append(drvc->instances, sdi);
@@ -270,13 +261,14 @@ static GSList *scan(GSList *options)
        return devices;
 }
 
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
 {
        return ((struct drv_context *)(di->priv))->instances;
 }
 
 static int dev_open(struct sr_dev_inst *sdi)
 {
+       struct sr_dev_driver *di = sdi->driver;
        struct dev_context *devc;
        struct drv_context *drvc;
        struct sr_usb_dev_inst *usb;
@@ -390,7 +382,7 @@ 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 std_dev_clear(di, NULL);
 }