]> sigrok.org Git - libsigrok.git/blob - src/hardware/sysclk-lwla/api.c
sr_dev_close(): Factor out SR_ERR_DEV_CLOSED check.
[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         if (sdi->status != SR_ST_INACTIVE) {
277                 sr_err("Device already open.");
278                 return SR_ERR;
279         }
280
281         /* Try the whole shebang three times, fingers crossed. */
282         for (i = 0; i < 3; i++) {
283                 ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb);
284                 if (ret != SR_OK)
285                         return ret;
286
287                 ret = libusb_set_configuration(usb->devhdl, USB_CONFIG);
288                 if (ret != LIBUSB_SUCCESS) {
289                         sr_err("Failed to set USB configuration: %s.",
290                                 libusb_error_name(ret));
291                         sr_usb_close(usb);
292                         return SR_ERR;
293                 }
294
295                 ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
296                 if (ret != LIBUSB_SUCCESS) {
297                         sr_err("Failed to claim interface: %s.",
298                                 libusb_error_name(ret));
299                         sr_usb_close(usb);
300                         return SR_ERR;
301                 }
302
303                 ret = drain_usb(usb, EP_REPLY);
304                 if (ret != SR_OK) {
305                         sr_usb_close(usb);
306                         return ret;
307                 }
308                 /* This delay appears to be necessary for reliable operation. */
309                 g_usleep(30 * 1000);
310
311                 sdi->status = SR_ST_ACTIVE;
312
313                 devc->active_fpga_config = FPGA_NOCONF;
314                 devc->short_transfer_quirk = FALSE;
315                 devc->state = STATE_IDLE;
316
317                 ret = (*devc->model->apply_fpga_config)(sdi);
318
319                 if (ret == SR_OK)
320                         ret = (*devc->model->device_init_check)(sdi);
321                 if (ret == SR_OK)
322                         break;
323
324                 /* Rinse and repeat. */
325                 sdi->status = SR_ST_INACTIVE;
326                 sr_usb_close(usb);
327         }
328
329         if (ret == SR_OK && devc->short_transfer_quirk)
330                 sr_warn("Short transfer quirk detected! "
331                         "Memory reads will be slow.");
332         return ret;
333 }
334
335 /* Shutdown and close device.
336  */
337 static int dev_close(struct sr_dev_inst *sdi)
338 {
339         struct dev_context *devc;
340         struct sr_usb_dev_inst *usb;
341         int ret;
342
343         devc = sdi->priv;
344         usb = sdi->conn;
345
346         if (devc->acquisition) {
347                 sr_err("Cannot close device during acquisition!");
348                 /* Request stop, leak handle, and prepare for the worst. */
349                 devc->cancel_requested = TRUE;
350                 return SR_ERR_BUG;
351         }
352
353         sdi->status = SR_ST_INACTIVE;
354
355         /* Download of the shutdown bitstream, if any. */
356         ret = (*devc->model->apply_fpga_config)(sdi);
357         if (ret != SR_OK)
358                 sr_warn("Unable to shut down device.");
359
360         libusb_release_interface(usb->devhdl, USB_INTERFACE);
361         sr_usb_close(usb);
362
363         return ret;
364 }
365
366 /* Check whether the device options contain a specific key.
367  * Also match against get/set/list bits if specified.
368  */
369 static int has_devopt(const struct model_info *model, uint32_t key)
370 {
371         unsigned int i;
372
373         for (i = 0; i < model->num_devopts; i++) {
374                 if ((model->devopts[i] & (SR_CONF_MASK | key)) == key)
375                         return TRUE;
376         }
377
378         return FALSE;
379 }
380
381 /* Read device configuration setting.
382  */
383 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
384                       const struct sr_channel_group *cg)
385 {
386         struct dev_context *devc;
387         unsigned int idx;
388
389         (void)cg;
390
391         if (!sdi)
392                 return SR_ERR_ARG;
393
394         devc = sdi->priv;
395
396         if (!has_devopt(devc->model, key | SR_CONF_GET))
397                 return SR_ERR_NA;
398
399         switch (key) {
400         case SR_CONF_SAMPLERATE:
401                 *data = g_variant_new_uint64(devc->samplerate);
402                 break;
403         case SR_CONF_LIMIT_MSEC:
404                 *data = g_variant_new_uint64(devc->limit_msec);
405                 break;
406         case SR_CONF_LIMIT_SAMPLES:
407                 *data = g_variant_new_uint64(devc->limit_samples);
408                 break;
409         case SR_CONF_RLE:
410                 *data = g_variant_new_boolean(devc->cfg_rle);
411                 break;
412         case SR_CONF_EXTERNAL_CLOCK:
413                 *data = g_variant_new_boolean(devc->cfg_clock_source
414                                                 == CLOCK_EXT_CLK);
415                 break;
416         case SR_CONF_CLOCK_EDGE:
417                 idx = devc->cfg_clock_edge;
418                 if (idx >= ARRAY_SIZE(signal_edge_names))
419                         return SR_ERR_BUG;
420                 *data = g_variant_new_string(signal_edge_names[idx]);
421                 break;
422         case SR_CONF_TRIGGER_SOURCE:
423                 idx = devc->cfg_trigger_source;
424                 if (idx >= ARRAY_SIZE(trigger_source_names))
425                         return SR_ERR_BUG;
426                 *data = g_variant_new_string(trigger_source_names[idx]);
427                 break;
428         case SR_CONF_TRIGGER_SLOPE:
429                 idx = devc->cfg_trigger_slope;
430                 if (idx >= ARRAY_SIZE(signal_edge_names))
431                         return SR_ERR_BUG;
432                 *data = g_variant_new_string(signal_edge_names[idx]);
433                 break;
434         default:
435                 /* Must not happen for a key listed in devopts. */
436                 return SR_ERR_BUG;
437         }
438
439         return SR_OK;
440 }
441
442 /* Helper for mapping a string-typed configuration value to an index
443  * within a table of possible values.
444  */
445 static int lookup_index(GVariant *value, const char *const *table, int len)
446 {
447         const char *entry;
448         int i;
449
450         entry = g_variant_get_string(value, NULL);
451         if (!entry)
452                 return -1;
453
454         /* Linear search is fine for very small tables. */
455         for (i = 0; i < len; i++) {
456                 if (strcmp(entry, table[i]) == 0)
457                         return i;
458         }
459
460         return -1;
461 }
462
463 /* Write device configuration setting.
464  */
465 static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
466                       const struct sr_channel_group *cg)
467 {
468         uint64_t value;
469         struct dev_context *devc;
470         int idx;
471
472         (void)cg;
473
474         if (!sdi)
475                 return SR_ERR_ARG;
476
477         devc = sdi->priv;
478
479         if (!has_devopt(devc->model, key | SR_CONF_SET))
480                 return SR_ERR_NA;
481
482         switch (key) {
483         case SR_CONF_SAMPLERATE:
484                 value = g_variant_get_uint64(data);
485                 if (value < devc->model->samplerates[devc->model->num_samplerates - 1]
486                                 || value > devc->model->samplerates[0])
487                         return SR_ERR_SAMPLERATE;
488                 devc->samplerate = value;
489                 break;
490         case SR_CONF_LIMIT_MSEC:
491                 value = g_variant_get_uint64(data);
492                 if (value > MAX_LIMIT_MSEC)
493                         return SR_ERR_ARG;
494                 devc->limit_msec = value;
495                 break;
496         case SR_CONF_LIMIT_SAMPLES:
497                 value = g_variant_get_uint64(data);
498                 if (value > MAX_LIMIT_SAMPLES)
499                         return SR_ERR_ARG;
500                 devc->limit_samples = value;
501                 break;
502         case SR_CONF_RLE:
503                 devc->cfg_rle = g_variant_get_boolean(data);
504                 break;
505         case SR_CONF_EXTERNAL_CLOCK:
506                 devc->cfg_clock_source = (g_variant_get_boolean(data))
507                         ? CLOCK_EXT_CLK : CLOCK_INTERNAL;
508                 break;
509         case SR_CONF_CLOCK_EDGE:
510                 idx = lookup_index(data, signal_edge_names,
511                                    ARRAY_SIZE(signal_edge_names));
512                 if (idx < 0)
513                         return SR_ERR_ARG;
514                 devc->cfg_clock_edge = idx;
515                 break;
516         case SR_CONF_TRIGGER_SOURCE:
517                 idx = lookup_index(data, trigger_source_names,
518                                    ARRAY_SIZE(trigger_source_names));
519                 if (idx < 0)
520                         return SR_ERR_ARG;
521                 devc->cfg_trigger_source = idx;
522                 break;
523         case SR_CONF_TRIGGER_SLOPE:
524                 idx = lookup_index(data, signal_edge_names,
525                                    ARRAY_SIZE(signal_edge_names));
526                 if (idx < 0)
527                         return SR_ERR_ARG;
528                 devc->cfg_trigger_slope = idx;
529                 break;
530         default:
531                 /* Must not happen for a key listed in devopts. */
532                 return SR_ERR_BUG;
533         }
534
535         return SR_OK;
536 }
537
538 /* Apply channel configuration change.
539  */
540 static int config_channel_set(const struct sr_dev_inst *sdi,
541                               struct sr_channel *ch, unsigned int changes)
542 {
543         uint64_t channel_bit;
544         struct dev_context *devc;
545
546         if (!sdi)
547                 return SR_ERR_ARG;
548
549         devc = sdi->priv;
550
551         if (ch->index < 0 || ch->index >= devc->model->num_channels) {
552                 sr_err("Channel index %d out of range.", ch->index);
553                 return SR_ERR_BUG;
554         }
555
556         if ((changes & SR_CHANNEL_SET_ENABLED) != 0) {
557                 channel_bit = UINT64_C(1) << ch->index;
558
559                 /* Enable or disable logic input for this channel. */
560                 if (ch->enabled)
561                         devc->channel_mask |= channel_bit;
562                 else
563                         devc->channel_mask &= ~channel_bit;
564         }
565
566         return SR_OK;
567 }
568
569 /* Derive trigger masks from the session's trigger configuration.
570  */
571 static int prepare_trigger_masks(const struct sr_dev_inst *sdi)
572 {
573         uint64_t trigger_mask, trigger_values, trigger_edge_mask;
574         uint64_t level_bit, type_bit;
575         struct dev_context *devc;
576         struct sr_trigger *trigger;
577         struct sr_trigger_stage *stage;
578         struct sr_trigger_match *match;
579         const GSList *node;
580         int idx;
581         enum sr_trigger_matches trg;
582
583         devc = sdi->priv;
584
585         trigger = sr_session_trigger_get(sdi->session);
586         if (!trigger || !trigger->stages)
587                 return SR_OK;
588
589         if (trigger->stages->next) {
590                 sr_err("This device only supports 1 trigger stage.");
591                 return SR_ERR_ARG;
592         }
593         stage = trigger->stages->data;
594
595         trigger_mask = 0;
596         trigger_values = 0;
597         trigger_edge_mask = 0;
598
599         for (node = stage->matches; node; node = node->next) {
600                 match = node->data;
601
602                 if (!match->channel->enabled)
603                         continue; /* Ignore disabled channel. */
604
605                 idx = match->channel->index;
606                 trg = match->match;
607
608                 if (idx < 0 || idx >= devc->model->num_channels) {
609                         sr_err("Channel index %d out of range.", idx);
610                         return SR_ERR_BUG; /* Should not happen. */
611                 }
612                 if (trg != SR_TRIGGER_ZERO
613                                 && trg != SR_TRIGGER_ONE
614                                 && trg != SR_TRIGGER_RISING
615                                 && trg != SR_TRIGGER_FALLING) {
616                         sr_err("Unsupported trigger match for CH%d.", idx + 1);
617                         return SR_ERR_ARG;
618                 }
619                 level_bit = (trg == SR_TRIGGER_ONE
620                         || trg == SR_TRIGGER_RISING) ? 1 : 0;
621                 type_bit = (trg == SR_TRIGGER_RISING
622                         || trg == SR_TRIGGER_FALLING) ? 1 : 0;
623
624                 trigger_mask |= UINT64_C(1) << idx;
625                 trigger_values |= level_bit << idx;
626                 trigger_edge_mask |= type_bit << idx;
627         }
628         devc->trigger_mask = trigger_mask;
629         devc->trigger_values = trigger_values;
630         devc->trigger_edge_mask = trigger_edge_mask;
631
632         return SR_OK;
633 }
634
635 /* Apply current device configuration to the hardware.
636  */
637 static int config_commit(const struct sr_dev_inst *sdi)
638 {
639         struct dev_context *devc;
640         int ret;
641
642         devc = sdi->priv;
643
644         if (devc->acquisition) {
645                 sr_err("Acquisition still in progress?");
646                 return SR_ERR;
647         }
648
649         ret = prepare_trigger_masks(sdi);
650         if (ret != SR_OK)
651                 return ret;
652
653         ret = (*devc->model->apply_fpga_config)(sdi);
654         if (ret != SR_OK) {
655                 sr_err("Failed to apply FPGA configuration.");
656                 return ret;
657         }
658
659         return SR_OK;
660 }
661
662 /* List available choices for a configuration setting.
663  */
664 static int config_list(uint32_t key, GVariant **data,
665                        const struct sr_dev_inst *sdi,
666                        const struct sr_channel_group *cg)
667 {
668         struct dev_context *devc;
669         GVariant *gvar;
670         GVariantBuilder gvb;
671
672         (void)cg;
673
674         if (key == SR_CONF_SCAN_OPTIONS) {
675                 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
676                         scanopts, ARRAY_SIZE(scanopts), sizeof(scanopts[0]));
677                 return SR_OK;
678         }
679         if (!sdi) {
680                 if (key != SR_CONF_DEVICE_OPTIONS)
681                         return SR_ERR_ARG;
682
683                 /* List driver capabilities. */
684                 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
685                         drvopts, ARRAY_SIZE(drvopts), sizeof(drvopts[0]));
686                 return SR_OK;
687         }
688
689         devc = sdi->priv;
690
691         /* List the model's device options. */
692         if (key == SR_CONF_DEVICE_OPTIONS) {
693                 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
694                         devc->model->devopts, devc->model->num_devopts,
695                         sizeof(devc->model->devopts[0]));
696                 return SR_OK;
697         }
698
699         if (!has_devopt(devc->model, key | SR_CONF_LIST))
700                 return SR_ERR_NA;
701
702         switch (key) {
703         case SR_CONF_SAMPLERATE:
704                 g_variant_builder_init(&gvb, G_VARIANT_TYPE_VARDICT);
705                 gvar = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
706                         devc->model->samplerates, devc->model->num_samplerates,
707                         sizeof(devc->model->samplerates[0]));
708                 g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
709                 *data = g_variant_builder_end(&gvb);
710                 break;
711         case SR_CONF_TRIGGER_MATCH:
712                 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
713                         trigger_matches, ARRAY_SIZE(trigger_matches),
714                         sizeof(trigger_matches[0]));
715                 break;
716         case SR_CONF_TRIGGER_SOURCE:
717                 *data = g_variant_new_strv(trigger_source_names,
718                         ARRAY_SIZE(trigger_source_names));
719                 break;
720         case SR_CONF_TRIGGER_SLOPE:
721         case SR_CONF_CLOCK_EDGE:
722                 *data = g_variant_new_strv(signal_edge_names,
723                         ARRAY_SIZE(signal_edge_names));
724                 break;
725         default:
726                 /* Must not happen for a key listed in devopts. */
727                 return SR_ERR_BUG;
728         }
729
730         return SR_OK;
731 }
732
733 /* Set up the device hardware to begin capturing samples as soon as the
734  * configured trigger conditions are met, or immediately if no triggers
735  * are configured.
736  */
737 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
738 {
739         return lwla_start_acquisition(sdi);
740 }
741
742 /* Request that a running capture operation be stopped.
743  */
744 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
745 {
746         struct dev_context *devc;
747
748         devc = sdi->priv;
749
750         if (devc->state != STATE_IDLE && !devc->cancel_requested) {
751                 devc->cancel_requested = TRUE;
752                 sr_dbg("Requesting cancel.");
753         }
754
755         return SR_OK;
756 }
757
758 /* SysClk LWLA driver descriptor.
759  */
760 static struct sr_dev_driver sysclk_lwla_driver_info = {
761         .name = "sysclk-lwla",
762         .longname = "SysClk LWLA series",
763         .api_version = 1,
764         .init = std_init,
765         .cleanup = std_cleanup,
766         .scan = scan,
767         .dev_list = std_dev_list,
768         .dev_clear = dev_clear,
769         .config_get = config_get,
770         .config_set = config_set,
771         .config_channel_set = config_channel_set,
772         .config_commit = config_commit,
773         .config_list = config_list,
774         .dev_open = dev_open,
775         .dev_close = dev_close,
776         .dev_acquisition_start = dev_acquisition_start,
777         .dev_acquisition_stop = dev_acquisition_stop,
778         .context = NULL,
779 };
780 SR_REGISTER_DEV_DRIVER(sysclk_lwla_driver_info);