X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Ffx2lafw%2Fapi.c;h=c2dc2e0c2772d465c7b28763fee78b8297e1d1b6;hb=aeff7fa28622367115c3c8bdbd965c07dd536458;hp=00b8ad5d0eefc6b78736bd92bed99dbd271e017f;hpb=b0ccd64d021ae7c9dbcebc8413dc2ebe94099f68;p=libsigrok.git diff --git a/hardware/fx2lafw/api.c b/hardware/fx2lafw/api.c index 00b8ad5d..c2dc2e0c 100644 --- a/hardware/fx2lafw/api.c +++ b/hardware/fx2lafw/api.c @@ -28,21 +28,21 @@ static const struct fx2lafw_profile supported_fx2[] = { */ { 0x08a9, 0x0014, "CWAV", "USBee AX", NULL, FIRMWARE_DIR "/fx2lafw-cwav-usbeeax.fw", - 0 }, + 0, NULL, NULL}, /* * CWAV USBee DX * XZL-Studio DX */ { 0x08a9, 0x0015, "CWAV", "USBee DX", NULL, FIRMWARE_DIR "/fx2lafw-cwav-usbeedx.fw", - DEV_CAPS_16BIT }, + DEV_CAPS_16BIT, NULL, NULL }, /* * CWAV USBee SX */ { 0x08a9, 0x0009, "CWAV", "USBee SX", NULL, FIRMWARE_DIR "/fx2lafw-cwav-usbeesx.fw", - 0 }, + 0, NULL, NULL}, /* * Saleae Logic @@ -52,7 +52,7 @@ static const struct fx2lafw_profile supported_fx2[] = { */ { 0x0925, 0x3881, "Saleae", "Logic", NULL, FIRMWARE_DIR "/fx2lafw-saleae-logic.fw", - 0 }, + 0, NULL, NULL}, /* * Default Cypress FX2 without EEPROM, e.g.: @@ -61,16 +61,16 @@ static const struct fx2lafw_profile supported_fx2[] = { */ { 0x04B4, 0x8613, "Cypress", "FX2", NULL, FIRMWARE_DIR "/fx2lafw-cypress-fx2.fw", - DEV_CAPS_16BIT }, + DEV_CAPS_16BIT, NULL, NULL }, /* * Braintechnology USB-LPS */ { 0x16d0, 0x0498, "Braintechnology", "USB-LPS", NULL, FIRMWARE_DIR "/fx2lafw-braintechnology-usb-lps.fw", - DEV_CAPS_16BIT }, + DEV_CAPS_16BIT, NULL, NULL }, - { 0, 0, 0, 0, 0, 0, 0 } + { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; static const int32_t hwopts[] = { @@ -132,8 +132,10 @@ static GSList *scan(GSList *options) GSList *l, *devices, *conn_devices; struct libusb_device_descriptor des; libusb_device **devlist; + struct libusb_device_handle *hdl; int devcnt, num_logic_channels, ret, i, j; const char *conn; + char manufacturer[64], product[64]; drvc = di->priv; @@ -175,11 +177,41 @@ static GSList *scan(GSList *options) continue; } + if ((ret = libusb_open(devlist[i], &hdl)) < 0) + continue; + + if (des.iManufacturer == 0) { + manufacturer[0] = '\0'; + } else if ((ret = libusb_get_string_descriptor_ascii(hdl, + des.iManufacturer, (unsigned char *) manufacturer, + sizeof(manufacturer))) < 0) { + sr_warn("Failed to get manufacturer string descriptor: %s.", + libusb_error_name(ret)); + continue; + } + + if (des.iProduct == 0) { + product[0] = '\0'; + } else if ((ret = libusb_get_string_descriptor_ascii(hdl, + des.iProduct, (unsigned char *) product, + sizeof(product))) < 0) { + sr_warn("Failed to get product string descriptor: %s.", + libusb_error_name(ret)); + continue; + } + + libusb_close(hdl); + prof = NULL; for (j = 0; supported_fx2[j].vid; j++) { if (des.idVendor == supported_fx2[j].vid && - des.idProduct == supported_fx2[j].pid) { + des.idProduct == supported_fx2[j].pid && + (!supported_fx2[j].usb_manufacturer || + !strcmp(manufacturer, supported_fx2[j].usb_manufacturer)) && + (!supported_fx2[j].usb_manufacturer || + !strcmp(product, supported_fx2[j].usb_product))) { prof = &supported_fx2[j]; + break; } } @@ -355,9 +387,14 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, (void)cg; + if (!sdi) + return SR_ERR_ARG; + + devc = sdi->priv; + switch (id) { case SR_CONF_CONN: - if (!sdi || !sdi->conn) + if (!sdi->conn) return SR_ERR_ARG; usb = sdi->conn; if (usb->address == 255) @@ -367,10 +404,10 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, snprintf(str, 128, "%d.%d", usb->bus, usb->address); *data = g_variant_new_string(str); break; + case SR_CONF_LIMIT_SAMPLES: + *data = g_variant_new_uint64(devc->limit_samples); + break; case SR_CONF_SAMPLERATE: - if (!sdi) - return SR_ERR; - devc = sdi->priv; *data = g_variant_new_uint64(devc->cur_samplerate); break; default: @@ -388,19 +425,26 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, (void)cg; + if (!sdi) + return SR_ERR_ARG; + if (sdi->status != SR_ST_ACTIVE) return SR_ERR; devc = sdi->priv; - if (id == SR_CONF_SAMPLERATE) { - devc->cur_samplerate = g_variant_get_uint64(data); - ret = SR_OK; - } else if (id == SR_CONF_LIMIT_SAMPLES) { - devc->limit_samples = g_variant_get_uint64(data); - ret = SR_OK; - } else { - ret = SR_ERR_NA; + ret = SR_OK; + + switch (id) + { + case SR_CONF_SAMPLERATE: + devc->cur_samplerate = g_variant_get_uint64(data); + break; + case SR_CONF_LIMIT_SAMPLES: + devc->limit_samples = g_variant_get_uint64(data); + break; + default: + ret = SR_ERR_NA; } return ret; @@ -432,7 +476,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_builder_end(&gvb); break; case SR_CONF_TRIGGER_TYPE: - *data = g_variant_new_string(TRIGGER_TYPE); + *data = g_variant_new_string(SOFT_TRIGGER_TYPES); break; default: return SR_ERR_NA; @@ -527,8 +571,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); - if ((ret = fx2lafw_command_start_acquisition(usb->devhdl, - devc->cur_samplerate, devc->sample_wide)) != SR_OK) { + if ((ret = fx2lafw_command_start_acquisition(sdi)) != SR_OK) { fx2lafw_abort_acquisition(devc); return ret; }