]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/zeroplus-logic-cube/api.c
Put driver pointers into special section
[libsigrok.git] / src / hardware / zeroplus-logic-cube / api.c
index c85a40892b69a297317d67c6267bfe0552c3f4d9..2cbb5f614357f83c290ae26a55ce1996ce8bbfb7 100644 (file)
@@ -79,8 +79,6 @@ static const char *channel_names[] = {
        "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
 };
 
-SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info;
-
 /*
  * The hardware supports more samplerates than these, but these are the
  * options hardcoded into the vendor's Windows GUI.
@@ -155,11 +153,6 @@ SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate)
        return SR_OK;
 }
 
-static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
-{
-       return std_init(sr_ctx, di, LOG_PREFIX);
-}
-
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        struct sr_dev_inst *sdi;
@@ -256,58 +249,23 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        return devices;
 }
 
-static GSList *dev_list(const struct sr_dev_driver *di)
-{
-       return ((struct drv_context *)(di->context))->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;
-       libusb_device **devlist, *dev;
-       int device_count, ret, i;
-       char connection_id[64];
+       int ret;
 
        drvc = di->context;
        usb = sdi->conn;
+       devc = sdi->priv;
 
-       if (!(devc = sdi->priv)) {
-               sr_err("%s: sdi->priv was NULL", __func__);
-               return SR_ERR_ARG;
-       }
-
-       device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx,
-                                             &devlist);
-       if (device_count < 0) {
-               sr_err("Failed to retrieve device list.");
-               return SR_ERR;
-       }
-
-       dev = NULL;
-       for (i = 0; i < device_count; i++) {
-               usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
-               if (!strcmp(sdi->connection_id, connection_id)) {
-                       dev = devlist[i];
-                       break;
-               }
-       }
-       if (!dev) {
-               sr_err("Device on %d.%d (logical) / %s (physical) disappeared!",
-                      usb->bus, usb->address, sdi->connection_id);
-               return SR_ERR;
-       }
+       ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb);
+       if (ret != SR_OK)
+               return ret;
 
-       if (!(ret = libusb_open(dev, &(usb->devhdl)))) {
-               sdi->status = SR_ST_ACTIVE;
-               sr_info("Opened device on %d.%d (logical) / %s (physical) interface %d.",
-                       usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
-       } else {
-               sr_err("Failed to open device: %s.", libusb_error_name(ret));
-               return SR_ERR;
-       }
+       sdi->status = SR_ST_ACTIVE;
 
        ret = libusb_set_configuration(usb->devhdl, USB_CONFIGURATION);
        if (ret < 0) {
@@ -377,11 +335,6 @@ static int dev_close(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int cleanup(const struct sr_dev_driver *di)
-{
-       return std_dev_clear(di, NULL);
-}
-
 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
@@ -425,10 +378,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
-       if (!(devc = sdi->priv)) {
-               sr_err("%s: sdi->priv was NULL", __func__);
-               return SR_ERR_ARG;
-       }
+       devc = sdi->priv;
 
        switch (key) {
        case SR_CONF_SAMPLERATE:
@@ -705,14 +655,14 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = {
+static struct sr_dev_driver zeroplus_logic_cube_driver_info = {
        .name = "zeroplus-logic-cube",
        .longname = "ZEROPLUS Logic Cube LAP-C series",
        .api_version = 1,
-       .init = init,
-       .cleanup = cleanup,
+       .init = std_init,
+       .cleanup = std_cleanup,
        .scan = scan,
-       .dev_list = dev_list,
+       .dev_list = std_dev_list,
        .dev_clear = NULL,
        .config_get = config_get,
        .config_set = config_set,
@@ -723,3 +673,4 @@ SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = {
        .dev_acquisition_stop = dev_acquisition_stop,
        .context = NULL,
 };
+SR_REGISTER_DEV_DRIVER(zeroplus_logic_cube_driver_info);