]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/microchip-pickit2/api.c
korad-kaxxxxp: use ID text prefix with optional version for RND models
[libsigrok.git] / src / hardware / microchip-pickit2 / api.c
index 48fb849a9a001e3f14042bfa85f7d876a73d2b3d..79c79d3eae7286dfa78d39c5419190608b0fa10a 100644 (file)
@@ -159,9 +159,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                sdi->connection_id = g_strdup(conn);
 
                /* Create the logic channels group. */
-               cg = g_malloc0(sizeof(*cg));
-               sdi->channel_groups = g_slist_append(NULL, cg);
-               cg->name = g_strdup("Logic");
+               cg = sr_channel_group_new(sdi, "Logic", NULL);
                ch_count = ARRAY_SIZE(channel_names);
                for (ch_idx = 0; ch_idx < ch_count; ch_idx++) {
                        ch = sr_channel_new(sdi, ch_idx, SR_CHANNEL_LOGIC,
@@ -232,6 +230,8 @@ static int dev_close(struct sr_dev_inst *sdi)
        usb = sdi->conn;
        devc = sdi->priv;
 
+       if (!usb)
+               return SR_OK;
        if (!usb->devhdl)
                return SR_OK;
 
@@ -267,21 +267,27 @@ static int config_get(uint32_t key, GVariant **data,
        (void)cg;
 
        devc = sdi ? sdi->priv : NULL;
+       usb = sdi ? sdi->conn : NULL;
 
        switch (key) {
        case SR_CONF_CONN:
-               if (!sdi->conn)
+               if (!usb)
                        return SR_ERR_ARG;
-               usb = sdi->conn;
                *data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
                return SR_OK;
        case SR_CONF_SAMPLERATE:
+               if (!devc)
+                       return SR_ERR_ARG;
                rate = devc->samplerates[devc->curr_samplerate_idx];
                *data = g_variant_new_uint64(rate);
                return SR_OK;
        case SR_CONF_LIMIT_SAMPLES:
+               if (!devc)
+                       return SR_ERR_ARG;
                return sr_sw_limits_config_get(&devc->sw_limits, key, data);
        case SR_CONF_CAPTURE_RATIO:
+               if (!devc)
+                       return SR_ERR_ARG;
                ratio = devc->captureratios[devc->curr_captureratio_idx];
                *data = g_variant_new_uint64(ratio);
                return SR_OK;