]> sigrok.org Git - libsigrok.git/blob - src/hardware/kingst-la2016/api.c
kingst-la2016: rephrase samplerate list code path, prepare 500MHz
[libsigrok.git] / src / hardware / kingst-la2016 / api.c
1 /*
2  * This file is part of the libsigrok project.
3  *
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>
8  *
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.
13  *
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.
18  *
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/>.
21  */
22
23 /*
24  * This driver implementation initially was derived from the
25  * src/hardware/saleae-logic16/ source code.
26  */
27
28 #include <config.h>
29
30 #include <libsigrok/libsigrok.h>
31 #include <string.h>
32
33 #include "libsigrok-internal.h"
34 #include "protocol.h"
35
36 /*
37  * Default device configuration. Must be applicable to any of the
38  * supported devices (no model specific default values yet). Specific
39  * firmware implementation details unfortunately won't let us detect
40  * and keep using previously configured values.
41  */
42 #define LA2016_DFLT_SAMPLERATE  SR_MHZ(100)
43 #define LA2016_DFLT_SAMPLEDEPTH (5 * 1000 * 1000)
44 #define LA2016_DFLT_CAPT_RATIO  5 /* Capture ratio, in percent. */
45
46 static const uint32_t scanopts[] = {
47         SR_CONF_CONN,
48 };
49
50 static const uint32_t drvopts[] = {
51         SR_CONF_LOGIC_ANALYZER,
52 };
53
54 static const uint32_t devopts[] = {
55         /* TODO: SR_CONF_CONTINUOUS, */
56         SR_CONF_CONN | SR_CONF_GET,
57         SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
58         SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
59         SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
60         SR_CONF_VOLTAGE_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
61         SR_CONF_LOGIC_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
62         SR_CONF_LOGIC_THRESHOLD_CUSTOM | SR_CONF_GET | SR_CONF_SET,
63         SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
64         SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
65 };
66
67 static const int32_t trigger_matches[] = {
68         SR_TRIGGER_ZERO,
69         SR_TRIGGER_ONE,
70         SR_TRIGGER_RISING,
71         SR_TRIGGER_FALLING,
72 };
73
74 static const char *channel_names[] = {
75         "CH0", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7",
76         "CH8", "CH9", "CH10", "CH11", "CH12", "CH13", "CH14", "CH15",
77 };
78
79 /*
80  * The hardware uses a 100/200/500MHz base clock (model dependent) and
81  * a 16bit divider (common across all models). The range from 10kHz to
82  * 100/200/500MHz should be applicable to all devices. High rates may
83  * suffer from coarse resolution (e.g. in the "500MHz div 2" case) and
84  * may not provide the desired 1/2/5 steps. Fortunately this exclusively
85  * affects the 500MHz model where 250MHz is used instead of 200MHz and
86  * the 166MHz and 125MHz rates are not presented to users. Deep memory
87  * of these models and hardware compression reduce the necessity to let
88  * users pick from a huge list of possible rates.
89  *
90  */
91
92 static const uint64_t rates_500mhz[] = {
93         SR_KHZ(10),
94         SR_KHZ(20),
95         SR_KHZ(50),
96         SR_KHZ(100),
97         SR_KHZ(200),
98         SR_KHZ(500),
99         SR_MHZ(1),
100         SR_MHZ(2),
101         SR_MHZ(5),
102         SR_MHZ(10),
103         SR_MHZ(20),
104         SR_MHZ(50),
105         SR_MHZ(100),
106         SR_MHZ(250),
107         SR_MHZ(500),
108 };
109
110 static const uint64_t rates_200mhz[] = {
111         SR_KHZ(10),
112         SR_KHZ(20),
113         SR_KHZ(50),
114         SR_KHZ(100),
115         SR_KHZ(200),
116         SR_KHZ(500),
117         SR_MHZ(1),
118         SR_MHZ(2),
119         SR_MHZ(5),
120         SR_MHZ(10),
121         SR_MHZ(20),
122         SR_MHZ(50),
123         SR_MHZ(100),
124         SR_MHZ(200),
125 };
126
127 static const uint64_t rates_100mhz[] = {
128         SR_KHZ(10),
129         SR_KHZ(20),
130         SR_KHZ(50),
131         SR_KHZ(100),
132         SR_KHZ(200),
133         SR_KHZ(500),
134         SR_MHZ(1),
135         SR_MHZ(2),
136         SR_MHZ(5),
137         SR_MHZ(10),
138         SR_MHZ(20),
139         SR_MHZ(50),
140         SR_MHZ(100),
141 };
142
143 static const float logic_threshold_value[] = {
144         1.58,
145         2.5,
146         1.165,
147         1.5,
148         1.25,
149         0.9,
150         0.75,
151         0.60,
152         0.45,
153 };
154
155 static const char *logic_threshold[] = {
156         "TTL 5V",
157         "CMOS 5V",
158         "CMOS 3.3V",
159         "CMOS 3.0V",
160         "CMOS 2.5V",
161         "CMOS 1.8V",
162         "CMOS 1.5V",
163         "CMOS 1.2V",
164         "CMOS 0.9V",
165         "USER",
166 };
167
168 #define LOGIC_THRESHOLD_IDX_USER        (ARRAY_SIZE(logic_threshold) - 1)
169
170 static GSList *scan(struct sr_dev_driver *di, GSList *options)
171 {
172         struct drv_context *drvc;
173         struct sr_context *ctx;
174         struct dev_context *devc;
175         struct sr_dev_inst *sdi;
176         struct sr_usb_dev_inst *usb;
177         struct sr_config *src;
178         GSList *l;
179         GSList *devices;
180         GSList *conn_devices;
181         struct libusb_device_descriptor des;
182         libusb_device **devlist, *dev;
183         size_t dev_count, dev_idx, ch_idx;
184         uint8_t bus, addr;
185         const char *conn;
186         char conn_id[64];
187         uint64_t fw_uploaded;
188         int ret;
189
190         drvc = di->context;
191         ctx = drvc->sr_ctx;;
192
193         conn = NULL;
194         for (l = options; l; l = l->next) {
195                 src = l->data;
196                 switch (src->key) {
197                 case SR_CONF_CONN:
198                         conn = g_variant_get_string(src->data, NULL);
199                         break;
200                 }
201         }
202         if (conn)
203                 conn_devices = sr_usb_find(ctx->libusb_ctx, conn);
204         else
205                 conn_devices = NULL;
206
207         /* Find all LA2016 devices, optionally upload firmware to them. */
208         devices = NULL;
209         ret = libusb_get_device_list(ctx->libusb_ctx, &devlist);
210         if (ret < 0) {
211                 sr_err("Cannot get device list: %s.", libusb_error_name(ret));
212                 return devices;
213         }
214         dev_count = ret;
215         for (dev_idx = 0; dev_idx < dev_count; dev_idx++) {
216                 dev = devlist[dev_idx];
217                 bus = libusb_get_bus_number(dev);
218                 addr = libusb_get_device_address(dev);
219                 if (conn) {
220                         usb = NULL;
221                         for (l = conn_devices; l; l = l->next) {
222                                 usb = l->data;
223                                 if (usb->bus == bus && usb->address == addr)
224                                         break;
225                         }
226                         if (!l) {
227                                 /*
228                                  * A connection parameter was specified and
229                                  * this device does not match the filter.
230                                  */
231                                 continue;
232                         }
233                 }
234
235                 libusb_get_device_descriptor(dev, &des);
236                 ret = usb_get_port_path(dev, conn_id, sizeof(conn_id));
237                 if (ret < 0)
238                         continue;
239                 if (des.idVendor != LA2016_VID || des.idProduct != LA2016_PID)
240                         continue;
241
242                 /* USB identification matches, a device was found. */
243                 sr_dbg("Found a device (USB identification).");
244                 sdi = g_malloc0(sizeof(*sdi));
245                 sdi->status = SR_ST_INITIALIZING;
246                 sdi->connection_id = g_strdup(conn_id);
247
248                 fw_uploaded = 0;
249                 if (des.iProduct != LA2016_IPRODUCT_INDEX) {
250                         sr_info("Device at '%s' has no firmware loaded.",
251                                 conn_id);
252
253                         ret = la2016_upload_firmware(ctx, dev, des.idProduct);
254                         if (ret != SR_OK) {
255                                 sr_err("MCU firmware upload failed.");
256                                 g_free(sdi->connection_id);
257                                 g_free(sdi);
258                                 continue;
259                         }
260                         fw_uploaded = g_get_monotonic_time();
261                         /* Will re-enumerate. Mark as "unknown address yet". */
262                         addr = 0xff;
263                 }
264
265                 sdi->vendor = g_strdup("Kingst");
266                 sdi->model = g_strdup("LA2016");
267
268                 for (ch_idx = 0; ch_idx < ARRAY_SIZE(channel_names); ch_idx++) {
269                         sr_channel_new(sdi, ch_idx, SR_CHANNEL_LOGIC,
270                                 TRUE, channel_names[ch_idx]);
271                 }
272
273                 devices = g_slist_append(devices, sdi);
274
275                 devc = g_malloc0(sizeof(*devc));
276                 sdi->priv = devc;
277                 devc->fw_uploaded = fw_uploaded;
278                 sr_sw_limits_init(&devc->sw_limits);
279                 devc->sw_limits.limit_samples = LA2016_DFLT_SAMPLEDEPTH;
280                 devc->capture_ratio = LA2016_DFLT_CAPT_RATIO;
281                 devc->cur_samplerate = LA2016_DFLT_SAMPLERATE;
282                 devc->threshold_voltage_idx = 0;
283                 devc->threshold_voltage = logic_threshold_value[devc->threshold_voltage_idx];
284
285                 sdi->status = SR_ST_INACTIVE;
286                 sdi->inst_type = SR_INST_USB;
287
288                 sdi->conn = sr_usb_dev_inst_new(bus, addr, NULL);
289         }
290         libusb_free_device_list(devlist, 1);
291         g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free);
292
293         return std_scan_complete(di, devices);
294 }
295
296 static int la2016_dev_open(struct sr_dev_inst *sdi)
297 {
298         struct sr_dev_driver *di;
299         struct drv_context *drvc;
300         struct sr_context *ctx;
301         libusb_device **devlist, *dev;
302         struct sr_usb_dev_inst *usb;
303         struct libusb_device_descriptor des;
304         int ret;
305         size_t device_count, dev_idx;
306         gboolean check_conn;
307         char conn_id[64];
308
309         di = sdi->driver;
310         drvc = di->context;
311         ctx = drvc->sr_ctx;;
312         usb = sdi->conn;
313         ret = SR_ERR;
314
315         ret = libusb_get_device_list(ctx->libusb_ctx, &devlist);
316         if (ret < 0) {
317                 sr_err("Cannot get device list: %s.", libusb_error_name(ret));
318                 return SR_ERR;
319         }
320         device_count = ret;
321         if (!device_count) {
322                 sr_warn("Device list is empty. Cannot open.");
323                 return SR_ERR;
324         }
325         for (dev_idx = 0; dev_idx < device_count; dev_idx++) {
326                 dev = devlist[dev_idx];
327                 libusb_get_device_descriptor(dev, &des);
328
329                 if (des.idVendor != LA2016_VID || des.idProduct != LA2016_PID)
330                         continue;
331                 if (des.iProduct != LA2016_IPRODUCT_INDEX)
332                         continue;
333
334                 check_conn = sdi->status == SR_ST_INITIALIZING;
335                 check_conn |= sdi->status == SR_ST_INACTIVE;
336                 if (check_conn) {
337                         /* Check physical USB bus/port address. */
338                         ret = usb_get_port_path(dev, conn_id, sizeof(conn_id));
339                         if (ret < 0)
340                                 continue;
341                         if (strcmp(sdi->connection_id, conn_id) != 0) {
342                                 /* Not the device we looked up before. */
343                                 continue;
344                         }
345                 }
346
347                 ret = libusb_open(dev, &usb->devhdl);
348                 if (ret != 0) {
349                         sr_err("Cannot open device: %s.",
350                                 libusb_error_name(ret));
351                         ret = SR_ERR_IO;
352                         break;
353                 }
354
355                 if (usb->address == 0xff) {
356                         /*
357                          * First encounter after firmware upload.
358                          * Grab current address after enumeration.
359                          */
360                         usb->address = libusb_get_device_address(dev);
361                 }
362
363                 ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
364                 if (ret == LIBUSB_ERROR_BUSY) {
365                         sr_err("Cannot claim USB interface. Another program or driver using it?");
366                         ret = SR_ERR;
367                         break;
368                 } else if (ret == LIBUSB_ERROR_NO_DEVICE) {
369                         sr_err("Device has been disconnected.");
370                         ret = SR_ERR;
371                         break;
372                 } else if (ret != 0) {
373                         sr_err("Cannot claim USB interface: %s.",
374                                 libusb_error_name(ret));
375                         ret = SR_ERR;
376                         break;
377                 }
378
379                 if ((ret = la2016_init_device(sdi)) != SR_OK) {
380                         sr_err("Cannot initialize device.");
381                         break;
382                 }
383
384                 sr_info("Opened device on %d.%d (logical) / %s (physical), interface %d.",
385                         usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
386                 ret = SR_OK;
387                 break;
388         }
389         libusb_free_device_list(devlist, 1);
390
391         if (ret != SR_OK) {
392                 if (usb->devhdl) {
393                         libusb_release_interface(usb->devhdl, USB_INTERFACE);
394                         libusb_close(usb->devhdl);
395                         usb->devhdl = NULL;
396                 }
397                 return ret;
398         }
399
400         return SR_OK;
401 }
402
403 static int dev_open(struct sr_dev_inst *sdi)
404 {
405         struct dev_context *devc;
406         uint64_t reset_done, now, elapsed_ms;
407         int ret;
408
409         devc = sdi->priv;
410
411         /*
412          * When the sigrok driver recently has uploaded MCU firmware,
413          * then wait for the FX2 to re-enumerate. Allow the USB device
414          * to vanish before it reappears. Timeouts are rough estimates
415          * after all, the imprecise time of the last check (potentially
416          * executes after the total check period) simplifies code paths
417          * with optional diagnostics. And increases the probability of
418          * successfully detecting "late/slow" devices.
419          */
420         if (devc->fw_uploaded) {
421                 sr_info("Waiting for device to reset after firmware upload.");
422                 now = g_get_monotonic_time();
423                 reset_done = devc->fw_uploaded + RENUM_GONE_DELAY_MS * 1000;
424                 if (now < reset_done)
425                         g_usleep(reset_done - now);
426                 do {
427                         now = g_get_monotonic_time();
428                         elapsed_ms = (now - devc->fw_uploaded) / 1000;
429                         sr_spew("Waited %" PRIu64 "ms.", elapsed_ms);
430                         ret = la2016_dev_open(sdi);
431                         if (ret == SR_OK) {
432                                 devc->fw_uploaded = 0;
433                                 break;
434                         }
435                         g_usleep(RENUM_POLL_INTERVAL_MS * 1000);
436                 } while (elapsed_ms < RENUM_CHECK_PERIOD_MS);
437                 if (ret != SR_OK) {
438                         sr_err("Device failed to re-enumerate.");
439                         return ret;
440                 }
441                 sr_info("Device came back after %" PRIi64 "ms.", elapsed_ms);
442         } else {
443                 ret = la2016_dev_open(sdi);
444         }
445
446         if (ret != SR_OK) {
447                 sr_err("Cannot open device.");
448                 return ret;
449         }
450
451         return SR_OK;
452 }
453
454 static int dev_close(struct sr_dev_inst *sdi)
455 {
456         struct sr_usb_dev_inst *usb;
457
458         usb = sdi->conn;
459
460         if (!usb->devhdl)
461                 return SR_ERR_BUG;
462
463         la2016_deinit_device(sdi);
464
465         sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
466                 usb->bus, usb->address, sdi->connection_id, USB_INTERFACE);
467         libusb_release_interface(usb->devhdl, USB_INTERFACE);
468         libusb_close(usb->devhdl);
469         usb->devhdl = NULL;
470
471         return SR_OK;
472 }
473
474 static int config_get(uint32_t key, GVariant **data,
475         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
476 {
477         struct dev_context *devc;
478         struct sr_usb_dev_inst *usb;
479         double rounded;
480         const char *label;
481
482         (void)cg;
483
484         if (!sdi)
485                 return SR_ERR_ARG;
486         devc = sdi->priv;
487
488         switch (key) {
489         case SR_CONF_CONN:
490                 if (!sdi->conn)
491                         return SR_ERR_ARG;
492                 usb = sdi->conn;
493                 if (usb->address == 0xff) {
494                         /*
495                          * Device still needs to re-enumerate after firmware
496                          * upload, so we don't know its (future) address.
497                          */
498                         return SR_ERR;
499                 }
500                 *data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
501                 break;
502         case SR_CONF_SAMPLERATE:
503                 *data = g_variant_new_uint64(devc->cur_samplerate);
504                 break;
505         case SR_CONF_LIMIT_SAMPLES:
506         case SR_CONF_LIMIT_MSEC:
507                 return sr_sw_limits_config_get(&devc->sw_limits, key, data);
508         case SR_CONF_CAPTURE_RATIO:
509                 *data = g_variant_new_uint64(devc->capture_ratio);
510                 break;
511         case SR_CONF_VOLTAGE_THRESHOLD:
512                 rounded = (int)(devc->threshold_voltage / 0.1) * 0.1;
513                 *data = std_gvar_tuple_double(rounded, rounded + 0.1);
514                 return SR_OK;
515         case SR_CONF_LOGIC_THRESHOLD:
516                 label = logic_threshold[devc->threshold_voltage_idx];
517                 *data = g_variant_new_string(label);
518                 break;
519         case SR_CONF_LOGIC_THRESHOLD_CUSTOM:
520                 *data = g_variant_new_double(devc->threshold_voltage);
521                 break;
522
523         default:
524                 return SR_ERR_NA;
525         }
526
527         return SR_OK;
528 }
529
530 static int config_set(uint32_t key, GVariant *data,
531         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
532 {
533         struct dev_context *devc;
534         double low, high;
535         int idx;
536
537         (void)cg;
538
539         devc = sdi->priv;
540
541         switch (key) {
542         case SR_CONF_SAMPLERATE:
543                 devc->cur_samplerate = g_variant_get_uint64(data);
544                 break;
545         case SR_CONF_LIMIT_SAMPLES:
546         case SR_CONF_LIMIT_MSEC:
547                 return sr_sw_limits_config_set(&devc->sw_limits, key, data);
548         case SR_CONF_CAPTURE_RATIO:
549                 devc->capture_ratio = g_variant_get_uint64(data);
550                 break;
551         case SR_CONF_VOLTAGE_THRESHOLD:
552                 g_variant_get(data, "(dd)", &low, &high);
553                 devc->threshold_voltage = (low + high) / 2.0;
554                 devc->threshold_voltage_idx = LOGIC_THRESHOLD_IDX_USER;
555                 break;
556         case SR_CONF_LOGIC_THRESHOLD: {
557                 idx = std_str_idx(data, ARRAY_AND_SIZE(logic_threshold));
558                 if (idx < 0)
559                         return SR_ERR_ARG;
560                 if (idx != LOGIC_THRESHOLD_IDX_USER) {
561                         devc->threshold_voltage = logic_threshold_value[idx];
562                 }
563                 devc->threshold_voltage_idx = idx;
564                 break;
565         }
566         case SR_CONF_LOGIC_THRESHOLD_CUSTOM:
567                 devc->threshold_voltage = g_variant_get_double(data);
568                 break;
569         default:
570                 return SR_ERR_NA;
571         }
572
573         return SR_OK;
574 }
575
576 static int config_list(uint32_t key, GVariant **data,
577         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
578 {
579         struct dev_context *devc;
580
581         devc = sdi ? sdi->priv : NULL;
582
583         switch (key) {
584         case SR_CONF_SCAN_OPTIONS:
585         case SR_CONF_DEVICE_OPTIONS:
586                 return STD_CONFIG_LIST(key, data, sdi, cg,
587                         scanopts, drvopts, devopts);
588         case SR_CONF_SAMPLERATE:
589                 if (!sdi)
590                         return SR_ERR_ARG;
591                 if (devc->max_samplerate == SR_MHZ(500))
592                         *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_500mhz));
593                 else if (devc->max_samplerate == SR_MHZ(200))
594                         *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_200mhz));
595                 else
596                         *data = std_gvar_samplerates(ARRAY_AND_SIZE(rates_100mhz));
597                 break;
598         case SR_CONF_LIMIT_SAMPLES:
599                 *data = std_gvar_tuple_u64(LA2016_NUM_SAMPLES_MIN,
600                         LA2016_NUM_SAMPLES_MAX);
601                 break;
602         case SR_CONF_VOLTAGE_THRESHOLD:
603                 *data = std_gvar_min_max_step_thresholds(
604                         LA2016_THR_VOLTAGE_MIN,
605                         LA2016_THR_VOLTAGE_MAX, 0.1);
606                 break;
607         case SR_CONF_TRIGGER_MATCH:
608                 *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
609                 break;
610         case SR_CONF_LOGIC_THRESHOLD:
611                 *data = g_variant_new_strv(ARRAY_AND_SIZE(logic_threshold));
612                 break;
613         default:
614                 return SR_ERR_NA;
615         }
616
617         return SR_OK;
618 }
619
620 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
621 {
622         struct sr_dev_driver *di;
623         struct drv_context *drvc;
624         struct sr_context *ctx;
625         struct dev_context *devc;
626         int ret;
627
628         di = sdi->driver;
629         drvc = di->context;
630         ctx = drvc->sr_ctx;;
631         devc = sdi->priv;
632
633         if (!devc->feed_queue) {
634                 devc->feed_queue = feed_queue_logic_alloc(sdi,
635                         LA2016_CONVBUFFER_SIZE, sizeof(uint16_t));
636                 if (!devc->feed_queue) {
637                         sr_err("Cannot allocate buffer for session feed.");
638                         return SR_ERR_MALLOC;
639                 }
640         }
641
642         sr_sw_limits_acquisition_start(&devc->sw_limits);
643
644         ret = la2016_setup_acquisition(sdi);
645         if (ret != SR_OK) {
646                 feed_queue_logic_free(devc->feed_queue);
647                 devc->feed_queue = NULL;
648                 return ret;
649         }
650
651         ret = la2016_start_acquisition(sdi);
652         if (ret != SR_OK) {
653                 la2016_abort_acquisition(sdi);
654                 feed_queue_logic_free(devc->feed_queue);
655                 devc->feed_queue = NULL;
656                 return ret;
657         }
658
659         devc->completion_seen = FALSE;
660         usb_source_add(sdi->session, ctx, 50,
661                 la2016_receive_data, (void *)sdi);
662
663         std_session_send_df_header(sdi);
664
665         return SR_OK;
666 }
667
668 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
669 {
670         int ret;
671
672         ret = la2016_abort_acquisition(sdi);
673
674         return ret;
675 }
676
677 static struct sr_dev_driver kingst_la2016_driver_info = {
678         .name = "kingst-la2016",
679         .longname = "Kingst LA2016",
680         .api_version = 1,
681         .init = std_init,
682         .cleanup = std_cleanup,
683         .scan = scan,
684         .dev_list = std_dev_list,
685         .dev_clear = std_dev_clear,
686         .config_get = config_get,
687         .config_set = config_set,
688         .config_list = config_list,
689         .dev_open = dev_open,
690         .dev_close = dev_close,
691         .dev_acquisition_start = dev_acquisition_start,
692         .dev_acquisition_stop = dev_acquisition_stop,
693         .context = NULL,
694 };
695 SR_REGISTER_DEV_DRIVER(kingst_la2016_driver_info);