]> sigrok.org Git - libsigrok.git/blobdiff - hardware/rigol-ds1xx2/api.c
rigol-ds1xx2: detect Rigol DS1xx2 with upgraded bandwith
[libsigrok.git] / hardware / rigol-ds1xx2 / api.c
index 708c6015d48dd1d8e2608c1b0e30b21edb1315de..ba59c2156af26c66e7026565617d408c76b6277f 100644 (file)
@@ -133,44 +133,30 @@ static const char *coupling[] = {
 static const char *supported_models[] = {
        "DS1052E",
        "DS1102E",
+       "DS1152E",
        "DS1052D",
        "DS1102D",
+       "DS1152D",
 };
 
 SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info;
 static struct sr_dev_driver *di = &rigol_ds1xx2_driver_info;
 
-/* Properly close and free all devices. */
-static int clear_instances(void)
+static void clear_helper(void *priv)
 {
-       struct sr_dev_inst *sdi;
-       struct drv_context *drvc;
        struct dev_context *devc;
-       GSList *l;
-
-       if (!(drvc = di->priv))
-               return SR_OK;
-
-       for (l = drvc->instances; l; l = l->next) {
-               if (!(sdi = l->data))
-                       continue;
 
-               if (sdi->conn)
-                       sr_serial_dev_inst_free(sdi->conn);
+       devc = priv;
 
-               if ((devc = sdi->priv)) {
-                       g_free(devc->coupling[0]);
-                       g_free(devc->coupling[1]);
-                       g_free(devc->trigger_source);
-                       g_free(devc->trigger_slope);
-               }
-               sr_dev_inst_free(sdi);
-       }
-
-       g_slist_free(drvc->instances);
-       drvc->instances = NULL;
+       g_free(devc->coupling[0]);
+       g_free(devc->coupling[1]);
+       g_free(devc->trigger_source);
+       g_free(devc->trigger_slope);
+}
 
-       return SR_OK;
+static int dev_clear(void)
+{
+       return std_dev_clear(di, clear_helper);
 }
 
 static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
@@ -192,9 +178,9 @@ static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
        return SR_OK;
 }
 
-static int hw_init(struct sr_context *sr_ctx)
+static int init(struct sr_context *sr_ctx)
 {
-       return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
+       return std_init(sr_ctx, di, LOG_PREFIX);
 }
 
 static int probe_port(const char *port, GSList **devices)
@@ -266,6 +252,7 @@ static int probe_port(const char *port, GSList **devices)
        if (!(sdi->conn = sr_serial_dev_inst_new(port, NULL)))
                return SR_ERR_MALLOC;
        sdi->driver = di;
+       sdi->inst_type = SR_INST_SERIAL;
 
        if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
                return SR_ERR_MALLOC;
@@ -297,7 +284,7 @@ static int probe_port(const char *port, GSList **devices)
        return SR_OK;
 }
 
-static GSList *hw_scan(GSList *options)
+static GSList *scan(GSList *options)
 {
        struct drv_context *drvc;
        struct sr_config *src;
@@ -322,8 +309,9 @@ static GSList *hw_scan(GSList *options)
                if (probe_port(port, &devices) == SR_ERR_MALLOC)
                        return NULL;
        } else {
-               if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL)))
-                       return NULL;
+               if (!(dir = g_dir_open("/sys/class/usbmisc/", 0, NULL)))
+                       if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL)))
+                               return NULL;
                while ((dev_name = g_dir_read_name(dir))) {
                        if (strncmp(dev_name, "usbtmc", 6))
                                continue;
@@ -345,12 +333,12 @@ static GSList *hw_scan(GSList *options)
        return devices;
 }
 
-static GSList *hw_dev_list(void)
+static GSList *dev_list(void)
 {
        return ((struct drv_context *)(di->priv))->instances;
 }
 
-static int hw_dev_open(struct sr_dev_inst *sdi)
+static int dev_open(struct sr_dev_inst *sdi)
 {
 
        if (serial_open(sdi->conn, SERIAL_RDWR) != SR_OK)
@@ -364,7 +352,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int hw_dev_close(struct sr_dev_inst *sdi)
+static int dev_close(struct sr_dev_inst *sdi)
 {
        struct sr_serial_dev_inst *serial;
 
@@ -377,11 +365,9 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int hw_cleanup(void)
+static int cleanup(void)
 {
-       clear_instances();
-
-       return SR_OK;
+       return dev_clear();
 }
 
 static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
@@ -414,10 +400,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 
        devc = sdi->priv;
 
-       if (sdi->status != SR_ST_ACTIVE) {
-               sr_err("Device inactive, can't set config options.");
-               return SR_ERR;
-       }
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        ret = SR_OK;
        switch (id) {
@@ -575,7 +559,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        GSList *l;
        char cmd[256];
 
-       (void)cb_data;
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
 
        serial = sdi->conn;
        devc = sdi->priv;
@@ -613,7 +598,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        sr_source_add(serial->fd, G_IO_IN, 50, rigol_ds1xx2_receive, (void *)sdi);
 
        /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
+       std_session_send_df_header(cb_data, LOG_PREFIX);
 
        /* Fetch the first frame. */
        if (devc->enabled_analog_probes) {
@@ -660,16 +645,16 @@ SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info = {
        .name = "rigol-ds1xx2",
        .longname = "Rigol DS1xx2",
        .api_version = 1,
-       .init = hw_init,
-       .cleanup = hw_cleanup,
-       .scan = hw_scan,
-       .dev_list = hw_dev_list,
-       .dev_clear = clear_instances,
+       .init = init,
+       .cleanup = cleanup,
+       .scan = scan,
+       .dev_list = dev_list,
+       .dev_clear = dev_clear,
        .config_get = config_get,
        .config_set = config_set,
        .config_list = config_list,
-       .dev_open = hw_dev_open,
-       .dev_close = hw_dev_close,
+       .dev_open = dev_open,
+       .dev_close = dev_close,
        .dev_acquisition_start = dev_acquisition_start,
        .dev_acquisition_stop = dev_acquisition_stop,
        .priv = NULL,