2 * This file is part of the libsigrok project.
4 * Copyright (C) 2022 Gerhard Sittig <gerhard.sittig@gmx.net>
5 * Copyright (C) 2020 Florian Schmidt <schmidt_florian@gmx.de>
6 * Copyright (C) 2013 Marcus Comstedt <marcus@mc.pp.se>
7 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
8 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * This driver implementation initially was derived from the
26 * src/hardware/saleae-logic16/ source code.
31 #include <libsigrok/libsigrok.h>
34 #include "libsigrok-internal.h"
37 static const uint32_t scanopts[] = {
42 static const uint32_t drvopts[] = {
43 SR_CONF_LOGIC_ANALYZER,
44 SR_CONF_SIGNAL_GENERATOR,
47 static const uint32_t devopts[] = {
48 SR_CONF_CONN | SR_CONF_GET,
49 SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
50 SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
51 SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
52 #if WITH_THRESHOLD_DEVCFG
53 SR_CONF_VOLTAGE_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
55 SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
56 SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
57 SR_CONF_CONTINUOUS | SR_CONF_GET | SR_CONF_SET,
60 static const uint32_t devopts_cg_logic[] = {
61 #if !WITH_THRESHOLD_DEVCFG
62 SR_CONF_VOLTAGE_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
66 static const uint32_t devopts_cg_pwm[] = {
67 SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
68 SR_CONF_OUTPUT_FREQUENCY | SR_CONF_GET | SR_CONF_SET,
69 SR_CONF_DUTY_CYCLE | SR_CONF_GET | SR_CONF_SET,
72 static const int32_t trigger_matches[] = {
79 static const char *channel_names_logic[] = {
80 "CH0", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7",
81 "CH8", "CH9", "CH10", "CH11", "CH12", "CH13", "CH14", "CH15",
82 "CH16", "CH17", "CH18", "CH19", "CH20", "CH21", "CH22", "CH23",
83 "CH24", "CH25", "CH26", "CH27", "CH28", "CH29", "CH30", "CH31",
86 static const char *channel_names_pwm[] = {
91 * The devices have an upper samplerate limit of 100/200/500 MHz each.
92 * But their hardware uses different base clocks (100/200/800MHz, this
93 * is _not_ a typo) and a 16bit divider. Which results in per-model ranges
94 * of supported rates which not only differ in the upper boundary, but
95 * also at the lower boundary. It's assumed that the 10kHz rate is not
96 * useful enough to provide by all means. Starting at 20kHz for all models
97 * simplfies the implementation of the config API routines, and eliminates
98 * redundancy in these samplerates tables.
100 * Streaming mode is constrained by the channel count and samplerate
101 * product (the bits per second which need to travel the USB connection
102 * while the acquisition is executing). Because streaming mode does not
103 * compress the capture data, a later implementation may desire a finer
104 * resolution. For now let's just stick with the 1/2/5 steps.
107 static const uint64_t rates_500mhz[] = {
124 static const uint64_t rates_200mhz[] = {
140 static const uint64_t rates_100mhz[] = {
156 * Only list a few discrete voltages, to form a useful set which covers
157 * most logic families. Too many choices can make some applications use
158 * a slider again. Which may lack a scale for the current value, and
159 * leave users without feedback what the currently used value might be.
161 static const double threshold_ranges[][2] = {
166 { 1.4, 1.4, }, /* Default, 1.4V, index 4. */
171 #define LOGIC_THRESHOLD_IDX_DFLT 4
173 static double threshold_voltage(const struct sr_dev_inst *sdi, double *high)
175 struct dev_context *devc;
180 idx = devc->threshold_voltage_idx;
181 voltage = threshold_ranges[idx][0];
183 *high = threshold_ranges[idx][1];
188 /* Convenience. Release an allocated devc from error paths. */
189 static void kingst_la2016_free_devc(struct dev_context *devc)
193 g_free(devc->mcu_firmware);
194 g_free(devc->fpga_bitstream);
198 /* Convenience. Release an allocated sdi from error paths. */
199 static void kingst_la2016_free_sdi(struct sr_dev_inst *sdi)
205 g_free(sdi->version);
206 g_free(sdi->serial_num);
207 g_free(sdi->connection_id);
208 sr_usb_dev_inst_free(sdi->conn);
209 kingst_la2016_free_devc(sdi->priv);
212 /* Convenience. Open a USB device (including claiming an interface). */
213 static int la2016_open_usb(struct sr_usb_dev_inst *usb,
214 libusb_device *dev, gboolean show_message)
218 ret = libusb_open(dev, &usb->devhdl);
221 sr_err("Cannot open device: %s.",
222 libusb_error_name(ret));
227 if (usb->address == 0xff) {
229 * First encounter after firmware upload.
230 * Grab current address after enumeration.
232 usb->address = libusb_get_device_address(dev);
235 ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
236 if (ret == LIBUSB_ERROR_BUSY) {
237 sr_err("Cannot claim USB interface. Another program or driver using it?");
239 } else if (ret == LIBUSB_ERROR_NO_DEVICE) {
240 sr_err("Device has been disconnected.");
242 } else if (ret != 0) {
243 sr_err("Cannot claim USB interface: %s.",
244 libusb_error_name(ret));
251 /* Convenience. Close an opened USB device (and release the interface). */
252 static void la2016_close_usb(struct sr_usb_dev_inst *usb)
259 libusb_release_interface(usb->devhdl, USB_INTERFACE);
260 libusb_close(usb->devhdl);
265 /* Communicate to an USB device to identify the Kingst LA model. */
266 static int la2016_identify_read(struct sr_dev_inst *sdi,
267 struct sr_usb_dev_inst *usb, libusb_device *dev,
268 gboolean show_message)
272 ret = la2016_open_usb(usb, dev, show_message);
275 sr_err("Cannot communicate to MCU firmware.");
280 * Also complete the hardware configuration (FPGA bitstream)
281 * when MCU firmware communication became operational. Either
282 * failure is considered fatal when probing for the device.
284 ret = la2016_identify_device(sdi, show_message);
286 ret = la2016_init_hardware(sdi);
289 la2016_close_usb(usb);
294 /* Find given conn_id in another USB enum. Identify Kingst LA model. */
295 static int la2016_identify_enum(struct sr_dev_inst *sdi)
297 struct sr_dev_driver *di;
298 struct drv_context *drvc;
299 struct sr_context *ctx;
300 libusb_device **devlist, *dev;
301 struct libusb_device_descriptor des;
303 size_t device_count, dev_idx;
310 ret = libusb_get_device_list(ctx->libusb_ctx, &devlist);
317 for (dev_idx = 0; dev_idx < device_count; dev_idx++) {
318 dev = devlist[dev_idx];
319 libusb_get_device_descriptor(dev, &des);
320 if (des.idVendor != LA2016_VID || des.idProduct != LA2016_PID)
322 if (des.iProduct != LA2016_IPRODUCT_INDEX)
324 ret = usb_get_port_path(dev, conn_id, sizeof(conn_id));
327 if (strcmp(sdi->connection_id, conn_id) != 0)
329 id_ret = la2016_identify_read(sdi, sdi->conn, dev, FALSE);
332 libusb_free_device_list(devlist, 1);
337 /* Wait for a device to re-appear after firmware upload. */
338 static int la2016_identify_wait(struct sr_dev_inst *sdi)
340 struct dev_context *devc;
341 uint64_t reset_done, now, elapsed_ms;
346 sr_info("Waiting for device to reset after firmware upload.");
347 now = g_get_monotonic_time();
348 reset_done = devc->fw_uploaded + RENUM_GONE_DELAY_MS * 1000;
349 if (now < reset_done)
350 g_usleep(reset_done - now);
352 now = g_get_monotonic_time();
353 elapsed_ms = (now - devc->fw_uploaded) / 1000;
354 sr_spew("Waited %" PRIu64 "ms.", elapsed_ms);
355 ret = la2016_identify_enum(sdi);
357 devc->fw_uploaded = 0;
360 g_usleep(RENUM_POLL_INTERVAL_MS * 1000);
361 } while (elapsed_ms < RENUM_CHECK_PERIOD_MS);
363 sr_err("Device failed to re-enumerate.");
366 sr_info("Device came back after %" PRIi64 "ms.", elapsed_ms);
372 * Open given conn_id from another USB enum. Used by dev_open(). Similar
373 * to, and should be kept in sync with la2016_identify_enum().
375 static int la2016_open_enum(struct sr_dev_inst *sdi)
377 struct sr_dev_driver *di;
378 struct drv_context *drvc;
379 struct sr_context *ctx;
380 libusb_device **devlist, *dev;
381 struct libusb_device_descriptor des;
383 size_t device_count, dev_idx;
390 ret = libusb_get_device_list(ctx->libusb_ctx, &devlist);
396 open_ret = SR_ERR_IO;
397 for (dev_idx = 0; dev_idx < device_count; dev_idx++) {
398 dev = devlist[dev_idx];
399 libusb_get_device_descriptor(dev, &des);
400 if (des.idVendor != LA2016_VID || des.idProduct != LA2016_PID)
402 if (des.iProduct != LA2016_IPRODUCT_INDEX)
404 ret = usb_get_port_path(dev, conn_id, sizeof(conn_id));
407 if (strcmp(sdi->connection_id, conn_id) != 0)
409 open_ret = la2016_open_usb(sdi->conn, dev, TRUE);
412 libusb_free_device_list(devlist, 1);
417 static GSList *scan(struct sr_dev_driver *di, GSList *options)
419 struct drv_context *drvc;
420 struct sr_context *ctx;
421 struct dev_context *devc;
422 struct sr_dev_inst *sdi;
423 struct sr_usb_dev_inst *usb;
424 struct sr_config *src;
426 GSList *devices, *found_devices, *renum_devices;
427 GSList *conn_devices;
428 struct libusb_device_descriptor des;
429 libusb_device **devlist, *dev;
430 size_t dev_count, dev_idx, ch_idx;
434 const char *probe_names;
437 size_t ch_off, ch_max;
438 struct sr_channel *ch;
439 struct sr_channel_group *cg;
447 for (l = options; l; l = l->next) {
451 conn = g_variant_get_string(src->data, NULL);
453 case SR_CONF_PROBE_NAMES:
454 probe_names = g_variant_get_string(src->data, NULL);
459 conn_devices = sr_usb_find(ctx->libusb_ctx, conn);
460 if (conn && !conn_devices) {
461 sr_err("Cannot find the specified connection '%s'.", conn);
466 * Find all LA2016 devices, optionally upload firmware to them.
467 * Defer completion of sdi/devc creation until all (selected)
468 * devices were found in a usable state, and their models got
469 * identified which affect their feature set. It appears that
470 * we cannot communicate to the device within the same USB enum
471 * cycle, needs another USB enumeration after firmware upload.
474 found_devices = NULL;
475 renum_devices = NULL;
476 ret = libusb_get_device_list(ctx->libusb_ctx, &devlist);
478 sr_err("Cannot get device list: %s.", libusb_error_name(ret));
482 for (dev_idx = 0; dev_idx < dev_count; dev_idx++) {
483 dev = devlist[dev_idx];
484 bus = libusb_get_bus_number(dev);
485 addr = libusb_get_device_address(dev);
487 /* Filter by connection when externally specified. */
488 for (l = conn_devices; l; l = l->next) {
490 if (usb->bus == bus && usb->address == addr)
493 if (conn_devices && !l) {
494 sr_spew("Bus %hhu, addr %hhu do not match specified filter.",
499 /* Check USB VID:PID. Get the connection string. */
500 libusb_get_device_descriptor(dev, &des);
501 if (des.idVendor != LA2016_VID || des.idProduct != LA2016_PID)
504 ret = usb_get_port_path(dev, conn_id, sizeof(conn_id));
507 sr_dbg("USB enum found %04x:%04x at path %s, %d.%d.",
508 des.idVendor, des.idProduct, conn_id, bus, addr);
509 usb = sr_usb_dev_inst_new(bus, addr, NULL);
511 sdi = g_malloc0(sizeof(*sdi));
513 sdi->status = SR_ST_INITIALIZING;
514 sdi->inst_type = SR_INST_USB;
515 sdi->connection_id = g_strdup(conn_id);
518 devc = g_malloc0(sizeof(*devc));
522 * Load MCU firmware if it is currently missing. Which
523 * makes the device disappear and renumerate in USB.
524 * We need to come back another time to communicate to
527 devc->fw_uploaded = 0;
529 if (des.iProduct != LA2016_IPRODUCT_INDEX) {
530 sr_info("Uploading MCU firmware to '%s'.", conn_id);
531 ret = la2016_upload_firmware(sdi, ctx, dev, FALSE);
533 sr_err("MCU firmware upload failed.");
534 kingst_la2016_free_sdi(sdi);
537 devc->fw_uploaded = g_get_monotonic_time();
539 renum_devices = g_slist_append(renum_devices, sdi);
542 ret = la2016_upload_firmware(sdi, NULL, NULL, TRUE);
544 sr_err("MCU firmware filename check failed.");
545 kingst_la2016_free_sdi(sdi);
551 * Communicate to the MCU firmware to access EEPROM data
552 * which lets us identify the device type. Then stop, to
553 * share remaining sdi/devc creation with those devices
554 * which had their MCU firmware uploaded above and which
555 * get revisited later.
557 ret = la2016_identify_read(sdi, usb, dev, TRUE);
558 if (ret != SR_OK || !devc->model) {
559 sr_err("Unknown or unsupported device type.");
560 kingst_la2016_free_sdi(sdi);
563 found_devices = g_slist_append(found_devices, sdi);
565 libusb_free_device_list(devlist, 1);
566 g_slist_free_full(conn_devices, sr_usb_dev_inst_free_cb);
569 * Wait for devices to re-appear after firmware upload. Append
570 * the yet unidentified device to the list of found devices, or
571 * release the previously allocated sdi/devc.
573 for (l = renum_devices; l; l = l->next) {
576 ret = la2016_identify_wait(sdi);
577 if (ret != SR_OK || !devc->model) {
578 sr_dbg("Skipping unusable '%s'.", sdi->connection_id);
579 kingst_la2016_free_sdi(sdi);
582 found_devices = g_slist_append(found_devices, sdi);
584 g_slist_free(renum_devices);
587 * All found devices got identified, their type is known here.
588 * Complete the sdi/devc creation. Assign default settings
589 * because the vendor firmware would not let us read back the
590 * previously written configuration.
592 for (l = found_devices; l; l = l->next) {
596 sdi->vendor = g_strdup("Kingst");
597 sdi->model = g_strdup(devc->model->name);
600 /* Create the "Logic" channel group. */
601 ch_max = ARRAY_SIZE(channel_names_logic);
602 if (ch_max > devc->model->channel_count)
603 ch_max = devc->model->channel_count;
604 devc->channel_names_logic = sr_parse_probe_names(probe_names,
605 channel_names_logic, ch_max, ch_max, &ch_max);
606 cg = sr_channel_group_new(sdi, "Logic", NULL);
608 for (ch_idx = 0; ch_idx < ch_max; ch_idx++) {
609 ch = sr_channel_new(sdi, ch_off,
610 SR_CHANNEL_LOGIC, TRUE,
611 devc->channel_names_logic[ch_idx]);
613 cg->channels = g_slist_append(cg->channels, ch);
616 /* Create the "PWMx" channel groups. */
617 ch_max = ARRAY_SIZE(channel_names_pwm);
618 for (ch_idx = 0; ch_idx < ch_max; ch_idx++) {
620 name = channel_names_pwm[ch_idx];
621 cg = sr_channel_group_new(sdi, name, NULL);
624 ch = sr_channel_new(sdi, ch_off,
625 SR_CHANNEL_ANALOG, FALSE, name);
627 cg->channels = g_slist_append(cg->channels, ch);
631 * Ideally we'd get the previous configuration from the
632 * hardware, but this device is write-only. So we have
633 * to assign a fixed set of initial configuration values.
635 sr_sw_limits_init(&devc->sw_limits);
636 devc->sw_limits.limit_samples = 0;
637 devc->capture_ratio = 50;
638 devc->samplerate = devc->model->samplerate;
639 if (!devc->model->memory_bits)
640 devc->continuous = TRUE;
641 devc->threshold_voltage_idx = LOGIC_THRESHOLD_IDX_DFLT;
642 if (ARRAY_SIZE(devc->pwm_setting) >= 1) {
643 devc->pwm_setting[0].enabled = FALSE;
644 devc->pwm_setting[0].freq = SR_KHZ(1);
645 devc->pwm_setting[0].duty = 50;
647 if (ARRAY_SIZE(devc->pwm_setting) >= 2) {
648 devc->pwm_setting[1].enabled = FALSE;
649 devc->pwm_setting[1].freq = SR_KHZ(100);
650 devc->pwm_setting[1].duty = 50;
653 sdi->status = SR_ST_INACTIVE;
654 devices = g_slist_append(devices, sdi);
656 g_slist_free(found_devices);
658 return std_scan_complete(di, devices);
661 static int dev_open(struct sr_dev_inst *sdi)
663 struct dev_context *devc;
669 ret = la2016_open_enum(sdi);
671 sr_err("Cannot open device.");
675 /* Send most recent PWM configuration to the device. */
676 for (ch = 0; ch < ARRAY_SIZE(devc->pwm_setting); ch++) {
677 ret = la2016_write_pwm_config(sdi, ch);
685 static int dev_close(struct sr_dev_inst *sdi)
687 struct sr_usb_dev_inst *usb;
694 la2016_release_resources(sdi);
696 if (WITH_DEINIT_IN_CLOSE)
697 la2016_deinit_hardware(sdi);
699 sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
700 usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
701 la2016_close_usb(sdi->conn);
706 /* Config API helper. Get type and index of a channel group. */
707 static int get_cg_index(const struct sr_dev_inst *sdi,
708 const struct sr_channel_group *cg,
709 int *type, size_t *logic, size_t *analog)
711 struct dev_context *devc;
715 /* Preset return values. */
723 /* Start categorizing the received cg. */
729 l = sdi->channel_groups;
731 /* First sdi->channelgroups item is "Logic". */
736 *type = SR_CHANNEL_LOGIC;
743 /* Next sdi->channelgroups items are "PWMx". */
745 while (l && l->data != cg) {
749 if (l && idx < ARRAY_SIZE(devc->pwm_setting)) {
751 *type = SR_CHANNEL_ANALOG;
760 static int config_get(uint32_t key, GVariant **data,
761 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
763 struct dev_context *devc;
765 size_t logic_idx, analog_idx;
766 struct pwm_setting *pwm;
767 struct sr_usb_dev_inst *usb;
768 double voltage, rounded;
777 /* Check for types (and index) of channel groups. */
778 ret = get_cg_index(sdi, cg, &cg_type, &logic_idx, &analog_idx);
779 if (cg && ret != SR_OK)
782 /* Handle requests for the "Logic" channel group. */
783 if (cg && cg_type == SR_CHANNEL_LOGIC) {
785 #if !WITH_THRESHOLD_DEVCFG
786 case SR_CONF_VOLTAGE_THRESHOLD:
787 voltage = threshold_voltage(sdi, NULL);
788 *data = std_gvar_tuple_double(voltage, voltage);
790 #endif /* WITH_THRESHOLD_DEVCFG */
797 /* Handle requests for the "PWMx" channel groups. */
798 if (cg && cg_type == SR_CHANNEL_ANALOG) {
799 pwm = &devc->pwm_setting[analog_idx];
801 case SR_CONF_ENABLED:
802 *data = g_variant_new_boolean(pwm->enabled);
804 case SR_CONF_OUTPUT_FREQUENCY:
805 *data = g_variant_new_double(pwm->freq);
807 case SR_CONF_DUTY_CYCLE:
808 *data = g_variant_new_double(pwm->duty);
819 *data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
821 case SR_CONF_SAMPLERATE:
822 *data = g_variant_new_uint64(devc->samplerate);
824 case SR_CONF_LIMIT_SAMPLES:
825 case SR_CONF_LIMIT_MSEC:
826 return sr_sw_limits_config_get(&devc->sw_limits, key, data);
827 case SR_CONF_CAPTURE_RATIO:
828 *data = g_variant_new_uint64(devc->capture_ratio);
830 #if WITH_THRESHOLD_DEVCFG
831 case SR_CONF_VOLTAGE_THRESHOLD:
832 voltage = threshold_voltage(sdi, NULL);
833 *data = std_gvar_tuple_double(voltage, voltage);
835 #endif /* WITH_THRESHOLD_DEVCFG */
836 case SR_CONF_CONTINUOUS:
837 *data = g_variant_new_boolean(devc->continuous);
846 static int config_set(uint32_t key, GVariant *data,
847 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
849 struct dev_context *devc;
851 size_t logic_idx, analog_idx;
852 struct pwm_setting *pwm;
859 /* Check for types (and index) of channel groups. */
860 ret = get_cg_index(sdi, cg, &cg_type, &logic_idx, &analog_idx);
861 if (cg && ret != SR_OK)
864 /* Handle requests for the "Logic" channel group. */
865 if (cg && cg_type == SR_CHANNEL_LOGIC) {
867 #if !WITH_THRESHOLD_DEVCFG
868 case SR_CONF_LOGIC_THRESHOLD:
869 idx = std_double_tuple_idx(data,
870 ARRAY_AND_SIZE(threshold_ranges));
873 devc->threshold_voltage_idx = idx;
875 #endif /* WITH_THRESHOLD_DEVCFG */
882 /* Handle requests for the "PWMx" channel groups. */
883 if (cg && cg_type == SR_CHANNEL_ANALOG) {
884 pwm = &devc->pwm_setting[analog_idx];
886 case SR_CONF_ENABLED:
887 pwm->enabled = g_variant_get_boolean(data);
888 ret = la2016_write_pwm_config(sdi, analog_idx);
892 case SR_CONF_OUTPUT_FREQUENCY:
893 value_f = g_variant_get_double(data);
894 if (value_f <= 0.0 || value_f > MAX_PWM_FREQ)
897 ret = la2016_write_pwm_config(sdi, analog_idx);
901 case SR_CONF_DUTY_CYCLE:
902 value_f = g_variant_get_double(data);
903 if (value_f <= 0.0 || value_f > 100.0)
906 ret = la2016_write_pwm_config(sdi, analog_idx);
917 case SR_CONF_SAMPLERATE:
918 devc->samplerate = g_variant_get_uint64(data);
920 case SR_CONF_LIMIT_SAMPLES:
921 case SR_CONF_LIMIT_MSEC:
922 return sr_sw_limits_config_set(&devc->sw_limits, key, data);
923 case SR_CONF_CAPTURE_RATIO:
924 devc->capture_ratio = g_variant_get_uint64(data);
926 #if WITH_THRESHOLD_DEVCFG
927 case SR_CONF_VOLTAGE_THRESHOLD:
928 idx = std_double_tuple_idx(data,
929 ARRAY_AND_SIZE(threshold_ranges));
932 devc->threshold_voltage_idx = idx;
934 #endif /* WITH_THRESHOLD_DEVCFG */
935 case SR_CONF_CONTINUOUS:
936 on = g_variant_get_boolean(data);
937 if (!devc->model->memory_bits && !on)
939 devc->continuous = on;
948 static int config_list(uint32_t key, GVariant **data,
949 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
951 struct dev_context *devc;
953 size_t logic_idx, analog_idx;
955 devc = sdi ? sdi->priv : NULL;
957 /* Check for types (and index) of channel groups. */
958 ret = get_cg_index(sdi, cg, &cg_type, &logic_idx, &analog_idx);
959 if (cg && ret != SR_OK)
962 /* Handle requests for the "Logic" channel group. */
963 if (cg && cg_type == SR_CHANNEL_LOGIC) {
965 case SR_CONF_DEVICE_OPTIONS:
966 if (ARRAY_SIZE(devopts_cg_logic) == 0)
968 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
969 devopts_cg_logic, ARRAY_SIZE(devopts_cg_logic),
970 sizeof(devopts_cg_logic[0]));
972 #if !WITH_THRESHOLD_DEVCFG
973 case SR_CONF_VOLTAGE_THRESHOLD:
974 *data = std_gvar_thresholds(ARRAY_AND_SIZE(threshold_ranges));
976 #endif /* WITH_THRESHOLD_DEVCFG */
983 /* Handle requests for the "PWMx" channel groups. */
984 if (cg && cg_type == SR_CHANNEL_ANALOG) {
986 case SR_CONF_DEVICE_OPTIONS:
987 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
988 devopts_cg_pwm, ARRAY_SIZE(devopts_cg_pwm),
989 sizeof(devopts_cg_pwm[0]));
998 case SR_CONF_SCAN_OPTIONS:
999 case SR_CONF_DEVICE_OPTIONS:
1000 return STD_CONFIG_LIST(key, data, sdi, cg,
1001 scanopts, drvopts, devopts);
1002 case SR_CONF_SAMPLERATE:
1005 if (devc->model->samplerate == SR_MHZ(500))
1006 *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_500mhz));
1007 else if (devc->model->samplerate == SR_MHZ(200))
1008 *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_200mhz));
1009 else if (devc->model->samplerate == SR_MHZ(100))
1010 *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_100mhz));
1014 case SR_CONF_LIMIT_SAMPLES:
1015 *data = std_gvar_tuple_u64(0, LA2016_NUM_SAMPLES_MAX);
1017 #if WITH_THRESHOLD_DEVCFG
1018 case SR_CONF_VOLTAGE_THRESHOLD:
1019 *data = std_gvar_thresholds(ARRAY_AND_SIZE(threshold_ranges));
1021 #endif /* WITH_THRESHOLD_DEVCFG */
1022 case SR_CONF_TRIGGER_MATCH:
1023 *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
1032 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
1034 struct sr_dev_driver *di;
1035 struct drv_context *drvc;
1036 struct sr_context *ctx;
1037 struct dev_context *devc;
1038 size_t unitsize, xfersize, repsize, seqsize;
1044 ctx = drvc->sr_ctx;;
1047 if (!devc->feed_queue) {
1050 * Move this into protocol.c which concentrates the
1051 * wire format. The api.c source should not bother.
1053 if (devc->model->channel_count == 32) {
1054 unitsize = sizeof(uint32_t);
1055 repsize = sizeof(uint8_t);
1056 seqsize = 2 * sizeof(uint8_t);
1058 } else if (devc->model->channel_count == 16) {
1059 unitsize = sizeof(uint16_t);
1060 repsize = sizeof(uint8_t);
1061 seqsize = 1 * sizeof(uint8_t);
1066 devc->feed_queue = feed_queue_logic_alloc(sdi,
1067 LA2016_CONVBUFFER_SIZE, unitsize);
1068 if (!devc->feed_queue) {
1069 sr_err("Cannot allocate buffer for session feed.");
1070 return SR_ERR_MALLOC;
1072 devc->transfer_size = xfersize;
1073 devc->sequence_size = seqsize;
1074 devc->packets_per_chunk = xfersize;
1075 devc->packets_per_chunk -= seqsize;
1076 devc->packets_per_chunk /= unitsize + repsize;
1079 sr_sw_limits_acquisition_start(&devc->sw_limits);
1081 voltage = threshold_voltage(sdi, NULL);
1082 ret = la2016_setup_acquisition(sdi, voltage);
1084 feed_queue_logic_free(devc->feed_queue);
1085 devc->feed_queue = NULL;
1089 ret = la2016_start_acquisition(sdi);
1091 la2016_abort_acquisition(sdi);
1092 feed_queue_logic_free(devc->feed_queue);
1093 devc->feed_queue = NULL;
1097 devc->completion_seen = FALSE;
1098 usb_source_add(sdi->session, ctx, 50,
1099 la2016_receive_data, (void *)sdi);
1101 std_session_send_df_header(sdi);
1106 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
1110 ret = la2016_abort_acquisition(sdi);
1115 static struct sr_dev_driver kingst_la2016_driver_info = {
1116 .name = "kingst-la2016",
1117 .longname = "Kingst LA2016",
1120 .cleanup = std_cleanup,
1122 .dev_list = std_dev_list,
1123 .dev_clear = std_dev_clear,
1124 .config_get = config_get,
1125 .config_set = config_set,
1126 .config_list = config_list,
1127 .dev_open = dev_open,
1128 .dev_close = dev_close,
1129 .dev_acquisition_start = dev_acquisition_start,
1130 .dev_acquisition_stop = dev_acquisition_stop,
1133 SR_REGISTER_DEV_DRIVER(kingst_la2016_driver_info);