]> sigrok.org Git - libsigrok.git/blobdiff - hardware/tondaj-sl-814/api.c
Shorten/simplify hw_dev_list() implementations.
[libsigrok.git] / hardware / tondaj-sl-814 / api.c
index aa3fe6ff32eb534499f2eef1c2e47d1ee5f75279..36ec5c2635d9dba3110e7c03d1dca82969710066 100644 (file)
@@ -70,17 +70,7 @@ static int clear_instances(void)
 
 static int hw_init(struct sr_context *sr_ctx)
 {
-       struct drv_context *drvc;
-
-       if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
-               sr_err("Driver context malloc failed.");
-               return SR_ERR_MALLOC;
-       }
-
-       drvc->sr_ctx = sr_ctx;
-       di->priv = drvc;
-
-       return SR_OK;
+       return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
 }
 
 static GSList *hw_scan(GSList *options)
@@ -93,10 +83,11 @@ static GSList *hw_scan(GSList *options)
        GSList *devices, *l;
        const char *conn, *serialcomm;
 
-       devices = NULL;
        drvc = di->priv;
        drvc->instances = NULL;
 
+       devices = NULL;
+
        conn = serialcomm = NULL;
        for (l = options; l; l = l->next) {
                if (!(src = l->data)) {
@@ -153,11 +144,7 @@ static GSList *hw_scan(GSList *options)
 
 static GSList *hw_dev_list(void)
 {
-       struct drv_context *drvc;
-
-       drvc = di->priv;
-
-       return drvc->instances;
+       return ((struct drv_context *)(di->priv))->instances;
 }
 
 static int hw_dev_open(struct sr_dev_inst *sdi)
@@ -195,24 +182,6 @@ static int hw_cleanup(void)
        return SR_OK;
 }
 
-static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
-{
-       (void)sdi;
-
-       switch (id) {
-       case SR_DI_HWOPTS:
-               *data = hwopts;
-               break;
-       case SR_DI_HWCAPS:
-               *data = hwcaps;
-               break;
-       default:
-               return SR_ERR_ARG;
-       }
-
-       return SR_OK;
-}
-
 static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -244,6 +213,12 @@ static int config_list(int key, const void **data, const struct sr_dev_inst *sdi
        (void)sdi;
 
        switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
+               *data = hwopts;
+               break;
+       case SR_CONF_DEVICE_OPTIONS:
+               *data = hwcaps;
+               break;
        default:
                return SR_ERR_ARG;
        }
@@ -318,7 +293,6 @@ SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info = {
        .scan = hw_scan,
        .dev_list = hw_dev_list,
        .dev_clear = clear_instances,
-       .config_get = config_get,
        .config_set = config_set,
        .config_list = config_list,
        .dev_open = hw_dev_open,