X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Ffx2lafw%2Fapi.c;h=ccd769b2162e0cb43406924c90f7d59d57bf979d;hb=a7d7f93c1ba6f08c243b894dda29b8ac0349bf10;hp=a4a679a4e32159a5e71ed8bb8921b0d37820a663;hpb=aab4b8cb70e08369760383d9b9302085db298a44;p=libsigrok.git diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index a4a679a4..ccd769b2 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -44,6 +44,20 @@ static const struct fx2lafw_profile supported_fx2[] = { FIRMWARE_DIR "/fx2lafw-cwav-usbeesx.fw", 0, NULL, NULL}, + /* + * DreamSourceLab DSLogic (before FW upload) + */ + { 0x2a0e, 0x0001, "DreamSourceLab", "DSLogic", NULL, + FIRMWARE_DIR "/dreamsourcelab-dslogic-fx2.fw", + DEV_CAPS_16BIT, NULL, NULL}, + + /* + * DreamSourceLab DSLogic (after FW upload) + */ + { 0x2a0e, 0x0001, "DreamSourceLab", "DSLogic", NULL, + FIRMWARE_DIR "/dreamsourcelab-dslogic-fx2.fw", + DEV_CAPS_16BIT, "DreamSourceLab", "DSLogic"}, + /* * Saleae Logic * EE Electronics ESLA100 @@ -73,17 +87,21 @@ static const struct fx2lafw_profile supported_fx2[] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; +static const uint32_t drvopts[] = { + SR_CONF_LOGIC_ANALYZER, +}; + static const uint32_t scanopts[] = { SR_CONF_CONN, }; static const uint32_t devopts[] = { - SR_CONF_LOGIC_ANALYZER, - SR_CONF_CONTINUOUS, + SR_CONF_CONTINUOUS | SR_CONF_SET, + SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, SR_CONF_CONN | SR_CONF_GET, SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, - SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, SR_CONF_TRIGGER_MATCH | SR_CONF_LIST, + SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET, }; static const char *channel_names[] = { @@ -119,6 +137,25 @@ static const uint64_t samplerates[] = { SR_MHZ(24), }; +static const uint64_t dslogic_samplerates[] = { + SR_KHZ(10), + SR_KHZ(20), + SR_KHZ(50), + SR_KHZ(100), + SR_KHZ(200), + SR_KHZ(500), + SR_MHZ(1), + SR_MHZ(2), + SR_MHZ(5), + SR_MHZ(10), + SR_MHZ(20), + SR_MHZ(25), + SR_MHZ(50), + SR_MHZ(100), + SR_MHZ(200), + SR_MHZ(400), +}; + SR_PRIV struct sr_dev_driver fx2lafw_driver_info; static struct sr_dev_driver *di = &fx2lafw_driver_info; @@ -137,6 +174,7 @@ static GSList *scan(GSList *options) struct sr_config *src; const struct fx2lafw_profile *prof; GSList *l, *devices, *conn_devices; + gboolean has_firmware; struct libusb_device_descriptor des; libusb_device **devlist; struct libusb_device_handle *hdl; @@ -238,10 +276,11 @@ static GSList *scan(GSList *options) if (!prof) continue; - sdi = sr_dev_inst_new(SR_ST_INITIALIZING, - prof->vendor, prof->model, prof->model_version); - if (!sdi) - return NULL; + sdi = g_malloc0(sizeof(struct sr_dev_inst)); + sdi->status = SR_ST_INITIALIZING; + sdi->vendor = g_strdup(prof->vendor); + sdi->model = g_strdup(prof->model); + sdi->version = g_strdup(prof->model_version); sdi->driver = di; sdi->serial_num = g_strdup(serial_num); sdi->connection_id = g_strdup(connection_id); @@ -249,9 +288,8 @@ static GSList *scan(GSList *options) /* Fill in channellist according to this device's profile. */ num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8; for (j = 0; j < num_logic_channels; j++) { - if (!(ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, - channel_names[j]))) - return NULL; + ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, + channel_names[j]); sdi->channels = g_slist_append(sdi->channels, ch); } @@ -262,7 +300,21 @@ static GSList *scan(GSList *options) drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); - if (fx2lafw_check_conf_profile(devlist[i])) { + if (strcmp(prof->model, "DSLogic")) { + devc->dslogic = FALSE; + devc->samplerates = samplerates; + devc->num_samplerates = ARRAY_SIZE(samplerates); + has_firmware = match_manuf_prod(devlist[i], + "sigrok", "fx2lafw"); + } else { + devc->dslogic = TRUE; + devc->samplerates = dslogic_samplerates; + devc->num_samplerates = ARRAY_SIZE(dslogic_samplerates); + has_firmware = match_manuf_prod(devlist[i], + "DreamSourceLab", "DSLogic"); + } + + if (has_firmware) { /* Already has the firmware, so fix the new address. */ sr_dbg("Found an fx2lafw device."); sdi->status = SR_ST_INACTIVE; @@ -358,9 +410,15 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_ERR; } + if (devc->dslogic) { + if ((ret = dslogic_fpga_firmware_upload(usb->devhdl, + DSLOGIC_FPGA_FIRMWARE)) != SR_OK) + return ret; + } + if (devc->cur_samplerate == 0) { /* Samplerate hasn't been set; default to the slowest one. */ - devc->cur_samplerate = samplerates[0]; + devc->cur_samplerate = devc->samplerates[0]; } return SR_OK; @@ -432,6 +490,9 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s case SR_CONF_SAMPLERATE: *data = g_variant_new_uint64(devc->cur_samplerate); break; + case SR_CONF_CAPTURE_RATIO: + *data = g_variant_new_uint64(devc->capture_ratio); + break; default: return SR_ERR_NA; } @@ -474,6 +535,14 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); break; + case SR_CONF_CAPTURE_RATIO: + devc->capture_ratio = g_variant_get_uint64(data); + if (devc->capture_ratio > 100) { + devc->capture_ratio = 0; + ret = SR_ERR; + } else + ret = SR_OK; + break; default: ret = SR_ERR_NA; } @@ -484,10 +553,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { + struct dev_context *devc; GVariant *gvar; GVariantBuilder gvb; - (void)sdi; (void)cg; switch (key) { @@ -496,13 +565,20 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); break; case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); + if (!sdi) + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); + else + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); break; case SR_CONF_SAMPLERATE: + if (!sdi->priv) + return SR_ERR_ARG; + devc = sdi->priv; g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); - gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates, - ARRAY_SIZE(samplerates), sizeof(uint64_t)); + gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), devc->samplerates, + devc->num_samplerates, sizeof(uint64_t)); g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); *data = g_variant_builder_end(&gvb); break; @@ -560,7 +636,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->empty_transfer_count = 0; if ((trigger = sr_session_trigger_get(sdi->session))) { - devc->stl = soft_trigger_logic_new(sdi, trigger); + int pre_trigger_samples = 0; + if (devc->limit_samples > 0) + pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100; + devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples); + if (devc->stl == NULL) + return SR_ERR_MALLOC; devc->trigger_fired = FALSE; } else devc->trigger_fired = TRUE;