]>
Commit | Line | Data |
---|---|---|
aeaad0b0 DE |
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 | ||
6ec6c43b | 20 | #include <config.h> |
5874e88d DE |
21 | #include <glib.h> |
22 | #include <libusb.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
c1aae900 | 25 | #include <libsigrok/libsigrok.h> |
515ab088 UH |
26 | #include "libsigrok-internal.h" |
27 | #include "protocol.h" | |
5874e88d | 28 | |
a0e0bb41 | 29 | static const uint32_t scanopts[] = { |
99c76642 DE |
30 | SR_CONF_CONN, |
31 | }; | |
32 | ||
f254bc4b | 33 | static const uint32_t devopts[] = { |
5874e88d | 34 | SR_CONF_LOGIC_ANALYZER, |
5827f61b BV |
35 | SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, |
36 | SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, | |
37 | SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
38 | SR_CONF_EXTERNAL_CLOCK | SR_CONF_GET | SR_CONF_SET, | |
39 | SR_CONF_CLOCK_EDGE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
40 | SR_CONF_TRIGGER_MATCH | SR_CONF_LIST, | |
41 | SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
42 | SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, | |
5874e88d DE |
43 | }; |
44 | ||
bbe7e48a BV |
45 | static const int32_t trigger_matches[] = { |
46 | SR_TRIGGER_ZERO, | |
47 | SR_TRIGGER_ONE, | |
48 | SR_TRIGGER_RISING, | |
49 | SR_TRIGGER_FALLING, | |
50 | }; | |
51 | ||
5874e88d DE |
52 | /* The hardware supports more samplerates than these, but these are the |
53 | * options hardcoded into the vendor's Windows GUI. | |
54 | */ | |
55 | static const uint64_t samplerates[] = { | |
56 | SR_MHZ(125), SR_MHZ(100), | |
57 | SR_MHZ(50), SR_MHZ(20), SR_MHZ(10), | |
58 | SR_MHZ(5), SR_MHZ(2), SR_MHZ(1), | |
59 | SR_KHZ(500), SR_KHZ(200), SR_KHZ(100), | |
60 | SR_KHZ(50), SR_KHZ(20), SR_KHZ(10), | |
61 | SR_KHZ(5), SR_KHZ(2), SR_KHZ(1), | |
62 | SR_HZ(500), SR_HZ(200), SR_HZ(100), | |
63 | }; | |
aeaad0b0 | 64 | |
e6e54bd2 DE |
65 | /* Names assigned to available trigger sources. Indices must match |
66 | * trigger_source enum values. | |
67 | */ | |
68 | static const char *const trigger_source_names[] = { "CH", "TRG" }; | |
69 | ||
70 | /* Names assigned to available trigger slope choices. Indices must | |
6358f0a9 | 71 | * match the signal_edge enum values. |
e6e54bd2 | 72 | */ |
6358f0a9 | 73 | static const char *const signal_edge_names[] = { "r", "f" }; |
e6e54bd2 | 74 | |
aeaad0b0 | 75 | SR_PRIV struct sr_dev_driver sysclk_lwla_driver_info; |
5874e88d | 76 | static struct sr_dev_driver *const di = &sysclk_lwla_driver_info; |
aeaad0b0 | 77 | |
4f840ce9 | 78 | static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) |
aeaad0b0 DE |
79 | { |
80 | return std_init(sr_ctx, di, LOG_PREFIX); | |
81 | } | |
82 | ||
0af636be | 83 | static struct sr_dev_inst *dev_inst_new(void) |
43db3436 DE |
84 | { |
85 | struct sr_dev_inst *sdi; | |
86 | struct dev_context *devc; | |
5e23fcab ML |
87 | int i; |
88 | char name[8]; | |
43db3436 DE |
89 | |
90 | /* Allocate memory for our private driver context. */ | |
f57d8ffe | 91 | devc = g_malloc0(sizeof(struct dev_context)); |
43db3436 DE |
92 | |
93 | /* Register the device with libsigrok. */ | |
aac29cc1 | 94 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be UH |
95 | sdi->status = SR_ST_INACTIVE; |
96 | sdi->vendor = g_strdup(VENDOR_NAME); | |
97 | sdi->model = g_strdup(MODEL_NAME); | |
43db3436 | 98 | |
ba7dd8bb | 99 | /* Enable all channels to match the default channel configuration. */ |
43db3436 DE |
100 | devc->channel_mask = ALL_CHANNELS_MASK; |
101 | devc->samplerate = DEFAULT_SAMPLERATE; | |
102 | ||
103 | sdi->priv = devc; | |
fe473123 | 104 | for (i = 0; i < NUM_CHANNELS; ++i) { |
5e23fcab | 105 | /* The LWLA series simply number channels from CH1 to CHxx. */ |
fe473123 DE |
106 | g_snprintf(name, sizeof(name), "CH%d", i + 1); |
107 | sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, name); | |
5e23fcab | 108 | } |
43db3436 DE |
109 | |
110 | return sdi; | |
111 | } | |
112 | ||
4f840ce9 | 113 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
aeaad0b0 | 114 | { |
5874e88d | 115 | GSList *usb_devices, *devices, *node; |
aeaad0b0 | 116 | struct drv_context *drvc; |
5874e88d | 117 | struct sr_dev_inst *sdi; |
5874e88d | 118 | struct sr_usb_dev_inst *usb; |
7ebe9b9e DE |
119 | struct sr_config *src; |
120 | const char *conn; | |
aeaad0b0 | 121 | |
41812aca | 122 | drvc = di->context; |
7ebe9b9e | 123 | conn = USB_VID_PID; |
5874e88d | 124 | |
7ebe9b9e DE |
125 | for (node = options; node != NULL; node = node->next) { |
126 | src = node->data; | |
127 | if (src->key == SR_CONF_CONN) { | |
128 | conn = g_variant_get_string(src->data, NULL); | |
129 | break; | |
130 | } | |
131 | } | |
132 | usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn); | |
133 | devices = NULL; | |
5874e88d DE |
134 | |
135 | for (node = usb_devices; node != NULL; node = node->next) { | |
136 | usb = node->data; | |
137 | ||
43db3436 | 138 | /* Create sigrok device instance. */ |
c79d4444 | 139 | sdi = dev_inst_new(); |
5874e88d | 140 | if (!sdi) { |
5874e88d DE |
141 | sr_usb_dev_inst_free(usb); |
142 | continue; | |
143 | } | |
144 | sdi->driver = di; | |
5874e88d DE |
145 | sdi->inst_type = SR_INST_USB; |
146 | sdi->conn = usb; | |
5874e88d | 147 | |
43db3436 | 148 | /* Register device instance with driver. */ |
5874e88d DE |
149 | drvc->instances = g_slist_append(drvc->instances, sdi); |
150 | devices = g_slist_append(devices, sdi); | |
151 | } | |
aeaad0b0 | 152 | |
5874e88d | 153 | g_slist_free(usb_devices); |
aeaad0b0 DE |
154 | |
155 | return devices; | |
156 | } | |
157 | ||
4f840ce9 | 158 | static GSList *dev_list(const struct sr_dev_driver *di) |
aeaad0b0 | 159 | { |
5874e88d DE |
160 | struct drv_context *drvc; |
161 | ||
41812aca | 162 | drvc = di->context; |
5874e88d DE |
163 | |
164 | return drvc->instances; | |
165 | } | |
166 | ||
167 | static void clear_dev_context(void *priv) | |
168 | { | |
169 | struct dev_context *devc; | |
170 | ||
171 | devc = priv; | |
172 | ||
173 | sr_dbg("Device context cleared."); | |
174 | ||
175 | lwla_free_acquisition_state(devc->acquisition); | |
176 | g_free(devc); | |
aeaad0b0 DE |
177 | } |
178 | ||
4f840ce9 | 179 | static int dev_clear(const struct sr_dev_driver *di) |
aeaad0b0 | 180 | { |
5874e88d | 181 | return std_dev_clear(di, &clear_dev_context); |
aeaad0b0 DE |
182 | } |
183 | ||
184 | static int dev_open(struct sr_dev_inst *sdi) | |
185 | { | |
5874e88d | 186 | struct drv_context *drvc; |
5874e88d DE |
187 | struct sr_usb_dev_inst *usb; |
188 | int ret; | |
aeaad0b0 | 189 | |
41812aca | 190 | drvc = di->context; |
aeaad0b0 | 191 | |
5874e88d DE |
192 | if (!drvc) { |
193 | sr_err("Driver was not initialized."); | |
194 | return SR_ERR; | |
195 | } | |
aeaad0b0 | 196 | |
43db3436 | 197 | usb = sdi->conn; |
5874e88d DE |
198 | |
199 | ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb); | |
200 | if (ret != SR_OK) | |
201 | return ret; | |
202 | ||
203 | ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE); | |
204 | if (ret < 0) { | |
205 | sr_err("Failed to claim interface: %s.", | |
206 | libusb_error_name(ret)); | |
207 | return SR_ERR; | |
208 | } | |
209 | ||
210 | sdi->status = SR_ST_INITIALIZING; | |
211 | ||
5874e88d DE |
212 | ret = lwla_init_device(sdi); |
213 | ||
214 | if (ret == SR_OK) | |
215 | sdi->status = SR_ST_ACTIVE; | |
216 | ||
217 | return ret; | |
aeaad0b0 DE |
218 | } |
219 | ||
220 | static int dev_close(struct sr_dev_inst *sdi) | |
221 | { | |
5874e88d | 222 | struct sr_usb_dev_inst *usb; |
5874e88d | 223 | |
41812aca | 224 | if (!di->context) { |
5874e88d DE |
225 | sr_err("Driver was not initialized."); |
226 | return SR_ERR; | |
227 | } | |
228 | ||
6358f0a9 | 229 | usb = sdi->conn; |
5874e88d DE |
230 | if (!usb->devhdl) |
231 | return SR_OK; | |
aeaad0b0 | 232 | |
6358f0a9 | 233 | sdi->status = SR_ST_INACTIVE; |
5874e88d | 234 | |
6358f0a9 DE |
235 | /* Trigger download of the shutdown bitstream. */ |
236 | if (lwla_set_clock_config(sdi) != SR_OK) | |
5874e88d DE |
237 | sr_err("Unable to shut down device."); |
238 | ||
239 | libusb_release_interface(usb->devhdl, USB_INTERFACE); | |
240 | libusb_close(usb->devhdl); | |
241 | ||
242 | usb->devhdl = NULL; | |
aeaad0b0 DE |
243 | |
244 | return SR_OK; | |
245 | } | |
246 | ||
4f840ce9 | 247 | static int cleanup(const struct sr_dev_driver *di) |
aeaad0b0 | 248 | { |
4f840ce9 | 249 | return dev_clear(di); |
aeaad0b0 DE |
250 | } |
251 | ||
584560f1 | 252 | static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
53b4680f | 253 | const struct sr_channel_group *cg) |
aeaad0b0 | 254 | { |
5874e88d | 255 | struct dev_context *devc; |
e6e54bd2 | 256 | size_t idx; |
aeaad0b0 | 257 | |
53b4680f | 258 | (void)cg; |
aeaad0b0 | 259 | |
5874e88d DE |
260 | if (!sdi) |
261 | return SR_ERR_ARG; | |
262 | ||
263 | devc = sdi->priv; | |
264 | ||
aeaad0b0 | 265 | switch (key) { |
5874e88d DE |
266 | case SR_CONF_SAMPLERATE: |
267 | *data = g_variant_new_uint64(devc->samplerate); | |
268 | break; | |
29d58767 DE |
269 | case SR_CONF_LIMIT_MSEC: |
270 | *data = g_variant_new_uint64(devc->limit_msec); | |
271 | break; | |
5874e88d DE |
272 | case SR_CONF_LIMIT_SAMPLES: |
273 | *data = g_variant_new_uint64(devc->limit_samples); | |
274 | break; | |
275 | case SR_CONF_EXTERNAL_CLOCK: | |
6358f0a9 DE |
276 | *data = g_variant_new_boolean(devc->cfg_clock_source |
277 | == CLOCK_EXT_CLK); | |
278 | break; | |
279 | case SR_CONF_CLOCK_EDGE: | |
280 | idx = devc->cfg_clock_edge; | |
ce3ecb70 | 281 | if (idx >= ARRAY_SIZE(signal_edge_names)) |
6358f0a9 DE |
282 | return SR_ERR_BUG; |
283 | *data = g_variant_new_string(signal_edge_names[idx]); | |
5874e88d | 284 | break; |
e6e54bd2 DE |
285 | case SR_CONF_TRIGGER_SOURCE: |
286 | idx = devc->cfg_trigger_source; | |
ce3ecb70 | 287 | if (idx >= ARRAY_SIZE(trigger_source_names)) |
e6e54bd2 DE |
288 | return SR_ERR_BUG; |
289 | *data = g_variant_new_string(trigger_source_names[idx]); | |
290 | break; | |
291 | case SR_CONF_TRIGGER_SLOPE: | |
292 | idx = devc->cfg_trigger_slope; | |
ce3ecb70 | 293 | if (idx >= ARRAY_SIZE(signal_edge_names)) |
e6e54bd2 | 294 | return SR_ERR_BUG; |
6358f0a9 | 295 | *data = g_variant_new_string(signal_edge_names[idx]); |
e6e54bd2 | 296 | break; |
aeaad0b0 DE |
297 | default: |
298 | return SR_ERR_NA; | |
299 | } | |
300 | ||
5874e88d | 301 | return SR_OK; |
aeaad0b0 DE |
302 | } |
303 | ||
e6e54bd2 DE |
304 | /* Helper for mapping a string-typed configuration value to an index |
305 | * within a table of possible values. | |
306 | */ | |
307 | static int lookup_index(GVariant *value, const char *const *table, int len) | |
308 | { | |
309 | const char *entry; | |
310 | int i; | |
311 | ||
312 | entry = g_variant_get_string(value, NULL); | |
313 | if (!entry) | |
314 | return -1; | |
315 | ||
316 | /* Linear search is fine for very small tables. */ | |
317 | for (i = 0; i < len; ++i) { | |
318 | if (strcmp(entry, table[i]) == 0) | |
319 | return i; | |
320 | } | |
321 | return -1; | |
322 | } | |
323 | ||
584560f1 | 324 | static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, |
53b4680f | 325 | const struct sr_channel_group *cg) |
aeaad0b0 | 326 | { |
29d58767 | 327 | uint64_t value; |
5874e88d | 328 | struct dev_context *devc; |
e6e54bd2 | 329 | int idx; |
aeaad0b0 | 330 | |
53b4680f | 331 | (void)cg; |
aeaad0b0 | 332 | |
5874e88d DE |
333 | devc = sdi->priv; |
334 | if (!devc) | |
aeaad0b0 DE |
335 | return SR_ERR_DEV_CLOSED; |
336 | ||
aeaad0b0 | 337 | switch (key) { |
5874e88d | 338 | case SR_CONF_SAMPLERATE: |
29d58767 | 339 | value = g_variant_get_uint64(data); |
ce3ecb70 | 340 | if (value < samplerates[ARRAY_SIZE(samplerates) - 1] |
29d58767 | 341 | || value > samplerates[0]) |
5874e88d | 342 | return SR_ERR_SAMPLERATE; |
29d58767 DE |
343 | devc->samplerate = value; |
344 | break; | |
345 | case SR_CONF_LIMIT_MSEC: | |
346 | value = g_variant_get_uint64(data); | |
347 | if (value > MAX_LIMIT_MSEC) | |
348 | return SR_ERR_ARG; | |
349 | devc->limit_msec = value; | |
5874e88d DE |
350 | break; |
351 | case SR_CONF_LIMIT_SAMPLES: | |
29d58767 DE |
352 | value = g_variant_get_uint64(data); |
353 | if (value > MAX_LIMIT_SAMPLES) | |
354 | return SR_ERR_ARG; | |
355 | devc->limit_samples = value; | |
5874e88d DE |
356 | break; |
357 | case SR_CONF_EXTERNAL_CLOCK: | |
6358f0a9 DE |
358 | devc->cfg_clock_source = (g_variant_get_boolean(data)) |
359 | ? CLOCK_EXT_CLK : CLOCK_INTERNAL; | |
360 | break; | |
361 | case SR_CONF_CLOCK_EDGE: | |
362 | idx = lookup_index(data, signal_edge_names, | |
ce3ecb70 | 363 | ARRAY_SIZE(signal_edge_names)); |
6358f0a9 DE |
364 | if (idx < 0) |
365 | return SR_ERR_ARG; | |
366 | devc->cfg_clock_edge = idx; | |
5874e88d | 367 | break; |
e6e54bd2 DE |
368 | case SR_CONF_TRIGGER_SOURCE: |
369 | idx = lookup_index(data, trigger_source_names, | |
ce3ecb70 | 370 | ARRAY_SIZE(trigger_source_names)); |
e6e54bd2 DE |
371 | if (idx < 0) |
372 | return SR_ERR_ARG; | |
373 | devc->cfg_trigger_source = idx; | |
374 | break; | |
375 | case SR_CONF_TRIGGER_SLOPE: | |
6358f0a9 | 376 | idx = lookup_index(data, signal_edge_names, |
ce3ecb70 | 377 | ARRAY_SIZE(signal_edge_names)); |
e6e54bd2 DE |
378 | if (idx < 0) |
379 | return SR_ERR_ARG; | |
380 | devc->cfg_trigger_slope = idx; | |
381 | break; | |
aeaad0b0 | 382 | default: |
5874e88d | 383 | return SR_ERR_NA; |
aeaad0b0 DE |
384 | } |
385 | ||
5874e88d | 386 | return SR_OK; |
aeaad0b0 DE |
387 | } |
388 | ||
f3ca73ed | 389 | static int config_channel_set(const struct sr_dev_inst *sdi, |
bbe7e48a | 390 | struct sr_channel *ch, unsigned int changes) |
43db3436 | 391 | { |
ba7dd8bb | 392 | uint64_t channel_bit; |
43db3436 DE |
393 | struct dev_context *devc; |
394 | ||
395 | devc = sdi->priv; | |
396 | if (!devc) | |
397 | return SR_ERR_DEV_CLOSED; | |
398 | ||
3f239f08 | 399 | if (ch->index < 0 || ch->index >= NUM_CHANNELS) { |
ba7dd8bb | 400 | sr_err("Channel index %d out of range.", ch->index); |
43db3436 DE |
401 | return SR_ERR_BUG; |
402 | } | |
ba7dd8bb | 403 | channel_bit = (uint64_t)1 << ch->index; |
43db3436 | 404 | |
3f239f08 | 405 | if ((changes & SR_CHANNEL_SET_ENABLED) != 0) { |
ba7dd8bb UH |
406 | /* Enable or disable input channel for this channel. */ |
407 | if (ch->enabled) | |
408 | devc->channel_mask |= channel_bit; | |
43db3436 | 409 | else |
ba7dd8bb | 410 | devc->channel_mask &= ~channel_bit; |
43db3436 DE |
411 | } |
412 | ||
43db3436 DE |
413 | return SR_OK; |
414 | } | |
415 | ||
225d3cb0 DE |
416 | static int prepare_trigger_masks(const struct sr_dev_inst *sdi) |
417 | { | |
418 | uint64_t trigger_mask; | |
419 | uint64_t trigger_values; | |
420 | uint64_t trigger_edge_mask; | |
421 | uint64_t channel_bit; | |
422 | struct dev_context *devc; | |
423 | struct sr_trigger *trigger; | |
424 | struct sr_trigger_stage *stage; | |
425 | struct sr_trigger_match *match; | |
426 | const GSList *node; | |
427 | ||
428 | devc = sdi->priv; | |
429 | ||
430 | trigger = sr_session_trigger_get(sdi->session); | |
431 | if (!trigger || !trigger->stages) | |
432 | return SR_OK; | |
433 | ||
434 | if (trigger->stages->next) { | |
435 | sr_err("This device only supports 1 trigger stage."); | |
436 | return SR_ERR_ARG; | |
437 | } | |
438 | stage = trigger->stages->data; | |
439 | ||
440 | trigger_mask = 0; | |
441 | trigger_values = 0; | |
442 | trigger_edge_mask = 0; | |
443 | ||
444 | for (node = stage->matches; node; node = node->next) { | |
445 | match = node->data; | |
446 | ||
447 | if (!match->channel->enabled) | |
448 | continue; /* ignore disabled channel */ | |
449 | ||
450 | channel_bit = (uint64_t)1 << match->channel->index; | |
451 | trigger_mask |= channel_bit; | |
452 | ||
453 | switch (match->match) { | |
454 | case SR_TRIGGER_ZERO: | |
455 | break; | |
456 | case SR_TRIGGER_ONE: | |
457 | trigger_values |= channel_bit; | |
458 | break; | |
459 | case SR_TRIGGER_RISING: | |
460 | trigger_values |= channel_bit; | |
461 | /* Fall through for edge mask. */ | |
462 | case SR_TRIGGER_FALLING: | |
463 | trigger_edge_mask |= channel_bit; | |
464 | break; | |
465 | default: | |
466 | sr_err("Unsupported trigger match for CH%d.", | |
467 | match->channel->index + 1); | |
468 | return SR_ERR_ARG; | |
469 | } | |
470 | } | |
471 | devc->trigger_mask = trigger_mask; | |
472 | devc->trigger_values = trigger_values; | |
473 | devc->trigger_edge_mask = trigger_edge_mask; | |
474 | ||
475 | return SR_OK; | |
476 | } | |
477 | ||
ee38c8ba DE |
478 | static int config_commit(const struct sr_dev_inst *sdi) |
479 | { | |
225d3cb0 DE |
480 | struct dev_context *devc; |
481 | int rc; | |
482 | ||
483 | if (sdi->status != SR_ST_ACTIVE) | |
484 | return SR_ERR_DEV_CLOSED; | |
485 | ||
486 | devc = sdi->priv; | |
487 | if (devc->acquisition) { | |
488 | sr_err("Acquisition still in progress?"); | |
ee38c8ba DE |
489 | return SR_ERR; |
490 | } | |
225d3cb0 DE |
491 | rc = prepare_trigger_masks(sdi); |
492 | if (rc != SR_OK) | |
493 | return rc; | |
ee38c8ba | 494 | |
6358f0a9 | 495 | return lwla_set_clock_config(sdi); |
ee38c8ba DE |
496 | } |
497 | ||
584560f1 | 498 | static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
53b4680f | 499 | const struct sr_channel_group *cg) |
aeaad0b0 | 500 | { |
5874e88d DE |
501 | GVariant *gvar; |
502 | GVariantBuilder gvb; | |
aeaad0b0 DE |
503 | |
504 | (void)sdi; | |
53b4680f | 505 | (void)cg; |
aeaad0b0 | 506 | |
aeaad0b0 | 507 | switch (key) { |
99c76642 | 508 | case SR_CONF_SCAN_OPTIONS: |
584560f1 | 509 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
a0e0bb41 | 510 | scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); |
99c76642 | 511 | break; |
5874e88d | 512 | case SR_CONF_DEVICE_OPTIONS: |
584560f1 | 513 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
ce3ecb70 | 514 | devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); |
5874e88d DE |
515 | break; |
516 | case SR_CONF_SAMPLERATE: | |
517 | g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); | |
518 | gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), | |
ce3ecb70 | 519 | samplerates, ARRAY_SIZE(samplerates), |
5874e88d DE |
520 | sizeof(uint64_t)); |
521 | g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); | |
522 | *data = g_variant_builder_end(&gvb); | |
523 | break; | |
bbe7e48a BV |
524 | case SR_CONF_TRIGGER_MATCH: |
525 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, | |
526 | trigger_matches, ARRAY_SIZE(trigger_matches), | |
527 | sizeof(int32_t)); | |
5874e88d | 528 | break; |
e6e54bd2 DE |
529 | case SR_CONF_TRIGGER_SOURCE: |
530 | *data = g_variant_new_strv(trigger_source_names, | |
ce3ecb70 | 531 | ARRAY_SIZE(trigger_source_names)); |
e6e54bd2 DE |
532 | break; |
533 | case SR_CONF_TRIGGER_SLOPE: | |
6358f0a9 DE |
534 | case SR_CONF_CLOCK_EDGE: |
535 | *data = g_variant_new_strv(signal_edge_names, | |
ce3ecb70 | 536 | ARRAY_SIZE(signal_edge_names)); |
e6e54bd2 | 537 | break; |
aeaad0b0 DE |
538 | default: |
539 | return SR_ERR_NA; | |
540 | } | |
541 | ||
5874e88d | 542 | return SR_OK; |
aeaad0b0 DE |
543 | } |
544 | ||
5874e88d DE |
545 | static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) |
546 | { | |
547 | struct drv_context *drvc; | |
548 | struct dev_context *devc; | |
549 | struct acquisition_state *acq; | |
550 | int ret; | |
551 | ||
aeaad0b0 DE |
552 | (void)cb_data; |
553 | ||
554 | if (sdi->status != SR_ST_ACTIVE) | |
555 | return SR_ERR_DEV_CLOSED; | |
556 | ||
5874e88d | 557 | devc = sdi->priv; |
41812aca | 558 | drvc = di->context; |
5874e88d DE |
559 | |
560 | if (devc->acquisition) { | |
561 | sr_err("Acquisition still in progress?"); | |
562 | return SR_ERR; | |
563 | } | |
564 | acq = lwla_alloc_acquisition_state(); | |
565 | if (!acq) | |
566 | return SR_ERR_MALLOC; | |
567 | ||
568 | devc->stopping_in_progress = FALSE; | |
569 | devc->transfer_error = FALSE; | |
570 | ||
5874e88d DE |
571 | sr_info("Starting acquisition."); |
572 | ||
573 | devc->acquisition = acq; | |
574 | ret = lwla_setup_acquisition(sdi); | |
575 | if (ret != SR_OK) { | |
a84f6ad3 | 576 | sr_err("Failed to set up acquisition."); |
5874e88d DE |
577 | devc->acquisition = NULL; |
578 | lwla_free_acquisition_state(acq); | |
579 | return ret; | |
580 | } | |
581 | ||
582 | ret = lwla_start_acquisition(sdi); | |
583 | if (ret != SR_OK) { | |
a84f6ad3 | 584 | sr_err("Failed to start acquisition."); |
5874e88d DE |
585 | devc->acquisition = NULL; |
586 | lwla_free_acquisition_state(acq); | |
587 | return ret; | |
588 | } | |
102f1239 | 589 | usb_source_add(sdi->session, drvc->sr_ctx, 100, &lwla_receive_data, |
5874e88d DE |
590 | (struct sr_dev_inst *)sdi); |
591 | ||
592 | sr_info("Waiting for data."); | |
593 | ||
594 | /* Send header packet to the session bus. */ | |
595 | std_session_send_df_header(sdi, LOG_PREFIX); | |
aeaad0b0 DE |
596 | |
597 | return SR_OK; | |
598 | } | |
599 | ||
600 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) | |
601 | { | |
602 | (void)cb_data; | |
603 | ||
604 | if (sdi->status != SR_ST_ACTIVE) | |
605 | return SR_ERR_DEV_CLOSED; | |
606 | ||
5874e88d DE |
607 | sr_dbg("Stopping acquisition."); |
608 | ||
609 | sdi->status = SR_ST_STOPPING; | |
aeaad0b0 DE |
610 | |
611 | return SR_OK; | |
612 | } | |
613 | ||
614 | SR_PRIV struct sr_dev_driver sysclk_lwla_driver_info = { | |
615 | .name = "sysclk-lwla", | |
5874e88d | 616 | .longname = "SysClk LWLA series", |
aeaad0b0 DE |
617 | .api_version = 1, |
618 | .init = init, | |
619 | .cleanup = cleanup, | |
620 | .scan = scan, | |
621 | .dev_list = dev_list, | |
622 | .dev_clear = dev_clear, | |
623 | .config_get = config_get, | |
624 | .config_set = config_set, | |
f3ca73ed | 625 | .config_channel_set = config_channel_set, |
ee38c8ba | 626 | .config_commit = config_commit, |
aeaad0b0 DE |
627 | .config_list = config_list, |
628 | .dev_open = dev_open, | |
629 | .dev_close = dev_close, | |
630 | .dev_acquisition_start = dev_acquisition_start, | |
631 | .dev_acquisition_stop = dev_acquisition_stop, | |
41812aca | 632 | .context = NULL, |
aeaad0b0 | 633 | }; |