]> sigrok.org Git - libsigrok.git/commitdiff
microchip-pickit2: support user assigned channel names at probe time
authorGerhard Sittig <redacted>
Sun, 9 Apr 2023 08:02:49 +0000 (10:02 +0200)
committerGerhard Sittig <redacted>
Sun, 9 Apr 2023 21:33:35 +0000 (23:33 +0200)
Allow users to assign channel names at probe time already. Add support
for the SR_CONF_PROBE_NAMES scan option. Improves usability.

  $ sigrok-cli -d microchip-pickit2:probe_names=spi --samples 1024

src/hardware/microchip-pickit2/api.c
src/hardware/microchip-pickit2/protocol.h

index f4d5cb7a5307faa2e43e38ed78f6b152787d138e..97d5b13cd96392c70a5fc0eb382004e00a540d57 100644 (file)
@@ -72,6 +72,7 @@ static const char *channel_names[] = {
 
 static const uint32_t scanopts[] = {
        SR_CONF_CONN,
+       SR_CONF_PROBE_NAMES,
 };
 
 static const uint32_t drvopts[] = {
@@ -119,6 +120,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        struct drv_context *drvc;
        const char *conn;
+       const char *probe_names;
        GSList *l, *devices, *usb_devices;
        struct sr_config *cfg;
        struct sr_usb_dev_inst *usb;
@@ -131,12 +133,16 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        drvc = di->context;
 
        conn = PICKIT2_DEFAULT_ADDRESS;
+       probe_names = NULL;
        for (l = options; l; l = l->next) {
                cfg = l->data;
                switch (cfg->key) {
                case SR_CONF_CONN:
                        conn = g_variant_get_string(cfg->data, NULL);
                        break;
+               case SR_CONF_PROBE_NAMES:
+                       probe_names = g_variant_get_string(cfg->data, NULL);
+                       break;
                }
        }
 
@@ -171,13 +177,15 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                devc->num_captureratios = ARRAY_SIZE(captureratios);
                devc->curr_captureratio_idx = 0;
                devc->sw_limits.limit_samples = PICKIT2_SAMPLE_COUNT;
+               devc->channel_names = sr_parse_probe_names(probe_names,
+                       channel_names, ARRAY_SIZE(channel_names),
+                       ARRAY_SIZE(channel_names), &ch_count);
 
                /* Create the logic channels group. */
                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,
-                               TRUE, channel_names[ch_idx]);
+                               TRUE, devc->channel_names[ch_idx]);
                        cg->channels = g_slist_append(cg->channels, ch);
                }
        }
index 500964730980b5b392bc0f01cec6f897a475c963..28b152f00ea1f9ef3cdd12be1972556c148f9907 100644 (file)
@@ -40,6 +40,7 @@ enum pickit_state {
 };
 
 struct dev_context {
+       char **channel_names;
        enum pickit_state state;
        const uint64_t *samplerates;
        size_t num_samplerates;