2 * This file is part of the libsigrok project.
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>
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.
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.
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/>.
22 #ifndef LIBSIGROK_HARDWARE_HANTEK_DSO_PROTOCOL_H
23 #define LIBSIGROK_HARDWARE_HANTEK_DSO_PROTOCOL_H
25 #define LOG_PREFIX "hantek-dso"
27 #define USB_INTERFACE 0
28 #define USB_CONFIGURATION 1
29 #define DSO_EP_IN 0x86
30 #define DSO_EP_OUT 0x02
32 /* FX2 renumeration delay in ms */
33 #define MAX_RENUM_DELAY_MS 3000
35 #define MAX_CAPTURE_EMPTY 3
37 #define DEFAULT_VOLTAGE VDIV_500MV
38 #define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
39 #define DEFAULT_TIMEBASE TIME_100us
40 #define DEFAULT_SAMPLERATE SR_KHZ(10)
41 #define DEFAULT_TRIGGER_SOURCE "CH1"
42 #define DEFAULT_COUPLING COUPLING_DC
43 #define DEFAULT_CAPTURE_RATIO 100
44 #define DEFAULT_VERT_OFFSET 0.5
45 #define DEFAULT_VERT_TRIGGERPOS 0.5
47 #define MAX_VERT_TRIGGER 0xfe
49 /* Hantek DSO-specific protocol values */
50 #define EEPROM_CHANNEL_OFFSETS 0x08
52 /* All models have this for their "fast" mode. */
53 #define FRAMESIZE_SMALL (10 * 1024)
55 #define NUM_CHANNELS 2
57 enum control_requests {
58 CTRL_READ_EEPROM = 0xa2,
60 CTRL_BEGINCOMMAND = 0xb3,
61 CTRL_SETOFFSET = 0xb4,
62 CTRL_SETRELAYS = 0xb5,
66 CMD_SET_FILTERS = 0x0,
67 CMD_SET_TRIGGER_SAMPLERATE = 0x1,
68 CMD_FORCE_TRIGGER = 0x2,
69 CMD_CAPTURE_START = 0x3,
70 CMD_ENABLE_TRIGGER = 0x4,
71 CMD_GET_CHANNELDATA = 0x5,
72 CMD_GET_CAPTURESTATE = 0x6,
73 CMD_SET_VOLTAGE = 0x7,
75 CMD_SET_LOGICALDATA = 0x8,
76 CMD_GET_LOGICALDATA = 0x9,
79 * For the following and other specials please see
80 * http://openhantek.sourceforge.net/doc/namespaceHantek.html#ac1cd181814cf3da74771c29800b39028
82 CMD_2250_SET_CHANNELS = 0xb,
83 CMD_2250_SET_TRIGGERSOURCE = 0xc,
84 CMD_2250_SET_RECORD_LENGTH = 0xd,
85 CMD_2250_SET_SAMPLERATE = 0xe,
86 CMD_2250_SET_TRIGGERPOS_AND_BUFFER = 0xf,
89 /* Must match the coupling table. */
93 /* TODO not used, how to enable? */
97 /* Must match the timebases table. */
116 /* Must match the vdivs table. */
129 enum trigger_slopes {
134 enum trigger_sources {
143 CAPTURE_READY_8BIT = 2,
144 CAPTURE_READY_2250 = 3,
145 CAPTURE_READY_9BIT = 7,
146 CAPTURE_TIMEOUT = 127,
147 CAPTURE_UNKNOWN = 255,
165 /* VID/PID after cold boot */
168 /* VID/PID after firmware upload */
173 const uint64_t *buffersizes;
174 const char *firmware;
178 const struct dso_profile *profile;
179 uint64_t limit_frames;
181 GSList *enabled_channels;
182 /* We can't keep track of an FX2-based device after upgrading
183 * the firmware (it re-enumerates into a different device address
184 * after the upgrade) this is like a global lock. No device will open
185 * until a proper delay after the last device was upgraded.
188 int epin_maxpacketsize;
189 int capture_empty_count;
192 /* Oscilloscope settings. */
195 gboolean ch_enabled[2];
198 // voltage offset (vertical position)
201 float voffset_trigger;
202 uint16_t channel_levels[2][9][2];
203 unsigned int framesize;
207 uint64_t capture_ratio;
211 unsigned int samp_received;
212 unsigned int samp_buffered;
213 unsigned int trigger_offset;
214 unsigned char *framebuf;
217 SR_PRIV int dso_open(struct sr_dev_inst *sdi);
218 SR_PRIV void dso_close(struct sr_dev_inst *sdi);
219 SR_PRIV int dso_enable_trigger(const struct sr_dev_inst *sdi);
220 SR_PRIV int dso_force_trigger(const struct sr_dev_inst *sdi);
221 SR_PRIV int dso_init(const struct sr_dev_inst *sdi);
222 SR_PRIV int dso_get_capturestate(const struct sr_dev_inst *sdi,
223 uint8_t *capturestate, uint32_t *trigger_offset);
224 SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi);
225 SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
226 libusb_transfer_cb_fn cb);
227 SR_PRIV int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi);
228 SR_PRIV int dso_set_voffsets(const struct sr_dev_inst *sdi);