]> sigrok.org Git - libsigrok.git/blame_incremental - src/hardware/hantek-dso/protocol.h
rigol-ds: Fix crash when fetching logic channels
[libsigrok.git] / src / hardware / hantek-dso / protocol.h
... / ...
CommitLineData
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
5 * With protocol information from the hantekdso project,
6 * Copyright (C) 2008 Oleg Khudyakov <prcoder@gmail.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef LIBSIGROK_HARDWARE_HANTEK_DSO_PROTOCOL_H
23#define LIBSIGROK_HARDWARE_HANTEK_DSO_PROTOCOL_H
24
25#define LOG_PREFIX "hantek-dso"
26
27#define USB_INTERFACE 0
28#define USB_CONFIGURATION 1
29#define DSO_EP_IN 0x86
30#define DSO_EP_OUT 0x02
31
32/* FX2 renumeration delay in ms */
33#define MAX_RENUM_DELAY_MS 3000
34
35#define MAX_CAPTURE_EMPTY 3
36
37#define DEFAULT_VOLTAGE VDIV_500MV
38#define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
39#define DEFAULT_TIMEBASE TIME_100us
40#define DEFAULT_TRIGGER_SOURCE "CH1"
41#define DEFAULT_COUPLING COUPLING_DC
42#define DEFAULT_HORIZ_TRIGGERPOS 0.5
43#define DEFAULT_VERT_OFFSET 0.5
44#define DEFAULT_VERT_TRIGGERPOS 0.5
45
46#define MAX_VERT_TRIGGER 0xfe
47
48/* Hantek DSO-specific protocol values */
49#define EEPROM_CHANNEL_OFFSETS 0x08
50
51/* All models have this for their "fast" mode. */
52#define FRAMESIZE_SMALL (10 * 1024)
53
54#define NUM_CHANNELS 2
55
56enum control_requests {
57 CTRL_READ_EEPROM = 0xa2,
58 CTRL_GETSPEED = 0xb2,
59 CTRL_BEGINCOMMAND = 0xb3,
60 CTRL_SETOFFSET = 0xb4,
61 CTRL_SETRELAYS = 0xb5,
62};
63
64enum dso_commands {
65 CMD_SET_FILTERS = 0,
66 CMD_SET_TRIGGER_SAMPLERATE,
67 CMD_FORCE_TRIGGER,
68 CMD_CAPTURE_START,
69 CMD_ENABLE_TRIGGER,
70 CMD_GET_CHANNELDATA,
71 CMD_GET_CAPTURESTATE,
72 CMD_SET_VOLTAGE,
73 /* unused */
74 CMD_SET_LOGICALDATA,
75 CMD_GET_LOGICALDATA,
76};
77
78/* Must match the coupling table. */
79enum couplings {
80 COUPLING_AC = 0,
81 COUPLING_DC,
82 /* TODO not used, how to enable? */
83 COUPLING_GND,
84};
85
86/* Must match the timebases table. */
87enum time_bases {
88 TIME_10us = 0,
89 TIME_20us,
90 TIME_40us,
91 TIME_100us,
92 TIME_200us,
93 TIME_400us,
94 TIME_1ms,
95 TIME_2ms,
96 TIME_4ms,
97 TIME_10ms,
98 TIME_20ms,
99 TIME_40ms,
100 TIME_100ms,
101 TIME_200ms,
102 TIME_400ms,
103};
104
105/* Must match the vdivs table. */
106enum {
107 VDIV_10MV,
108 VDIV_20MV,
109 VDIV_50MV,
110 VDIV_100MV,
111 VDIV_200MV,
112 VDIV_500MV,
113 VDIV_1V,
114 VDIV_2V,
115 VDIV_5V,
116};
117
118enum trigger_slopes {
119 SLOPE_POSITIVE = 0,
120 SLOPE_NEGATIVE,
121};
122
123enum trigger_sources {
124 TRIGGER_CH2 = 0,
125 TRIGGER_CH1,
126 TRIGGER_EXT,
127};
128
129enum capturestates {
130 CAPTURE_EMPTY = 0,
131 CAPTURE_FILLING = 1,
132 CAPTURE_READY_8BIT = 2,
133 CAPTURE_READY_9BIT = 7,
134 CAPTURE_TIMEOUT = 127,
135 CAPTURE_UNKNOWN = 255,
136};
137
138enum triggermodes {
139 TRIGGERMODE_AUTO,
140 TRIGGERMODE_NORMAL,
141 TRIGGERMODE_SINGLE,
142};
143
144enum states {
145 IDLE,
146 NEW_CAPTURE,
147 CAPTURE,
148 FETCH_DATA,
149 STOPPING,
150};
151
152struct dso_profile {
153 /* VID/PID after cold boot */
154 uint16_t orig_vid;
155 uint16_t orig_pid;
156 /* VID/PID after firmware upload */
157 uint16_t fw_vid;
158 uint16_t fw_pid;
159 const char *vendor;
160 const char *model;
161 const uint64_t *buffersizes;
162 const char *firmware;
163};
164
165struct dev_context {
166 const struct dso_profile *profile;
167 uint64_t limit_frames;
168 uint64_t num_frames;
169 GSList *enabled_channels;
170 /* We can't keep track of an FX2-based device after upgrading
171 * the firmware (it re-enumerates into a different device address
172 * after the upgrade) this is like a global lock. No device will open
173 * until a proper delay after the last device was upgraded.
174 */
175 int64_t fw_updated;
176 int epin_maxpacketsize;
177 int capture_empty_count;
178 int dev_state;
179
180 /* Oscilloscope settings. */
181 int timebase;
182 gboolean ch_enabled[2];
183 int voltage[2];
184 int coupling[2];
185 // voltage offset (vertical position)
186 float voffset_ch1;
187 float voffset_ch2;
188 float voffset_trigger;
189 uint16_t channel_levels[2][9][2];
190 unsigned int framesize;
191 gboolean filter[2];
192 int triggerslope;
193 char *triggersource;
194 float triggerposition;
195 int triggermode;
196
197 /* Frame transfer */
198 unsigned int samp_received;
199 unsigned int samp_buffered;
200 unsigned int trigger_offset;
201 unsigned char *framebuf;
202};
203
204SR_PRIV int dso_open(struct sr_dev_inst *sdi);
205SR_PRIV void dso_close(struct sr_dev_inst *sdi);
206SR_PRIV int dso_enable_trigger(const struct sr_dev_inst *sdi);
207SR_PRIV int dso_force_trigger(const struct sr_dev_inst *sdi);
208SR_PRIV int dso_init(const struct sr_dev_inst *sdi);
209SR_PRIV int dso_get_capturestate(const struct sr_dev_inst *sdi,
210 uint8_t *capturestate, uint32_t *trigger_offset);
211SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi);
212SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
213 libusb_transfer_cb_fn cb);
214
215#endif