]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/sysclk-lwla/api.c
baylibre-acme: Add SR_CONF_POWERMETER key.
[libsigrok.git] / src / hardware / sysclk-lwla / api.c
index bb1e9e0b48719c1fa98eb3a36ac762e36a7e74d5..1ff70eeb8dce3eba523dc9793963f9bf0c6e14c8 100644 (file)
@@ -203,30 +203,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        return std_scan_complete(di, devices);
 }
 
-/* Destroy the private device context.
- */
-static void clear_dev_context(void *priv)
-{
-       struct dev_context *devc;
-
-       devc = priv;
-
-       if (devc->acquisition) {
-               sr_err("Cannot clear device context during acquisition!");
-               return; /* Leak and pray. */
-       }
-       sr_dbg("Device context cleared.");
-
-       g_free(devc);
-}
-
-/* Destroy all device instances.
- */
-static int dev_clear(const struct sr_dev_driver *di)
-{
-       return std_dev_clear(di, &clear_dev_context);
-}
-
 /* Drain any pending data from the USB transfer buffers on the device.
  * This may be necessary e.g. after a crash or generally to clean up after
  * an abnormal condition.
@@ -324,8 +300,7 @@ static int dev_open(struct sr_dev_inst *sdi)
        return ret;
 }
 
-/* Shutdown and close device.
- */
+/* Shutdown and close device. */
 static int dev_close(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -342,17 +317,16 @@ static int dev_close(struct sr_dev_inst *sdi)
                return SR_ERR_BUG;
        }
 
-       sdi->status = SR_ST_INACTIVE;
-
        /* Download of the shutdown bitstream, if any. */
        ret = (*devc->model->apply_fpga_config)(sdi);
        if (ret != SR_OK)
                sr_warn("Unable to shut down device.");
 
        libusb_release_interface(usb->devhdl, USB_INTERFACE);
+
        sr_usb_close(usb);
 
-       return ret;
+       return SR_OK;
 }
 
 /* Check whether the device options contain a specific key.
@@ -651,8 +625,6 @@ static int config_commit(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-/* List available choices for a configuration setting.
- */
 static int config_list(uint32_t key, GVariant **data,
                       const struct sr_dev_inst *sdi,
                       const struct sr_channel_group *cg)
@@ -661,31 +633,16 @@ static int config_list(uint32_t key, GVariant **data,
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       (void)cg;
-
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(scanopts[0]));
-               return SR_OK;
-       }
-       if (!sdi) {
-               if (key != SR_CONF_DEVICE_OPTIONS)
-                       return SR_ERR_ARG;
-
-               /* List driver capabilities. */
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       drvopts, ARRAY_SIZE(drvopts), sizeof(drvopts[0]));
-               return SR_OK;
-       }
-
-       devc = sdi->priv;
+       devc = (sdi) ? sdi->priv : NULL;
 
-       /* List the model's device options. */
-       if (key == SR_CONF_DEVICE_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       devc->model->devopts, devc->model->num_devopts,
-                       sizeof(devc->model->devopts[0]));
-               return SR_OK;
+       switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
+       case SR_CONF_DEVICE_OPTIONS:
+               return std_opts_config_list(key, data, sdi, cg,
+                       scanopts, ARRAY_SIZE(scanopts),
+                       drvopts, ARRAY_SIZE(drvopts),
+                       (devc) ? devc->model->devopts : NULL,
+                       (devc) ? devc->model->num_devopts : 0);
        }
 
        if (!has_devopt(devc->model, key | SR_CONF_LIST))
@@ -757,7 +714,7 @@ static struct sr_dev_driver sysclk_lwla_driver_info = {
        .cleanup = std_cleanup,
        .scan = scan,
        .dev_list = std_dev_list,
-       .dev_clear = dev_clear,
+       .dev_clear = std_dev_clear,
        .config_get = config_get,
        .config_set = config_set,
        .config_channel_set = config_channel_set,