From: Gerhard Sittig Date: Fri, 15 May 2020 11:59:29 +0000 (+0200) Subject: asix-sigma: keep remaining samplerate handling in protocol.c X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=abcd47719689178ebb5e9050eb128312b17d82fa;p=libsigrok.git asix-sigma: keep remaining samplerate handling in protocol.c Make the list of supported samplerates an internal detail of the protocol.c source file. Have the api.c source file retrieve the list as well as the currently configured value by means of query routines. Ideally the current rate could get retrieved from hardware at runtime. A future driver implementation could do that. This version sticks with the lowest supported rate, as in the previous version. --- diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index a9fa7718..140cbd83 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -245,7 +245,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) /* TODO Retrieve some of this state from hardware? */ devc->firmware_idx = SIGMA_FW_NONE; - devc->samplerate = samplerates[0]; + devc->samplerate = sigma_get_samplerate(sdi); } libusb_free_device_list(devlist, 1); g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free); @@ -363,7 +363,7 @@ static int config_list(uint32_t key, GVariant **data, return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); case SR_CONF_SAMPLERATE: - *data = std_gvar_samplerates(samplerates, samplerates_count); + *data = sigma_get_samplerates_list(); break; #if ASIX_SIGMA_WITH_TRIGGER case SR_CONF_TRIGGER_MATCH: diff --git a/src/hardware/asix-sigma/protocol.c b/src/hardware/asix-sigma/protocol.c index 02b4b658..d95d95bb 100644 --- a/src/hardware/asix-sigma/protocol.c +++ b/src/hardware/asix-sigma/protocol.c @@ -37,7 +37,7 @@ * few discrete values, while setter routines accept any user specified * rate that is supported by the hardware. */ -SR_PRIV const uint64_t samplerates[] = { +static const uint64_t samplerates[] = { /* 50MHz and integer divider. 1/2/5 steps (where possible). */ SR_KHZ(200), SR_KHZ(500), SR_MHZ(1), SR_MHZ(2), SR_MHZ(5), @@ -46,7 +46,10 @@ SR_PRIV const uint64_t samplerates[] = { SR_MHZ(100), SR_MHZ(200), }; -SR_PRIV const size_t samplerates_count = ARRAY_SIZE(samplerates); +SR_PRIV GVariant *sigma_get_samplerates_list(void) +{ + return std_gvar_samplerates(samplerates, ARRAY_SIZE(samplerates)); +} static const char *firmware_files[] = { [SIGMA_FW_50MHZ] = "asix-sigma-50.fw", /* 50MHz, 8bit divider. */ @@ -964,6 +967,13 @@ SR_PRIV int sigma_normalize_samplerate(uint64_t want_rate, uint64_t *have_rate) return SR_ERR_ARG; } +SR_PRIV uint64_t sigma_get_samplerate(const struct sr_dev_inst *sdi) +{ + /* TODO Retrieve value from hardware. */ + (void)sdi; + return samplerates[0]; +} + SR_PRIV int sigma_set_samplerate(const struct sr_dev_inst *sdi) { struct dev_context *devc; diff --git a/src/hardware/asix-sigma/protocol.h b/src/hardware/asix-sigma/protocol.h index dcb6126c..e3a9d512 100644 --- a/src/hardware/asix-sigma/protocol.h +++ b/src/hardware/asix-sigma/protocol.h @@ -359,9 +359,8 @@ SR_PRIV int sigma_write_trigger_lut(struct dev_context *devc, /* Samplerate constraints check, get/set/list helpers. */ SR_PRIV int sigma_normalize_samplerate(uint64_t want_rate, uint64_t *have_rate); - -extern SR_PRIV const uint64_t samplerates[]; -extern SR_PRIV const size_t samplerates_count; +SR_PRIV uint64_t sigma_get_samplerate(const struct sr_dev_inst *sdi); +SR_PRIV GVariant *sigma_get_samplerates_list(void); /* Preparation of data acquisition, spec conversion, hardware configuration. */ SR_PRIV int sigma_set_samplerate(const struct sr_dev_inst *sdi);