]> sigrok.org Git - libsigrok.git/blobdiff - hardware/chronovu-la8/api.c
Shorten/simplify hw_dev_list() implementations.
[libsigrok.git] / hardware / chronovu-la8 / api.c
index 4c349e5786f68554d2f855a5fa71d46e2ce39dff..6bbdcdbbc893197bfeb99433aea8e4ab6ddd9425 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)
@@ -96,6 +86,7 @@ static GSList *hw_scan(GSList *options)
        (void)options;
 
        drvc = di->priv;
+
        devices = NULL;
 
        /* Allocate memory for our private device context. */
@@ -169,8 +160,6 @@ static GSList *hw_scan(GSList *options)
        devices = g_slist_append(devices, sdi);
        drvc->instances = g_slist_append(drvc->instances, sdi);
 
-       sr_spew("Device init successful.");
-
        /* Close device. We'll reopen it again when we need it. */
        (void) la8_close(devc); /* Log, but ignore errors. */
 
@@ -191,11 +180,7 @@ err_free_nothing:
 
 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)
@@ -293,14 +278,6 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        switch (id) {
-       case SR_DI_HWCAPS:
-               *data = hwcaps;
-               break;
-       case SR_DI_TRIGGER_TYPES:
-               *data = (char *)TRIGGER_TYPES;
-               sr_spew("%s: Returning trigger types: %s.", __func__,
-                       TRIGGER_TYPES);
-               break;
        case SR_CONF_SAMPLERATE:
                if (sdi) {
                        devc = sdi->priv;
@@ -366,10 +343,16 @@ 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_SAMPLERATE:
                fill_supported_samplerates_if_needed();
                *data = &samplerates;
                break;
+       case SR_CONF_TRIGGER_TYPE:
+               *data = (char *)TRIGGER_TYPE;
+               break;
        default:
                return SR_ERR_ARG;
        }