]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/lascar-el-usb/api.c
Put driver pointers into special section
[libsigrok.git] / src / hardware / lascar-el-usb / api.c
index 6244172098f4eed6bdabab0294e80cb93e702d11..1fd86b7ea00052975b12d3780283cff3b7fd3929 100644 (file)
@@ -24,8 +24,6 @@
 #include "libsigrok-internal.h"
 #include "protocol.h"
 
-SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info;
-
 static const uint32_t scanopts[] = {
        SR_CONF_CONN,
 };
@@ -38,11 +36,6 @@ static const uint32_t devopts[] = {
        SR_CONF_DATALOG | SR_CONF_GET | SR_CONF_SET,
 };
 
-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 drv_context *drvc;
@@ -89,23 +82,13 @@ 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 drv_context *drvc;
+       struct drv_context *drvc = di->context;;
        struct sr_usb_dev_inst *usb;
        int ret;
 
-       if (!(drvc = di->context)) {
-               sr_err("Driver was not initialized.");
-               return SR_ERR;
-       }
-
        usb = sdi->conn;
 
        if (sr_usb_open(drvc->sr_ctx->libusb_ctx, usb) != SR_OK)
@@ -122,14 +105,8 @@ static int dev_open(struct sr_dev_inst *sdi)
 
 static int dev_close(struct sr_dev_inst *sdi)
 {
-       struct sr_dev_driver *di = sdi->driver;
        struct sr_usb_dev_inst *usb;
 
-       if (!di->context) {
-               sr_err("Driver was not initialized.");
-               return SR_ERR;
-       }
-
        usb = sdi->conn;
 
        if (!usb->devhdl)
@@ -183,7 +160,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
 static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       struct sr_dev_driver *di = sdi->driver;
        struct dev_context *devc;
        int ret;
 
@@ -192,11 +168,6 @@ 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 (!di->context) {
-               sr_err("Driver was not initialized.");
-               return SR_ERR;
-       }
-
        devc = sdi->priv;
        ret = SR_OK;
        switch (key) {
@@ -326,11 +297,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
-       if (!di->context) {
-               sr_err("Driver was not initialized.");
-               return SR_ERR;
-       }
-
        drvc = di->context;
        devc = sdi->priv;
        usb = sdi->conn;
@@ -432,13 +398,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
 SR_PRIV int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
-       struct sr_dev_driver *di = sdi->driver;
-
-       if (!di->context) {
-               sr_err("Driver was not initialized.");
-               return SR_ERR;
-       }
-
        if (sdi->status != SR_ST_ACTIVE) {
                sr_err("Device inactive, can't stop acquisition.");
                return SR_ERR;
@@ -454,10 +413,10 @@ SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info = {
        .name = "lascar-el-usb",
        .longname = "Lascar EL-USB",
        .api_version = 1,
-       .init = init,
+       .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,
@@ -468,3 +427,4 @@ SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info = {
        .dev_acquisition_stop = dev_acquisition_stop,
        .context = NULL,
 };
+SR_REGISTER_DEV_DRIVER(lascar_el_usb_driver_info);