2 * This file is part of the libsigrok project.
4 * Copyright (C) 2020 Florian Schmidt <schmidt_florian@gmx.de>
5 * Copyright (C) 2013 Marcus Comstedt <marcus@mc.pp.se>
6 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
7 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * This driver implementation initially was derived from the
25 * src/hardware/saleae-logic16/ source code.
30 #include <libsigrok/libsigrok.h>
33 #include "libsigrok-internal.h"
36 static const uint32_t scanopts[] = {
40 static const uint32_t drvopts[] = {
41 SR_CONF_LOGIC_ANALYZER,
42 SR_CONF_SIGNAL_GENERATOR,
45 static const uint32_t devopts[] = {
46 /* TODO: SR_CONF_CONTINUOUS, */
47 SR_CONF_CONN | SR_CONF_GET,
48 SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
49 SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
50 SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
51 SR_CONF_VOLTAGE_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
52 SR_CONF_LOGIC_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
53 SR_CONF_LOGIC_THRESHOLD_CUSTOM | SR_CONF_GET | SR_CONF_SET,
54 SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
55 SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
58 static const uint32_t devopts_cg_pwm[] = {
59 SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
60 SR_CONF_OUTPUT_FREQUENCY | SR_CONF_GET | SR_CONF_SET,
61 SR_CONF_DUTY_CYCLE | SR_CONF_GET | SR_CONF_SET,
64 static const int32_t trigger_matches[] = {
71 static const char *channel_names_logic[] = {
72 "CH0", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7",
73 "CH8", "CH9", "CH10", "CH11", "CH12", "CH13", "CH14", "CH15",
74 "CH16", "CH17", "CH18", "CH19", "CH20", "CH21", "CH22", "CH23",
75 "CH24", "CH25", "CH26", "CH27", "CH28", "CH29", "CH30", "CH31",
78 static const char *channel_names_pwm[] = {
83 * The hardware uses a 100/200/500MHz base clock (model dependent) and
84 * a 16bit divider (common across all models). The range from 10kHz to
85 * 100/200/500MHz should be applicable to all devices. High rates may
86 * suffer from coarse resolution (e.g. in the "500MHz div 2" case) and
87 * may not provide the desired 1/2/5 steps. Fortunately this exclusively
88 * affects the 500MHz model where 250MHz is used instead of 200MHz and
89 * the 166MHz and 125MHz rates are not presented to users. Deep memory
90 * of these models and hardware compression reduce the necessity to let
91 * users pick from a huge list of possible rates.
95 static const uint64_t rates_500mhz[] = {
113 static const uint64_t rates_200mhz[] = {
130 static const uint64_t rates_100mhz[] = {
146 static const float logic_threshold_value[] = {
158 static const char *logic_threshold[] = {
171 #define LOGIC_THRESHOLD_IDX_USER (ARRAY_SIZE(logic_threshold) - 1)
173 /* Convenience. Release an allocated devc from error paths. */
174 static void kingst_la2016_free_devc(struct dev_context *devc)
178 g_free(devc->mcu_firmware);
179 g_free(devc->fpga_bitstream);
183 /* Convenience. Release an allocated sdi from error paths. */
184 static void kingst_la2016_free_sdi(struct sr_dev_inst *sdi)
190 g_free(sdi->version);
191 g_free(sdi->serial_num);
192 g_free(sdi->connection_id);
193 sr_usb_dev_inst_free(sdi->conn);
194 kingst_la2016_free_devc(sdi->priv);
197 /* Convenience. Open a USB device (including claiming an interface). */
198 static int la2016_open_usb(struct sr_usb_dev_inst *usb,
199 libusb_device *dev, gboolean show_message)
203 ret = libusb_open(dev, &usb->devhdl);
206 sr_err("Cannot open device: %s.",
207 libusb_error_name(ret));
212 if (usb->address == 0xff) {
214 * First encounter after firmware upload.
215 * Grab current address after enumeration.
217 usb->address = libusb_get_device_address(dev);
220 ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
221 if (ret == LIBUSB_ERROR_BUSY) {
222 sr_err("Cannot claim USB interface. Another program or driver using it?");
224 } else if (ret == LIBUSB_ERROR_NO_DEVICE) {
225 sr_err("Device has been disconnected.");
227 } else if (ret != 0) {
228 sr_err("Cannot claim USB interface: %s.",
229 libusb_error_name(ret));
236 /* Convenience. Close an opened USB device (and release the interface). */
237 static void la2016_close_usb(struct sr_usb_dev_inst *usb)
244 libusb_release_interface(usb->devhdl, USB_INTERFACE);
245 libusb_close(usb->devhdl);
250 /* Communicate to an USB device to identify the Kingst LA model. */
251 static int la2016_identify_read(struct sr_dev_inst *sdi,
252 struct sr_usb_dev_inst *usb, libusb_device *dev,
253 gboolean show_message)
257 ret = la2016_open_usb(usb, dev, show_message);
260 sr_err("Cannot communicate to MCU firmware.");
265 * Also complete the hardware configuration (FPGA bitstream)
266 * when MCU firmware communication became operational. Either
267 * failure is considered fatal when probing for the device.
269 ret = la2016_identify_device(sdi, show_message);
271 ret = la2016_init_hardware(sdi);
274 la2016_close_usb(usb);
279 /* Find given conn_id in another USB enum. Identify Kingst LA model. */
280 static int la2016_identify_enum(struct sr_dev_inst *sdi)
282 struct sr_dev_driver *di;
283 struct drv_context *drvc;
284 struct sr_context *ctx;
285 libusb_device **devlist, *dev;
286 struct libusb_device_descriptor des;
288 size_t device_count, dev_idx;
295 ret = libusb_get_device_list(ctx->libusb_ctx, &devlist);
302 for (dev_idx = 0; dev_idx < device_count; dev_idx++) {
303 dev = devlist[dev_idx];
304 libusb_get_device_descriptor(dev, &des);
305 if (des.idVendor != LA2016_VID || des.idProduct != LA2016_PID)
307 if (des.iProduct != LA2016_IPRODUCT_INDEX)
309 ret = usb_get_port_path(dev, conn_id, sizeof(conn_id));
312 if (strcmp(sdi->connection_id, conn_id) != 0)
314 id_ret = la2016_identify_read(sdi, sdi->conn, dev, FALSE);
317 libusb_free_device_list(devlist, 1);
322 /* Wait for a device to re-appear after firmware upload. */
323 static int la2016_identify_wait(struct sr_dev_inst *sdi)
325 struct dev_context *devc;
326 uint64_t reset_done, now, elapsed_ms;
331 sr_info("Waiting for device to reset after firmware upload.");
332 now = g_get_monotonic_time();
333 reset_done = devc->fw_uploaded + RENUM_GONE_DELAY_MS * 1000;
334 if (now < reset_done)
335 g_usleep(reset_done - now);
337 now = g_get_monotonic_time();
338 elapsed_ms = (now - devc->fw_uploaded) / 1000;
339 sr_spew("Waited %" PRIu64 "ms.", elapsed_ms);
340 ret = la2016_identify_enum(sdi);
342 devc->fw_uploaded = 0;
345 g_usleep(RENUM_POLL_INTERVAL_MS * 1000);
346 } while (elapsed_ms < RENUM_CHECK_PERIOD_MS);
348 sr_err("Device failed to re-enumerate.");
351 sr_info("Device came back after %" PRIi64 "ms.", elapsed_ms);
357 * Open given conn_id from another USB enum. Used by dev_open(). Similar
358 * to, and should be kept in sync with la2016_identify_enum().
360 static int la2016_open_enum(struct sr_dev_inst *sdi)
362 struct sr_dev_driver *di;
363 struct drv_context *drvc;
364 struct sr_context *ctx;
365 libusb_device **devlist, *dev;
366 struct libusb_device_descriptor des;
368 size_t device_count, dev_idx;
375 ret = libusb_get_device_list(ctx->libusb_ctx, &devlist);
381 open_ret = SR_ERR_IO;
382 for (dev_idx = 0; dev_idx < device_count; dev_idx++) {
383 dev = devlist[dev_idx];
384 libusb_get_device_descriptor(dev, &des);
385 if (des.idVendor != LA2016_VID || des.idProduct != LA2016_PID)
387 if (des.iProduct != LA2016_IPRODUCT_INDEX)
389 ret = usb_get_port_path(dev, conn_id, sizeof(conn_id));
392 if (strcmp(sdi->connection_id, conn_id) != 0)
394 open_ret = la2016_open_usb(sdi->conn, dev, TRUE);
397 libusb_free_device_list(devlist, 1);
402 static GSList *scan(struct sr_dev_driver *di, GSList *options)
404 struct drv_context *drvc;
405 struct sr_context *ctx;
406 struct dev_context *devc;
407 struct sr_dev_inst *sdi;
408 struct sr_usb_dev_inst *usb;
409 struct sr_config *src;
411 GSList *devices, *found_devices, *renum_devices;
412 GSList *conn_devices;
413 struct libusb_device_descriptor des;
414 libusb_device **devlist, *dev;
415 size_t dev_count, dev_idx, ch_idx;
421 size_t ch_off, ch_max;
422 struct sr_channel *ch;
423 struct sr_channel_group *cg;
430 for (l = options; l; l = l->next) {
434 conn = g_variant_get_string(src->data, NULL);
439 conn_devices = sr_usb_find(ctx->libusb_ctx, conn);
440 if (conn && !conn_devices) {
441 sr_err("Cannot find the specified connection '%s'.", conn);
446 * Find all LA2016 devices, optionally upload firmware to them.
447 * Defer completion of sdi/devc creation until all (selected)
448 * devices were found in a usable state, and their models got
449 * identified which affect their feature set. It appears that
450 * we cannot communicate to the device within the same USB enum
451 * cycle, needs another USB enumeration after firmware upload.
454 found_devices = NULL;
455 renum_devices = NULL;
456 ret = libusb_get_device_list(ctx->libusb_ctx, &devlist);
458 sr_err("Cannot get device list: %s.", libusb_error_name(ret));
462 for (dev_idx = 0; dev_idx < dev_count; dev_idx++) {
463 dev = devlist[dev_idx];
464 bus = libusb_get_bus_number(dev);
465 addr = libusb_get_device_address(dev);
467 /* Filter by connection when externally specified. */
468 for (l = conn_devices; l; l = l->next) {
470 if (usb->bus == bus && usb->address == addr)
473 if (conn_devices && !l) {
474 sr_spew("Bus %hhu, addr %hhu do not match specified filter.",
479 /* Check USB VID:PID. Get the connection string. */
480 libusb_get_device_descriptor(dev, &des);
481 if (des.idVendor != LA2016_VID || des.idProduct != LA2016_PID)
484 ret = usb_get_port_path(dev, conn_id, sizeof(conn_id));
487 sr_dbg("USB enum found %04x:%04x at path %s, %d.%d.",
488 des.idVendor, des.idProduct, conn_id, bus, addr);
489 usb = sr_usb_dev_inst_new(bus, addr, NULL);
491 sdi = g_malloc0(sizeof(*sdi));
493 sdi->status = SR_ST_INITIALIZING;
494 sdi->inst_type = SR_INST_USB;
495 sdi->connection_id = g_strdup(conn_id);
498 devc = g_malloc0(sizeof(*devc));
502 * Load MCU firmware if it is currently missing. Which
503 * makes the device disappear and renumerate in USB.
504 * We need to come back another time to communicate to
507 devc->fw_uploaded = 0;
508 if (des.iProduct != LA2016_IPRODUCT_INDEX) {
509 sr_info("Uploading MCU firmware to '%s'.", conn_id);
510 ret = la2016_upload_firmware(sdi, ctx, dev, pid);
512 sr_err("MCU firmware upload failed.");
513 kingst_la2016_free_sdi(sdi);
516 devc->fw_uploaded = g_get_monotonic_time();
518 renum_devices = g_slist_append(renum_devices, sdi);
523 * Communicate to the MCU firmware to access EEPROM data
524 * which lets us identify the device type. Then stop, to
525 * share remaining sdi/devc creation with those devices
526 * which had their MCU firmware uploaded above and which
527 * get revisited later.
529 ret = la2016_identify_read(sdi, usb, dev, TRUE);
530 if (ret != SR_OK || !devc->model) {
531 sr_err("Unknown or unsupported device type.");
532 kingst_la2016_free_sdi(sdi);
535 found_devices = g_slist_append(found_devices, sdi);
537 libusb_free_device_list(devlist, 1);
538 g_slist_free_full(conn_devices, sr_usb_dev_inst_free_cb);
541 * Wait for devices to re-appear after firmware upload. Append
542 * the yet unidentified device to the list of found devices, or
543 * release the previously allocated sdi/devc.
545 for (l = renum_devices; l; l = l->next) {
548 ret = la2016_identify_wait(sdi);
549 if (ret != SR_OK || !devc->model) {
550 sr_dbg("Skipping unusable '%s'.", sdi->connection_id);
551 kingst_la2016_free_sdi(sdi);
554 found_devices = g_slist_append(found_devices, sdi);
556 g_slist_free(renum_devices);
559 * All found devices got identified, their type is known here.
560 * Complete the sdi/devc creation. Assign default settings
561 * because the vendor firmware would not let us read back the
562 * previously written configuration.
564 for (l = found_devices; l; l = l->next) {
568 sdi->vendor = g_strdup("Kingst");
569 sdi->model = g_strdup(devc->model->name);
572 /* Create the "Logic" channel group. */
573 ch_max = ARRAY_SIZE(channel_names_logic);
574 if (ch_max > devc->model->channel_count)
575 ch_max = devc->model->channel_count;
576 cg = sr_channel_group_new(sdi, "Logic", NULL);
578 for (ch_idx = 0; ch_idx < ch_max; ch_idx++) {
579 ch = sr_channel_new(sdi, ch_off,
580 SR_CHANNEL_LOGIC, TRUE,
581 channel_names_logic[ch_idx]);
583 cg->channels = g_slist_append(cg->channels, ch);
586 /* Create the "PWMx" channel groups. */
587 ch_max = ARRAY_SIZE(channel_names_pwm);
588 for (ch_idx = 0; ch_idx < ch_max; ch_idx++) {
590 name = channel_names_pwm[ch_idx];
591 cg = sr_channel_group_new(sdi, name, NULL);
594 ch = sr_channel_new(sdi, ch_off,
595 SR_CHANNEL_ANALOG, FALSE, name);
597 cg->channels = g_slist_append(cg->channels, ch);
601 * Ideally we'd get the previous configuration from the
602 * hardware, but this device is write-only. So we have
603 * to assign a fixed set of initial configuration values.
605 sr_sw_limits_init(&devc->sw_limits);
606 devc->sw_limits.limit_samples = 0;
607 devc->capture_ratio = 50;
608 devc->cur_samplerate = devc->model->samplerate;
609 devc->threshold_voltage_idx = 0;
610 devc->threshold_voltage = logic_threshold_value[devc->threshold_voltage_idx];
611 if (ARRAY_SIZE(devc->pwm_setting) >= 1) {
612 devc->pwm_setting[0].enabled = FALSE;
613 devc->pwm_setting[0].freq = SR_KHZ(1);
614 devc->pwm_setting[0].duty = 50;
616 if (ARRAY_SIZE(devc->pwm_setting) >= 2) {
617 devc->pwm_setting[1].enabled = FALSE;
618 devc->pwm_setting[1].freq = SR_KHZ(100);
619 devc->pwm_setting[1].duty = 50;
622 sdi->status = SR_ST_INACTIVE;
623 devices = g_slist_append(devices, sdi);
625 g_slist_free(found_devices);
627 return std_scan_complete(di, devices);
630 static int dev_open(struct sr_dev_inst *sdi)
632 struct dev_context *devc;
638 ret = la2016_open_enum(sdi);
640 sr_err("Cannot open device.");
644 /* Send most recent PWM configuration to the device. */
645 for (ch = 0; ch < ARRAY_SIZE(devc->pwm_setting); ch++) {
646 ret = la2016_write_pwm_config(sdi, ch);
654 static int dev_close(struct sr_dev_inst *sdi)
656 struct sr_usb_dev_inst *usb;
663 la2016_deinit_hardware(sdi);
665 sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
666 usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
667 la2016_close_usb(sdi->conn);
672 /* Config API helper. Get type and index of a channel group. */
673 static int get_cg_index(const struct sr_dev_inst *sdi,
674 const struct sr_channel_group *cg,
675 int *type, size_t *logic, size_t *analog)
677 struct dev_context *devc;
681 /* Preset return values. */
689 /* Start categorizing the received cg. */
695 l = sdi->channel_groups;
697 /* First sdi->channelgroups item is "Logic". */
702 *type = SR_CHANNEL_LOGIC;
709 /* Next sdi->channelgroups items are "PWMx". */
711 while (l && l->data != cg) {
715 if (l && idx < ARRAY_SIZE(devc->pwm_setting)) {
717 *type = SR_CHANNEL_ANALOG;
726 static int config_get(uint32_t key, GVariant **data,
727 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
729 struct dev_context *devc;
731 size_t logic_idx, analog_idx;
732 struct pwm_setting *pwm;
733 struct sr_usb_dev_inst *usb;
741 /* Check for types (and index) of channel groups. */
742 ret = get_cg_index(sdi, cg, &cg_type, &logic_idx, &analog_idx);
743 if (cg && ret != SR_OK)
746 /* Handle requests for the "Logic" channel group. */
747 if (cg && cg_type == SR_CHANNEL_LOGIC) {
752 /* Handle requests for the "PWMx" channel groups. */
753 if (cg && cg_type == SR_CHANNEL_ANALOG) {
754 pwm = &devc->pwm_setting[analog_idx];
756 case SR_CONF_ENABLED:
757 *data = g_variant_new_boolean(pwm->enabled);
759 case SR_CONF_OUTPUT_FREQUENCY:
760 *data = g_variant_new_double(pwm->freq);
762 case SR_CONF_DUTY_CYCLE:
763 *data = g_variant_new_double(pwm->duty);
774 *data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
776 case SR_CONF_SAMPLERATE:
777 *data = g_variant_new_uint64(devc->cur_samplerate);
779 case SR_CONF_LIMIT_SAMPLES:
780 case SR_CONF_LIMIT_MSEC:
781 return sr_sw_limits_config_get(&devc->sw_limits, key, data);
782 case SR_CONF_CAPTURE_RATIO:
783 *data = g_variant_new_uint64(devc->capture_ratio);
785 case SR_CONF_VOLTAGE_THRESHOLD:
786 rounded = (int)(devc->threshold_voltage / 0.1) * 0.1;
787 *data = std_gvar_tuple_double(rounded, rounded + 0.1);
789 case SR_CONF_LOGIC_THRESHOLD:
790 label = logic_threshold[devc->threshold_voltage_idx];
791 *data = g_variant_new_string(label);
793 case SR_CONF_LOGIC_THRESHOLD_CUSTOM:
794 *data = g_variant_new_double(devc->threshold_voltage);
804 static int config_set(uint32_t key, GVariant *data,
805 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
807 struct dev_context *devc;
809 size_t logic_idx, analog_idx;
810 struct pwm_setting *pwm;
817 /* Check for types (and index) of channel groups. */
818 ret = get_cg_index(sdi, cg, &cg_type, &logic_idx, &analog_idx);
819 if (cg && ret != SR_OK)
822 /* Handle requests for the "Logic" channel group. */
823 if (cg && cg_type == SR_CHANNEL_LOGIC) {
828 /* Handle requests for the "PWMx" channel groups. */
829 if (cg && cg_type == SR_CHANNEL_ANALOG) {
830 pwm = &devc->pwm_setting[analog_idx];
832 case SR_CONF_ENABLED:
833 pwm->enabled = g_variant_get_boolean(data);
834 ret = la2016_write_pwm_config(sdi, analog_idx);
838 case SR_CONF_OUTPUT_FREQUENCY:
839 value_f = g_variant_get_double(data);
840 if (value_f <= 0.0 || value_f > MAX_PWM_FREQ)
843 ret = la2016_write_pwm_config(sdi, analog_idx);
847 case SR_CONF_DUTY_CYCLE:
848 value_f = g_variant_get_double(data);
849 if (value_f <= 0.0 || value_f > 100.0)
852 ret = la2016_write_pwm_config(sdi, analog_idx);
863 case SR_CONF_SAMPLERATE:
864 devc->cur_samplerate = g_variant_get_uint64(data);
866 case SR_CONF_LIMIT_SAMPLES:
867 case SR_CONF_LIMIT_MSEC:
868 return sr_sw_limits_config_set(&devc->sw_limits, key, data);
869 case SR_CONF_CAPTURE_RATIO:
870 devc->capture_ratio = g_variant_get_uint64(data);
872 case SR_CONF_VOLTAGE_THRESHOLD:
873 g_variant_get(data, "(dd)", &low, &high);
874 devc->threshold_voltage = (low + high) / 2.0;
875 devc->threshold_voltage_idx = LOGIC_THRESHOLD_IDX_USER;
877 case SR_CONF_LOGIC_THRESHOLD: {
878 idx = std_str_idx(data, ARRAY_AND_SIZE(logic_threshold));
881 if (idx != LOGIC_THRESHOLD_IDX_USER) {
882 devc->threshold_voltage = logic_threshold_value[idx];
884 devc->threshold_voltage_idx = idx;
887 case SR_CONF_LOGIC_THRESHOLD_CUSTOM:
888 devc->threshold_voltage = g_variant_get_double(data);
897 static int config_list(uint32_t key, GVariant **data,
898 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
900 struct dev_context *devc;
902 size_t logic_idx, analog_idx;
904 devc = sdi ? sdi->priv : NULL;
906 /* Check for types (and index) of channel groups. */
907 ret = get_cg_index(sdi, cg, &cg_type, &logic_idx, &analog_idx);
908 if (cg && ret != SR_OK)
911 /* Handle requests for the "Logic" channel group. */
912 if (cg && cg_type == SR_CHANNEL_LOGIC) {
917 /* Handle requests for the "PWMx" channel groups. */
918 if (cg && cg_type == SR_CHANNEL_ANALOG) {
920 case SR_CONF_DEVICE_OPTIONS:
921 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
922 devopts_cg_pwm, ARRAY_SIZE(devopts_cg_pwm),
923 sizeof(devopts_cg_pwm[0]));
932 case SR_CONF_SCAN_OPTIONS:
933 case SR_CONF_DEVICE_OPTIONS:
934 return STD_CONFIG_LIST(key, data, sdi, cg,
935 scanopts, drvopts, devopts);
936 case SR_CONF_SAMPLERATE:
939 if (devc->model->samplerate == SR_MHZ(500))
940 *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_500mhz));
941 else if (devc->model->samplerate == SR_MHZ(200))
942 *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_200mhz));
944 *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_100mhz));
946 case SR_CONF_LIMIT_SAMPLES:
947 *data = std_gvar_tuple_u64(0, LA2016_NUM_SAMPLES_MAX);
949 case SR_CONF_VOLTAGE_THRESHOLD:
950 *data = std_gvar_min_max_step_thresholds(
951 LA2016_THR_VOLTAGE_MIN,
952 LA2016_THR_VOLTAGE_MAX, 0.1);
954 case SR_CONF_TRIGGER_MATCH:
955 *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
957 case SR_CONF_LOGIC_THRESHOLD:
958 *data = g_variant_new_strv(ARRAY_AND_SIZE(logic_threshold));
967 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
969 struct sr_dev_driver *di;
970 struct drv_context *drvc;
971 struct sr_context *ctx;
972 struct dev_context *devc;
980 if (!devc->feed_queue) {
981 devc->feed_queue = feed_queue_logic_alloc(sdi,
982 LA2016_CONVBUFFER_SIZE, sizeof(uint16_t));
983 if (!devc->feed_queue) {
984 sr_err("Cannot allocate buffer for session feed.");
985 return SR_ERR_MALLOC;
989 sr_sw_limits_acquisition_start(&devc->sw_limits);
991 ret = la2016_setup_acquisition(sdi);
993 feed_queue_logic_free(devc->feed_queue);
994 devc->feed_queue = NULL;
998 ret = la2016_start_acquisition(sdi);
1000 la2016_abort_acquisition(sdi);
1001 feed_queue_logic_free(devc->feed_queue);
1002 devc->feed_queue = NULL;
1006 devc->completion_seen = FALSE;
1007 usb_source_add(sdi->session, ctx, 50,
1008 la2016_receive_data, (void *)sdi);
1010 std_session_send_df_header(sdi);
1015 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
1019 ret = la2016_abort_acquisition(sdi);
1024 static struct sr_dev_driver kingst_la2016_driver_info = {
1025 .name = "kingst-la2016",
1026 .longname = "Kingst LA2016",
1029 .cleanup = std_cleanup,
1031 .dev_list = std_dev_list,
1032 .dev_clear = std_dev_clear,
1033 .config_get = config_get,
1034 .config_set = config_set,
1035 .config_list = config_list,
1036 .dev_open = dev_open,
1037 .dev_close = dev_close,
1038 .dev_acquisition_start = dev_acquisition_start,
1039 .dev_acquisition_stop = dev_acquisition_stop,
1042 SR_REGISTER_DEV_DRIVER(kingst_la2016_driver_info);