]> sigrok.org Git - libsigrok.git/blob - src/hardware/sysclk-lwla/api.c
59b368196ff749acd2a18f91ca842f7c7e461ad6
[libsigrok.git] / src / hardware / sysclk-lwla / api.c
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2014 Daniel Elstner <daniel.kitta@gmail.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 <config.h>
21 #include <glib.h>
22 #include <libusb.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <libsigrok/libsigrok.h>
26 #include <libsigrok-internal.h>
27 #include "protocol.h"
28
29 /* Supported device scan options.
30  */
31 static const uint32_t scanopts[] = {
32         SR_CONF_CONN,
33 };
34
35 /* Driver capabilities.
36  */
37 static const uint32_t drvopts[] = {
38         SR_CONF_LOGIC_ANALYZER,
39 };
40
41 /* Supported trigger match conditions.
42  */
43 static const int32_t trigger_matches[] = {
44         SR_TRIGGER_ZERO,
45         SR_TRIGGER_ONE,
46         SR_TRIGGER_RISING,
47         SR_TRIGGER_FALLING,
48 };
49
50 /* Names assigned to available trigger sources.
51  */
52 static const char *const trigger_source_names[] = {
53         [TRIGGER_CHANNELS] = "CH",
54         [TRIGGER_EXT_TRG] = "TRG",
55 };
56
57 /* Names assigned to available edge slope choices.
58  */
59 static const char *const signal_edge_names[] = {
60         [EDGE_POSITIVE] = "r",
61         [EDGE_NEGATIVE] = "f",
62 };
63
64 /* Create a new sigrok device instance for the indicated LWLA model.
65  */
66 static struct sr_dev_inst *dev_inst_new(const struct model_info *model)
67 {
68         struct sr_dev_inst *sdi;
69         struct dev_context *devc;
70         int i;
71         char name[8];
72
73         /* Initialize private device context. */
74         devc = g_malloc0(sizeof(struct dev_context));
75         devc->model = model;
76         devc->active_fpga_config = FPGA_NOCONF;
77         devc->cfg_rle = TRUE;
78         devc->samplerate = model->samplerates[0];
79         devc->channel_mask = (UINT64_C(1) << model->num_channels) - 1;
80
81         /* Create sigrok device instance. */
82         sdi = g_malloc0(sizeof(struct sr_dev_inst));
83         sdi->status = SR_ST_INACTIVE;
84         sdi->vendor = g_strdup(VENDOR_NAME);
85         sdi->model = g_strdup(model->name);
86         sdi->priv = devc;
87
88         /* Generate list of logic channels. */
89         for (i = 0; i < model->num_channels; i++) {
90                 /* The LWLA series simply number channels from CH1 to CHxx. */
91                 g_snprintf(name, sizeof(name), "CH%d", i + 1);
92                 sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, name);
93         }
94
95         return sdi;
96 }
97
98 /* Create a new device instance for a libusb device if it is a SysClk LWLA
99  * device and also matches the connection specification.
100  */
101 static struct sr_dev_inst *dev_inst_new_matching(GSList *conn_matches,
102                                                  libusb_device *dev)
103 {
104         GSList *node;
105         struct sr_usb_dev_inst *usb;
106         const struct model_info *model;
107         struct sr_dev_inst *sdi;
108         struct libusb_device_descriptor des;
109         int bus, address, ret;
110         unsigned int vid, pid;
111
112         bus = libusb_get_bus_number(dev);
113         address = libusb_get_device_address(dev);
114
115         for (node = conn_matches; node != NULL; node = node->next) {
116                 usb = node->data;
117                 if (usb && usb->bus == bus && usb->address == address)
118                         break; /* found */
119         }
120         if (conn_matches && !node)
121                 return NULL; /* no match */
122
123         ret = libusb_get_device_descriptor(dev, &des);
124         if (ret != 0) {
125                 sr_err("Failed to get USB device descriptor: %s.",
126                         libusb_error_name(ret));
127                 return NULL;
128         }
129         vid = des.idVendor;
130         pid = des.idProduct;
131
132         /* Create sigrok device instance. */
133         if (vid == USB_VID_SYSCLK && pid == USB_PID_LWLA1016) {
134                 model = &lwla1016_info;
135         } else if (vid == USB_VID_SYSCLK && pid == USB_PID_LWLA1034) {
136                 model = &lwla1034_info;
137         } else {
138                 if (conn_matches)
139                         sr_warn("USB device %d.%d (%04x:%04x) is not a"
140                                 " SysClk LWLA.", bus, address, vid, pid);
141                 return NULL;
142         }
143         sdi = dev_inst_new(model);
144
145         sdi->inst_type = SR_INST_USB;
146         sdi->conn = sr_usb_dev_inst_new(bus, address, NULL);
147
148         return sdi;
149 }
150
151 /* Scan for SysClk LWLA devices and create a device instance for each one.
152  */
153 static GSList *scan(struct sr_dev_driver *di, GSList *options)
154 {
155         GSList *conn_devices, *devices, *node;
156         struct drv_context *drvc;
157         struct sr_dev_inst *sdi;
158         struct sr_config *src;
159         const char *conn;
160         libusb_device **devlist;
161         ssize_t num_devs, i;
162
163         drvc = di->context;
164         conn = NULL;
165         conn_devices = NULL;
166         devices = NULL;
167
168         for (node = options; node != NULL; node = node->next) {
169                 src = node->data;
170                 if (src->key == SR_CONF_CONN) {
171                         conn = g_variant_get_string(src->data, NULL);
172                         break;
173                 }
174         }
175         if (conn) {
176                 /* Find devices matching the connection specification. */
177                 conn_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn);
178         }
179
180         /* List all libusb devices. */
181         num_devs = libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
182         if (num_devs < 0) {
183                 sr_err("Failed to list USB devices: %s.",
184                         libusb_error_name(num_devs));
185                 g_slist_free_full(conn_devices,
186                         (GDestroyNotify)&sr_usb_dev_inst_free);
187                 return NULL;
188         }
189
190         /* Scan the USB device list for matching LWLA devices. */
191         for (i = 0; i < num_devs; i++) {
192                 sdi = dev_inst_new_matching(conn_devices, devlist[i]);
193                 if (!sdi)
194                         continue; /* no match */
195
196                 /* Register device instance with driver. */
197                 devices = g_slist_append(devices, sdi);
198         }
199
200         libusb_free_device_list(devlist, 1);
201         g_slist_free_full(conn_devices, (GDestroyNotify)&sr_usb_dev_inst_free);
202
203         return std_scan_complete(di, devices);
204 }
205
206 /* Destroy the private device context.
207  */
208 static void clear_dev_context(void *priv)
209 {
210         struct dev_context *devc;
211
212         devc = priv;
213
214         if (devc->acquisition) {
215                 sr_err("Cannot clear device context during acquisition!");
216                 return; /* Leak and pray. */
217         }
218         sr_dbg("Device context cleared.");
219
220         g_free(devc);
221 }
222
223 /* Destroy all device instances.
224  */
225 static int dev_clear(const struct sr_dev_driver *di)
226 {
227         return std_dev_clear(di, &clear_dev_context);
228 }
229
230 /* Drain any pending data from the USB transfer buffers on the device.
231  * This may be necessary e.g. after a crash or generally to clean up after
232  * an abnormal condition.
233  */
234 static int drain_usb(struct sr_usb_dev_inst *usb, unsigned int endpoint)
235 {
236         int drained, xfer_len, ret;
237         unsigned char buf[512];
238         const unsigned int drain_timeout_ms = 10;
239
240         drained = 0;
241         do {
242                 xfer_len = 0;
243                 ret = libusb_bulk_transfer(usb->devhdl, endpoint,
244                                            buf, sizeof(buf), &xfer_len,
245                                            drain_timeout_ms);
246                 drained += xfer_len;
247         } while (ret == LIBUSB_SUCCESS && xfer_len != 0);
248
249         if (ret != LIBUSB_SUCCESS && ret != LIBUSB_ERROR_TIMEOUT) {
250                 sr_err("Failed to drain USB endpoint %u: %s.",
251                        endpoint & (LIBUSB_ENDPOINT_IN - 1),
252                        libusb_error_name(ret));
253                 return SR_ERR;
254         }
255         if (drained > 0) {
256                 sr_warn("Drained %d bytes from USB endpoint %u.",
257                         drained, endpoint & (LIBUSB_ENDPOINT_IN - 1));
258         }
259
260         return SR_OK;
261 }
262
263 /* Open and initialize device.
264  */
265 static int dev_open(struct sr_dev_inst *sdi)
266 {
267         struct drv_context *drvc;
268         struct dev_context *devc;
269         struct sr_usb_dev_inst *usb;
270         int i, ret;
271
272         drvc = sdi->driver->context;
273         devc = sdi->priv;
274         usb = sdi->conn;
275
276         /* Try the whole shebang three times, fingers crossed. */
277         for (i = 0; i < 3; i++) {
278                 ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb);
279                 if (ret != SR_OK)
280                         return ret;
281
282                 ret = libusb_set_configuration(usb->devhdl, USB_CONFIG);
283                 if (ret != LIBUSB_SUCCESS) {
284                         sr_err("Failed to set USB configuration: %s.",
285                                 libusb_error_name(ret));
286                         sr_usb_close(usb);
287                         return SR_ERR;
288                 }
289
290                 ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
291                 if (ret != LIBUSB_SUCCESS) {
292                         sr_err("Failed to claim interface: %s.",
293                                 libusb_error_name(ret));
294                         sr_usb_close(usb);
295                         return SR_ERR;
296                 }
297
298                 ret = drain_usb(usb, EP_REPLY);
299                 if (ret != SR_OK) {
300                         sr_usb_close(usb);
301                         return ret;
302                 }
303                 /* This delay appears to be necessary for reliable operation. */
304                 g_usleep(30 * 1000);
305
306                 sdi->status = SR_ST_ACTIVE;
307
308                 devc->active_fpga_config = FPGA_NOCONF;
309                 devc->short_transfer_quirk = FALSE;
310                 devc->state = STATE_IDLE;
311
312                 ret = (*devc->model->apply_fpga_config)(sdi);
313
314                 if (ret == SR_OK)
315                         ret = (*devc->model->device_init_check)(sdi);
316                 if (ret == SR_OK)
317                         break;
318
319                 /* Rinse and repeat. */
320                 sdi->status = SR_ST_INACTIVE;
321                 sr_usb_close(usb);
322         }
323
324         if (ret == SR_OK && devc->short_transfer_quirk)
325                 sr_warn("Short transfer quirk detected! "
326                         "Memory reads will be slow.");
327         return ret;
328 }
329
330 /* Shutdown and close device.
331  */
332 static int dev_close(struct sr_dev_inst *sdi)
333 {
334         struct dev_context *devc;
335         struct sr_usb_dev_inst *usb;
336         int ret;
337
338         devc = sdi->priv;
339         usb = sdi->conn;
340
341         if (devc->acquisition) {
342                 sr_err("Cannot close device during acquisition!");
343                 /* Request stop, leak handle, and prepare for the worst. */
344                 devc->cancel_requested = TRUE;
345                 return SR_ERR_BUG;
346         }
347
348         sdi->status = SR_ST_INACTIVE;
349
350         /* Download of the shutdown bitstream, if any. */
351         ret = (*devc->model->apply_fpga_config)(sdi);
352         if (ret != SR_OK)
353                 sr_warn("Unable to shut down device.");
354
355         libusb_release_interface(usb->devhdl, USB_INTERFACE);
356         sr_usb_close(usb);
357
358         return ret;
359 }
360
361 /* Check whether the device options contain a specific key.
362  * Also match against get/set/list bits if specified.
363  */
364 static int has_devopt(const struct model_info *model, uint32_t key)
365 {
366         unsigned int i;
367
368         for (i = 0; i < model->num_devopts; i++) {
369                 if ((model->devopts[i] & (SR_CONF_MASK | key)) == key)
370                         return TRUE;
371         }
372
373         return FALSE;
374 }
375
376 /* Read device configuration setting.
377  */
378 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
379                       const struct sr_channel_group *cg)
380 {
381         struct dev_context *devc;
382         unsigned int idx;
383
384         (void)cg;
385
386         if (!sdi)
387                 return SR_ERR_ARG;
388
389         devc = sdi->priv;
390
391         if (!has_devopt(devc->model, key | SR_CONF_GET))
392                 return SR_ERR_NA;
393
394         switch (key) {
395         case SR_CONF_SAMPLERATE:
396                 *data = g_variant_new_uint64(devc->samplerate);
397                 break;
398         case SR_CONF_LIMIT_MSEC:
399                 *data = g_variant_new_uint64(devc->limit_msec);
400                 break;
401         case SR_CONF_LIMIT_SAMPLES:
402                 *data = g_variant_new_uint64(devc->limit_samples);
403                 break;
404         case SR_CONF_RLE:
405                 *data = g_variant_new_boolean(devc->cfg_rle);
406                 break;
407         case SR_CONF_EXTERNAL_CLOCK:
408                 *data = g_variant_new_boolean(devc->cfg_clock_source
409                                                 == CLOCK_EXT_CLK);
410                 break;
411         case SR_CONF_CLOCK_EDGE:
412                 idx = devc->cfg_clock_edge;
413                 if (idx >= ARRAY_SIZE(signal_edge_names))
414                         return SR_ERR_BUG;
415                 *data = g_variant_new_string(signal_edge_names[idx]);
416                 break;
417         case SR_CONF_TRIGGER_SOURCE:
418                 idx = devc->cfg_trigger_source;
419                 if (idx >= ARRAY_SIZE(trigger_source_names))
420                         return SR_ERR_BUG;
421                 *data = g_variant_new_string(trigger_source_names[idx]);
422                 break;
423         case SR_CONF_TRIGGER_SLOPE:
424                 idx = devc->cfg_trigger_slope;
425                 if (idx >= ARRAY_SIZE(signal_edge_names))
426                         return SR_ERR_BUG;
427                 *data = g_variant_new_string(signal_edge_names[idx]);
428                 break;
429         default:
430                 /* Must not happen for a key listed in devopts. */
431                 return SR_ERR_BUG;
432         }
433
434         return SR_OK;
435 }
436
437 /* Helper for mapping a string-typed configuration value to an index
438  * within a table of possible values.
439  */
440 static int lookup_index(GVariant *value, const char *const *table, int len)
441 {
442         const char *entry;
443         int i;
444
445         entry = g_variant_get_string(value, NULL);
446         if (!entry)
447                 return -1;
448
449         /* Linear search is fine for very small tables. */
450         for (i = 0; i < len; i++) {
451                 if (strcmp(entry, table[i]) == 0)
452                         return i;
453         }
454
455         return -1;
456 }
457
458 /* Write device configuration setting.
459  */
460 static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
461                       const struct sr_channel_group *cg)
462 {
463         uint64_t value;
464         struct dev_context *devc;
465         int idx;
466
467         (void)cg;
468
469         if (!sdi)
470                 return SR_ERR_ARG;
471
472         devc = sdi->priv;
473
474         if (!has_devopt(devc->model, key | SR_CONF_SET))
475                 return SR_ERR_NA;
476
477         switch (key) {
478         case SR_CONF_SAMPLERATE:
479                 value = g_variant_get_uint64(data);
480                 if (value < devc->model->samplerates[devc->model->num_samplerates - 1]
481                                 || value > devc->model->samplerates[0])
482                         return SR_ERR_SAMPLERATE;
483                 devc->samplerate = value;
484                 break;
485         case SR_CONF_LIMIT_MSEC:
486                 value = g_variant_get_uint64(data);
487                 if (value > MAX_LIMIT_MSEC)
488                         return SR_ERR_ARG;
489                 devc->limit_msec = value;
490                 break;
491         case SR_CONF_LIMIT_SAMPLES:
492                 value = g_variant_get_uint64(data);
493                 if (value > MAX_LIMIT_SAMPLES)
494                         return SR_ERR_ARG;
495                 devc->limit_samples = value;
496                 break;
497         case SR_CONF_RLE:
498                 devc->cfg_rle = g_variant_get_boolean(data);
499                 break;
500         case SR_CONF_EXTERNAL_CLOCK:
501                 devc->cfg_clock_source = (g_variant_get_boolean(data))
502                         ? CLOCK_EXT_CLK : CLOCK_INTERNAL;
503                 break;
504         case SR_CONF_CLOCK_EDGE:
505                 idx = lookup_index(data, signal_edge_names,
506                                    ARRAY_SIZE(signal_edge_names));
507                 if (idx < 0)
508                         return SR_ERR_ARG;
509                 devc->cfg_clock_edge = idx;
510                 break;
511         case SR_CONF_TRIGGER_SOURCE:
512                 idx = lookup_index(data, trigger_source_names,
513                                    ARRAY_SIZE(trigger_source_names));
514                 if (idx < 0)
515                         return SR_ERR_ARG;
516                 devc->cfg_trigger_source = idx;
517                 break;
518         case SR_CONF_TRIGGER_SLOPE:
519                 idx = lookup_index(data, signal_edge_names,
520                                    ARRAY_SIZE(signal_edge_names));
521                 if (idx < 0)
522                         return SR_ERR_ARG;
523                 devc->cfg_trigger_slope = idx;
524                 break;
525         default:
526                 /* Must not happen for a key listed in devopts. */
527                 return SR_ERR_BUG;
528         }
529
530         return SR_OK;
531 }
532
533 /* Apply channel configuration change.
534  */
535 static int config_channel_set(const struct sr_dev_inst *sdi,
536                               struct sr_channel *ch, unsigned int changes)
537 {
538         uint64_t channel_bit;
539         struct dev_context *devc;
540
541         if (!sdi)
542                 return SR_ERR_ARG;
543
544         devc = sdi->priv;
545
546         if (ch->index < 0 || ch->index >= devc->model->num_channels) {
547                 sr_err("Channel index %d out of range.", ch->index);
548                 return SR_ERR_BUG;
549         }
550
551         if ((changes & SR_CHANNEL_SET_ENABLED) != 0) {
552                 channel_bit = UINT64_C(1) << ch->index;
553
554                 /* Enable or disable logic input for this channel. */
555                 if (ch->enabled)
556                         devc->channel_mask |= channel_bit;
557                 else
558                         devc->channel_mask &= ~channel_bit;
559         }
560
561         return SR_OK;
562 }
563
564 /* Derive trigger masks from the session's trigger configuration.
565  */
566 static int prepare_trigger_masks(const struct sr_dev_inst *sdi)
567 {
568         uint64_t trigger_mask, trigger_values, trigger_edge_mask;
569         uint64_t level_bit, type_bit;
570         struct dev_context *devc;
571         struct sr_trigger *trigger;
572         struct sr_trigger_stage *stage;
573         struct sr_trigger_match *match;
574         const GSList *node;
575         int idx;
576         enum sr_trigger_matches trg;
577
578         devc = sdi->priv;
579
580         trigger = sr_session_trigger_get(sdi->session);
581         if (!trigger || !trigger->stages)
582                 return SR_OK;
583
584         if (trigger->stages->next) {
585                 sr_err("This device only supports 1 trigger stage.");
586                 return SR_ERR_ARG;
587         }
588         stage = trigger->stages->data;
589
590         trigger_mask = 0;
591         trigger_values = 0;
592         trigger_edge_mask = 0;
593
594         for (node = stage->matches; node; node = node->next) {
595                 match = node->data;
596
597                 if (!match->channel->enabled)
598                         continue; /* Ignore disabled channel. */
599
600                 idx = match->channel->index;
601                 trg = match->match;
602
603                 if (idx < 0 || idx >= devc->model->num_channels) {
604                         sr_err("Channel index %d out of range.", idx);
605                         return SR_ERR_BUG; /* Should not happen. */
606                 }
607                 if (trg != SR_TRIGGER_ZERO
608                                 && trg != SR_TRIGGER_ONE
609                                 && trg != SR_TRIGGER_RISING
610                                 && trg != SR_TRIGGER_FALLING) {
611                         sr_err("Unsupported trigger match for CH%d.", idx + 1);
612                         return SR_ERR_ARG;
613                 }
614                 level_bit = (trg == SR_TRIGGER_ONE
615                         || trg == SR_TRIGGER_RISING) ? 1 : 0;
616                 type_bit = (trg == SR_TRIGGER_RISING
617                         || trg == SR_TRIGGER_FALLING) ? 1 : 0;
618
619                 trigger_mask |= UINT64_C(1) << idx;
620                 trigger_values |= level_bit << idx;
621                 trigger_edge_mask |= type_bit << idx;
622         }
623         devc->trigger_mask = trigger_mask;
624         devc->trigger_values = trigger_values;
625         devc->trigger_edge_mask = trigger_edge_mask;
626
627         return SR_OK;
628 }
629
630 /* Apply current device configuration to the hardware.
631  */
632 static int config_commit(const struct sr_dev_inst *sdi)
633 {
634         struct dev_context *devc;
635         int ret;
636
637         devc = sdi->priv;
638
639         if (devc->acquisition) {
640                 sr_err("Acquisition still in progress?");
641                 return SR_ERR;
642         }
643
644         ret = prepare_trigger_masks(sdi);
645         if (ret != SR_OK)
646                 return ret;
647
648         ret = (*devc->model->apply_fpga_config)(sdi);
649         if (ret != SR_OK) {
650                 sr_err("Failed to apply FPGA configuration.");
651                 return ret;
652         }
653
654         return SR_OK;
655 }
656
657 /* List available choices for a configuration setting.
658  */
659 static int config_list(uint32_t key, GVariant **data,
660                        const struct sr_dev_inst *sdi,
661                        const struct sr_channel_group *cg)
662 {
663         struct dev_context *devc;
664         GVariant *gvar;
665         GVariantBuilder gvb;
666
667         (void)cg;
668
669         if (key == SR_CONF_SCAN_OPTIONS) {
670                 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
671                         scanopts, ARRAY_SIZE(scanopts), sizeof(scanopts[0]));
672                 return SR_OK;
673         }
674         if (!sdi) {
675                 if (key != SR_CONF_DEVICE_OPTIONS)
676                         return SR_ERR_ARG;
677
678                 /* List driver capabilities. */
679                 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
680                         drvopts, ARRAY_SIZE(drvopts), sizeof(drvopts[0]));
681                 return SR_OK;
682         }
683
684         devc = sdi->priv;
685
686         /* List the model's device options. */
687         if (key == SR_CONF_DEVICE_OPTIONS) {
688                 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
689                         devc->model->devopts, devc->model->num_devopts,
690                         sizeof(devc->model->devopts[0]));
691                 return SR_OK;
692         }
693
694         if (!has_devopt(devc->model, key | SR_CONF_LIST))
695                 return SR_ERR_NA;
696
697         switch (key) {
698         case SR_CONF_SAMPLERATE:
699                 g_variant_builder_init(&gvb, G_VARIANT_TYPE_VARDICT);
700                 gvar = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
701                         devc->model->samplerates, devc->model->num_samplerates,
702                         sizeof(devc->model->samplerates[0]));
703                 g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
704                 *data = g_variant_builder_end(&gvb);
705                 break;
706         case SR_CONF_TRIGGER_MATCH:
707                 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
708                         trigger_matches, ARRAY_SIZE(trigger_matches),
709                         sizeof(trigger_matches[0]));
710                 break;
711         case SR_CONF_TRIGGER_SOURCE:
712                 *data = g_variant_new_strv(trigger_source_names,
713                         ARRAY_SIZE(trigger_source_names));
714                 break;
715         case SR_CONF_TRIGGER_SLOPE:
716         case SR_CONF_CLOCK_EDGE:
717                 *data = g_variant_new_strv(signal_edge_names,
718                         ARRAY_SIZE(signal_edge_names));
719                 break;
720         default:
721                 /* Must not happen for a key listed in devopts. */
722                 return SR_ERR_BUG;
723         }
724
725         return SR_OK;
726 }
727
728 /* Set up the device hardware to begin capturing samples as soon as the
729  * configured trigger conditions are met, or immediately if no triggers
730  * are configured.
731  */
732 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
733 {
734         return lwla_start_acquisition(sdi);
735 }
736
737 /* Request that a running capture operation be stopped.
738  */
739 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
740 {
741         struct dev_context *devc;
742
743         devc = sdi->priv;
744
745         if (devc->state != STATE_IDLE && !devc->cancel_requested) {
746                 devc->cancel_requested = TRUE;
747                 sr_dbg("Requesting cancel.");
748         }
749
750         return SR_OK;
751 }
752
753 /* SysClk LWLA driver descriptor.
754  */
755 static struct sr_dev_driver sysclk_lwla_driver_info = {
756         .name = "sysclk-lwla",
757         .longname = "SysClk LWLA series",
758         .api_version = 1,
759         .init = std_init,
760         .cleanup = std_cleanup,
761         .scan = scan,
762         .dev_list = std_dev_list,
763         .dev_clear = dev_clear,
764         .config_get = config_get,
765         .config_set = config_set,
766         .config_channel_set = config_channel_set,
767         .config_commit = config_commit,
768         .config_list = config_list,
769         .dev_open = dev_open,
770         .dev_close = dev_close,
771         .dev_acquisition_start = dev_acquisition_start,
772         .dev_acquisition_stop = dev_acquisition_stop,
773         .context = NULL,
774 };
775 SR_REGISTER_DEV_DRIVER(sysclk_lwla_driver_info);