]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/uni-t-ut32x/api.c
Put driver pointers into special section
[libsigrok.git] / src / hardware / uni-t-ut32x / api.c
index f19dabeff55015f0bad2d20de530650b8821aec5..789b72def626ca97bbbad01ae6965b3480d25093 100644 (file)
@@ -37,13 +37,6 @@ static const char *data_sources[] = {
        "Memory",
 };
 
-SR_PRIV struct sr_dev_driver uni_t_ut32x_driver_info;
-
-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;
@@ -101,15 +94,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 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)
@@ -145,14 +133,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)
                /*  Nothing to do. */
@@ -194,7 +176,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;
        const char *tmp_str;
 
@@ -203,11 +184,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;
 
        switch (key) {
@@ -324,11 +300,11 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-SR_PRIV struct sr_dev_driver uni_t_ut32x_driver_info = {
+static struct sr_dev_driver uni_t_ut32x_driver_info = {
        .name = "uni-t-ut32x",
        .longname = "UNI-T UT32x",
        .api_version = 1,
-       .init = init,
+       .init = std_init,
        .cleanup = std_cleanup,
        .scan = scan,
        .dev_list = std_dev_list,
@@ -342,3 +318,4 @@ SR_PRIV struct sr_dev_driver uni_t_ut32x_driver_info = {
        .dev_acquisition_stop = dev_acquisition_stop,
        .context = NULL,
 };
+SR_REGISTER_DEV_DRIVER(uni_t_ut32x_driver_info);