]> sigrok.org Git - libsigrok.git/blobdiff - hardware/rigol-ds1xx2/api.c
Factor out common hw_init() driver code.
[libsigrok.git] / hardware / rigol-ds1xx2 / api.c
index 5d6e3dc786b71277d1252c13f6a69ad339d8cc0a..8107fb8a9ab71380d98dd00f23098538629b823c 100644 (file)
@@ -152,17 +152,7 @@ static int clear_instances(void)
 
 static int hw_init(struct sr_context *sr_ctx)
 {
-       struct drv_context *drvc;
-       (void)sr_ctx;
-
-       if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
-               sr_err("Driver context malloc failed.");
-               return SR_ERR_MALLOC;
-       }
-
-       di->priv = drvc;
-
-       return SR_OK;
+       return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
 }
 
 static GSList *hw_scan(GSList *options)
@@ -188,10 +178,11 @@ static GSList *hw_scan(GSList *options)
 
        (void)options;
 
-       devices = NULL;
        drvc = di->priv;
        drvc->instances = NULL;
 
+       devices = NULL;
+
        dir = g_dir_open("/sys/class/usb/", 0, NULL);
 
        if (dir == NULL)
@@ -324,27 +315,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_HWCAPS:
-               *data = hwcaps;
-               break;
-       case SR_DI_TIMEBASES:
-               *data = timebases;
-               break;
-       case SR_DI_TRIGGER_SOURCES:
-               *data = trigger_sources;
-               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;
@@ -439,12 +409,21 @@ static int config_list(int key, const void **data, const struct sr_dev_inst *sdi
        (void)sdi;
 
        switch (key) {
+       case SR_CONF_DEVICE_OPTIONS:
+               *data = hwcaps;
+               break;
        case SR_CONF_COUPLING:
                *data = coupling;
                break;
        case SR_CONF_VDIV:
                *data = vdivs;
                break;
+       case SR_CONF_TIMEBASE:
+               *data = timebases;
+               break;
+       case SR_CONF_TRIGGER_SOURCE:
+               *data = trigger_sources;
+               break;
        default:
                return SR_ERR_ARG;
        }
@@ -520,7 +499,6 @@ SR_PRIV struct sr_dev_driver rigol_ds1xx2_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,