X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fmicrochip-pickit2%2Fapi.c;h=97d5b13cd96392c70a5fc0eb382004e00a540d57;hb=02a4f485de76b401eca7d3b82aac1808a12df4fe;hp=41e7baa2e909e30f56463cf36a493d5405bdd3b3;hpb=bde6a99b33fd520152c05183f5b80cff63d75675;p=libsigrok.git diff --git a/src/hardware/microchip-pickit2/api.c b/src/hardware/microchip-pickit2/api.c index 41e7baa2..97d5b13c 100644 --- a/src/hardware/microchip-pickit2/api.c +++ b/src/hardware/microchip-pickit2/api.c @@ -42,7 +42,7 @@ * - The current implementation silently accepts sample count limits beyond * 1024, just won't provide more than 1024 samples to the session. A * future implementation could cap the settings upon reception. Apps - * like Pulseview may not be able to specify 1024, and pass 1000 or + * like PulseView may not be able to specify 1024, and pass 1000 or * 2000 instead (the latter results in 1024 getting used). * - The manual suggests that users can assign names to devices. The * current implementation supports conn= specs with USB VID:PID pairs @@ -66,12 +66,13 @@ static struct sr_dev_driver microchip_pickit2_driver_info; -static const char *pickit2_channel_names[] = { +static const char *channel_names[] = { "pin4", "pin5", "pin6", }; 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; } } @@ -158,17 +164,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->conn = usb; 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"); - ch_count = ARRAY_SIZE(pickit2_channel_names); - for (ch_idx = 0; ch_idx < ch_count; ch_idx++) { - ch = sr_channel_new(sdi, ch_idx, SR_CHANNEL_LOGIC, - TRUE, pickit2_channel_names[ch_idx]); - cg->channels = g_slist_append(cg->channels, ch); - } - /* * Create the device context. Pre-select the highest * samplerate and the deepest sample count available. @@ -182,6 +177,17 @@ 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); + for (ch_idx = 0; ch_idx < ch_count; ch_idx++) { + ch = sr_channel_new(sdi, ch_idx, SR_CHANNEL_LOGIC, + TRUE, devc->channel_names[ch_idx]); + cg->channels = g_slist_append(cg->channels, ch); + } } return std_scan_complete(di, devices); @@ -232,6 +238,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; @@ -264,24 +272,30 @@ static int config_get(uint32_t key, GVariant **data, struct sr_usb_dev_inst *usb; uint64_t rate, ratio; - devc = sdi ? sdi->priv : NULL; - (void)devc; (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; @@ -296,10 +310,10 @@ static int config_set(uint32_t key, GVariant *data, struct dev_context *devc; int idx; - devc = sdi ? sdi->priv : NULL; - (void)cg; + devc = sdi ? sdi->priv : NULL; + switch (key) { case SR_CONF_SAMPLERATE: if (!devc) @@ -454,5 +468,4 @@ static struct sr_dev_driver microchip_pickit2_driver_info = { .dev_acquisition_stop = dev_acquisition_stop, .context = NULL, }; - SR_REGISTER_DEV_DRIVER(microchip_pickit2_driver_info);