]> sigrok.org Git - libsigrok.git/blame - hardware/hantek-dso/dso.h
hantek-dso: Use message logging helpers.
[libsigrok.git] / hardware / hantek-dso / dso.h
CommitLineData
3b533202
BV
1/*
2 * This file is part of the sigrok 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
e98b7f1b
UH
25#define USB_INTERFACE 0
26#define USB_CONFIGURATION 1
27#define DSO_EP_IN 0x86
28#define DSO_EP_OUT 0x02
29#define NUM_PROBES 2
3b533202
BV
30
31/* FX2 renumeration delay in ms */
e98b7f1b 32#define MAX_RENUM_DELAY_MS 3000
3b533202 33
e98b7f1b 34#define MAX_CAPTURE_EMPTY 3
3b533202 35
e98b7f1b
UH
36#define DEFAULT_VOLTAGE VDIV_500MV
37#define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
38#define DEFAULT_TIMEBASE TIME_100us
39#define DEFAULT_TRIGGER_SOURCE "CH1"
40#define DEFAULT_COUPLING COUPLING_DC
41#define DEFAULT_HORIZ_TRIGGERPOS 0.5
42#define DEFAULT_VERT_OFFSET 0.5
43#define DEFAULT_VERT_TRIGGERPOS 0.5
3b533202 44
e98b7f1b 45#define MAX_VERT_TRIGGER 0xfe
3b533202
BV
46
47/* Hantek DSO-specific protocol values */
e98b7f1b 48#define EEPROM_CHANNEL_OFFSETS 0x08
3b533202 49
e98b7f1b
UH
50#define FRAMESIZE_SMALL 10240
51#define FRAMESIZE_LARGE 32768
3b533202
BV
52
53enum control_requests {
54 CTRL_READ_EEPROM = 0xa2,
55 CTRL_GETSPEED = 0xb2,
56 CTRL_BEGINCOMMAND = 0xb3,
57 CTRL_SETOFFSET = 0xb4,
e98b7f1b 58 CTRL_SETRELAYS = 0xb5,
3b533202
BV
59};
60
61enum dso_commands {
62 CMD_SET_FILTERS = 0,
63 CMD_SET_TRIGGER_SAMPLERATE,
64 CMD_FORCE_TRIGGER,
65 CMD_CAPTURE_START,
66 CMD_ENABLE_TRIGGER,
67 CMD_GET_CHANNELDATA,
68 CMD_GET_CAPTURESTATE,
69 CMD_SET_VOLTAGE,
313deed2 70 /* unused */
3b533202 71 cmdSetLogicalData,
e98b7f1b 72 cmdGetLogicalData,
3b533202
BV
73};
74
b58fbd99 75/* Must match the coupling table. */
3b533202
BV
76enum couplings {
77 COUPLING_AC = 0,
78 COUPLING_DC,
2715c0b8 79 /* TODO not used, how to enable? */
e98b7f1b 80 COUPLING_GND,
3b533202
BV
81};
82
b58fbd99 83/* Must match the timebases table. */
3b533202
BV
84enum time_bases {
85 TIME_10us = 0,
86 TIME_20us,
87 TIME_40us,
88 TIME_100us,
89 TIME_200us,
90 TIME_400us,
91 TIME_1ms,
92 TIME_2ms,
93 TIME_4ms,
94 TIME_10ms,
95 TIME_20ms,
96 TIME_40ms,
97 TIME_100ms,
98 TIME_200ms,
e98b7f1b 99 TIME_400ms,
3b533202
BV
100};
101
b58fbd99 102/* Must match the vdivs table. */
313deed2
BV
103enum {
104 VDIV_10MV,
105 VDIV_20MV,
106 VDIV_50MV,
107 VDIV_100MV,
108 VDIV_200MV,
109 VDIV_500MV,
110 VDIV_1V,
111 VDIV_2V,
112 VDIV_5V,
113};
114
3b533202
BV
115enum trigger_slopes {
116 SLOPE_POSITIVE = 0,
e98b7f1b 117 SLOPE_NEGATIVE,
3b533202
BV
118};
119
120enum trigger_sources {
121 TRIGGER_CH2 = 0,
122 TRIGGER_CH1,
3b533202 123 TRIGGER_EXT,
3b533202
BV
124};
125
3b533202
BV
126enum capturestates {
127 CAPTURE_EMPTY = 0,
128 CAPTURE_FILLING = 1,
129 CAPTURE_READY_8BIT = 2,
130 CAPTURE_READY_9BIT = 7,
131 CAPTURE_TIMEOUT = 127,
e98b7f1b 132 CAPTURE_UNKNOWN = 255,
3b533202
BV
133};
134
135enum triggermodes {
136 TRIGGERMODE_AUTO,
137 TRIGGERMODE_NORMAL,
e98b7f1b 138 TRIGGERMODE_SINGLE,
3b533202
BV
139};
140
141enum states {
142 IDLE,
143 NEW_CAPTURE,
144 CAPTURE,
a3508e33
BV
145 FETCH_DATA,
146 STOPPING,
3b533202
BV
147};
148
149struct dso_profile {
150 /* VID/PID after cold boot */
151 uint16_t orig_vid;
152 uint16_t orig_pid;
153 /* VID/PID after firmware upload */
154 uint16_t fw_vid;
155 uint16_t fw_pid;
156 char *vendor;
157 char *model;
3b533202
BV
158 char *firmware;
159};
160
269971dd 161struct dev_context {
62bb8840 162 const struct dso_profile *profile;
3b533202
BV
163 struct sr_usb_dev_inst *usb;
164 void *cb_data;
ae88b97b
BV
165 uint64_t limit_frames;
166 uint64_t num_frames;
3b533202
BV
167 /* We can't keep track of an FX2-based device after upgrading
168 * the firmware (it re-enumerates into a different device address
169 * after the upgrade) this is like a global lock. No device will open
170 * until a proper delay after the last device was upgraded.
171 */
fc8fe3e3 172 int64_t fw_updated;
3b533202
BV
173 int epin_maxpacketsize;
174 int capture_empty_count;
3b533202
BV
175 int dev_state;
176
e749a8cb 177 /* Oscilloscope settings. */
3b533202
BV
178 int timebase;
179 gboolean ch1_enabled;
180 gboolean ch2_enabled;
181 int voltage_ch1;
182 int voltage_ch2;
183 int coupling_ch1;
184 int coupling_ch2;
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];
e749a8cb 190 unsigned int framesize;
3b533202
BV
191 gboolean filter_ch1;
192 gboolean filter_ch2;
193 gboolean filter_trigger;
194 int triggerslope;
a370ef19 195 char *triggersource;
bc79e906 196 float triggerposition;
3b533202 197 int triggermode;
e749a8cb
BV
198
199 /* Frame transfer */
200 unsigned int samp_received;
201 unsigned int samp_buffered;
202 unsigned int trigger_offset;
203 unsigned char *framebuf;
3b533202
BV
204};
205
25a0f108 206SR_PRIV int dso_open(struct sr_dev_inst *sdi);
3b533202 207SR_PRIV void dso_close(struct sr_dev_inst *sdi);
269971dd
BV
208SR_PRIV int dso_enable_trigger(struct dev_context *devc);
209SR_PRIV int dso_force_trigger(struct dev_context *devc);
210SR_PRIV int dso_init(struct dev_context *devc);
e98b7f1b
UH
211SR_PRIV int dso_get_capturestate(struct dev_context *devc,
212 uint8_t *capturestate, uint32_t *trigger_offset);
269971dd 213SR_PRIV int dso_capture_start(struct dev_context *devc);
e98b7f1b
UH
214SR_PRIV int dso_get_channeldata(struct dev_context *devc,
215 libusb_transfer_cb_fn cb);
3b533202
BV
216
217#endif