]> sigrok.org Git - libsigrok.git/blame_incremental - hardware/hantek-dso/dso.h
GPL headers: Use correct project name.
[libsigrok.git] / hardware / hantek-dso / dso.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_H
23#define LIBSIGROK_HARDWARE_HANTEK_DSO_H
24
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)
33
34#define USB_INTERFACE 0
35#define USB_CONFIGURATION 1
36#define DSO_EP_IN 0x86
37#define DSO_EP_OUT 0x02
38
39/* FX2 renumeration delay in ms */
40#define MAX_RENUM_DELAY_MS 3000
41
42#define MAX_CAPTURE_EMPTY 3
43
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
52
53#define MAX_VERT_TRIGGER 0xfe
54
55/* Hantek DSO-specific protocol values */
56#define EEPROM_CHANNEL_OFFSETS 0x08
57
58/* All models have this for their "fast" mode. */
59#define FRAMESIZE_SMALL 10240
60
61enum control_requests {
62 CTRL_READ_EEPROM = 0xa2,
63 CTRL_GETSPEED = 0xb2,
64 CTRL_BEGINCOMMAND = 0xb3,
65 CTRL_SETOFFSET = 0xb4,
66 CTRL_SETRELAYS = 0xb5,
67};
68
69enum dso_commands {
70 CMD_SET_FILTERS = 0,
71 CMD_SET_TRIGGER_SAMPLERATE,
72 CMD_FORCE_TRIGGER,
73 CMD_CAPTURE_START,
74 CMD_ENABLE_TRIGGER,
75 CMD_GET_CHANNELDATA,
76 CMD_GET_CAPTURESTATE,
77 CMD_SET_VOLTAGE,
78 /* unused */
79 cmdSetLogicalData,
80 cmdGetLogicalData,
81};
82
83/* Must match the coupling table. */
84enum couplings {
85 COUPLING_AC = 0,
86 COUPLING_DC,
87 /* TODO not used, how to enable? */
88 COUPLING_GND,
89};
90
91/* Must match the timebases table. */
92enum time_bases {
93 TIME_10us = 0,
94 TIME_20us,
95 TIME_40us,
96 TIME_100us,
97 TIME_200us,
98 TIME_400us,
99 TIME_1ms,
100 TIME_2ms,
101 TIME_4ms,
102 TIME_10ms,
103 TIME_20ms,
104 TIME_40ms,
105 TIME_100ms,
106 TIME_200ms,
107 TIME_400ms,
108};
109
110/* Must match the vdivs table. */
111enum {
112 VDIV_10MV,
113 VDIV_20MV,
114 VDIV_50MV,
115 VDIV_100MV,
116 VDIV_200MV,
117 VDIV_500MV,
118 VDIV_1V,
119 VDIV_2V,
120 VDIV_5V,
121};
122
123enum trigger_slopes {
124 SLOPE_POSITIVE = 0,
125 SLOPE_NEGATIVE,
126};
127
128enum trigger_sources {
129 TRIGGER_CH2 = 0,
130 TRIGGER_CH1,
131 TRIGGER_EXT,
132};
133
134enum capturestates {
135 CAPTURE_EMPTY = 0,
136 CAPTURE_FILLING = 1,
137 CAPTURE_READY_8BIT = 2,
138 CAPTURE_READY_9BIT = 7,
139 CAPTURE_TIMEOUT = 127,
140 CAPTURE_UNKNOWN = 255,
141};
142
143enum triggermodes {
144 TRIGGERMODE_AUTO,
145 TRIGGERMODE_NORMAL,
146 TRIGGERMODE_SINGLE,
147};
148
149enum states {
150 IDLE,
151 NEW_CAPTURE,
152 CAPTURE,
153 FETCH_DATA,
154 STOPPING,
155};
156
157struct dso_profile {
158 /* VID/PID after cold boot */
159 uint16_t orig_vid;
160 uint16_t orig_pid;
161 /* VID/PID after firmware upload */
162 uint16_t fw_vid;
163 uint16_t fw_pid;
164 char *vendor;
165 char *model;
166 const uint64_t *buffersizes;
167 char *firmware;
168};
169
170struct dev_context {
171 const struct dso_profile *profile;
172 void *cb_data;
173 uint64_t limit_frames;
174 uint64_t num_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.
180 */
181 int64_t fw_updated;
182 int epin_maxpacketsize;
183 int capture_empty_count;
184 int dev_state;
185
186 /* Oscilloscope settings. */
187 int timebase;
188 gboolean ch1_enabled;
189 gboolean ch2_enabled;
190 int voltage_ch1;
191 int voltage_ch2;
192 int coupling_ch1;
193 int coupling_ch2;
194 // voltage offset (vertical position)
195 float voffset_ch1;
196 float voffset_ch2;
197 float voffset_trigger;
198 uint16_t channel_levels[2][9][2];
199 unsigned int framesize;
200 gboolean filter_ch1;
201 gboolean filter_ch2;
202 gboolean filter_trigger;
203 int triggerslope;
204 char *triggersource;
205 float triggerposition;
206 int triggermode;
207
208 /* Frame transfer */
209 unsigned int samp_received;
210 unsigned int samp_buffered;
211 unsigned int trigger_offset;
212 unsigned char *framebuf;
213};
214
215SR_PRIV int dso_open(struct sr_dev_inst *sdi);
216SR_PRIV void dso_close(struct sr_dev_inst *sdi);
217SR_PRIV int dso_enable_trigger(const struct sr_dev_inst *sdi);
218SR_PRIV int dso_force_trigger(const struct sr_dev_inst *sdi);
219SR_PRIV int dso_init(const struct sr_dev_inst *sdi);
220SR_PRIV int dso_get_capturestate(const struct sr_dev_inst *sdi,
221 uint8_t *capturestate, uint32_t *trigger_offset);
222SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi);
223SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
224 libusb_transfer_cb_fn cb);
225
226#endif