]> sigrok.org Git - libsigrok.git/blobdiff - hardware/chronovu-la8/api.c
sr/drivers: add API calls sr_dev_inst_list() and sr_dev_inst_clear()
[libsigrok.git] / hardware / chronovu-la8 / api.c
index 7d64176c72f730fb73e18c1d35708ccee9c7a9f3..012ad6f1e3e8773fb8621b5701a33459ebfa8e04 100644 (file)
@@ -41,7 +41,7 @@ static const uint16_t usb_pids[] = {
 static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
                void *cb_data);
 
-static void clear_instances(void)
+static int clear_instances(void)
 {
        GSList *l;
        struct sr_dev_inst *sdi;
@@ -60,13 +60,13 @@ static void clear_instances(void)
                if (sdi->priv) {
                        devc = sdi->priv;
                        ftdi_free(devc->ftdic);
-                       g_free(devc);
                }
                sr_dev_inst_free(sdi);
        }
        g_slist_free(drvc->instances);
        drvc->instances = NULL;
 
+       return SR_OK;
 }
 
 static int hw_init(void)
@@ -187,6 +187,15 @@ err_free_nothing:
        return NULL;
 }
 
+static GSList *hw_dev_list(void)
+{
+       struct drv_context *drvc;
+
+       drvc = cdi->priv;
+
+       return drvc->instances;
+}
+
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -253,7 +262,6 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 
        if (sdi->status == SR_ST_ACTIVE) {
                sr_dbg("la8: Status ACTIVE, closing device.");
-               /* TODO: Really ignore errors here, or return SR_ERR? */
                (void) la8_close_usb_reset_sequencer(devc); /* Ignore errors. */
        } else {
                sr_spew("la8: Status not ACTIVE, nothing to do.");
@@ -340,12 +348,6 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
                }
                sr_dbg("la8: SAMPLERATE = %" PRIu64, devc->cur_samplerate);
                break;
-       case SR_HWCAP_PROBECONFIG:
-               if (configure_probes(devc, (const GSList *)value) != SR_OK) {
-                       sr_err("la8: %s: probe config failed.", __func__);
-                       return SR_ERR;
-               }
-               break;
        case SR_HWCAP_LIMIT_MSEC:
                if (*(const uint64_t *)value == 0) {
                        sr_err("la8: %s: LIMIT_MSEC can't be 0.", __func__);
@@ -418,7 +420,6 @@ static int receive_data(int fd, int revents, void *cb_data)
 
        hw_dev_acquisition_stop(sdi, sdi);
 
-       // return FALSE; /* FIXME? */
        return TRUE;
 }
 
@@ -448,6 +449,11 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR;
        }
 
+       if (configure_probes(sdi) != SR_OK) {
+               sr_err("chronovu-la8: failed to configured probes");
+               return SR_ERR;
+       }
+
        sr_dbg("la8: Starting acquisition.");
 
        /* Fill acquisition parameters into buf[]. */
@@ -464,7 +470,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR;
        } else if (bytes_written != 4) {
                sr_err("la8: Acquisition failed to start.");
-               return SR_ERR; /* TODO: Other error and return code? */
+               return SR_ERR;
        }
 
        sr_dbg("la8: Acquisition started successfully.");
@@ -501,15 +507,12 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
                void *cb_data)
 {
-       struct dev_context *devc;
        struct sr_datafeed_packet packet;
 
-       sr_dbg("la8: Stopping acquisition.");
+       (void)sdi;
 
-       if (!(devc = sdi->priv)) {
-               sr_err("la8: %s: sdi->priv was NULL", __func__);
-               return SR_ERR_BUG;
-       }
+       sr_dbg("la8: Stopping acquisition.");
+       sr_source_remove(-1);
 
        /* Send end packet to the session bus. */
        sr_dbg("la8: Sending SR_DF_END.");
@@ -526,6 +529,8 @@ SR_PRIV struct sr_dev_driver chronovu_la8_driver_info = {
        .init = hw_init,
        .cleanup = hw_cleanup,
        .scan = hw_scan,
+       .dev_list = hw_dev_list,
+       .dev_clear = clear_instances,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,