]> sigrok.org Git - libsigrok.git/blame_incremental - src/hardware/demo/protocol.h
udev: Split SiLabs CP210x/CP2110 items, mention more devices.
[libsigrok.git] / src / hardware / demo / protocol.h
... / ...
CommitLineData
1/*
2 * This file is part of the libsigrok project.
3 *
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>
9 *
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.
14 *
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.
19 *
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/>.
22 */
23
24#ifndef LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
25#define LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
26
27#include <stdint.h>
28#include <libsigrok/libsigrok.h>
29#include "libsigrok-internal.h"
30
31#define LOG_PREFIX "demo"
32
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
40
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.
45
46/* Logic patterns we can generate. */
47enum logic_pattern_type {
48 /**
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
52 * in time by one bit.
53 */
54 PATTERN_SIGROK,
55
56 /** Pseudo-random values on all channels. */
57 PATTERN_RANDOM,
58
59 /**
60 * Incrementing number across 8 channels. The pattern is repeated
61 * every 8 channels, shifted to the right in time by one bit.
62 */
63 PATTERN_INC,
64
65 /**
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)
71 */
72 PATTERN_WALKING_ONE,
73 PATTERN_WALKING_ZERO,
74
75 /** All channels have a low logic state. */
76 PATTERN_ALL_LOW,
77
78 /** All channels have a high logic state. */
79 PATTERN_ALL_HIGH,
80
81 /**
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.
85 */
86 PATTERN_SQUID,
87
88 /** Gray encoded data, like rotary encoder signals. */
89 PATTERN_GRAYCODE,
90};
91
92/* Analog patterns we can generate. */
93enum analog_pattern_type {
94 PATTERN_SQUARE,
95 PATTERN_SINE,
96 PATTERN_TRIANGLE,
97 PATTERN_SAWTOOTH,
98};
99
100static const char *analog_pattern_str[] = {
101 "square",
102 "sine",
103 "triangle",
104 "sawtooth",
105};
106
107struct analog_pattern {
108 float data[ANALOG_BUFSIZE];
109 unsigned int num_samples;
110};
111
112struct dev_context {
113 uint64_t cur_samplerate;
114 uint64_t limit_samples;
115 uint64_t limit_msec;
116 uint64_t limit_frames;
117 uint64_t sent_samples;
118 uint64_t sent_frame_samples; /* Number of samples that were sent for current frame. */
119 int64_t start_us;
120 int64_t spent_us;
121 uint64_t step;
122 /* Logic */
123 int32_t num_logic_channels;
124 size_t logic_unitsize;
125 uint64_t all_logic_channels_mask;
126 /* There is only ever one logic channel group, so its pattern goes here. */
127 enum logic_pattern_type logic_pattern;
128 uint8_t logic_data[LOGIC_BUFSIZE];
129 /* Analog */
130 struct analog_pattern *analog_patterns[ARRAY_SIZE(analog_pattern_str)];
131 int32_t num_analog_channels;
132 GHashTable *ch_ag;
133 gboolean avg; /* True if averaging is enabled */
134 uint64_t avg_samples;
135 size_t enabled_logic_channels;
136 size_t enabled_analog_channels;
137 size_t first_partial_logic_index;
138 uint8_t first_partial_logic_mask;
139 /* Triggers */
140 uint64_t capture_ratio;
141 gboolean trigger_fired;
142 struct soft_trigger_logic *stl;
143};
144
145struct analog_gen {
146 struct sr_channel *ch;
147 enum sr_mq mq;
148 enum sr_mqflag mq_flags;
149 enum sr_unit unit;
150 enum analog_pattern_type pattern;
151 float amplitude;
152 float offset;
153 struct sr_datafeed_analog packet;
154 struct sr_analog_encoding encoding;
155 struct sr_analog_meaning meaning;
156 struct sr_analog_spec spec;
157 float avg_val; /* Average value */
158 unsigned int num_avgs; /* Number of samples averaged */
159};
160
161SR_PRIV void demo_generate_analog_pattern(struct dev_context *devc);
162SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data);
163
164#endif