2 * This file is part of the libsigrok project.
4 * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
5 * Copyright (C) 2011 Olivier Fauchon <olivier@aixmarseille.com>
6 * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
7 * Copyright (C) 2015 Bartosz Golaszewski <bgolaszewski@baylibre.com>
8 * Copyright (C) 2019 Frank Stettner <frank-stettner@gmx.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #ifndef LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
25 #define LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
28 #include <libsigrok/libsigrok.h>
29 #include "libsigrok-internal.h"
31 #define LOG_PREFIX "demo"
33 /* The size in bytes of chunks to send through the session bus. */
34 #define LOGIC_BUFSIZE 4096
35 /* Size of the analog pattern space per channel. */
36 #define ANALOG_BUFSIZE 4096
37 /* This is a development feature: it starts a new frame every n samples. */
38 #define SAMPLES_PER_FRAME 1000UL
39 #define DEFAULT_LIMIT_FRAMES 0
41 #define DEFAULT_ANALOG_ENCODING_DIGITS 4
42 #define DEFAULT_ANALOG_SPEC_DIGITS 4
43 #define DEFAULT_ANALOG_AMPLITUDE 10
44 #define DEFAULT_ANALOG_OFFSET 0.
46 /* Logic patterns we can generate. */
47 enum logic_pattern_type {
49 * Spells "sigrok" across 8 channels using '0's (with '1's as
50 * "background") when displayed using the 'bits' output format.
51 * The pattern is repeated every 8 channels, shifted to the right
56 /** Pseudo-random values on all channels. */
60 * Incrementing number across 8 channels. The pattern is repeated
61 * every 8 channels, shifted to the right in time by one bit.
66 * Single bit "walking" across all logic channels by being
67 * shifted across data lines, restarting after the last line
68 * was used. An all-zero (all-one) state is inserted to prevent
69 * repetitive patterns (e.g. with 8 data lines, every 8th state
70 * would show the same line state)
75 /** All channels have a low logic state. */
78 /** All channels have a high logic state. */
82 * Mimics a cable squid. Derived from the "works with" logo
83 * to occupy a larger number of channels yet "painting"
84 * something that can get recognized.
88 /** Gray encoded data, like rotary encoder signals. */
92 /* Analog patterns we can generate. */
93 enum analog_pattern_type {
98 PATTERN_ANALOG_RANDOM,
101 static const char *analog_pattern_str[] = {
109 struct analog_pattern {
110 float data[ANALOG_BUFSIZE];
111 unsigned int num_samples;
115 uint64_t cur_samplerate;
116 uint64_t limit_samples;
118 uint64_t limit_frames;
119 uint64_t sent_samples;
120 uint64_t sent_frame_samples; /* Number of samples that were sent for current frame. */
125 int32_t num_logic_channels;
126 size_t logic_unitsize;
127 uint64_t all_logic_channels_mask;
128 /* There is only ever one logic channel group, so its pattern goes here. */
129 enum logic_pattern_type logic_pattern;
130 uint8_t logic_data[LOGIC_BUFSIZE];
132 struct analog_pattern *analog_patterns[ARRAY_SIZE(analog_pattern_str)];
133 int32_t num_analog_channels;
135 gboolean avg; /* True if averaging is enabled */
136 uint64_t avg_samples;
137 size_t enabled_logic_channels;
138 size_t enabled_analog_channels;
139 size_t first_partial_logic_index;
140 uint8_t first_partial_logic_mask;
142 uint64_t capture_ratio;
143 gboolean trigger_fired;
144 struct soft_trigger_logic *stl;
148 struct sr_channel *ch;
150 enum sr_mqflag mq_flags;
152 enum analog_pattern_type pattern;
155 struct sr_datafeed_analog packet;
156 struct sr_analog_encoding encoding;
157 struct sr_analog_meaning meaning;
158 struct sr_analog_spec spec;
159 float avg_val; /* Average value */
160 unsigned int num_avgs; /* Number of samples averaged */
163 SR_PRIV void demo_generate_analog_pattern(struct dev_context *devc);
164 SR_PRIV void demo_free_analog_pattern(struct dev_context *devc);
165 SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data);