2 * This file is part of the sigrok 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_H
23 #define LIBSIGROK_HARDWARE_HANTEK_DSO_H
25 /* Message logging helpers with driver-specific prefix string. */
26 #define DRIVER_LOG_DOMAIN "hantek-dso: "
27 #define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
28 #define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
29 #define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
30 #define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
31 #define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
32 #define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
34 #define USB_INTERFACE 0
35 #define USB_CONFIGURATION 1
36 #define DSO_EP_IN 0x86
37 #define DSO_EP_OUT 0x02
39 /* FX2 renumeration delay in ms */
40 #define MAX_RENUM_DELAY_MS 3000
42 #define MAX_CAPTURE_EMPTY 3
44 #define DEFAULT_VOLTAGE VDIV_500MV
45 #define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
46 #define DEFAULT_TIMEBASE TIME_100us
47 #define DEFAULT_TRIGGER_SOURCE "CH1"
48 #define DEFAULT_COUPLING COUPLING_DC
49 #define DEFAULT_HORIZ_TRIGGERPOS 0.5
50 #define DEFAULT_VERT_OFFSET 0.5
51 #define DEFAULT_VERT_TRIGGERPOS 0.5
53 #define MAX_VERT_TRIGGER 0xfe
55 /* Hantek DSO-specific protocol values */
56 #define EEPROM_CHANNEL_OFFSETS 0x08
58 /* All models have this for their "fast" mode. */
59 #define FRAMESIZE_SMALL 10240
61 enum control_requests {
62 CTRL_READ_EEPROM = 0xa2,
64 CTRL_BEGINCOMMAND = 0xb3,
65 CTRL_SETOFFSET = 0xb4,
66 CTRL_SETRELAYS = 0xb5,
71 CMD_SET_TRIGGER_SAMPLERATE,
83 /* Must match the coupling table. */
87 /* TODO not used, how to enable? */
91 /* Must match the timebases table. */
110 /* Must match the vdivs table. */
123 enum trigger_slopes {
128 enum trigger_sources {
137 CAPTURE_READY_8BIT = 2,
138 CAPTURE_READY_9BIT = 7,
139 CAPTURE_TIMEOUT = 127,
140 CAPTURE_UNKNOWN = 255,
158 /* VID/PID after cold boot */
161 /* VID/PID after firmware upload */
166 const uint64_t *buffersizes;
171 const struct dso_profile *profile;
173 uint64_t limit_frames;
175 GSList *enabled_probes;
176 /* We can't keep track of an FX2-based device after upgrading
177 * the firmware (it re-enumerates into a different device address
178 * after the upgrade) this is like a global lock. No device will open
179 * until a proper delay after the last device was upgraded.
182 int epin_maxpacketsize;
183 int capture_empty_count;
186 /* Oscilloscope settings. */
188 gboolean ch1_enabled;
189 gboolean ch2_enabled;
194 // voltage offset (vertical position)
197 float voffset_trigger;
198 uint16_t channel_levels[2][9][2];
199 unsigned int framesize;
202 gboolean filter_trigger;
205 float triggerposition;
209 unsigned int samp_received;
210 unsigned int samp_buffered;
211 unsigned int trigger_offset;
212 unsigned char *framebuf;
215 SR_PRIV int dso_open(struct sr_dev_inst *sdi);
216 SR_PRIV void dso_close(struct sr_dev_inst *sdi);
217 SR_PRIV int dso_enable_trigger(const struct sr_dev_inst *sdi);
218 SR_PRIV int dso_force_trigger(const struct sr_dev_inst *sdi);
219 SR_PRIV int dso_init(const struct sr_dev_inst *sdi);
220 SR_PRIV int dso_get_capturestate(const struct sr_dev_inst *sdi,
221 uint8_t *capturestate, uint32_t *trigger_offset);
222 SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi);
223 SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
224 libusb_transfer_cb_fn cb);