]> sigrok.org Git - libsigrok.git/blob - hardware/zeroplus-logic-cube/zeroplus.c
sr: zeroplus: Fix segfault, add debug output.
[libsigrok.git] / hardware / zeroplus-logic-cube / zeroplus.c
1 /*
2  * This file is part of the sigrok project.
3  *
4  * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/time.h>
24 #include <inttypes.h>
25 #include <glib.h>
26 #include <libusb.h>
27 #include "config.h"
28 #include "sigrok.h"
29 #include "sigrok-internal.h"
30 #include "analyzer.h"
31
32 #define USB_VENDOR                      0x0c12
33 #define USB_VENDOR_NAME                 "Zeroplus"
34 #define USB_MODEL_NAME                  "Logic Cube"
35 #define USB_MODEL_VERSION               ""
36
37 #define NUM_PROBES                      16
38 #define USB_INTERFACE                   0
39 #define USB_CONFIGURATION               1
40 #define NUM_TRIGGER_STAGES              4
41 #define TRIGGER_TYPES                   "01"
42
43 #define PACKET_SIZE                     2048    /* ?? */
44
45 typedef struct {
46         unsigned short pid;
47         char model_name[64];
48         unsigned int channels;
49         unsigned int sample_depth;      /* In Ksamples/channel */
50         unsigned int max_sampling_freq;
51 } model_t;
52
53 /*
54  * Note -- 16032, 16064 and 16128 *usually* -- but not always -- have the
55  * same 128K sample depth.
56  */
57 static model_t zeroplus_models[] = {
58         {0x7009, "LAP-C(16064)",  16, 64,   100},
59         {0x700A, "LAP-C(16128)",  16, 128,  200},
60         {0x700B, "LAP-C(32128)",  32, 128,  200},
61         {0x700C, "LAP-C(321000)", 32, 1024, 200},
62         {0x700D, "LAP-C(322000)", 32, 2048, 200},
63         {0x700E, "LAP-C(16032)",  16, 32,   100},
64         {0x7016, "LAP-C(162000)", 16, 2048, 200},
65 };
66
67 static int hwcaps[] = {
68         SR_HWCAP_LOGIC_ANALYZER,
69         SR_HWCAP_SAMPLERATE,
70         SR_HWCAP_PROBECONFIG,
71         SR_HWCAP_CAPTURE_RATIO,
72
73         /* These are really implemented in the driver, not the hardware. */
74         SR_HWCAP_LIMIT_SAMPLES,
75         0,
76 };
77
78 /*
79  * ZEROPLUS LAP-C (16032) numbers the 16 probes A0-A7 and B0-B7.
80  * We currently ignore other untested/unsupported devices here.
81  */
82 static const char *probe_names[NUM_PROBES + 1] = {
83         "A0",
84         "A1",
85         "A2",
86         "A3",
87         "A4",
88         "A5",
89         "A6",
90         "A7",
91         "B0",
92         "B1",
93         "B2",
94         "B3",
95         "B4",
96         "B5",
97         "B6",
98         "B7",
99         NULL,
100 };
101
102 /* List of struct sr_dev_inst, maintained by dev_open()/dev_close(). */
103 static GSList *dev_insts = NULL;
104
105 static libusb_context *usb_context = NULL;
106
107 /*
108  * The hardware supports more samplerates than these, but these are the
109  * options hardcoded into the vendor's Windows GUI.
110  */
111
112 /*
113  * TODO: We shouldn't support 150MHz and 200MHz on devices that don't go up
114  * that high.
115  */
116 static uint64_t supported_samplerates[] = {
117         SR_HZ(100),
118         SR_HZ(500),
119         SR_KHZ(1),
120         SR_KHZ(5),
121         SR_KHZ(25),
122         SR_KHZ(50),
123         SR_KHZ(100),
124         SR_KHZ(200),
125         SR_KHZ(400),
126         SR_KHZ(800),
127         SR_MHZ(1),
128         SR_MHZ(10),
129         SR_MHZ(25),
130         SR_MHZ(50),
131         SR_MHZ(80),
132         SR_MHZ(100),
133         SR_MHZ(150),
134         SR_MHZ(200),
135         0,
136 };
137
138 static struct sr_samplerates samplerates = {
139         0,
140         0,
141         0,
142         supported_samplerates,
143 };
144
145 /* Private, per-device-instance driver context. */
146 struct context {
147         uint64_t cur_samplerate;
148         uint64_t limit_samples;
149         int num_channels; /* TODO: This isn't initialized before it's needed :( */
150         uint64_t memory_size;
151         uint8_t probe_mask;
152         uint8_t trigger_mask[NUM_TRIGGER_STAGES];
153         uint8_t trigger_value[NUM_TRIGGER_STAGES];
154         // uint8_t trigger_buffer[NUM_TRIGGER_STAGES];
155
156         struct sr_usb_dev_inst *usb;
157 };
158
159 static int hw_dev_config_set(int dev_index, int hwcap, void *value);
160
161 static unsigned int get_memory_size(int type)
162 {
163         if (type == MEMORY_SIZE_8K)
164                 return 8 * 1024;
165         else if (type == MEMORY_SIZE_64K)
166                 return 64 * 1024;
167         else if (type == MEMORY_SIZE_128K)
168                 return 128 * 1024;
169         else if (type == MEMORY_SIZE_512K)
170                 return 512 * 1024;
171         else
172                 return 0;
173 }
174
175 static int opendev4(struct sr_dev_inst **sdi, libusb_device *dev,
176                     struct libusb_device_descriptor *des)
177 {
178         struct context *ctx;
179         unsigned int i;
180         int ret;
181
182         /* Note: sdi is non-NULL, the caller already checked this. */
183
184         if (!(ctx = (*sdi)->priv)) {
185                 sr_err("zp: %s: (*sdi)->priv was NULL", __func__);
186                 return -1;
187         }
188
189         if ((ret = libusb_get_device_descriptor(dev, des))) {
190                 sr_err("zp: failed to get device descriptor: %d", ret);
191                 return -1;
192         }
193
194         if (des->idVendor != USB_VENDOR)
195                 return 0;
196
197         if (libusb_get_bus_number(dev) == ctx->usb->bus
198             && libusb_get_device_address(dev) == ctx->usb->address) {
199
200                 for (i = 0; i < ARRAY_SIZE(zeroplus_models); i++) {
201                         if (!(des->idProduct == zeroplus_models[i].pid))
202                                 continue;
203
204                         sr_info("zp: Found ZeroPlus device 0x%04x (%s)",
205                                 des->idProduct, zeroplus_models[i].model_name);
206                         ctx->num_channels = zeroplus_models[i].channels;
207                         ctx->memory_size = zeroplus_models[i].sample_depth * 1024;
208                         break;
209                 }
210
211                 if (ctx->num_channels == 0) {
212                         sr_err("zp: Unknown ZeroPlus device 0x%04x",
213                                des->idProduct);
214                         return -2;
215                 }
216
217                 /* Found it. */
218                 if (!(ret = libusb_open(dev, &(ctx->usb->devhdl)))) {
219                         (*sdi)->status = SR_ST_ACTIVE;
220                         sr_info("zp: opened device %d on %d.%d interface %d",
221                                 (*sdi)->index, ctx->usb->bus,
222                                 ctx->usb->address, USB_INTERFACE);
223                 } else {
224                         sr_err("zp: failed to open device: %d", ret);
225                         *sdi = NULL;
226                 }
227         }
228
229         return 0;
230 }
231
232 static struct sr_dev_inst *zp_open_dev(int dev_index)
233 {
234         struct sr_dev_inst *sdi;
235         libusb_device **devlist;
236         struct libusb_device_descriptor des;
237         int i;
238
239         if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
240                 return NULL;
241
242         libusb_get_device_list(usb_context, &devlist);
243         if (sdi->status == SR_ST_INACTIVE) {
244                 /* Find the device by vendor, product, bus and address. */
245                 libusb_get_device_list(usb_context, &devlist);
246                 for (i = 0; devlist[i]; i++) {
247                         /* TODO: Error handling. */
248                         opendev4(&sdi, devlist[i], &des);
249                 }
250         } else {
251                 /* Status must be SR_ST_ACTIVE, i.e. already in use... */
252                 sdi = NULL;
253         }
254         libusb_free_device_list(devlist, 1);
255
256         if (sdi && sdi->status != SR_ST_ACTIVE)
257                 sdi = NULL;
258
259         return sdi;
260 }
261
262 static void close_dev(struct sr_dev_inst *sdi)
263 {
264         struct context *ctx;
265
266         if (!(ctx = sdi->priv)) {
267                 sr_err("zp: %s: sdi->priv was NULL", __func__);
268                 return; /* FIXME */
269         }
270
271         if (!ctx->usb->devhdl)
272                 return;
273
274         sr_info("zp: closing device %d on %d.%d interface %d", sdi->index,
275                 ctx->usb->bus, ctx->usb->address, USB_INTERFACE);
276         libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE);
277         libusb_reset_device(ctx->usb->devhdl);
278         libusb_close(ctx->usb->devhdl);
279         ctx->usb->devhdl = NULL;
280         /* TODO: Call libusb_exit() here or only in hw_cleanup()? */
281         sdi->status = SR_ST_INACTIVE;
282 }
283
284 static int configure_probes(struct sr_dev_inst *sdi, GSList *probes)
285 {
286         struct context *ctx;
287         struct sr_probe *probe;
288         GSList *l;
289         int probe_bit, stage, i;
290         char *tc;
291
292         /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */
293         ctx = sdi->priv;
294
295         ctx->probe_mask = 0;
296         for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
297                 ctx->trigger_mask[i] = 0;
298                 ctx->trigger_value[i] = 0;
299         }
300
301         stage = -1;
302         for (l = probes; l; l = l->next) {
303                 probe = (struct sr_probe *)l->data;
304                 if (probe->enabled == FALSE)
305                         continue;
306                 probe_bit = 1 << (probe->index - 1);
307                 ctx->probe_mask |= probe_bit;
308
309                 if (probe->trigger) {
310                         stage = 0;
311                         for (tc = probe->trigger; *tc; tc++) {
312                                 ctx->trigger_mask[stage] |= probe_bit;
313                                 if (*tc == '1')
314                                         ctx->trigger_value[stage] |= probe_bit;
315                                 stage++;
316                                 if (stage > NUM_TRIGGER_STAGES)
317                                         return SR_ERR;
318                         }
319                 }
320         }
321
322         return SR_OK;
323 }
324
325 /*
326  * API callbacks
327  */
328
329 static int hw_init(const char *devinfo)
330 {
331         struct sr_dev_inst *sdi;
332         struct libusb_device_descriptor des;
333         libusb_device **devlist;
334         int ret, devcnt, i;
335         struct context *ctx;
336
337         /* Avoid compiler warnings. */
338         (void)devinfo;
339
340         /* Allocate memory for our private driver context. */
341         if (!(ctx = g_try_malloc(sizeof(struct context)))) {
342                 sr_err("zp: %s: ctx malloc failed", __func__);
343                 return 0;
344         }
345
346         /* Set some sane defaults. */
347         ctx->cur_samplerate = 0;
348         ctx->limit_samples = 0;
349         /* TODO: num_channels isn't initialized before it's needed :( */
350         ctx->num_channels = NUM_PROBES;
351         ctx->memory_size = 0;
352         ctx->probe_mask = 0;
353         memset(ctx->trigger_mask, 0, NUM_TRIGGER_STAGES);
354         memset(ctx->trigger_value, 0, NUM_TRIGGER_STAGES);
355         // memset(ctx->trigger_buffer, 0, NUM_TRIGGER_STAGES);
356
357         if (libusb_init(&usb_context) != 0) {
358                 sr_err("zp: Failed to initialize USB.");
359                 return 0;
360         }
361
362         /* Find all ZeroPlus analyzers and add them to device list. */
363         devcnt = 0;
364         libusb_get_device_list(usb_context, &devlist); /* TODO: Errors. */
365
366         for (i = 0; devlist[i]; i++) {
367                 ret = libusb_get_device_descriptor(devlist[i], &des);
368                 if (ret != 0) {
369                         sr_err("zp: failed to get device descriptor: %d", ret);
370                         continue;
371                 }
372
373                 if (des.idVendor == USB_VENDOR) {
374                         /*
375                          * Definitely a Zeroplus.
376                          * TODO: Any way to detect specific model/version in
377                          * the zeroplus range?
378                          */
379                         /* Register the device with libsigrok. */
380                         if (!(sdi = sr_dev_inst_new(devcnt,
381                                         SR_ST_INACTIVE, USB_VENDOR_NAME,
382                                         USB_MODEL_NAME, USB_MODEL_VERSION))) {
383                                 sr_err("zp: %s: sr_dev_inst_new failed",
384                                        __func__);
385                                 return 0;
386                         }
387
388                         sdi->priv = ctx;
389
390                         dev_insts =
391                             g_slist_append(dev_insts, sdi);
392                         ctx->usb = sr_usb_dev_inst_new(
393                                 libusb_get_bus_number(devlist[i]),
394                                 libusb_get_device_address(devlist[i]), NULL);
395                         devcnt++;
396                 }
397         }
398         libusb_free_device_list(devlist, 1);
399
400         return devcnt;
401 }
402
403 static int hw_dev_open(int dev_index)
404 {
405         struct sr_dev_inst *sdi;
406         struct context *ctx;
407         int ret;
408
409         if (!(sdi = zp_open_dev(dev_index))) {
410                 sr_err("zp: unable to open device");
411                 return SR_ERR;
412         }
413
414         /* TODO: Note: sdi is retrieved in zp_open_dev(). */
415
416         if (!(ctx = sdi->priv)) {
417                 sr_err("zp: %s: sdi->priv was NULL", __func__);
418                 return SR_ERR_ARG;
419         }
420
421         ret = libusb_set_configuration(ctx->usb->devhdl, USB_CONFIGURATION);
422         if (ret < 0) {
423                 sr_err("zp: Unable to set USB configuration %d: %d",
424                        USB_CONFIGURATION, ret);
425                 return SR_ERR;
426         }
427
428         ret = libusb_claim_interface(ctx->usb->devhdl, USB_INTERFACE);
429         if (ret != 0) {
430                 sr_err("zp: Unable to claim interface: %d", ret);
431                 return SR_ERR;
432         }
433
434         analyzer_reset(ctx->usb->devhdl);
435         analyzer_initialize(ctx->usb->devhdl);
436
437         analyzer_set_memory_size(MEMORY_SIZE_512K);
438         // analyzer_set_freq(g_freq, g_freq_scale);
439         analyzer_set_trigger_count(1);
440         // analyzer_set_ramsize_trigger_address((((100 - g_pre_trigger)
441         // * get_memory_size(g_memory_size)) / 100) >> 2);
442         analyzer_set_ramsize_trigger_address(
443                 (100 * get_memory_size(MEMORY_SIZE_512K) / 100) >> 2);
444
445 #if 0
446         if (g_double_mode == 1)
447                 analyzer_set_compression(COMPRESSION_DOUBLE);
448         else if (g_compression == 1)
449                 analyzer_set_compression(COMPRESSION_ENABLE);
450         else
451 #endif
452         analyzer_set_compression(COMPRESSION_NONE);
453
454         if (ctx->cur_samplerate == 0) {
455                 /* Samplerate hasn't been set. Default to the slowest one. */
456                 if (hw_dev_config_set(dev_index, SR_HWCAP_SAMPLERATE,
457                      &samplerates.list[0]) == SR_ERR)
458                         return SR_ERR;
459         }
460
461         return SR_OK;
462 }
463
464 static int hw_dev_close(int dev_index)
465 {
466         struct sr_dev_inst *sdi;
467
468         if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
469                 sr_err("zp: %s: sdi was NULL", __func__);
470                 return SR_ERR; /* TODO: SR_ERR_ARG? */
471         }
472
473         /* TODO */
474         close_dev(sdi);
475
476         return SR_OK;
477 }
478
479 static int hw_cleanup(void)
480 {
481         GSList *l;
482         struct sr_dev_inst *sdi;
483
484         for (l = dev_insts; l; l = l->next) {
485                 sdi = l->data;
486                 /* Properly close all devices... */
487                 close_dev(sdi);
488                 /* ...and free all their memory. */
489                 sr_dev_inst_free(sdi);
490         }
491         g_slist_free(dev_insts);
492         dev_insts = NULL;
493
494         if (usb_context)
495                 libusb_exit(usb_context);
496         usb_context = NULL;
497
498         return SR_OK;
499 }
500
501 static void *hw_dev_info_get(int dev_index, int dev_info_id)
502 {
503         struct sr_dev_inst *sdi;
504         struct context *ctx;
505         void *info;
506
507         if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
508                 sr_err("zp: %s: sdi was NULL", __func__);
509                 return NULL;
510         }
511
512         if (!(ctx = sdi->priv)) {
513                 sr_err("zp: %s: sdi->priv was NULL", __func__);
514                 return NULL;
515         }
516
517         sr_spew("zp: %s: dev_index %d, dev_info_id %d.", __func__,
518                 dev_index, dev_info_id);
519
520         switch (dev_info_id) {
521         case SR_DI_INST:
522                 info = sdi;
523                 sr_spew("zp: %s: Returning sdi.", __func__);
524                 break;
525         case SR_DI_NUM_PROBES:
526                 info = GINT_TO_POINTER(ctx->num_channels);
527                 sr_spew("zp: %s: Returning number of probes: %d.", __func__,
528                         NUM_PROBES);
529                 break;
530         case SR_DI_PROBE_NAMES:
531                 info = probe_names;
532                 sr_spew("zp: %s: Returning probenames.", __func__);
533                 break;
534         case SR_DI_SAMPLERATES:
535                 info = &samplerates;
536                 sr_spew("zp: %s: Returning samplerates.", __func__);
537                 break;
538         case SR_DI_TRIGGER_TYPES:
539                 info = TRIGGER_TYPES;
540                 sr_spew("zp: %s: Returning triggertypes: %s.", __func__, info);
541                 break;
542         case SR_DI_CUR_SAMPLERATE:
543                 info = &ctx->cur_samplerate;
544                 sr_spew("zp: %s: Returning samplerate: %" PRIu64 "Hz.",
545                         __func__, ctx->cur_samplerate);
546                 break;
547         default:
548                 /* Unknown device info ID, return NULL. */
549                 sr_err("zp: %s: Unknown device info ID", __func__);
550                 info = NULL;
551                 break;
552         }
553
554         return info;
555 }
556
557 static int hw_dev_status_get(int dev_index)
558 {
559         struct sr_dev_inst *sdi;
560
561         sdi = sr_dev_inst_get(dev_insts, dev_index);
562         if (sdi)
563                 return sdi->status;
564         else
565                 return SR_ST_NOT_FOUND;
566 }
567
568 static int *hw_hwcap_get_all(void)
569 {
570         return hwcaps;
571 }
572
573 static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate)
574 {
575         struct context *ctx;
576
577         if (!sdi) {
578                 sr_err("zp: %s: sdi was NULL", __func__);
579                 return SR_ERR_ARG;
580         }
581
582         if (!(ctx = sdi->priv)) {
583                 sr_err("zp: %s: sdi->priv was NULL", __func__);
584                 return SR_ERR_ARG;
585         }
586
587         sr_info("zp: Setting samplerate to %" PRIu64 "Hz.", samplerate);
588
589         if (samplerate > SR_MHZ(1))
590                 analyzer_set_freq(samplerate / SR_MHZ(1), FREQ_SCALE_MHZ);
591         else if (samplerate > SR_KHZ(1))
592                 analyzer_set_freq(samplerate / SR_KHZ(1), FREQ_SCALE_KHZ);
593         else
594                 analyzer_set_freq(samplerate, FREQ_SCALE_HZ);
595
596         ctx->cur_samplerate = samplerate;
597
598         return SR_OK;
599 }
600
601 static int hw_dev_config_set(int dev_index, int hwcap, void *value)
602 {
603         struct sr_dev_inst *sdi;
604         struct context *ctx;
605
606         if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
607                 sr_err("zp: %s: sdi was NULL", __func__);
608                 return SR_ERR;
609         }
610
611         if (!(ctx = sdi->priv)) {
612                 sr_err("zp: %s: sdi->priv was NULL", __func__);
613                 return SR_ERR_ARG;
614         }
615
616         switch (hwcap) {
617         case SR_HWCAP_SAMPLERATE:
618                 return set_samplerate(sdi, *(uint64_t *)value);
619         case SR_HWCAP_PROBECONFIG:
620                 return configure_probes(sdi, (GSList *)value);
621         case SR_HWCAP_LIMIT_SAMPLES:
622                 ctx->limit_samples = *(uint64_t *)value;
623                 return SR_OK;
624         default:
625                 return SR_ERR;
626         }
627 }
628
629 static int hw_dev_acquisition_start(int dev_index, void *cb_data)
630 {
631         struct sr_dev_inst *sdi;
632         struct sr_datafeed_packet packet;
633         struct sr_datafeed_logic logic;
634         struct sr_datafeed_header header;
635         uint64_t samples_read;
636         int res;
637         unsigned int packet_num;
638         unsigned char *buf;
639         struct context *ctx;
640
641         if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
642                 sr_err("zp: %s: sdi was NULL", __func__);
643                 return SR_ERR;
644         }
645
646         if (!(ctx = sdi->priv)) {
647                 sr_err("zp: %s: sdi->priv was NULL", __func__);
648                 return SR_ERR_ARG;
649         }
650
651         /* push configured settings to device */
652         analyzer_configure(ctx->usb->devhdl);
653
654         analyzer_start(ctx->usb->devhdl);
655         sr_info("zp: Waiting for data");
656         analyzer_wait_data(ctx->usb->devhdl);
657
658         sr_info("zp: Stop address    = 0x%x",
659                 analyzer_get_stop_address(ctx->usb->devhdl));
660         sr_info("zp: Now address     = 0x%x",
661                 analyzer_get_now_address(ctx->usb->devhdl));
662         sr_info("zp: Trigger address = 0x%x",
663                 analyzer_get_trigger_address(ctx->usb->devhdl));
664
665         packet.type = SR_DF_HEADER;
666         packet.payload = &header;
667         header.feed_version = 1;
668         gettimeofday(&header.starttime, NULL);
669         header.samplerate = ctx->cur_samplerate;
670         header.num_logic_probes = ctx->num_channels;
671         sr_session_send(cb_data, &packet);
672
673         if (!(buf = g_try_malloc(PACKET_SIZE))) {
674                 sr_err("zp: %s: buf malloc failed", __func__);
675                 return SR_ERR_MALLOC;
676         }
677
678         samples_read = 0;
679         analyzer_read_start(ctx->usb->devhdl);
680         /* Send the incoming transfer to the session bus. */
681         for (packet_num = 0; packet_num < (ctx->memory_size * 4 / PACKET_SIZE);
682              packet_num++) {
683                 res = analyzer_read_data(ctx->usb->devhdl, buf, PACKET_SIZE);
684                 sr_info("zp: Tried to read %llx bytes, actually read %x bytes",
685                         PACKET_SIZE, res);
686
687                 packet.type = SR_DF_LOGIC;
688                 packet.payload = &logic;
689                 logic.length = PACKET_SIZE;
690                 logic.unitsize = 4;
691                 logic.data = buf;
692                 sr_session_send(cb_data, &packet);
693                 samples_read += res / 4;
694         }
695         analyzer_read_stop(ctx->usb->devhdl);
696         g_free(buf);
697
698         packet.type = SR_DF_END;
699         sr_session_send(cb_data, &packet);
700
701         return SR_OK;
702 }
703
704 /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
705 static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
706 {
707         struct sr_datafeed_packet packet;
708         struct sr_dev_inst *sdi;
709         struct context *ctx;
710
711         packet.type = SR_DF_END;
712         sr_session_send(cb_data, &packet);
713
714         if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
715                 sr_err("zp: %s: sdi was NULL", __func__);
716                 return SR_ERR_BUG;
717         }
718
719         if (!(ctx = sdi->priv)) {
720                 sr_err("zp: %s: sdi->priv was NULL", __func__);
721                 return SR_ERR_BUG;
722         }
723
724         analyzer_reset(ctx->usb->devhdl);
725         /* TODO: Need to cancel and free any queued up transfers. */
726
727         return SR_OK;
728 }
729
730 SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = {
731         .name = "zeroplus-logic-cube",
732         .longname = "Zeroplus Logic Cube LAP-C series",
733         .api_version = 1,
734         .init = hw_init,
735         .cleanup = hw_cleanup,
736         .dev_open = hw_dev_open,
737         .dev_close = hw_dev_close,
738         .dev_info_get = hw_dev_info_get,
739         .dev_status_get = hw_dev_status_get,
740         .hwcap_get_all = hw_hwcap_get_all,
741         .dev_config_set = hw_dev_config_set,
742         .dev_acquisition_start = hw_dev_acquisition_start,
743         .dev_acquisition_stop = hw_dev_acquisition_stop,
744 };