]> sigrok.org Git - libsigrok.git/blame - src/libsigrok-internal.h
rigol-ds: improve robustness in samplerate getting code path
[libsigrok.git] / src / libsigrok-internal.h
CommitLineData
1483577e 1/*
50985c20 2 * This file is part of the libsigrok project.
1483577e 3 *
13d8e03c 4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
1483577e
UH
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
a5827886
UH
20#ifndef LIBSIGROK_LIBSIGROK_INTERNAL_H
21#define LIBSIGROK_LIBSIGROK_INTERNAL_H
1483577e 22
1df81f4b
GS
23#include "config.h"
24
cc8a7d25 25#include <glib.h>
4417074c
GS
26#ifdef HAVE_LIBHIDAPI
27#include <hidapi.h>
28#endif
c4f2dfd0 29#ifdef HAVE_LIBSERIALPORT
dc991353 30#include <libserialport.h>
c4f2dfd0 31#endif
fdcdfe53
GS
32#ifdef HAVE_LIBUSB_1_0
33#include <libusb.h>
34#endif
e1a712ca
GS
35#ifdef HAVE_LIBFTDI
36#include <ftdi.h>
37#endif
fdcdfe53 38#include <stdarg.h>
ad5aa993 39#include <stdint.h>
fdcdfe53 40#include <stdio.h>
ae4c1fb6 41#include <stdlib.h>
b08024a8 42
98654c99
DE
43struct zip;
44struct zip_stat;
45
393fb9cb
UH
46/**
47 * @file
48 *
49 * libsigrok private header file, only to be used internally.
50 */
51
4cea9eb2
UH
52/*--- Macros ----------------------------------------------------------------*/
53
54#ifndef ARRAY_SIZE
55#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
56#endif
57
58#ifndef ARRAY_AND_SIZE
59#define ARRAY_AND_SIZE(a) (a), ARRAY_SIZE(a)
60#endif
61
6cfc6c5c
UH
62#ifndef G_SOURCE_FUNC
63#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f)) /* Since 2.58. */
64#endif
65
66#define SR_RECEIVE_DATA_CALLBACK(f) \
67 ((sr_receive_data_callback) (void (*)(void)) (f))
68
a4f9c35b 69/**
5bf0dd6a 70 * Read a 8 bits unsigned integer out of memory.
a4f9c35b 71 * @param x a pointer to the input memory
5bf0dd6a 72 * @return the corresponding unsigned integer
a4f9c35b 73 */
f1833600
GS
74static inline uint8_t read_u8(const uint8_t *p)
75{
76 return p[0];
77}
78#define R8(x) read_u8((const uint8_t *)(x))
a4f9c35b 79
e4bcc63d
GS
80/**
81 * Read an 8 bits signed integer out of memory.
82 * @param x a pointer to the input memory
83 * @return the corresponding signed integer
84 */
85static inline int8_t read_i8(const uint8_t *p)
86{
87 return (int8_t)p[0];
88}
89
e28ef28a 90/**
5bf0dd6a 91 * Read a 16 bits big endian unsigned integer out of memory.
e28ef28a 92 * @param x a pointer to the input memory
5bf0dd6a 93 * @return the corresponding unsigned integer
e28ef28a 94 */
f1833600
GS
95static inline uint16_t read_u16be(const uint8_t *p)
96{
97 uint16_t u;
98
99 u = 0;
100 u <<= 8; u |= p[0];
101 u <<= 8; u |= p[1];
102
103 return u;
104}
105#define RB16(x) read_u16be((const uint8_t *)(x))
e28ef28a
AJ
106
107/**
5bf0dd6a 108 * Read a 16 bits little endian unsigned integer out of memory.
e28ef28a 109 * @param x a pointer to the input memory
5bf0dd6a 110 * @return the corresponding unsigned integer
e28ef28a 111 */
f1833600
GS
112static inline uint16_t read_u16le(const uint8_t *p)
113{
114 uint16_t u;
115
116 u = 0;
117 u <<= 8; u |= p[1];
118 u <<= 8; u |= p[0];
119
120 return u;
121}
122#define RL16(x) read_u16le((const uint8_t *)(x))
e28ef28a 123
4d376e08
SB
124/**
125 * Read a 16 bits big endian signed integer out of memory.
126 * @param x a pointer to the input memory
127 * @return the corresponding signed integer
128 */
f1833600
GS
129static inline int16_t read_i16be(const uint8_t *p)
130{
131 uint16_t u;
132 int16_t i;
133
134 u = read_u16be(p);
135 i = (int16_t)u;
136
137 return i;
138}
139#define RB16S(x) read_i16be((const uint8_t *)(x))
4d376e08 140
e28ef28a 141/**
5bf0dd6a 142 * Read a 16 bits little endian signed integer out of memory.
e28ef28a 143 * @param x a pointer to the input memory
5bf0dd6a
BV
144 * @return the corresponding signed integer
145 */
f1833600
GS
146static inline int16_t read_i16le(const uint8_t *p)
147{
148 uint16_t u;
149 int16_t i;
150
151 u = read_u16le(p);
152 i = (int16_t)u;
153
154 return i;
155}
156#define RL16S(x) read_i16le((const uint8_t *)(x))
5bf0dd6a 157
080b6bcf
GS
158/**
159 * Read a 24 bits little endian unsigned integer out of memory.
160 * @param x a pointer to the input memory
161 * @return the corresponding unsigned integer
162 */
163static inline uint32_t read_u24le(const uint8_t *p)
164{
165 uint32_t u;
166
167 u = 0;
168 u <<= 8; u |= p[2];
169 u <<= 8; u |= p[1];
170 u <<= 8; u |= p[0];
171
172 return u;
173}
174
5bf0dd6a
BV
175/**
176 * Read a 32 bits big endian unsigned integer out of memory.
177 * @param x a pointer to the input memory
178 * @return the corresponding unsigned integer
e28ef28a 179 */
f1833600
GS
180static inline uint32_t read_u32be(const uint8_t *p)
181{
182 uint32_t u;
183
184 u = 0;
185 u <<= 8; u |= p[0];
186 u <<= 8; u |= p[1];
187 u <<= 8; u |= p[2];
188 u <<= 8; u |= p[3];
189
190 return u;
191}
192#define RB32(x) read_u32be((const uint8_t *)(x))
e28ef28a
AJ
193
194/**
5bf0dd6a 195 * Read a 32 bits little endian unsigned integer out of memory.
e28ef28a 196 * @param x a pointer to the input memory
5bf0dd6a 197 * @return the corresponding unsigned integer
e28ef28a 198 */
f1833600
GS
199static inline uint32_t read_u32le(const uint8_t *p)
200{
201 uint32_t u;
202
203 u = 0;
204 u <<= 8; u |= p[3];
205 u <<= 8; u |= p[2];
206 u <<= 8; u |= p[1];
207 u <<= 8; u |= p[0];
208
209 return u;
210}
211#define RL32(x) read_u32le((const uint8_t *)(x))
e28ef28a 212
4d376e08
SB
213/**
214 * Read a 32 bits big endian signed integer out of memory.
215 * @param x a pointer to the input memory
216 * @return the corresponding signed integer
217 */
f1833600
GS
218static inline int32_t read_i32be(const uint8_t *p)
219{
220 uint32_t u;
221 int32_t i;
222
223 u = read_u32be(p);
224 i = (int32_t)u;
225
226 return i;
227}
228#define RB32S(x) read_i32be((const uint8_t *)(x))
4d376e08 229
ea2d6d99 230/**
5bf0dd6a
BV
231 * Read a 32 bits little endian signed integer out of memory.
232 * @param x a pointer to the input memory
233 * @return the corresponding signed integer
234 */
f1833600
GS
235static inline int32_t read_i32le(const uint8_t *p)
236{
237 uint32_t u;
238 int32_t i;
239
240 u = read_u32le(p);
241 i = (int32_t)u;
242
243 return i;
244}
245#define RL32S(x) read_i32le((const uint8_t *)(x))
5bf0dd6a 246
17b93fd7
TS
247/**
248 * Read a 64 bits big endian unsigned integer out of memory.
249 * @param x a pointer to the input memory
250 * @return the corresponding unsigned integer
251 */
f1833600
GS
252static inline uint64_t read_u64be(const uint8_t *p)
253{
254 uint64_t u;
255
256 u = 0;
257 u <<= 8; u |= p[0];
258 u <<= 8; u |= p[1];
259 u <<= 8; u |= p[2];
260 u <<= 8; u |= p[3];
261 u <<= 8; u |= p[4];
262 u <<= 8; u |= p[5];
263 u <<= 8; u |= p[6];
264 u <<= 8; u |= p[7];
265
266 return u;
267}
268#define RB64(x) read_u64be((const uint8_t *)(x))
17b93fd7 269
8a66b077
SA
270/**
271 * Read a 64 bits little endian unsigned integer out of memory.
272 * @param x a pointer to the input memory
273 * @return the corresponding unsigned integer
274 */
f1833600
GS
275static inline uint64_t read_u64le(const uint8_t *p)
276{
277 uint64_t u;
278
279 u = 0;
280 u <<= 8; u |= p[7];
281 u <<= 8; u |= p[6];
282 u <<= 8; u |= p[5];
283 u <<= 8; u |= p[4];
284 u <<= 8; u |= p[3];
285 u <<= 8; u |= p[2];
286 u <<= 8; u |= p[1];
287 u <<= 8; u |= p[0];
288
289 return u;
290}
291#define RL64(x) read_u64le((const uint8_t *)(x))
292
293/**
294 * Read a 64 bits big endian signed integer out of memory.
295 * @param x a pointer to the input memory
296 * @return the corresponding unsigned integer
297 */
298static inline int64_t read_i64be(const uint8_t *p)
299{
300 uint64_t u;
301 int64_t i;
302
303 u = read_u64be(p);
304 i = (int64_t)u;
305
306 return i;
307}
308#define RB64S(x) read_i64be((const uint8_t *)(x))
8a66b077
SA
309
310/**
311 * Read a 64 bits little endian signed integer out of memory.
312 * @param x a pointer to the input memory
313 * @return the corresponding unsigned integer
314 */
f1833600
GS
315static inline int64_t read_i64le(const uint8_t *p)
316{
317 uint64_t u;
318 int64_t i;
319
320 u = read_u64le(p);
321 i = (int64_t)u;
322
323 return i;
324}
325#define RL64S(x) read_i64le((const uint8_t *)(x))
8a66b077 326
a2632bca 327/**
daa895cb 328 * Read a 32 bits big endian float out of memory (single precision).
a2632bca
AJ
329 * @param x a pointer to the input memory
330 * @return the corresponding float
331 */
f1833600
GS
332static inline float read_fltbe(const uint8_t *p)
333{
334 /*
335 * Implementor's note: Strictly speaking the "union" trick
336 * is not portable. But this phrase was found to work on the
337 * project's supported platforms, and serve well until a more
338 * appropriate phrase is found.
339 */
340 union { uint32_t u32; float flt; } u;
341 float f;
342
343 u.u32 = read_u32be(p);
344 f = u.flt;
345
346 return f;
347}
348#define RBFL(x) read_fltbe((const uint8_t *)(x))
a2632bca
AJ
349
350/**
daa895cb 351 * Read a 32 bits little endian float out of memory (single precision).
a2632bca
AJ
352 * @param x a pointer to the input memory
353 * @return the corresponding float
354 */
f1833600
GS
355static inline float read_fltle(const uint8_t *p)
356{
357 /*
358 * Implementor's note: Strictly speaking the "union" trick
359 * is not portable. But this phrase was found to work on the
360 * project's supported platforms, and serve well until a more
361 * appropriate phrase is found.
362 */
363 union { uint32_t u32; float flt; } u;
364 float f;
365
366 u.u32 = read_u32le(p);
367 f = u.flt;
368
369 return f;
370}
371#define RLFL(x) read_fltle((const uint8_t *)(x))
a2632bca 372
e4bcc63d
GS
373/**
374 * Read a 64 bits big endian float out of memory (double precision).
375 * @param x a pointer to the input memory
376 * @return the corresponding floating point value
377 */
378static inline double read_dblbe(const uint8_t *p)
379{
380 /*
381 * Implementor's note: Strictly speaking the "union" trick
382 * is not portable. But this phrase was found to work on the
383 * project's supported platforms, and serve well until a more
384 * appropriate phrase is found.
385 */
386 union { uint64_t u64; double flt; } u;
387 double f;
388
389 u.u64 = read_u64be(p);
390 f = u.flt;
391
392 return f;
393}
394
daa895cb
GS
395/**
396 * Read a 64 bits little endian float out of memory (double precision).
397 * @param x a pointer to the input memory
398 * @return the corresponding floating point value
399 */
400static inline double read_dblle(const uint8_t *p)
401{
402 /*
403 * Implementor's note: Strictly speaking the "union" trick
404 * is not portable. But this phrase was found to work on the
405 * project's supported platforms, and serve well until a more
406 * appropriate phrase is found.
407 */
408 union { uint64_t u64; double flt; } u;
409 double f;
410
411 u.u64 = read_u64le(p);
412 f = u.flt;
413
414 return f;
415}
416#define RLDB(x) read_dblle((const uint8_t *)(x))
417
5bf0dd6a
BV
418/**
419 * Write a 8 bits unsigned integer to memory.
ea2d6d99 420 * @param p a pointer to the output memory
5bf0dd6a 421 * @param x the input unsigned integer
ea2d6d99 422 */
f1833600
GS
423static inline void write_u8(uint8_t *p, uint8_t x)
424{
425 p[0] = x;
426}
427#define W8(p, x) write_u8((uint8_t *)(p), (uint8_t)(x))
ea2d6d99
AJ
428
429/**
5bf0dd6a 430 * Write a 16 bits unsigned integer to memory stored as big endian.
ea2d6d99 431 * @param p a pointer to the output memory
5bf0dd6a 432 * @param x the input unsigned integer
ea2d6d99 433 */
f1833600
GS
434static inline void write_u16be(uint8_t *p, uint16_t x)
435{
436 p[1] = x & 0xff; x >>= 8;
437 p[0] = x & 0xff; x >>= 8;
438}
439#define WB16(p, x) write_u16be((uint8_t *)(p), (uint16_t)(x))
ea2d6d99
AJ
440
441/**
5bf0dd6a 442 * Write a 16 bits unsigned integer to memory stored as little endian.
ea2d6d99 443 * @param p a pointer to the output memory
5bf0dd6a 444 * @param x the input unsigned integer
ea2d6d99 445 */
f1833600
GS
446static inline void write_u16le(uint8_t *p, uint16_t x)
447{
448 p[0] = x & 0xff; x >>= 8;
449 p[1] = x & 0xff; x >>= 8;
450}
451#define WL16(p, x) write_u16le((uint8_t *)(p), (uint16_t)(x))
ea2d6d99
AJ
452
453/**
5bf0dd6a 454 * Write a 32 bits unsigned integer to memory stored as big endian.
ea2d6d99 455 * @param p a pointer to the output memory
5bf0dd6a 456 * @param x the input unsigned integer
ea2d6d99 457 */
f1833600
GS
458static inline void write_u32be(uint8_t *p, uint32_t x)
459{
460 p[3] = x & 0xff; x >>= 8;
461 p[2] = x & 0xff; x >>= 8;
462 p[1] = x & 0xff; x >>= 8;
463 p[0] = x & 0xff; x >>= 8;
464}
465#define WB32(p, x) write_u32be((uint8_t *)(p), (uint32_t)(x))
ea2d6d99
AJ
466
467/**
5bf0dd6a 468 * Write a 32 bits unsigned integer to memory stored as little endian.
ea2d6d99 469 * @param p a pointer to the output memory
5bf0dd6a 470 * @param x the input unsigned integer
ea2d6d99 471 */
f1833600
GS
472static inline void write_u32le(uint8_t *p, uint32_t x)
473{
474 p[0] = x & 0xff; x >>= 8;
475 p[1] = x & 0xff; x >>= 8;
476 p[2] = x & 0xff; x >>= 8;
477 p[3] = x & 0xff; x >>= 8;
478}
479#define WL32(p, x) write_u32le((uint8_t *)(p), (uint32_t)(x))
ea2d6d99 480
797c8d90
GS
481/**
482 * Write a 48 bits unsigned integer to memory stored as little endian.
483 * @param p a pointer to the output memory
484 * @param x the input unsigned integer
485 */
486static inline void write_u48le(uint8_t *p, uint64_t x)
487{
488 p[0] = x & 0xff; x >>= 8;
489 p[1] = x & 0xff; x >>= 8;
490 p[2] = x & 0xff; x >>= 8;
491 p[3] = x & 0xff; x >>= 8;
492 p[4] = x & 0xff; x >>= 8;
493 p[5] = x & 0xff; x >>= 8;
494}
495#define WL48(p, x) write_u48le((uint8_t *)(p), (uint64_t)(x))
496
efce57da
GS
497/**
498 * Write a 64 bits unsigned integer to memory stored as big endian.
499 * @param p a pointer to the output memory
500 * @param x the input unsigned integer
501 */
502static inline void write_u64be(uint8_t *p, uint64_t x)
503{
504 p[7] = x & 0xff; x >>= 8;
505 p[6] = x & 0xff; x >>= 8;
506 p[5] = x & 0xff; x >>= 8;
507 p[4] = x & 0xff; x >>= 8;
508 p[3] = x & 0xff; x >>= 8;
509 p[2] = x & 0xff; x >>= 8;
510 p[1] = x & 0xff; x >>= 8;
511 p[0] = x & 0xff; x >>= 8;
512}
513
daa895cb
GS
514/**
515 * Write a 64 bits unsigned integer to memory stored as little endian.
516 * @param p a pointer to the output memory
517 * @param x the input unsigned integer
518 */
519static inline void write_u64le(uint8_t *p, uint64_t x)
520{
521 p[0] = x & 0xff; x >>= 8;
522 p[1] = x & 0xff; x >>= 8;
523 p[2] = x & 0xff; x >>= 8;
524 p[3] = x & 0xff; x >>= 8;
525 p[4] = x & 0xff; x >>= 8;
526 p[5] = x & 0xff; x >>= 8;
527 p[6] = x & 0xff; x >>= 8;
528 p[7] = x & 0xff; x >>= 8;
529}
530#define WL64(p, x) write_u64le((uint8_t *)(p), (uint64_t)(x))
531
a2632bca
AJ
532/**
533 * Write a 32 bits float to memory stored as big endian.
534 * @param p a pointer to the output memory
535 * @param x the input float
536 */
f1833600
GS
537static inline void write_fltbe(uint8_t *p, float x)
538{
539 union { uint32_t u; float f; } u;
540 u.f = x;
541 write_u32be(p, u.u);
542}
543#define WBFL(p, x) write_fltbe((uint8_t *)(p), (x))
a2632bca
AJ
544
545/**
546 * Write a 32 bits float to memory stored as little endian.
547 * @param p a pointer to the output memory
548 * @param x the input float
549 */
f1833600
GS
550static inline void write_fltle(uint8_t *p, float x)
551{
552 union { uint32_t u; float f; } u;
553 u.f = x;
554 write_u32le(p, u.u);
555}
556#define WLFL(p, x) write_fltle((uint8_t *)(p), float (x))
557
daa895cb
GS
558/**
559 * Write a 64 bits float to memory stored as little endian.
560 * @param p a pointer to the output memory
561 * @param x the input floating point value
562 */
563static inline void write_dblle(uint8_t *p, double x)
564{
565 union { uint64_t u; double f; } u;
566 u.f = x;
567 write_u64le(p, u.u);
568}
569#define WLDB(p, x) write_dblle((uint8_t *)(p), float (x))
570
f1833600
GS
571/* Endianess conversion helpers with read/write position increment. */
572
573/**
574 * Read unsigned 8bit integer from raw memory, increment read position.
575 * @param[in, out] p Pointer into byte stream.
576 * @return Retrieved integer value, unsigned.
577 */
578static inline uint8_t read_u8_inc(const uint8_t **p)
579{
580 uint8_t v;
581
582 if (!p || !*p)
583 return 0;
584 v = read_u8(*p);
585 *p += sizeof(v);
586
587 return v;
588}
589
e4bcc63d
GS
590/**
591 * Read signed 8bit integer from raw memory, increment read position.
592 * @param[in, out] p Pointer into byte stream.
593 * @return Retrieved integer value, signed.
594 */
595static inline int8_t read_i8_inc(const uint8_t **p)
596{
597 int8_t v;
598
599 if (!p || !*p)
600 return 0;
601 v = read_i8(*p);
602 *p += sizeof(v);
603
604 return v;
605}
606
f1833600
GS
607/**
608 * Read unsigned 16bit integer from raw memory (big endian format), increment read position.
609 * @param[in, out] p Pointer into byte stream.
610 * @return Retrieved integer value, unsigned.
611 */
612static inline uint16_t read_u16be_inc(const uint8_t **p)
613{
614 uint16_t v;
615
616 if (!p || !*p)
617 return 0;
618 v = read_u16be(*p);
619 *p += sizeof(v);
620
621 return v;
622}
623
624/**
625 * Read unsigned 16bit integer from raw memory (little endian format), increment read position.
626 * @param[in, out] p Pointer into byte stream.
627 * @return Retrieved integer value, unsigned.
628 */
629static inline uint16_t read_u16le_inc(const uint8_t **p)
630{
631 uint16_t v;
632
633 if (!p || !*p)
634 return 0;
635 v = read_u16le(*p);
636 *p += sizeof(v);
637
638 return v;
639}
640
641/**
e4bcc63d 642 * Read signed 16bit integer from raw memory (big endian format), increment read position.
f1833600 643 * @param[in, out] p Pointer into byte stream.
e4bcc63d 644 * @return Retrieved integer value, signed.
f1833600 645 */
e4bcc63d 646static inline int16_t read_i16be_inc(const uint8_t **p)
f1833600 647{
e4bcc63d 648 int16_t v;
f1833600
GS
649
650 if (!p || !*p)
651 return 0;
e4bcc63d
GS
652 v = read_i16be(*p);
653 *p += sizeof(v);
654
655 return v;
656}
657
658/**
659 * Read signed 16bit integer from raw memory (little endian format), increment read position.
660 * @param[in, out] p Pointer into byte stream.
661 * @return Retrieved integer value, signed.
662 */
663static inline int16_t read_i16le_inc(const uint8_t **p)
664{
665 int16_t v;
666
667 if (!p || !*p)
668 return 0;
669 v = read_i16le(*p);
f1833600
GS
670 *p += sizeof(v);
671
672 return v;
673}
674
080b6bcf
GS
675/**
676 * Read unsigned 24bit integer from raw memory (little endian format), increment read position.
677 * @param[in, out] p Pointer into byte stream.
678 * @return Retrieved integer value, unsigned.
679 */
680static inline uint32_t read_u24le_inc(const uint8_t **p)
681{
682 uint32_t v;
683
684 if (!p || !*p)
685 return 0;
686 v = read_u24le(*p);
687 *p += 3 * sizeof(uint8_t);
688
689 return v;
690}
691
e4bcc63d
GS
692/**
693 * Read unsigned 32bit integer from raw memory (big endian format), increment read position.
694 * @param[in, out] p Pointer into byte stream.
695 * @return Retrieved integer value, unsigned.
696 */
697static inline uint32_t read_u32be_inc(const uint8_t **p)
698{
699 uint32_t v;
700
701 if (!p || !*p)
702 return 0;
703 v = read_u32be(*p);
704 *p += sizeof(v);
705
706 return v;
707}
708
f1833600
GS
709/**
710 * Read unsigned 32bit integer from raw memory (little endian format), increment read position.
711 * @param[in, out] p Pointer into byte stream.
712 * @return Retrieved integer value, unsigned.
713 */
714static inline uint32_t read_u32le_inc(const uint8_t **p)
715{
716 uint32_t v;
717
718 if (!p || !*p)
719 return 0;
720 v = read_u32le(*p);
721 *p += sizeof(v);
722
723 return v;
724}
725
e4bcc63d
GS
726/**
727 * Read signed 32bit integer from raw memory (big endian format), increment read position.
728 * @param[in, out] p Pointer into byte stream.
729 * @return Retrieved integer value, signed.
730 */
731static inline int32_t read_i32be_inc(const uint8_t **p)
732{
733 int32_t v;
734
735 if (!p || !*p)
736 return 0;
737 v = read_i32be(*p);
738 *p += sizeof(v);
739
740 return v;
741}
742
743/**
744 * Read signed 32bit integer from raw memory (little endian format), increment read position.
745 * @param[in, out] p Pointer into byte stream.
746 * @return Retrieved integer value, signed.
747 */
748static inline int32_t read_i32le_inc(const uint8_t **p)
749{
750 int32_t v;
751
752 if (!p || !*p)
753 return 0;
754 v = read_i32le(*p);
755 *p += sizeof(v);
756
757 return v;
758}
759
f1833600
GS
760/**
761 * Read unsigned 64bit integer from raw memory (big endian format), increment read position.
762 * @param[in, out] p Pointer into byte stream.
763 * @return Retrieved integer value, unsigned.
764 */
765static inline uint64_t read_u64be_inc(const uint8_t **p)
766{
767 uint64_t v;
768
769 if (!p || !*p)
770 return 0;
771 v = read_u64be(*p);
772 *p += sizeof(v);
773
774 return v;
775}
776
777/**
778 * Read unsigned 64bit integer from raw memory (little endian format), increment read position.
779 * @param[in, out] p Pointer into byte stream.
780 * @return Retrieved integer value, unsigned.
781 */
782static inline uint64_t read_u64le_inc(const uint8_t **p)
783{
784 uint64_t v;
785
786 if (!p || !*p)
787 return 0;
788 v = read_u64le(*p);
789 *p += sizeof(v);
790
791 return v;
792}
793
e4bcc63d
GS
794/**
795 * Read 32bit float from raw memory (big endian format), increment read position.
796 * @param[in, out] p Pointer into byte stream.
797 * @return Retrieved float value.
798 */
799static inline float read_fltbe_inc(const uint8_t **p)
800{
801 float v;
802
803 if (!p || !*p)
804 return 0;
805 v = read_fltbe(*p);
806 *p += sizeof(v);
807
808 return v;
809}
810
daa895cb
GS
811/**
812 * Read 32bit float from raw memory (little endian format), increment read position.
813 * @param[in, out] p Pointer into byte stream.
814 * @return Retrieved float value.
815 */
816static inline float read_fltle_inc(const uint8_t **p)
817{
818 float v;
819
820 if (!p || !*p)
821 return 0;
822 v = read_fltle(*p);
823 *p += sizeof(v);
824
825 return v;
826}
827
e4bcc63d
GS
828/**
829 * Read 64bit float from raw memory (big endian format), increment read position.
830 * @param[in, out] p Pointer into byte stream.
831 * @return Retrieved float value.
832 */
833static inline double read_dblbe_inc(const uint8_t **p)
834{
835 double v;
836
837 if (!p || !*p)
838 return 0;
839 v = read_dblbe(*p);
840 *p += sizeof(v);
841
842 return v;
843}
844
daa895cb
GS
845/**
846 * Read 64bit float from raw memory (little endian format), increment read position.
847 * @param[in, out] p Pointer into byte stream.
848 * @return Retrieved float value.
849 */
850static inline double read_dblle_inc(const uint8_t **p)
851{
852 double v;
853
854 if (!p || !*p)
855 return 0;
856 v = read_dblle(*p);
857 *p += sizeof(v);
858
859 return v;
860}
861
f1833600
GS
862/**
863 * Write unsigned 8bit integer to raw memory, increment write position.
864 * @param[in, out] p Pointer into byte stream.
865 * @param[in] x Value to write.
866 */
867static inline void write_u8_inc(uint8_t **p, uint8_t x)
868{
869 if (!p || !*p)
870 return;
871 write_u8(*p, x);
872 *p += sizeof(x);
873}
874
875/**
876 * Write unsigned 16bit big endian integer to raw memory, increment write position.
877 * @param[in, out] p Pointer into byte stream.
878 * @param[in] x Value to write.
879 */
880static inline void write_u16be_inc(uint8_t **p, uint16_t x)
881{
882 if (!p || !*p)
883 return;
884 write_u16be(*p, x);
885 *p += sizeof(x);
886}
887
888/**
889 * Write unsigned 16bit little endian integer to raw memory, increment write position.
890 * @param[in, out] p Pointer into byte stream.
891 * @param[in] x Value to write.
892 */
893static inline void write_u16le_inc(uint8_t **p, uint16_t x)
894{
895 if (!p || !*p)
896 return;
897 write_u16le(*p, x);
898 *p += sizeof(x);
899}
900
901/**
902 * Write unsigned 32bit big endian integer to raw memory, increment write position.
903 * @param[in, out] p Pointer into byte stream.
904 * @param[in] x Value to write.
905 */
906static inline void write_u32be_inc(uint8_t **p, uint32_t x)
907{
908 if (!p || !*p)
909 return;
910 write_u32be(*p, x);
911 *p += sizeof(x);
912}
913
914/**
915 * Write unsigned 32bit little endian integer to raw memory, increment write position.
916 * @param[in, out] p Pointer into byte stream.
917 * @param[in] x Value to write.
918 */
919static inline void write_u32le_inc(uint8_t **p, uint32_t x)
920{
921 if (!p || !*p)
922 return;
923 write_u32le(*p, x);
924 *p += sizeof(x);
925}
a2632bca 926
797c8d90
GS
927/**
928 * Write unsigned 48bit little endian integer to raw memory, increment write position.
929 * @param[in, out] p Pointer into byte stream.
930 * @param[in] x Value to write.
931 */
932static inline void write_u48le_inc(uint8_t **p, uint64_t x)
933{
934 if (!p || !*p)
935 return;
936 write_u48le(*p, x);
937 *p += 48 / 8 * sizeof(uint8_t);
938}
939
daa895cb
GS
940/**
941 * Write unsigned 64bit little endian integer to raw memory, increment write position.
942 * @param[in, out] p Pointer into byte stream.
943 * @param[in] x Value to write.
944 */
945static inline void write_u64le_inc(uint8_t **p, uint64_t x)
946{
947 if (!p || !*p)
948 return;
949 write_u64le(*p, x);
950 *p += sizeof(x);
951}
952
953/**
954 * Write single precision little endian float to raw memory, increment write position.
955 * @param[in, out] p Pointer into byte stream.
956 * @param[in] x Value to write.
957 */
958static inline void write_fltle_inc(uint8_t **p, float x)
959{
960 if (!p || !*p)
961 return;
962 write_fltle(*p, x);
963 *p += sizeof(x);
964}
965
966/**
967 * Write double precision little endian float to raw memory, increment write position.
968 * @param[in, out] p Pointer into byte stream.
969 * @param[in] x Value to write.
970 */
971static inline void write_dblle_inc(uint8_t **p, double x)
972{
973 if (!p || !*p)
974 return;
975 write_dblle(*p, x);
976 *p += sizeof(x);
977}
978
6bf4273e
UH
979/* Portability fixes for FreeBSD. */
980#ifdef __FreeBSD__
981#define LIBUSB_CLASS_APPLICATION 0xfe
15eea61a 982#define libusb_has_capability(x) 0
6bf4273e
UH
983#define libusb_handle_events_timeout_completed(ctx, tv, c) \
984 libusb_handle_events_timeout(ctx, tv)
985#endif
986
e1a712ca
GS
987/*
988 * Convenience for FTDI library version dependency.
989 * - Version 1.5 introduced ftdi_tciflush(), ftdi_tcoflush(), and
990 * ftdi_tcioflush() all within the same commit, and deprecated
991 * ftdi_usb_purge_buffers() which suffered from inverse semantics.
992 * The API is drop-in compatible (arguments count and data types are
993 * identical). The libsigrok source code always flushes RX and TX at
994 * the same time, never individually.
995 */
996#if defined HAVE_FTDI_TCIOFLUSH && HAVE_FTDI_TCIOFLUSH
997# define PURGE_FTDI_BOTH ftdi_tcioflush
998#else
999# define PURGE_FTDI_BOTH ftdi_usb_purge_buffers
1000#endif
1001
1685c276
BV
1002/* Static definitions of structs ending with an all-zero entry are a
1003 * problem when compiling with -Wmissing-field-initializers: GCC
1004 * suppresses the warning only with { 0 }, clang wants { } */
1005#ifdef __clang__
1006#define ALL_ZERO { }
1007#else
1008#define ALL_ZERO { 0 }
1009#endif
1010
dd5c48a6
LPC
1011#ifdef __APPLE__
1012#define SR_DRIVER_LIST_SECTION "__DATA,__sr_driver_list"
1013#else
02a8c07d 1014#define SR_DRIVER_LIST_SECTION "__sr_driver_list"
dd5c48a6
LPC
1015#endif
1016
3decd3b1
GS
1017#if !defined SR_DRIVER_LIST_NOREORDER && defined __has_attribute
1018#if __has_attribute(no_reorder)
1019#define SR_DRIVER_LIST_NOREORDER __attribute__((no_reorder))
1020#endif
1021#endif
1022#if !defined SR_DRIVER_LIST_NOREORDER
1023#define SR_DRIVER_LIST_NOREORDER /* EMPTY */
1024#endif
1025
dd5c48a6
LPC
1026/**
1027 * Register a list of hardware drivers.
1028 *
1029 * This macro can be used to register multiple hardware drivers to the library.
1030 * This is useful when a driver supports multiple similar but slightly
1031 * different devices that require different sr_dev_driver struct definitions.
1032 *
1033 * For registering only a single driver see SR_REGISTER_DEV_DRIVER().
1034 *
1035 * Example:
1036 * @code{c}
1037 * #define MY_DRIVER(_name) \
1038 * &(struct sr_dev_driver){ \
1039 * .name = _name, \
1040 * ...
1041 * };
1042 *
1043 * SR_REGISTER_DEV_DRIVER_LIST(my_driver_infos,
1044 * MY_DRIVER("driver 1"),
1045 * MY_DRIVER("driver 2"),
1046 * ...
1047 * );
1048 * @endcode
1049 *
1050 * @param name Name to use for the driver list identifier.
1051 * @param ... Comma separated list of pointers to sr_dev_driver structs.
1052 */
1053#define SR_REGISTER_DEV_DRIVER_LIST(name, ...) \
1054 static const struct sr_dev_driver *name[] \
3decd3b1 1055 SR_DRIVER_LIST_NOREORDER \
dd5c48a6
LPC
1056 __attribute__((section (SR_DRIVER_LIST_SECTION), used, \
1057 aligned(sizeof(struct sr_dev_driver *)))) \
1058 = { \
1059 __VA_ARGS__ \
1060 };
1061
1062/**
1063 * Register a hardware driver.
1064 *
1065 * This macro is used to register a hardware driver with the library. It has
1066 * to be used in order to make the driver accessible to applications using the
1067 * library.
1068 *
1069 * The macro invocation should be placed directly under the struct
1070 * sr_dev_driver definition.
1071 *
1072 * Example:
1073 * @code{c}
1074 * static struct sr_dev_driver driver_info = {
1075 * .name = "driver",
1076 * ....
1077 * };
1078 * SR_REGISTER_DEV_DRIVER(driver_info);
1079 * @endcode
1080 *
1081 * @param name Identifier name of sr_dev_driver struct to register.
1082 */
1083#define SR_REGISTER_DEV_DRIVER(name) \
1084 SR_REGISTER_DEV_DRIVER_LIST(name##_list, &name);
1085
ced48274 1086SR_API void sr_drivers_init(struct sr_context *context);
5d8b3913 1087
b8072700 1088struct sr_context {
032da34b 1089 struct sr_dev_driver **driver_list;
785b9ff2
PS
1090#ifdef HAVE_LIBUSB_1_0
1091 libusb_context *libusb_ctx;
1092#endif
bee24666
DE
1093 sr_resource_open_callback resource_open_cb;
1094 sr_resource_close_callback resource_close_cb;
1095 sr_resource_read_callback resource_read_cb;
1096 void *resource_cb_data;
b8072700
PS
1097};
1098
20e88821
BV
1099/** Input module metadata keys. */
1100enum sr_input_meta_keys {
1101 /** The input filename, if there is one. */
1102 SR_INPUT_META_FILENAME = 0x01,
1103 /** The input file's size in bytes. */
1104 SR_INPUT_META_FILESIZE = 0x02,
1105 /** The first 128 bytes of the file, provided as a GString. */
1106 SR_INPUT_META_HEADER = 0x04,
20e88821
BV
1107
1108 /** The module cannot identify a file without this metadata. */
1109 SR_INPUT_META_REQUIRED = 0x80,
1110};
1111
d514d35d
BV
1112/** Input (file) module struct. */
1113struct sr_input {
1114 /**
1115 * A pointer to this input module's 'struct sr_input_module'.
d514d35d 1116 */
17bfaca6
BV
1117 const struct sr_input_module *module;
1118 GString *buf;
d514d35d 1119 struct sr_dev_inst *sdi;
d0181813 1120 gboolean sdi_ready;
17bfaca6 1121 void *priv;
d514d35d
BV
1122};
1123
1124/** Input (file) module driver. */
1125struct sr_input_module {
17bfaca6 1126 /**
d65fcbcd 1127 * A unique ID for this input module, suitable for use in command-line
17bfaca6
BV
1128 * clients, [a-z0-9-]. Must not be NULL.
1129 */
1130 const char *id;
d514d35d
BV
1131
1132 /**
d65fcbcd 1133 * A unique name for this input module, suitable for use in GUI
17bfaca6 1134 * clients, can contain UTF-8. Must not be NULL.
d514d35d 1135 */
17bfaca6 1136 const char *name;
d514d35d
BV
1137
1138 /**
d65fcbcd 1139 * A short description of the input module. Must not be NULL.
d514d35d 1140 *
d65fcbcd 1141 * This can be displayed by frontends, e.g. when selecting the input
17bfaca6
BV
1142 * module for saving a file.
1143 */
1144 const char *desc;
1145
c7bc82ff
JH
1146 /**
1147 * A NULL terminated array of strings containing a list of file name
1148 * extensions typical for the input file format, or NULL if there is
1149 * no typical extension for this file format.
1150 */
1151 const char *const *exts;
1152
17bfaca6
BV
1153 /**
1154 * Zero-terminated list of metadata items the module needs to be able
1155 * to identify an input stream. Can be all-zero, if the module cannot
1156 * identify streams at all, i.e. has to be forced into use.
1157 *
1158 * Each item is one of:
1159 * SR_INPUT_META_FILENAME
1160 * SR_INPUT_META_FILESIZE
1161 * SR_INPUT_META_HEADER
17bfaca6
BV
1162 *
1163 * If the high bit (SR_INPUT META_REQUIRED) is set, the module cannot
1164 * identify a stream without the given metadata.
1165 */
1166 const uint8_t metadata[8];
1167
1168 /**
1169 * Returns a NULL-terminated list of options this module can take.
1170 * Can be NULL, if the module has no options.
1171 */
2c240774 1172 const struct sr_option *(*options) (void);
17bfaca6
BV
1173
1174 /**
1175 * Check if this input module can load and parse the specified stream.
1176 *
1177 * @param[in] metadata Metadata the module can use to identify the stream.
54ee427d
GS
1178 * @param[out] confidence "Strength" of the detection.
1179 * Specialized handlers can take precedence over generic/basic support.
d514d35d 1180 *
4f979115 1181 * @retval SR_OK This module knows the format.
753793ef 1182 * @retval SR_ERR_NA There wasn't enough data for this module to
4f979115 1183 * positively identify the format.
d9251a2c
UH
1184 * @retval SR_ERR_DATA This module knows the format, but cannot handle
1185 * it. This means the stream is either corrupt, or indicates a
1186 * feature that the module does not support.
4f979115 1187 * @retval SR_ERR This module does not know the format.
54ee427d
GS
1188 *
1189 * Lower numeric values of 'confidence' mean that the input module
1190 * stronger believes in its capability to handle this specific format.
1191 * This way, multiple input modules can claim support for a format,
1192 * and the application can pick the best match, or try fallbacks
1193 * in case of errors. This approach also copes with formats that
1194 * are unreliable to detect in the absence of magic signatures.
d514d35d 1195 */
54ee427d 1196 int (*format_match) (GHashTable *metadata, unsigned int *confidence);
d514d35d
BV
1197
1198 /**
1199 * Initialize the input module.
1200 *
d514d35d
BV
1201 * @retval SR_OK Success
1202 * @retval other Negative error code.
1203 */
17bfaca6 1204 int (*init) (struct sr_input *in, GHashTable *options);
d514d35d
BV
1205
1206 /**
753793ef 1207 * Send data to the specified input instance.
d514d35d 1208 *
753793ef
BV
1209 * When an input module instance is created with sr_input_new(), this
1210 * function is used to feed data to the instance.
d514d35d 1211 *
753793ef
BV
1212 * As enough data gets fed into this function to completely populate
1213 * the device instance associated with this input instance, this is
1214 * guaranteed to return the moment it's ready. This gives the caller
1215 * the chance to examine the device instance, attach session callbacks
1216 * and so on.
17bfaca6
BV
1217 *
1218 * @retval SR_OK Success
1219 * @retval other Negative error code.
1220 */
d0181813 1221 int (*receive) (struct sr_input *in, GString *buf);
17bfaca6 1222
753793ef
BV
1223 /**
1224 * Signal the input module no more data will come.
1225 *
1226 * This will cause the module to process any data it may have buffered.
1227 * The SR_DF_END packet will also typically be sent at this time.
1228 */
7066fd46
BV
1229 int (*end) (struct sr_input *in);
1230
d9251a2c
UH
1231 /**
1232 * Reset the input module's input handling structures.
1233 *
1234 * Causes the input module to reset its internal state so that we can
1235 * re-send the input data from the beginning without having to
1236 * re-create the entire input module.
1237 *
1238 * @retval SR_OK Success.
1239 * @retval other Negative error code.
1240 */
b6b4f03e
SA
1241 int (*reset) (struct sr_input *in);
1242
17bfaca6
BV
1243 /**
1244 * This function is called after the caller is finished using
1245 * the input module, and can be used to free any internal
1246 * resources the module may keep.
d514d35d 1247 *
753793ef
BV
1248 * This function is optional.
1249 *
d514d35d
BV
1250 * @retval SR_OK Success
1251 * @retval other Negative error code.
1252 */
d5cc282f 1253 void (*cleanup) (struct sr_input *in);
d514d35d
BV
1254};
1255
a755b0e1
BV
1256/** Output module instance. */
1257struct sr_output {
d9251a2c 1258 /** A pointer to this output's module. */
a755b0e1
BV
1259 const struct sr_output_module *module;
1260
1261 /**
1262 * The device for which this output module is creating output. This
1263 * can be used by the module to find out channel names and numbers.
1264 */
1265 const struct sr_dev_inst *sdi;
1266
81b3ce37
SA
1267 /**
1268 * The name of the file that the data should be written to.
1269 */
1270 const char *filename;
1271
a755b0e1
BV
1272 /**
1273 * A generic pointer which can be used by the module to keep internal
1274 * state between calls into its callback functions.
1275 *
1276 * For example, the module might store a pointer to a chunk of output
1277 * there, and only flush it when it reaches a certain size.
1278 */
d686c5ec 1279 void *priv;
a755b0e1
BV
1280};
1281
1282/** Output module driver. */
1283struct sr_output_module {
1284 /**
1285 * A unique ID for this output module, suitable for use in command-line
1286 * clients, [a-z0-9-]. Must not be NULL.
1287 */
2c240774 1288 const char *id;
a755b0e1
BV
1289
1290 /**
1291 * A unique name for this output module, suitable for use in GUI
1292 * clients, can contain UTF-8. Must not be NULL.
1293 */
1294 const char *name;
1295
1296 /**
1297 * A short description of the output module. Must not be NULL.
1298 *
1299 * This can be displayed by frontends, e.g. when selecting the output
1300 * module for saving a file.
1301 */
2c240774 1302 const char *desc;
a755b0e1 1303
8a174d23
JH
1304 /**
1305 * A NULL terminated array of strings containing a list of file name
1306 * extensions typical for the input file format, or NULL if there is
1307 * no typical extension for this file format.
1308 */
1309 const char *const *exts;
1310
3cd4b381
SA
1311 /**
1312 * Bitfield containing flags that describe certain properties
1313 * this output module may or may not have.
1314 * @see sr_output_flags
1315 */
1316 const uint64_t flags;
1317
a755b0e1
BV
1318 /**
1319 * Returns a NULL-terminated list of options this module can take.
1320 * Can be NULL, if the module has no options.
a755b0e1 1321 */
af7d656d 1322 const struct sr_option *(*options) (void);
a755b0e1
BV
1323
1324 /**
1325 * This function is called once, at the beginning of an output stream.
1326 *
1327 * The device struct will be available in the output struct passed in,
1328 * as well as the param field -- which may be NULL or an empty string,
1329 * if no parameter was passed.
1330 *
1331 * The module can use this to initialize itself, create a struct for
1332 * keeping state and storing it in the <code>internal</code> field.
1333 *
1334 * @param o Pointer to the respective 'struct sr_output'.
1335 *
1336 * @retval SR_OK Success
1337 * @retval other Negative error code.
1338 */
1339 int (*init) (struct sr_output *o, GHashTable *options);
1340
1341 /**
f3f19d11 1342 * This function is passed a copy of every packet in the data feed.
a755b0e1
BV
1343 * Any output generated by the output module in response to the
1344 * packet should be returned in a newly allocated GString
1345 * <code>out</code>, which will be freed by the caller.
1346 *
1347 * Packets not of interest to the output module can just be ignored,
1348 * and the <code>out</code> parameter set to NULL.
1349 *
1350 * @param o Pointer to the respective 'struct sr_output'.
1351 * @param sdi The device instance that generated the packet.
1352 * @param packet The complete packet.
1353 * @param out A pointer where a GString * should be stored if
1354 * the module generates output, or NULL if not.
1355 *
1356 * @retval SR_OK Success
1357 * @retval other Negative error code.
1358 */
1359 int (*receive) (const struct sr_output *o,
1360 const struct sr_datafeed_packet *packet, GString **out);
1361
1362 /**
1363 * This function is called after the caller is finished using
1364 * the output module, and can be used to free any internal
1365 * resources the module may keep.
1366 *
1367 * @retval SR_OK Success
1368 * @retval other Negative error code.
1369 */
1370 int (*cleanup) (struct sr_output *o);
1371};
1372
790320f6
UH
1373/** Transform module instance. */
1374struct sr_transform {
d9251a2c 1375 /** A pointer to this transform's module. */
790320f6
UH
1376 const struct sr_transform_module *module;
1377
1378 /**
1379 * The device for which this transform module is used. This
1380 * can be used by the module to find out channel names and numbers.
1381 */
1382 const struct sr_dev_inst *sdi;
1383
1384 /**
1385 * A generic pointer which can be used by the module to keep internal
1386 * state between calls into its callback functions.
1387 */
1388 void *priv;
1389};
1390
1391struct sr_transform_module {
1392 /**
1393 * A unique ID for this transform module, suitable for use in
1394 * command-line clients, [a-z0-9-]. Must not be NULL.
1395 */
2c240774 1396 const char *id;
790320f6
UH
1397
1398 /**
1399 * A unique name for this transform module, suitable for use in GUI
1400 * clients, can contain UTF-8. Must not be NULL.
1401 */
1402 const char *name;
1403
1404 /**
1405 * A short description of the transform module. Must not be NULL.
1406 *
1407 * This can be displayed by frontends, e.g. when selecting
1408 * which transform module(s) to add.
1409 */
2c240774 1410 const char *desc;
790320f6
UH
1411
1412 /**
1413 * Returns a NULL-terminated list of options this transform module
1414 * can take. Can be NULL, if the transform module has no options.
1415 */
1416 const struct sr_option *(*options) (void);
1417
1418 /**
1419 * This function is called once, at the beginning of a stream.
1420 *
1421 * @param t Pointer to the respective 'struct sr_transform'.
1422 * @param options Hash table of options for this transform module.
1423 * Can be NULL if no options are to be used.
1424 *
1425 * @retval SR_OK Success
1426 * @retval other Negative error code.
1427 */
1428 int (*init) (struct sr_transform *t, GHashTable *options);
1429
1430 /**
1431 * This function is passed a pointer to every packet in the data feed.
1432 *
1433 * It can either return (in packet_out) a pointer to another packet
1434 * (possibly the exact same packet it got as input), or NULL.
1435 *
1436 * @param t Pointer to the respective 'struct sr_transform'.
1437 * @param packet_in Pointer to a datafeed packet.
1438 * @param packet_out Pointer to the resulting datafeed packet after
1439 * this function was run. If NULL, the transform
1440 * module intentionally didn't output a new packet.
1441 *
1442 * @retval SR_OK Success
1443 * @retval other Negative error code.
1444 */
1445 int (*receive) (const struct sr_transform *t,
1446 struct sr_datafeed_packet *packet_in,
1447 struct sr_datafeed_packet **packet_out);
1448
1449 /**
1450 * This function is called after the caller is finished using
1451 * the transform module, and can be used to free any internal
1452 * resources the module may keep.
1453 *
1454 * @retval SR_OK Success
1455 * @retval other Negative error code.
1456 */
1457 int (*cleanup) (struct sr_transform *t);
1458};
1459
69890f73 1460#ifdef HAVE_LIBUSB_1_0
04cb9157 1461/** USB device instance */
d68e2d1a 1462struct sr_usb_dev_inst {
98582bf5
BV
1463 /** USB bus */
1464 uint8_t bus;
1465 /** Device address on USB bus */
1466 uint8_t address;
1467 /** libusb device handle */
1468 struct libusb_device_handle *devhdl;
69890f73
UH
1469};
1470#endif
1471
1ac8c218 1472struct sr_serial_dev_inst;
1df81f4b 1473#ifdef HAVE_SERIAL_COMM
a7b8692e 1474struct ser_lib_functions;
edec0436 1475struct ser_hid_chip_functions;
b79c3422 1476struct sr_bt_desc;
d4787248
GS
1477typedef void (*serial_rx_chunk_callback)(struct sr_serial_dev_inst *serial,
1478 void *cb_data, const void *buf, size_t count);
d68e2d1a 1479struct sr_serial_dev_inst {
98582bf5
BV
1480 /** Port name, e.g. '/dev/tty42'. */
1481 char *port;
1482 /** Comm params for serial_set_paramstr(). */
1483 char *serialcomm;
a7b8692e 1484 struct ser_lib_functions *lib_funcs;
639c6f61
GS
1485 struct {
1486 int bit_rate;
1487 int data_bits;
1488 int parity_bits;
1489 int stop_bits;
1490 } comm_params;
ad5aa993 1491 GString *rcv_buffer;
d4787248
GS
1492 serial_rx_chunk_callback rx_chunk_cb_func;
1493 void *rx_chunk_cb_data;
a7b8692e 1494#ifdef HAVE_LIBSERIALPORT
98582bf5 1495 /** libserialport port handle */
271392d9 1496 struct sp_port *sp_data;
a7b8692e 1497#endif
4417074c 1498#ifdef HAVE_LIBHIDAPI
edec0436
GS
1499 enum ser_hid_chip_t {
1500 SER_HID_CHIP_UNKNOWN, /**!< place holder */
a10284cd 1501 SER_HID_CHIP_BTC_BU86X, /**!< Brymen BU86x */
616bc3a1 1502 SER_HID_CHIP_SIL_CP2110, /**!< SiLabs CP2110 */
0cdb72c8 1503 SER_HID_CHIP_VICTOR_DMM, /**!< Victor 70/86 DMM cable */
828eeea2 1504 SER_HID_CHIP_WCH_CH9325, /**!< WCH CH9325 */
edec0436
GS
1505 SER_HID_CHIP_LAST, /**!< sentinel */
1506 } hid_chip;
1507 struct ser_hid_chip_functions *hid_chip_funcs;
1508 char *usb_path;
1509 char *usb_serno;
1510 const char *hid_path;
4417074c 1511 hid_device *hid_dev;
edec0436 1512 GSList *hid_source_args;
4417074c 1513#endif
b79c3422
GS
1514#ifdef HAVE_BLUETOOTH
1515 enum ser_bt_conn_t {
1516 SER_BT_CONN_UNKNOWN, /**!< place holder */
1517 SER_BT_CONN_RFCOMM, /**!< BT classic, RFCOMM channel */
1518 SER_BT_CONN_BLE122, /**!< BLE, BLE122 module, indications */
1519 SER_BT_CONN_NRF51, /**!< BLE, Nordic nRF51, notifications */
1520 SER_BT_CONN_CC254x, /**!< BLE, TI CC254x, notifications */
1521 SER_BT_CONN_MAX, /**!< sentinel */
1522 } bt_conn_type;
1523 char *bt_addr_local;
1524 char *bt_addr_remote;
1525 size_t bt_rfcomm_channel;
1526 uint16_t bt_notify_handle_read;
1527 uint16_t bt_notify_handle_write;
1528 uint16_t bt_notify_handle_cccd;
1529 uint16_t bt_notify_value_cccd;
1530 struct sr_bt_desc *bt_desc;
1531 GSList *bt_source_args;
1532#endif
69890f73 1533};
c4f2dfd0 1534#endif
69890f73 1535
ae67644f
ML
1536struct sr_usbtmc_dev_inst {
1537 char *device;
1538 int fd;
1539};
1540
026c822d
UH
1541/* Private driver context. */
1542struct drv_context {
98582bf5
BV
1543 /** sigrok context */
1544 struct sr_context *sr_ctx;
026c822d
UH
1545 GSList *instances;
1546};
1547
48a486cd
BV
1548/*--- log.c -----------------------------------------------------------------*/
1549
00f0016c 1550#if defined(_WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
7419638d
DE
1551/*
1552 * On MinGW, we need to specify the gnu_printf format flavor or GCC
1553 * will assume non-standard Microsoft printf syntax.
1554 */
1555SR_PRIV int sr_log(int loglevel, const char *format, ...)
1556 __attribute__((__format__ (__gnu_printf__, 2, 3)));
1557#else
be92d5b4 1558SR_PRIV int sr_log(int loglevel, const char *format, ...) G_GNUC_PRINTF(2, 3);
7419638d 1559#endif
48a486cd 1560
3544f848 1561/* Message logging helpers with subsystem-specific prefix string. */
be92d5b4
DE
1562#define sr_spew(...) sr_log(SR_LOG_SPEW, LOG_PREFIX ": " __VA_ARGS__)
1563#define sr_dbg(...) sr_log(SR_LOG_DBG, LOG_PREFIX ": " __VA_ARGS__)
1564#define sr_info(...) sr_log(SR_LOG_INFO, LOG_PREFIX ": " __VA_ARGS__)
1565#define sr_warn(...) sr_log(SR_LOG_WARN, LOG_PREFIX ": " __VA_ARGS__)
1566#define sr_err(...) sr_log(SR_LOG_ERR, LOG_PREFIX ": " __VA_ARGS__)
3544f848 1567
48a486cd
BV
1568/*--- device.c --------------------------------------------------------------*/
1569
cffdc3e6
ML
1570/** Scan options supported by a driver. */
1571#define SR_CONF_SCAN_OPTIONS 0x7FFF0000
1572
1573/** Device options for a particular device. */
1574#define SR_CONF_DEVICE_OPTIONS 0x7FFF0001
1575
e318f01b
ML
1576/** Mask for separating config keys from capabilities. */
1577#define SR_CONF_MASK 0x1fffffff
1578
f3ca73ed 1579/** Values for the changes argument of sr_dev_driver.config_channel_set. */
2a854d71 1580enum {
fca75cbb 1581 /** The enabled state of the channel has been changed. */
3f239f08 1582 SR_CHANNEL_SET_ENABLED = 1 << 0,
2a854d71
DE
1583};
1584
5e23fcab
ML
1585SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi,
1586 int index, int type, gboolean enabled, const char *name);
fe71c7e4
GS
1587SR_PRIV void sr_channel_free(struct sr_channel *ch);
1588SR_PRIV void sr_channel_free_cb(void *p);
9c24d16a
BV
1589SR_PRIV struct sr_channel *sr_next_enabled_channel(const struct sr_dev_inst *sdi,
1590 struct sr_channel *cur_channel);
712f981d
GS
1591SR_PRIV gboolean sr_channels_differ(struct sr_channel *ch1, struct sr_channel *ch2);
1592SR_PRIV gboolean sr_channel_lists_differ(GSList *l1, GSList *l2);
48a486cd 1593
96727ef0
UH
1594/** Device instance data */
1595struct sr_dev_inst {
1596 /** Device driver. */
1597 struct sr_dev_driver *driver;
1598 /** Device instance status. SR_ST_NOT_FOUND, etc. */
1599 int status;
1600 /** Device instance type. SR_INST_USB, etc. */
1601 int inst_type;
1602 /** Device vendor. */
1603 char *vendor;
1604 /** Device model. */
1605 char *model;
1606 /** Device version. */
1607 char *version;
1608 /** Serial number. */
1609 char *serial_num;
1610 /** Connection string to uniquely identify devices. */
1611 char *connection_id;
1612 /** List of channels. */
1613 GSList *channels;
1614 /** List of sr_channel_group structs */
1615 GSList *channel_groups;
1616 /** Device instance connection data (used?) */
1617 void *conn;
1618 /** Device instance private data (used?) */
1619 void *priv;
1620 /** Session to which this device is currently assigned. */
1621 struct sr_session *session;
1622};
1623
48a486cd 1624/* Generic device instances */
48a486cd 1625SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi);
48a486cd 1626
545f9786 1627#ifdef HAVE_LIBUSB_1_0
69890f73 1628/* USB-specific instances */
d68e2d1a 1629SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
69890f73 1630 uint8_t address, struct libusb_device_handle *hdl);
d68e2d1a 1631SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb);
69890f73
UH
1632#endif
1633
1df81f4b 1634#ifdef HAVE_SERIAL_COMM
1ac8c218
GS
1635#ifndef HAVE_LIBSERIALPORT
1636/*
1637 * Some identifiers which initially got provided by libserialport are
1638 * used internally within the libsigrok serial layer's implementation,
1639 * while libserialport no longer is the exclusive provider of serial
1640 * communication support. Declare the identifiers here so they remain
1641 * available across all build configurations.
1642 */
1643enum libsp_parity {
1644 SP_PARITY_NONE = 0,
1645 SP_PARITY_ODD = 1,
1646 SP_PARITY_EVEN = 2,
1647 SP_PARITY_MARK = 3,
1648 SP_PARITY_SPACE = 4,
1649};
1650
1651enum libsp_flowcontrol {
1652 SP_FLOWCONTROL_NONE = 0,
1653 SP_FLOWCONTROL_XONXOFF = 1,
1654 SP_FLOWCONTROL_RTSCTS = 2,
1655 SP_FLOWCONTROL_DTRDSR = 3,
1656};
1657#endif
1658
69890f73 1659/* Serial-specific instances */
299bdb24
BV
1660SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
1661 const char *serialcomm);
d68e2d1a 1662SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial);
c4f2dfd0 1663#endif
69890f73 1664
ae67644f
ML
1665/* USBTMC-specific instances */
1666SR_PRIV struct sr_usbtmc_dev_inst *sr_usbtmc_dev_inst_new(const char *device);
1667SR_PRIV void sr_usbtmc_dev_inst_free(struct sr_usbtmc_dev_inst *usbtmc);
b08024a8 1668
c09f0b57 1669/*--- hwdriver.c ------------------------------------------------------------*/
996b0c72 1670
13fef1ed 1671SR_PRIV const GVariantType *sr_variant_type_get(int datatype);
584560f1 1672SR_PRIV int sr_variant_type_check(uint32_t key, GVariant *data);
032da34b 1673SR_PRIV void sr_hw_cleanup_all(const struct sr_context *ctx);
584560f1 1674SR_PRIV struct sr_config *sr_config_new(uint32_t key, GVariant *data);
722db131 1675SR_PRIV void sr_config_free(struct sr_config *src);
f670835f 1676SR_PRIV int sr_dev_acquisition_start(struct sr_dev_inst *sdi);
d2f7c417 1677SR_PRIV int sr_dev_acquisition_stop(struct sr_dev_inst *sdi);
996b0c72 1678
a1645fcd
BV
1679/*--- session.c -------------------------------------------------------------*/
1680
e2b23821 1681struct sr_session {
4ed5d21d
ML
1682 /** Context this session exists in. */
1683 struct sr_context *ctx;
c0e3ba4b 1684 /** List of struct sr_dev_inst pointers. */
e2b23821 1685 GSList *devs;
1de3cced
ML
1686 /** List of struct sr_dev_inst pointers owned by this session. */
1687 GSList *owned_devs;
e2b23821
UH
1688 /** List of struct datafeed_callback pointers. */
1689 GSList *datafeed_callbacks;
c0a1e532 1690 GSList *transforms;
7b5e6d29 1691 struct sr_trigger *trigger;
62d7945f 1692
5de0fc55
DE
1693 /** Callback to invoke on session stop. */
1694 sr_session_stopped_callback stopped_callback;
1695 /** User data to be passed to the session stop callback. */
1696 void *stopped_cb_data;
1697
2e5e3df4 1698 /** Mutex protecting the main context pointer. */
c2bf5506
DE
1699 GMutex main_mutex;
1700 /** Context of the session main loop. */
1701 GMainContext *main_context;
e2b23821 1702
c2bf5506
DE
1703 /** Registered event sources for this session. */
1704 GHashTable *event_sources;
1705 /** Session main loop. */
1706 GMainLoop *main_loop;
5de0fc55
DE
1707 /** ID of idle source for dispatching the session stop notification. */
1708 unsigned int stop_check_id;
2e5e3df4
DE
1709 /** Whether the session has been started. */
1710 gboolean running;
e2b23821
UH
1711};
1712
62d7945f 1713SR_PRIV int sr_session_source_add_internal(struct sr_session *session,
c2bf5506 1714 void *key, GSource *source);
92248e78 1715SR_PRIV int sr_session_source_remove_internal(struct sr_session *session,
c2bf5506
DE
1716 void *key);
1717SR_PRIV int sr_session_source_destroyed(struct sr_session *session,
1718 void *key, GSource *source);
cbc1413f
DE
1719SR_PRIV int sr_session_fd_source_add(struct sr_session *session,
1720 void *key, gintptr fd, int events, int timeout,
1721 sr_receive_data_callback cb, void *cb_data);
ee9953ef
DE
1722
1723SR_PRIV int sr_session_source_add(struct sr_session *session, int fd,
1724 int events, int timeout, sr_receive_data_callback cb, void *cb_data);
1725SR_PRIV int sr_session_source_add_pollfd(struct sr_session *session,
1726 GPollFD *pollfd, int timeout, sr_receive_data_callback cb,
1727 void *cb_data);
1728SR_PRIV int sr_session_source_add_channel(struct sr_session *session,
1729 GIOChannel *channel, int events, int timeout,
1730 sr_receive_data_callback cb, void *cb_data);
1731SR_PRIV int sr_session_source_remove(struct sr_session *session, int fd);
1732SR_PRIV int sr_session_source_remove_pollfd(struct sr_session *session,
1733 GPollFD *pollfd);
1734SR_PRIV int sr_session_source_remove_channel(struct sr_session *session,
1735 GIOChannel *channel);
1736
7d1a4a52
FS
1737SR_PRIV int sr_session_send_meta(const struct sr_dev_inst *sdi,
1738 uint32_t key, GVariant *var);
de4d3f99 1739SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
ae5859ff 1740 const struct sr_datafeed_packet *packet);
f438e0c9 1741SR_PRIV int sr_sessionfile_check(const char *filename);
7c69b528
SA
1742SR_PRIV struct sr_dev_inst *sr_session_prepare_sdi(const char *filename,
1743 struct sr_session **session);
a1645fcd 1744
98654c99
DE
1745/*--- session_file.c --------------------------------------------------------*/
1746
a6dc3dac
DE
1747#if !HAVE_ZIP_DISCARD
1748/* Replace zip_discard() if not available. */
1749#define zip_discard(zip) sr_zip_discard(zip)
1750SR_PRIV void sr_zip_discard(struct zip *archive);
1751#endif
1752
98654c99
DE
1753SR_PRIV GKeyFile *sr_sessionfile_read_metadata(struct zip *archive,
1754 const struct zip_stat *entry);
1755
41caa319
AJ
1756/*--- analog.c --------------------------------------------------------------*/
1757
edb691fc 1758SR_PRIV int sr_analog_init(struct sr_datafeed_analog *analog,
41caa319
AJ
1759 struct sr_analog_encoding *encoding,
1760 struct sr_analog_meaning *meaning,
1761 struct sr_analog_spec *spec,
1762 int digits);
1763
063e7aef
UH
1764/*--- std.c -----------------------------------------------------------------*/
1765
144f6660
UH
1766typedef int (*dev_close_callback)(struct sr_dev_inst *sdi);
1767typedef void (*std_dev_clear_callback)(void *priv);
cd2f0fe2 1768
c45c32ce 1769SR_PRIV int std_init(struct sr_dev_driver *di, struct sr_context *sr_ctx);
700d6b64 1770SR_PRIV int std_cleanup(const struct sr_dev_driver *di);
4d67b9d9
UH
1771SR_PRIV int std_dummy_dev_open(struct sr_dev_inst *sdi);
1772SR_PRIV int std_dummy_dev_close(struct sr_dev_inst *sdi);
1773SR_PRIV int std_dummy_dev_acquisition_start(const struct sr_dev_inst *sdi);
1774SR_PRIV int std_dummy_dev_acquisition_stop(struct sr_dev_inst *sdi);
1df81f4b 1775#ifdef HAVE_SERIAL_COMM
23dc6661 1776SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi);
1b38775b 1777SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi);
c4f2dfd0 1778#endif
bee2b016
LPC
1779SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi);
1780SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi);
10cf8113 1781SR_PRIV int std_session_send_df_trigger(const struct sr_dev_inst *sdi);
7f7702b8
UH
1782SR_PRIV int std_session_send_df_frame_begin(const struct sr_dev_inst *sdi);
1783SR_PRIV int std_session_send_df_frame_end(const struct sr_dev_inst *sdi);
6e43c3d5 1784SR_PRIV int std_dev_clear_with_callback(const struct sr_dev_driver *driver,
144f6660 1785 std_dev_clear_callback clear_private);
f778bf02 1786SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver);
c01bf34c 1787SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di);
043e899a 1788SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
15a5bfe4 1789SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices);
4afdfd46 1790
e66d1892
UH
1791SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data,
1792 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg,
1793 const uint32_t scanopts[], size_t scansize, const uint32_t drvopts[],
1794 size_t drvsize, const uint32_t devopts[], size_t devsize);
1795
23772462
UH
1796extern SR_PRIV const uint32_t NO_OPTS[1];
1797
e66d1892
UH
1798#define STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts) \
1799 std_opts_config_list(key, data, sdi, cg, ARRAY_AND_SIZE(scanopts), \
1800 ARRAY_AND_SIZE(drvopts), ARRAY_AND_SIZE(devopts))
1801
58ffcf97 1802SR_PRIV GVariant *std_gvar_tuple_array(const uint64_t a[][2], unsigned int n);
db944f16 1803SR_PRIV GVariant *std_gvar_tuple_rational(const struct sr_rational *r, unsigned int n);
463160cb
UH
1804SR_PRIV GVariant *std_gvar_samplerates(const uint64_t samplerates[], unsigned int n);
1805SR_PRIV GVariant *std_gvar_samplerates_steps(const uint64_t samplerates[], unsigned int n);
54d471f4
UH
1806SR_PRIV GVariant *std_gvar_min_max_step(double min, double max, double step);
1807SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3]);
7bc3cfe6 1808SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double dmin, const double dmax, const double dstep);
db944f16 1809
a162eeb2 1810SR_PRIV GVariant *std_gvar_tuple_u64(uint64_t low, uint64_t high);
43995cda 1811SR_PRIV GVariant *std_gvar_tuple_double(double low, double high);
a162eeb2 1812
769561cb
UH
1813SR_PRIV GVariant *std_gvar_array_i32(const int32_t a[], unsigned int n);
1814SR_PRIV GVariant *std_gvar_array_u32(const uint32_t a[], unsigned int n);
1815SR_PRIV GVariant *std_gvar_array_u64(const uint64_t a[], unsigned int n);
70635036 1816SR_PRIV GVariant *std_gvar_array_str(const char *a[], unsigned int n);
db944f16 1817
94e64a0b 1818SR_PRIV GVariant *std_gvar_thresholds(const double a[][2], unsigned int n);
9fb9afb5 1819
697fb6dd
UH
1820SR_PRIV int std_str_idx(GVariant *data, const char *a[], unsigned int n);
1821SR_PRIV int std_u64_idx(GVariant *data, const uint64_t a[], unsigned int n);
1822SR_PRIV int std_u8_idx(GVariant *data, const uint8_t a[], unsigned int n);
1823
1824SR_PRIV int std_str_idx_s(const char *s, const char *a[], unsigned int n);
1825SR_PRIV int std_u8_idx_s(uint8_t b, const uint8_t a[], unsigned int n);
1826
1827SR_PRIV int std_u64_tuple_idx(GVariant *data, const uint64_t a[][2], unsigned int n);
1828SR_PRIV int std_double_tuple_idx(GVariant *data, const double a[][2], unsigned int n);
1829SR_PRIV int std_double_tuple_idx_d0(const double d, const double a[][2], unsigned int n);
1830
fcd6a8bd
UH
1831SR_PRIV int std_cg_idx(const struct sr_channel_group *cg, struct sr_channel_group *a[], unsigned int n);
1832
c0aa074e
UH
1833SR_PRIV int std_dummy_set_params(struct sr_serial_dev_inst *serial,
1834 int baudrate, int bits, int parity, int stopbits,
1835 int flowcontrol, int rts, int dtr);
3ad30b4e
GS
1836SR_PRIV int std_dummy_set_handshake(struct sr_serial_dev_inst *serial,
1837 int rts, int dtr);
c0aa074e 1838
bee24666
DE
1839/*--- resource.c ------------------------------------------------------------*/
1840
7d89fd60
DE
1841SR_PRIV int64_t sr_file_get_size(FILE *file);
1842
bee24666
DE
1843SR_PRIV int sr_resource_open(struct sr_context *ctx,
1844 struct sr_resource *res, int type, const char *name)
1845 G_GNUC_WARN_UNUSED_RESULT;
1846SR_PRIV int sr_resource_close(struct sr_context *ctx,
1847 struct sr_resource *res);
32ba0d80 1848SR_PRIV gssize sr_resource_read(struct sr_context *ctx,
bee24666
DE
1849 const struct sr_resource *res, void *buf, size_t count)
1850 G_GNUC_WARN_UNUSED_RESULT;
1851SR_PRIV void *sr_resource_load(struct sr_context *ctx, int type,
1852 const char *name, size_t *size, size_t max_size)
1853 G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
1854
8d558c7a
UH
1855/*--- strutil.c -------------------------------------------------------------*/
1856
1857SR_PRIV int sr_atol(const char *str, long *ret);
97aa41e9 1858SR_PRIV int sr_atol_base(const char *str, long *ret, char **end, int base);
30903c40 1859SR_PRIV int sr_atoul_base(const char *str, unsigned long *ret, char **end, int base);
8d558c7a
UH
1860SR_PRIV int sr_atoi(const char *str, int *ret);
1861SR_PRIV int sr_atod(const char *str, double *ret);
1862SR_PRIV int sr_atof(const char *str, float *ret);
4f0463a0 1863SR_PRIV int sr_atod_ascii(const char *str, double *ret);
91ab2f64 1864SR_PRIV int sr_atod_ascii_digits(const char *str, double *ret, int *digits);
9806c2d5 1865SR_PRIV int sr_atof_ascii(const char *str, float *ret);
8d558c7a 1866
d8bc7ca3
GS
1867SR_PRIV GString *sr_hexdump_new(const uint8_t *data, const size_t len);
1868SR_PRIV void sr_hexdump_free(GString *s);
1869
ac136b57
BV
1870/*--- soft-trigger.c --------------------------------------------------------*/
1871
1872struct soft_trigger_logic {
1873 const struct sr_dev_inst *sdi;
1874 const struct sr_trigger *trigger;
1875 int count;
1876 int unitsize;
1877 int cur_stage;
1878 uint8_t *prev_sample;
fe5a7355
AJ
1879 uint8_t *pre_trigger_buffer;
1880 uint8_t *pre_trigger_head;
1881 int pre_trigger_size;
1882 int pre_trigger_fill;
ac136b57
BV
1883};
1884
d1078180 1885SR_PRIV int logic_channel_unitsize(GSList *channels);
ac136b57 1886SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new(
fe5a7355
AJ
1887 const struct sr_dev_inst *sdi, struct sr_trigger *trigger,
1888 int pre_trigger_samples);
ac136b57
BV
1889SR_PRIV void soft_trigger_logic_free(struct soft_trigger_logic *st);
1890SR_PRIV int soft_trigger_logic_check(struct soft_trigger_logic *st, uint8_t *buf,
fe5a7355 1891 int len, int *pre_trigger_samples);
ac136b57 1892
fcfa36fd 1893/*--- serial.c --------------------------------------------------------------*/
058b7035 1894
1df81f4b 1895#ifdef HAVE_SERIAL_COMM
a54dd31e
UH
1896enum {
1897 SERIAL_RDWR = 1,
1898 SERIAL_RDONLY = 2,
a54dd31e
UH
1899};
1900
144f6660 1901typedef gboolean (*packet_valid_callback)(const uint8_t *buf);
1a7adeac
GS
1902typedef int (*packet_valid_len_callback)(void *st,
1903 const uint8_t *p, size_t l, size_t *pl);
766456be 1904
ae4c1fb6
GS
1905typedef GSList *(*sr_ser_list_append_t)(GSList *devs, const char *name,
1906 const char *desc);
1907typedef GSList *(*sr_ser_find_append_t)(GSList *devs, const char *name);
1908
299bdb24
BV
1909SR_PRIV int serial_open(struct sr_serial_dev_inst *serial, int flags);
1910SR_PRIV int serial_close(struct sr_serial_dev_inst *serial);
1911SR_PRIV int serial_flush(struct sr_serial_dev_inst *serial);
bce75f94 1912SR_PRIV int serial_drain(struct sr_serial_dev_inst *serial);
8c3df6e5 1913SR_PRIV size_t serial_has_receive_data(struct sr_serial_dev_inst *serial);
9a474211 1914SR_PRIV int serial_write_blocking(struct sr_serial_dev_inst *serial,
eead2782 1915 const void *buf, size_t count, unsigned int timeout_ms);
9a474211
ML
1916SR_PRIV int serial_write_nonblocking(struct sr_serial_dev_inst *serial,
1917 const void *buf, size_t count);
9a474211 1918SR_PRIV int serial_read_blocking(struct sr_serial_dev_inst *serial, void *buf,
eead2782 1919 size_t count, unsigned int timeout_ms);
9a474211
ML
1920SR_PRIV int serial_read_nonblocking(struct sr_serial_dev_inst *serial, void *buf,
1921 size_t count);
d4787248
GS
1922SR_PRIV int serial_set_read_chunk_cb(struct sr_serial_dev_inst *serial,
1923 serial_rx_chunk_callback cb, void *cb_data);
299bdb24 1924SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
71caaad4 1925 int bits, int parity, int stopbits, int flowcontrol, int rts, int dtr);
3ad30b4e
GS
1926SR_PRIV int serial_set_handshake(struct sr_serial_dev_inst *serial,
1927 int rts, int dtr);
299bdb24
BV
1928SR_PRIV int serial_set_paramstr(struct sr_serial_dev_inst *serial,
1929 const char *paramstr);
1930SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf,
1931 int *buflen, gint64 timeout_ms);
766456be 1932SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
1a7adeac
GS
1933 uint8_t *buf, size_t *buflen,
1934 size_t packet_size, packet_valid_callback is_valid,
1935 packet_valid_len_callback is_valid_len, size_t *return_size,
1936 uint64_t timeout_ms);
102f1239
BV
1937SR_PRIV int serial_source_add(struct sr_session *session,
1938 struct sr_serial_dev_inst *serial, int events, int timeout,
1939 sr_receive_data_callback cb, void *cb_data);
1940SR_PRIV int serial_source_remove(struct sr_session *session,
1941 struct sr_serial_dev_inst *serial);
b541f837 1942SR_PRIV GSList *sr_serial_find_usb(uint16_t vendor_id, uint16_t product_id);
c5cfc735 1943SR_PRIV int serial_timeout(struct sr_serial_dev_inst *port, int num_bytes);
ae4c1fb6 1944
ad5aa993
GS
1945SR_PRIV void sr_ser_discard_queued_data(struct sr_serial_dev_inst *serial);
1946SR_PRIV size_t sr_ser_has_queued_data(struct sr_serial_dev_inst *serial);
1947SR_PRIV void sr_ser_queue_rx_data(struct sr_serial_dev_inst *serial,
1948 const uint8_t *data, size_t len);
1949SR_PRIV size_t sr_ser_unqueue_rx_data(struct sr_serial_dev_inst *serial,
1950 uint8_t *data, size_t len);
1951
a7b8692e
GS
1952struct ser_lib_functions {
1953 int (*open)(struct sr_serial_dev_inst *serial, int flags);
1954 int (*close)(struct sr_serial_dev_inst *serial);
1955 int (*flush)(struct sr_serial_dev_inst *serial);
1956 int (*drain)(struct sr_serial_dev_inst *serial);
1957 int (*write)(struct sr_serial_dev_inst *serial,
1958 const void *buf, size_t count,
1959 int nonblocking, unsigned int timeout_ms);
1960 int (*read)(struct sr_serial_dev_inst *serial,
1961 void *buf, size_t count,
1962 int nonblocking, unsigned int timeout_ms);
1963 int (*set_params)(struct sr_serial_dev_inst *serial,
1964 int baudrate, int bits, int parity, int stopbits,
1965 int flowcontrol, int rts, int dtr);
3ad30b4e
GS
1966 int (*set_handshake)(struct sr_serial_dev_inst *serial,
1967 int rts, int dtr);
a7b8692e
GS
1968 int (*setup_source_add)(struct sr_session *session,
1969 struct sr_serial_dev_inst *serial,
1970 int events, int timeout,
1971 sr_receive_data_callback cb, void *cb_data);
1972 int (*setup_source_remove)(struct sr_session *session,
1973 struct sr_serial_dev_inst *serial);
1974 GSList *(*list)(GSList *list, sr_ser_list_append_t append);
1975 GSList *(*find_usb)(GSList *list, sr_ser_find_append_t append,
1976 uint16_t vendor_id, uint16_t product_id);
1977 int (*get_frame_format)(struct sr_serial_dev_inst *serial,
1978 int *baud, int *bits);
1979 size_t (*get_rx_avail)(struct sr_serial_dev_inst *serial);
1980};
1981extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_libsp;
4417074c
GS
1982SR_PRIV int ser_name_is_hid(struct sr_serial_dev_inst *serial);
1983extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_hid;
b79c3422
GS
1984SR_PRIV int ser_name_is_bt(struct sr_serial_dev_inst *serial);
1985extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_bt;
edec0436
GS
1986
1987#ifdef HAVE_LIBHIDAPI
1988struct vid_pid_item {
1989 uint16_t vid, pid;
1990};
edec0436
GS
1991
1992struct ser_hid_chip_functions {
1993 const char *chipname;
1994 const char *chipdesc;
1995 const struct vid_pid_item *vid_pid_items;
1996 const int max_bytes_per_request;
1997 int (*set_params)(struct sr_serial_dev_inst *serial,
1998 int baudrate, int bits, int parity, int stopbits,
1999 int flowcontrol, int rts, int dtr);
2000 int (*read_bytes)(struct sr_serial_dev_inst *serial,
2001 uint8_t *data, int space, unsigned int timeout);
2002 int (*write_bytes)(struct sr_serial_dev_inst *serial,
2003 const uint8_t *data, int space);
2004 int (*flush)(struct sr_serial_dev_inst *serial);
2005 int (*drain)(struct sr_serial_dev_inst *serial);
2006};
a10284cd 2007extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x;
828eeea2 2008extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_ch9325;
616bc3a1 2009extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_cp2110;
0cdb72c8 2010extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_victor;
edec0436
GS
2011SR_PRIV const char *ser_hid_chip_find_name_vid_pid(uint16_t vid, uint16_t pid);
2012#endif
c4f2dfd0 2013#endif
1483577e 2014
7fd8a8f7
GS
2015SR_PRIV int sr_serial_extract_options(GSList *options,
2016 const char **serial_device, const char **serial_options);
2017
7c8ae47d
GS
2018/*--- bt/ API ---------------------------------------------------------------*/
2019
2020#ifdef HAVE_BLUETOOTH
2021SR_PRIV const char *sr_bt_adapter_get_address(size_t idx);
2022
2023struct sr_bt_desc;
2024typedef void (*sr_bt_scan_cb)(void *cb_data, const char *addr, const char *name);
2025typedef int (*sr_bt_data_cb)(void *cb_data, uint8_t *data, size_t dlen);
2026
2027SR_PRIV struct sr_bt_desc *sr_bt_desc_new(void);
2028SR_PRIV void sr_bt_desc_free(struct sr_bt_desc *desc);
2029
2030SR_PRIV int sr_bt_config_cb_scan(struct sr_bt_desc *desc,
2031 sr_bt_scan_cb cb, void *cb_data);
2032SR_PRIV int sr_bt_config_cb_data(struct sr_bt_desc *desc,
2033 sr_bt_data_cb cb, void *cb_data);
2034SR_PRIV int sr_bt_config_addr_local(struct sr_bt_desc *desc, const char *addr);
2035SR_PRIV int sr_bt_config_addr_remote(struct sr_bt_desc *desc, const char *addr);
2036SR_PRIV int sr_bt_config_rfcomm(struct sr_bt_desc *desc, size_t channel);
2037SR_PRIV int sr_bt_config_notify(struct sr_bt_desc *desc,
2038 uint16_t read_handle, uint16_t write_handle,
2039 uint16_t cccd_handle, uint16_t cccd_value);
2040
2041SR_PRIV int sr_bt_scan_le(struct sr_bt_desc *desc, int duration);
2042SR_PRIV int sr_bt_scan_bt(struct sr_bt_desc *desc, int duration);
2043
2044SR_PRIV int sr_bt_connect_ble(struct sr_bt_desc *desc);
2045SR_PRIV int sr_bt_connect_rfcomm(struct sr_bt_desc *desc);
2046SR_PRIV void sr_bt_disconnect(struct sr_bt_desc *desc);
2047
2048SR_PRIV ssize_t sr_bt_read(struct sr_bt_desc *desc,
2049 void *data, size_t len);
2050SR_PRIV ssize_t sr_bt_write(struct sr_bt_desc *desc,
2051 const void *data, size_t len);
2052
2053SR_PRIV int sr_bt_start_notify(struct sr_bt_desc *desc);
2054SR_PRIV int sr_bt_check_notify(struct sr_bt_desc *desc);
2055#endif
2056
fcfa36fd 2057/*--- ezusb.c ---------------------------------------------------------------*/
058b7035 2058
22b02383 2059#ifdef HAVE_LIBUSB_1_0
1a081ca6 2060SR_PRIV int ezusb_reset(struct libusb_device_handle *hdl, int set_clear);
8e2d6c9d
DE
2061SR_PRIV int ezusb_install_firmware(struct sr_context *ctx, libusb_device_handle *hdl,
2062 const char *name);
2063SR_PRIV int ezusb_upload_firmware(struct sr_context *ctx, libusb_device *dev,
2064 int configuration, const char *name);
22b02383 2065#endif
058b7035 2066
fcfa36fd 2067/*--- usb.c -----------------------------------------------------------------*/
0c632d36
UH
2068
2069#ifdef HAVE_LIBUSB_1_0
7ae6a758 2070SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn);
0c632d36 2071SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb);
67e95ed3 2072SR_PRIV void sr_usb_close(struct sr_usb_dev_inst *usb);
102f1239
BV
2073SR_PRIV int usb_source_add(struct sr_session *session, struct sr_context *ctx,
2074 int timeout, sr_receive_data_callback cb, void *cb_data);
2075SR_PRIV int usb_source_remove(struct sr_session *session, struct sr_context *ctx);
76bc5f63 2076SR_PRIV int usb_get_port_path(libusb_device *dev, char *path, int path_len);
69f7d9b4
JH
2077SR_PRIV gboolean usb_match_manuf_prod(libusb_device *dev,
2078 const char *manufacturer, const char *product);
0c632d36
UH
2079#endif
2080
18698b40
AS
2081/*--- binary_helpers.c ------------------------------------------------------*/
2082
2083/** Binary value type */
2084enum binary_value_type {
d65f51bf
GS
2085 BVT_INVALID,
2086
2087 BVT_UINT8,
18698b40
AS
2088 BVT_BE_UINT8 = BVT_UINT8,
2089 BVT_LE_UINT8 = BVT_UINT8,
2090
2091 BVT_BE_UINT16,
2092 BVT_BE_UINT32,
2093 BVT_BE_UINT64,
2094 BVT_BE_FLOAT,
2095
2096 BVT_LE_UINT16,
2097 BVT_LE_UINT32,
2098 BVT_LE_UINT64,
2099 BVT_LE_FLOAT,
2100};
2101
2102/** Binary value specification */
2103struct binary_value_spec {
2104 /** Offset into binary blob */
2105 size_t offset;
2106 /** Data type to decode */
2107 enum binary_value_type type;
2108 /** Scale factor to get native units */
2109 float scale;
2110};
2111
2112/** Binary channel definition */
2113struct binary_analog_channel {
2114 /** Channel name */
2115 const char *name;
2116 /** Binary value in data stream */
2117 struct binary_value_spec spec;
2118 /** Significant digits */
2119 int digits;
2120 /** Measured quantity */
2121 enum sr_mq mq;
2122 /** Measured unit */
2123 enum sr_unit unit;
2124};
2125
2126/**
2127 * Read extract a value from a binary blob.
2128 *
2129 * @param out Pointer to output buffer.
2130 * @param spec Binary value specification
2131 * @param data Pointer to binary blob
2132 * @param length Size of binary blob
2133 * @return SR_OK on success, SR_ERR_* error code on failure.
2134 */
2135SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec, const void *data, size_t length);
2136
2137/**
2138 * Send an analog channel packet based on a binary analog channel
2139 * specification.
2140 *
2141 * @param sdi Device instance
2142 * @param ch Sigrok channel
2143 * @param spec Channel specification
2144 * @param data Pointer to binary blob
2145 * @param length Size of binary blob
2146 * @return SR_OK on success, SR_ERR_* error code on failure.
2147 */
2148SR_PRIV int bv_send_analog_channel(const struct sr_dev_inst *sdi, struct sr_channel *ch,
2149 const struct binary_analog_channel *spec, const void *data, size_t length);
7b9d7320 2150
4ea012bd
AS
2151/*--- crc.c -----------------------------------------------------------------*/
2152
2153#define SR_CRC16_DEFAULT_INIT 0xffffU
2154
2155/**
2156 * Calculate a CRC16 checksum using the 0x8005 polynomial.
2157 *
2158 * This CRC16 flavor is also known as CRC16-ANSI or CRC16-MODBUS.
2159 *
2160 * @param crc Initial value (typically 0xffff)
2161 * @param buffer Input buffer
2162 * @param len Buffer length
2163 * @return Checksum
2164 */
2165SR_PRIV uint16_t sr_crc16(uint16_t crc, const uint8_t *buffer, int len);
2166
daa39012
AJ
2167/*--- modbus/modbus.c -------------------------------------------------------*/
2168
2169struct sr_modbus_dev_inst {
2170 const char *name;
2171 const char *prefix;
2172 int priv_size;
2173 GSList *(*scan)(int modbusaddr);
2174 int (*dev_inst_new)(void *priv, const char *resource,
2175 char **params, const char *serialcomm, int modbusaddr);
2176 int (*open)(void *priv);
2177 int (*source_add)(struct sr_session *session, void *priv, int events,
2178 int timeout, sr_receive_data_callback cb, void *cb_data);
2179 int (*source_remove)(struct sr_session *session, void *priv);
2180 int (*send)(void *priv, const uint8_t *buffer, int buffer_size);
2181 int (*read_begin)(void *priv, uint8_t *function_code);
2182 int (*read_data)(void *priv, uint8_t *buf, int maxlen);
2183 int (*read_end)(void *priv);
2184 int (*close)(void *priv);
2185 void (*free)(void *priv);
2186 unsigned int read_timeout_ms;
2187 void *priv;
2188};
2189
2190SR_PRIV GSList *sr_modbus_scan(struct drv_context *drvc, GSList *options,
2191 struct sr_dev_inst *(*probe_device)(struct sr_modbus_dev_inst *modbus));
2192SR_PRIV struct sr_modbus_dev_inst *modbus_dev_inst_new(const char *resource,
2193 const char *serialcomm, int modbusaddr);
2194SR_PRIV int sr_modbus_open(struct sr_modbus_dev_inst *modbus);
2195SR_PRIV int sr_modbus_source_add(struct sr_session *session,
2196 struct sr_modbus_dev_inst *modbus, int events, int timeout,
2197 sr_receive_data_callback cb, void *cb_data);
2198SR_PRIV int sr_modbus_source_remove(struct sr_session *session,
2199 struct sr_modbus_dev_inst *modbus);
2200SR_PRIV int sr_modbus_request(struct sr_modbus_dev_inst *modbus,
2201 uint8_t *request, int request_size);
2202SR_PRIV int sr_modbus_reply(struct sr_modbus_dev_inst *modbus,
2203 uint8_t *reply, int reply_size);
2204SR_PRIV int sr_modbus_request_reply(struct sr_modbus_dev_inst *modbus,
2205 uint8_t *request, int request_size,
2206 uint8_t *reply, int reply_size);
2207SR_PRIV int sr_modbus_read_coils(struct sr_modbus_dev_inst *modbus,
2208 int address, int nb_coils, uint8_t *coils);
2209SR_PRIV int sr_modbus_read_holding_registers(struct sr_modbus_dev_inst *modbus,
2210 int address, int nb_registers,
2211 uint16_t *registers);
2212SR_PRIV int sr_modbus_write_coil(struct sr_modbus_dev_inst *modbus,
2213 int address, int value);
2214SR_PRIV int sr_modbus_write_multiple_registers(struct sr_modbus_dev_inst*modbus,
2215 int address, int nb_registers,
2216 uint16_t *registers);
2217SR_PRIV int sr_modbus_close(struct sr_modbus_dev_inst *modbus);
2218SR_PRIV void sr_modbus_free(struct sr_modbus_dev_inst *modbus);
2219
fcfa36fd 2220/*--- dmm/es519xx.c ---------------------------------------------------------*/
c01bdebc 2221
bfb926c1
AJ
2222/**
2223 * All 11-byte es519xx chips repeat each block twice for each conversion cycle
2224 * so always read 2 blocks at a time.
2225 */
2226#define ES519XX_11B_PACKET_SIZE (11 * 2)
72e1672f 2227#define ES519XX_14B_PACKET_SIZE 14
c01bdebc
AJ
2228
2229struct es519xx_info {
2230 gboolean is_judge, is_voltage, is_auto, is_micro, is_current;
2231 gboolean is_milli, is_resistance, is_continuity, is_diode;
2232 gboolean is_frequency, is_rpm, is_capacitance, is_duty_cycle;
2233 gboolean is_temperature, is_celsius, is_fahrenheit;
2234 gboolean is_adp0, is_adp1, is_adp2, is_adp3;
2235 gboolean is_sign, is_batt, is_ol, is_pmax, is_pmin, is_apo;
2236 gboolean is_dc, is_ac, is_vahz, is_min, is_max, is_rel, is_hold;
2237 gboolean is_digit4, is_ul, is_vasel, is_vbar, is_lpf1, is_lpf0, is_rmr;
2238 uint32_t baudrate;
2239 int packet_size;
2240 gboolean alt_functions, fivedigits, clampmeter, selectable_lpf;
8cbf5627 2241 int digits;
c01bdebc
AJ
2242};
2243
72e1672f
UH
2244SR_PRIV gboolean sr_es519xx_2400_11b_packet_valid(const uint8_t *buf);
2245SR_PRIV int sr_es519xx_2400_11b_parse(const uint8_t *buf, float *floatval,
8c677240 2246 struct sr_datafeed_analog *analog, void *info);
2588e50c
AJ
2247SR_PRIV gboolean sr_es519xx_2400_11b_altfn_packet_valid(const uint8_t *buf);
2248SR_PRIV int sr_es519xx_2400_11b_altfn_parse(const uint8_t *buf,
8c677240 2249 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f 2250SR_PRIV gboolean sr_es519xx_19200_11b_5digits_packet_valid(const uint8_t *buf);
93d719cd 2251SR_PRIV int sr_es519xx_19200_11b_5digits_parse(const uint8_t *buf,
8c677240 2252 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2253SR_PRIV gboolean sr_es519xx_19200_11b_clamp_packet_valid(const uint8_t *buf);
2254SR_PRIV int sr_es519xx_19200_11b_clamp_parse(const uint8_t *buf,
8c677240 2255 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2256SR_PRIV gboolean sr_es519xx_19200_11b_packet_valid(const uint8_t *buf);
2257SR_PRIV int sr_es519xx_19200_11b_parse(const uint8_t *buf, float *floatval,
8c677240 2258 struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2259SR_PRIV gboolean sr_es519xx_19200_14b_packet_valid(const uint8_t *buf);
2260SR_PRIV int sr_es519xx_19200_14b_parse(const uint8_t *buf, float *floatval,
8c677240 2261 struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2262SR_PRIV gboolean sr_es519xx_19200_14b_sel_lpf_packet_valid(const uint8_t *buf);
2263SR_PRIV int sr_es519xx_19200_14b_sel_lpf_parse(const uint8_t *buf,
8c677240 2264 float *floatval, struct sr_datafeed_analog *analog, void *info);
c01bdebc 2265
fcfa36fd 2266/*--- dmm/fs9922.c ----------------------------------------------------------*/
79081ec8 2267
913abe83
UH
2268#define FS9922_PACKET_SIZE 14
2269
2270struct fs9922_info {
2271 gboolean is_auto, is_dc, is_ac, is_rel, is_hold, is_bpn, is_z1, is_z2;
2272 gboolean is_max, is_min, is_apo, is_bat, is_nano, is_z3, is_micro;
2273 gboolean is_milli, is_kilo, is_mega, is_beep, is_diode, is_percent;
2274 gboolean is_z4, is_volt, is_ampere, is_ohm, is_hfe, is_hertz, is_farad;
2275 gboolean is_celsius, is_fahrenheit;
2276 int bargraph_sign, bargraph_value;
2277};
2278
913abe83
UH
2279SR_PRIV gboolean sr_fs9922_packet_valid(const uint8_t *buf);
2280SR_PRIV int sr_fs9922_parse(const uint8_t *buf, float *floatval,
8c677240
UH
2281 struct sr_datafeed_analog *analog, void *info);
2282SR_PRIV void sr_fs9922_z1_diode(struct sr_datafeed_analog *analog, void *info);
79081ec8 2283
fcfa36fd 2284/*--- dmm/fs9721.c ----------------------------------------------------------*/
6c701476 2285
8c1adf37
UH
2286#define FS9721_PACKET_SIZE 14
2287
2288struct fs9721_info {
2289 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
2290 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
2291 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
2292 gboolean is_c2c1_11, is_c2c1_10, is_c2c1_01, is_c2c1_00, is_sign;
2293};
2294
8c1adf37
UH
2295SR_PRIV gboolean sr_fs9721_packet_valid(const uint8_t *buf);
2296SR_PRIV int sr_fs9721_parse(const uint8_t *buf, float *floatval,
8c677240
UH
2297 struct sr_datafeed_analog *analog, void *info);
2298SR_PRIV void sr_fs9721_00_temp_c(struct sr_datafeed_analog *analog, void *info);
2299SR_PRIV void sr_fs9721_01_temp_c(struct sr_datafeed_analog *analog, void *info);
2300SR_PRIV void sr_fs9721_10_temp_c(struct sr_datafeed_analog *analog, void *info);
2301SR_PRIV void sr_fs9721_01_10_temp_f_c(struct sr_datafeed_analog *analog, void *info);
2302SR_PRIV void sr_fs9721_max_c_min(struct sr_datafeed_analog *analog, void *info);
dcd212f7 2303
4c29bba1
PS
2304/*--- dmm/mm38xr.c ---------------------------------------------------------*/
2305
2306#define METERMAN_38XR_PACKET_SIZE 15
2307
2308struct meterman_38xr_info { int dummy; };
2309
2310SR_PRIV gboolean meterman_38xr_packet_valid(const uint8_t *buf);
2311SR_PRIV int meterman_38xr_parse(const uint8_t *buf, float *floatval,
2312 struct sr_datafeed_analog *analog, void *info);
2313
dcd212f7
VV
2314/*--- dmm/ms2115b.c ---------------------------------------------------------*/
2315
2316#define MS2115B_PACKET_SIZE 9
2317
2318enum ms2115b_display {
2319 MS2115B_DISPLAY_MAIN,
2320 MS2115B_DISPLAY_SUB,
2321 MS2115B_DISPLAY_COUNT,
2322};
2323
2324struct ms2115b_info {
2325 /* Selected channel. */
2326 size_t ch_idx;
2327 gboolean is_ac, is_dc, is_auto;
2328 gboolean is_diode, is_beep, is_farad;
2329 gboolean is_ohm, is_ampere, is_volt, is_hz;
2330 gboolean is_duty_cycle, is_percent;
2331};
2332
2333extern SR_PRIV const char *ms2115b_channel_formats[];
2334SR_PRIV gboolean sr_ms2115b_packet_valid(const uint8_t *buf);
2335SR_PRIV int sr_ms2115b_parse(const uint8_t *buf, float *floatval,
2336 struct sr_datafeed_analog *analog, void *info);
6c701476 2337
fcfa36fd 2338/*--- dmm/ms8250d.c ---------------------------------------------------------*/
67070942
M
2339
2340#define MS8250D_PACKET_SIZE 18
2341
2342struct ms8250d_info {
2343 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
2344 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
2345 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
2346 gboolean is_ncv, is_min, is_max, is_sign, is_autotimer;
2347};
2348
2349SR_PRIV gboolean sr_ms8250d_packet_valid(const uint8_t *buf);
2350SR_PRIV int sr_ms8250d_parse(const uint8_t *buf, float *floatval,
2351 struct sr_datafeed_analog *analog, void *info);
2352
fcfa36fd 2353/*--- dmm/dtm0660.c ---------------------------------------------------------*/
eed3dec8
MG
2354
2355#define DTM0660_PACKET_SIZE 15
2356
2357struct dtm0660_info {
2358 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
2359 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
2360 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
2361 gboolean is_degf, is_degc, is_c2c1_01, is_c2c1_00, is_apo, is_min;
2362 gboolean is_minmax, is_max, is_sign;
2363};
2364
2365SR_PRIV gboolean sr_dtm0660_packet_valid(const uint8_t *buf);
2366SR_PRIV int sr_dtm0660_parse(const uint8_t *buf, float *floatval,
8c677240 2367 struct sr_datafeed_analog *analog, void *info);
eed3dec8 2368
fcfa36fd 2369/*--- dmm/m2110.c -----------------------------------------------------------*/
825da8b2
MH
2370
2371#define BBCGM_M2110_PACKET_SIZE 9
2372
9d12555f
UH
2373/* Dummy info struct. The parser does not use it. */
2374struct m2110_info { int dummy; };
2375
825da8b2
MH
2376SR_PRIV gboolean sr_m2110_packet_valid(const uint8_t *buf);
2377SR_PRIV int sr_m2110_parse(const uint8_t *buf, float *floatval,
8c677240 2378 struct sr_datafeed_analog *analog, void *info);
825da8b2 2379
fcfa36fd 2380/*--- dmm/metex14.c ---------------------------------------------------------*/
ac913e5c
UH
2381
2382#define METEX14_PACKET_SIZE 14
2383
2384struct metex14_info {
556a926d 2385 size_t ch_idx;
ac913e5c
UH
2386 gboolean is_ac, is_dc, is_resistance, is_capacity, is_temperature;
2387 gboolean is_diode, is_frequency, is_ampere, is_volt, is_farad;
7fb4ff02
FS
2388 gboolean is_hertz, is_ohm, is_celsius, is_fahrenheit, is_watt;
2389 gboolean is_pico, is_nano, is_micro, is_milli, is_kilo, is_mega;
fd8dc1db 2390 gboolean is_gain, is_decibel, is_power, is_decibel_mw, is_power_factor;
7fb4ff02 2391 gboolean is_hfe, is_unitless, is_logic, is_min, is_max, is_avg;
ac913e5c
UH
2392};
2393
1df81f4b 2394#ifdef HAVE_SERIAL_COMM
ce3777ad 2395SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial);
c4f2dfd0 2396#endif
ac913e5c
UH
2397SR_PRIV gboolean sr_metex14_packet_valid(const uint8_t *buf);
2398SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval,
8c677240 2399 struct sr_datafeed_analog *analog, void *info);
556a926d
GS
2400SR_PRIV gboolean sr_metex14_4packets_valid(const uint8_t *buf);
2401SR_PRIV int sr_metex14_4packets_parse(const uint8_t *buf, float *floatval,
2402 struct sr_datafeed_analog *analog, void *info);
ac913e5c 2403
fcfa36fd 2404/*--- dmm/rs9lcd.c ----------------------------------------------------------*/
05f134ab 2405
21829e67 2406#define RS9LCD_PACKET_SIZE 9
05f134ab 2407
e7ed87a4 2408/* Dummy info struct. The parser does not use it. */
bf6f8399 2409struct rs9lcd_info { int dummy; };
e7ed87a4 2410
05f134ab
AG
2411SR_PRIV gboolean sr_rs9lcd_packet_valid(const uint8_t *buf);
2412SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval,
8c677240 2413 struct sr_datafeed_analog *analog, void *info);
05f134ab 2414
fcfa36fd 2415/*--- dmm/bm25x.c -----------------------------------------------------------*/
a24c3f4a
JH
2416
2417#define BRYMEN_BM25X_PACKET_SIZE 15
2418
2419/* Dummy info struct. The parser does not use it. */
2420struct bm25x_info { int dummy; };
2421
2422SR_PRIV gboolean sr_brymen_bm25x_packet_valid(const uint8_t *buf);
2423SR_PRIV int sr_brymen_bm25x_parse(const uint8_t *buf, float *floatval,
8c677240 2424 struct sr_datafeed_analog *analog, void *info);
a24c3f4a 2425
400bc4ff
GS
2426/*--- dmm/bm52x.c -----------------------------------------------------------*/
2427
2428#define BRYMEN_BM52X_PACKET_SIZE 24
2429#define BRYMEN_BM52X_DISPLAY_COUNT 2
2430
2431struct brymen_bm52x_info { size_t ch_idx; };
2432
2433#ifdef HAVE_SERIAL_COMM
2434SR_PRIV int sr_brymen_bm52x_packet_request(struct sr_serial_dev_inst *serial);
6bee394d 2435SR_PRIV int sr_brymen_bm82x_packet_request(struct sr_serial_dev_inst *serial);
400bc4ff
GS
2436#endif
2437SR_PRIV gboolean sr_brymen_bm52x_packet_valid(const uint8_t *buf);
6bee394d
GS
2438SR_PRIV gboolean sr_brymen_bm82x_packet_valid(const uint8_t *buf);
2439/* BM520s and BM820s protocols are similar, the parse routine is shared. */
400bc4ff
GS
2440SR_PRIV int sr_brymen_bm52x_parse(const uint8_t *buf, float *floatval,
2441 struct sr_datafeed_analog *analog, void *info);
2442
0931639a
GS
2443struct brymen_bm52x_state;
2444
2445SR_PRIV void *brymen_bm52x_state_init(void);
2446SR_PRIV void brymen_bm52x_state_free(void *state);
2447SR_PRIV int brymen_bm52x_config_get(void *state, uint32_t key, GVariant **data,
2448 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2449SR_PRIV int brymen_bm52x_config_set(void *state, uint32_t key, GVariant *data,
2450 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2451SR_PRIV int brymen_bm52x_config_list(void *state, uint32_t key, GVariant **data,
2452 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2453SR_PRIV int brymen_bm52x_acquire_start(void *state,
2454 const struct sr_dev_inst *sdi,
2455 sr_receive_data_callback *cb, void **cb_data);
2456
27186eda
GS
2457/*--- dmm/bm85x.c -----------------------------------------------------------*/
2458
2459#define BRYMEN_BM85x_PACKET_SIZE_MIN 4
2460
2461struct brymen_bm85x_info { int dummy; };
2462
2463#ifdef HAVE_SERIAL_COMM
2464SR_PRIV int brymen_bm85x_after_open(struct sr_serial_dev_inst *serial);
2465SR_PRIV int brymen_bm85x_packet_request(struct sr_serial_dev_inst *serial);
2466#endif
2467SR_PRIV gboolean brymen_bm85x_packet_valid(void *state,
2468 const uint8_t *buf, size_t len, size_t *pkt_len);
2469SR_PRIV int brymen_bm85x_parse(void *state, const uint8_t *buf, size_t len,
2470 double *floatval, struct sr_datafeed_analog *analog, void *info);
2471
0759e2f5
GS
2472/*--- dmm/bm86x.c -----------------------------------------------------------*/
2473
2474#define BRYMEN_BM86X_PACKET_SIZE 24
2475#define BRYMEN_BM86X_DISPLAY_COUNT 2
2476
2477struct brymen_bm86x_info { size_t ch_idx; };
2478
2479#ifdef HAVE_SERIAL_COMM
2480SR_PRIV int sr_brymen_bm86x_packet_request(struct sr_serial_dev_inst *serial);
2481#endif
2482SR_PRIV gboolean sr_brymen_bm86x_packet_valid(const uint8_t *buf);
2483SR_PRIV int sr_brymen_bm86x_parse(const uint8_t *buf, float *floatval,
2484 struct sr_datafeed_analog *analog, void *info);
2485
fcfa36fd 2486/*--- dmm/ut71x.c -----------------------------------------------------------*/
626027df
UH
2487
2488#define UT71X_PACKET_SIZE 11
2489
2490struct ut71x_info {
2491 gboolean is_voltage, is_resistance, is_capacitance, is_temperature;
2492 gboolean is_celsius, is_fahrenheit, is_current, is_continuity;
2493 gboolean is_diode, is_frequency, is_duty_cycle, is_dc, is_ac;
2494 gboolean is_auto, is_manual, is_sign, is_power, is_loop_current;
2495};
2496
2497SR_PRIV gboolean sr_ut71x_packet_valid(const uint8_t *buf);
2498SR_PRIV int sr_ut71x_parse(const uint8_t *buf, float *floatval,
8c677240 2499 struct sr_datafeed_analog *analog, void *info);
626027df 2500
fcfa36fd 2501/*--- dmm/vc870.c -----------------------------------------------------------*/
c36f78f7
UH
2502
2503#define VC870_PACKET_SIZE 23
2504
2505struct vc870_info {
2506 gboolean is_voltage, is_dc, is_ac, is_temperature, is_resistance;
2507 gboolean is_continuity, is_capacitance, is_diode, is_loop_current;
2508 gboolean is_current, is_micro, is_milli, is_power;
ee2e9be2 2509 gboolean is_power_factor_freq, is_power_apparent_power, is_v_a_rms_value;
c36f78f7
UH
2510 gboolean is_sign2, is_sign1, is_batt, is_ol1, is_max, is_min;
2511 gboolean is_maxmin, is_rel, is_ol2, is_open, is_manu, is_hold;
2512 gboolean is_light, is_usb, is_warning, is_auto_power, is_misplug_warn;
2513 gboolean is_lo, is_hi, is_open2;
2514
3591481e 2515 gboolean is_frequency, is_dual_display, is_auto;
c36f78f7
UH
2516};
2517
2518SR_PRIV gboolean sr_vc870_packet_valid(const uint8_t *buf);
2519SR_PRIV int sr_vc870_parse(const uint8_t *buf, float *floatval,
8c677240 2520 struct sr_datafeed_analog *analog, void *info);
c36f78f7 2521
fcfa36fd 2522/*--- dmm/vc96.c ------------------------------------------------------------*/
9456d636
MS
2523
2524#define VC96_PACKET_SIZE 13
2525
2526struct vc96_info {
2527 size_t ch_idx;
2528 gboolean is_ac, is_dc, is_resistance, is_diode, is_ampere, is_volt;
2529 gboolean is_ohm, is_micro, is_milli, is_kilo, is_mega, is_hfe;
2530 gboolean is_unitless;
2531};
2532
2533SR_PRIV gboolean sr_vc96_packet_valid(const uint8_t *buf);
2534SR_PRIV int sr_vc96_parse(const uint8_t *buf, float *floatval,
2535 struct sr_datafeed_analog *analog, void *info);
2536
fcfa36fd 2537/*--- lcr/es51919.c ---------------------------------------------------------*/
6bcb3ee8 2538
bf5c4d46
GS
2539/* Acquisition details which apply to all supported serial-lcr devices. */
2540struct lcr_parse_info {
2541 size_t ch_idx;
2542 uint64_t output_freq;
2543 const char *circuit_model;
2544};
2545
2546#define ES51919_PACKET_SIZE 17
2547#define ES51919_CHANNEL_COUNT 2
2548#define ES51919_COMM_PARAM "9600/8n1/rts=1/dtr=1"
2549
2550SR_PRIV int es51919_config_get(uint32_t key, GVariant **data,
2551 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2552SR_PRIV int es51919_config_set(uint32_t key, GVariant *data,
2553 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2554SR_PRIV int es51919_config_list(uint32_t key, GVariant **data,
2555 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2556SR_PRIV gboolean es51919_packet_valid(const uint8_t *pkt);
2557SR_PRIV int es51919_packet_parse(const uint8_t *pkt, float *floatval,
b50970a5
GS
2558 struct sr_datafeed_analog *analog, void *info);
2559
2560/*--- lcr/vc4080.c ----------------------------------------------------------*/
2561
2562/* Note: Also uses 'struct lcr_parse_info' from es51919 above. */
2563
2564#define VC4080_PACKET_SIZE 39
2565#define VC4080_COMM_PARAM "1200/8n1"
2566#define VC4080_WITH_DQ_CHANS 0 /* Enable separate D/Q channels? */
2567
2568enum vc4080_display {
2569 VC4080_DISPLAY_PRIMARY,
2570 VC4080_DISPLAY_SECONDARY,
2571#if VC4080_WITH_DQ_CHANS
2572 VC4080_DISPLAY_D_VALUE,
2573 VC4080_DISPLAY_Q_VALUE,
2574#endif
2575 VC4080_CHANNEL_COUNT,
2576};
2577
2578extern SR_PRIV const char *vc4080_channel_formats[VC4080_CHANNEL_COUNT];
2579
2580SR_PRIV int vc4080_config_list(uint32_t key, GVariant **data,
2581 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2582SR_PRIV int vc4080_packet_request(struct sr_serial_dev_inst *serial);
2583SR_PRIV gboolean vc4080_packet_valid(const uint8_t *pkt);
2584SR_PRIV int vc4080_packet_parse(const uint8_t *pkt, float *floatval,
bf5c4d46 2585 struct sr_datafeed_analog *analog, void *info);
6bcb3ee8 2586
fcfa36fd 2587/*--- dmm/ut372.c -----------------------------------------------------------*/
f3cde309
ML
2588
2589#define UT372_PACKET_SIZE 27
2590
2591struct ut372_info {
2592 int dummy;
2593};
2594
2595SR_PRIV gboolean sr_ut372_packet_valid(const uint8_t *buf);
2596SR_PRIV int sr_ut372_parse(const uint8_t *buf, float *floatval,
8c677240 2597 struct sr_datafeed_analog *analog, void *info);
f3cde309 2598
fcfa36fd 2599/*--- dmm/asycii.c ----------------------------------------------------------*/
4ba4d52a
GS
2600
2601#define ASYCII_PACKET_SIZE 16
2602
2603struct asycii_info {
2604 gboolean is_ac, is_dc, is_ac_and_dc;
2605 gboolean is_resistance, is_capacitance, is_diode, is_gain;
2606 gboolean is_frequency, is_duty_cycle, is_duty_pos, is_duty_neg;
2607 gboolean is_pulse_width, is_period_pos, is_period_neg;
2608 gboolean is_pulse_count, is_count_pos, is_count_neg;
2609 gboolean is_ampere, is_volt, is_volt_ampere, is_farad, is_ohm;
2610 gboolean is_hertz, is_percent, is_seconds, is_decibel;
2611 gboolean is_pico, is_nano, is_micro, is_milli, is_kilo, is_mega;
2612 gboolean is_unitless;
2613 gboolean is_peak_min, is_peak_max;
2614 gboolean is_invalid;
2615};
2616
1df81f4b 2617#ifdef HAVE_SERIAL_COMM
4ba4d52a
GS
2618SR_PRIV int sr_asycii_packet_request(struct sr_serial_dev_inst *serial);
2619#endif
2620SR_PRIV gboolean sr_asycii_packet_valid(const uint8_t *buf);
2621SR_PRIV int sr_asycii_parse(const uint8_t *buf, float *floatval,
2622 struct sr_datafeed_analog *analog, void *info);
2623
fcfa36fd 2624/*--- dmm/eev121gw.c --------------------------------------------------------*/
1c3098aa
GS
2625
2626#define EEV121GW_PACKET_SIZE 19
2627
2628enum eev121gw_display {
2629 EEV121GW_DISPLAY_MAIN,
2630 EEV121GW_DISPLAY_SUB,
2631 EEV121GW_DISPLAY_BAR,
2632 EEV121GW_DISPLAY_COUNT,
2633};
2634
2635struct eev121gw_info {
2636 /* Selected channel. */
2637 size_t ch_idx;
2638 /*
2639 * Measured value, number and sign/overflow flags, scale factor
2640 * and significant digits.
2641 */
2642 uint32_t uint_value;
2643 gboolean is_ofl, is_neg;
2644 int factor, digits;
2645 /* Currently active mode (meter's function). */
2646 gboolean is_ac, is_dc, is_voltage, is_current, is_power, is_gain;
2647 gboolean is_resistance, is_capacitance, is_diode, is_temperature;
2648 gboolean is_continuity, is_frequency, is_period, is_duty_cycle;
2649 /* Quantities associated with mode/function. */
2650 gboolean is_ampere, is_volt, is_volt_ampere, is_dbm;
2651 gboolean is_ohm, is_farad, is_celsius, is_fahrenheit;
2652 gboolean is_hertz, is_seconds, is_percent, is_loop_current;
2653 gboolean is_unitless, is_logic;
2654 /* Other indicators. */
2655 gboolean is_min, is_max, is_avg, is_1ms_peak, is_rel, is_hold;
2656 gboolean is_low_pass, is_mem, is_bt, is_auto_range, is_test;
2657 gboolean is_auto_poweroff, is_low_batt;
2658};
2659
015df4ae 2660extern SR_PRIV const char *eev121gw_channel_formats[];
1c3098aa 2661SR_PRIV gboolean sr_eev121gw_packet_valid(const uint8_t *buf);
1c3098aa 2662SR_PRIV int sr_eev121gw_3displays_parse(const uint8_t *buf, float *floatval,
8556703a 2663 struct sr_datafeed_analog *analog, void *info);
1c3098aa 2664
fcfa36fd 2665/*--- scale/kern.c ----------------------------------------------------------*/
e5d953b5
UH
2666
2667struct kern_info {
2668 gboolean is_gram, is_carat, is_ounce, is_pound, is_troy_ounce;
2669 gboolean is_pennyweight, is_grain, is_tael, is_momme, is_tola;
2670 gboolean is_percentage, is_piece, is_unstable, is_stable, is_error;
2671 int buflen;
2672};
2673
2674SR_PRIV gboolean sr_kern_packet_valid(const uint8_t *buf);
2675SR_PRIV int sr_kern_parse(const uint8_t *buf, float *floatval,
563ba4a5 2676 struct sr_datafeed_analog *analog, void *info);
e5d953b5 2677
aea4e458
LPC
2678/*--- sw_limits.c -----------------------------------------------------------*/
2679
2680struct sr_sw_limits {
2681 uint64_t limit_samples;
67785f25 2682 uint64_t limit_frames;
aea4e458
LPC
2683 uint64_t limit_msec;
2684 uint64_t samples_read;
67785f25 2685 uint64_t frames_read;
aea4e458
LPC
2686 uint64_t start_time;
2687};
2688
d579755a 2689SR_PRIV int sr_sw_limits_config_get(const struct sr_sw_limits *limits, uint32_t key,
aea4e458
LPC
2690 GVariant **data);
2691SR_PRIV int sr_sw_limits_config_set(struct sr_sw_limits *limits, uint32_t key,
2692 GVariant *data);
2693SR_PRIV void sr_sw_limits_acquisition_start(struct sr_sw_limits *limits);
2694SR_PRIV gboolean sr_sw_limits_check(struct sr_sw_limits *limits);
5aba93c3
GS
2695SR_PRIV int sr_sw_limits_get_remain(const struct sr_sw_limits *limits,
2696 uint64_t *samples, uint64_t *frames, uint64_t *msecs,
2697 gboolean *exceeded);
aea4e458
LPC
2698SR_PRIV void sr_sw_limits_update_samples_read(struct sr_sw_limits *limits,
2699 uint64_t samples_read);
67785f25
GS
2700SR_PRIV void sr_sw_limits_update_frames_read(struct sr_sw_limits *limits,
2701 uint64_t frames_read);
aea4e458
LPC
2702SR_PRIV void sr_sw_limits_init(struct sr_sw_limits *limits);
2703
47a102f9
GS
2704/*--- feed_queue.h ----------------------------------------------------------*/
2705
2706struct feed_queue_logic;
2707struct feed_queue_analog;
2708
2709SR_API struct feed_queue_logic *feed_queue_logic_alloc(
57140e5a 2710 const struct sr_dev_inst *sdi,
47a102f9
GS
2711 size_t sample_count, size_t unit_size);
2712SR_API int feed_queue_logic_submit(struct feed_queue_logic *q,
2713 const uint8_t *data, size_t count);
2714SR_API int feed_queue_logic_flush(struct feed_queue_logic *q);
f478c3e6 2715SR_API int feed_queue_logic_send_trigger(struct feed_queue_logic *q);
47a102f9
GS
2716SR_API void feed_queue_logic_free(struct feed_queue_logic *q);
2717
2718SR_API struct feed_queue_analog *feed_queue_analog_alloc(
57140e5a 2719 const struct sr_dev_inst *sdi,
47a102f9
GS
2720 size_t sample_count, int digits, struct sr_channel *ch);
2721SR_API int feed_queue_analog_submit(struct feed_queue_analog *q,
2722 float data, size_t count);
2723SR_API int feed_queue_analog_flush(struct feed_queue_analog *q);
2724SR_API void feed_queue_analog_free(struct feed_queue_analog *q);
2725
1483577e 2726#endif