]> sigrok.org Git - libsigrok.git/blob - hardware/hantek-dso/dso.h
sr: initial support for Hantek 2xxx/5200 USB oscilloscopes
[libsigrok.git] / hardware / hantek-dso / dso.h
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
25 #define USB_INTERFACE          0
26 #define USB_CONFIGURATION      1
27 #define DSO_EP_IN              0x86
28 #define DSO_EP_OUT             0x02
29
30 /* FX2 renumeration delay in ms */
31 #define MAX_RENUM_DELAY        3000
32
33 #define MAX_CAPTURE_EMPTY      3
34
35 #define DEFAULT_VOLTAGE            VOLTAGE_2V
36 #define DEFAULT_FRAMESIZE          FRAMESIZE_SMALL
37 #define DEFAULT_TIMEBASE           TIME_1ms
38 #define DEFAULT_TRIGGER_SOURCE     TRIGGER_CH1
39 #define DEFAULT_COUPLING           COUPLING_AC
40 #define DEFAULT_SELECTED_CHANNEL   SELECT_CH1CH2
41 /* Halfway between min and max = 0V */
42 #define DEFAULT_HORIZ_TRIGGERPOS   0x1400
43
44 #define DEFAULT_VERT_OFFSET        0.5
45 #define DEFAULT_VERT_TRIGGERPOS    0.0
46
47 #define MAX_VERT_TRIGGER           0xfe
48
49 /* Hantek DSO-specific protocol values */
50 #define EEPROM_CHANNEL_OFFSETS     0x08
51
52 #define FRAMESIZE_SMALL        10240
53 #define FRAMESIZE_LARGE        32768
54
55
56 enum 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
64 enum 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         cmdSetLogicalData,
74         cmdGetLogicalData
75 };
76
77 enum voltages {
78         VOLTAGE_5V = 0,
79         VOLTAGE_2V,
80         VOLTAGE_1V,
81         VOLTAGE_500mV,
82         VOLTAGE_200mV,
83         VOLTAGE_100mV,
84         VOLTAGE_50mV,
85         VOLTAGE_20mV,
86         VOLTAGE_10mV
87 };
88
89 enum couplings {
90         COUPLING_AC = 0,
91         COUPLING_DC,
92         COUPLING_OFF
93 };
94
95 enum time_bases {
96         TIME_10us = 0,
97         TIME_20us,
98         TIME_40us,
99         TIME_100us,
100         TIME_200us,
101         TIME_400us,
102         TIME_1ms,
103         TIME_2ms,
104         TIME_4ms,
105         TIME_10ms,
106         TIME_20ms,
107         TIME_40ms,
108         TIME_100ms,
109         TIME_200ms,
110         TIME_400ms
111 };
112
113 enum trigger_slopes {
114         SLOPE_POSITIVE = 0,
115         SLOPE_NEGATIVE
116 };
117
118 enum trigger_sources {
119         TRIGGER_CH2 = 0,
120         TRIGGER_CH1,
121         TRIGGER_ALT,
122         TRIGGER_EXT,
123         TRIGGER_EXT10
124 };
125
126 enum selected_channels {
127         SELECT_CH1 = 0,
128         SELECT_CH2,
129         SELECT_CH1CH2
130 };
131
132 enum capturestates {
133         CAPTURE_EMPTY = 0,
134         CAPTURE_FILLING = 1,
135         CAPTURE_READY_8BIT = 2,
136         CAPTURE_READY_9BIT = 7,
137         CAPTURE_TIMEOUT = 127,
138         CAPTURE_UNKNOWN = 255
139 };
140
141 enum triggermodes {
142         TRIGGERMODE_AUTO,
143         TRIGGERMODE_NORMAL,
144         TRIGGERMODE_SINGLE
145 };
146
147 enum states {
148         IDLE,
149         NEW_CAPTURE,
150         CAPTURE,
151         FETCH_DATA
152 };
153
154 struct dso_profile {
155         /* VID/PID after cold boot */
156         uint16_t orig_vid;
157         uint16_t orig_pid;
158         /* VID/PID after firmware upload */
159         uint16_t fw_vid;
160         uint16_t fw_pid;
161         char *vendor;
162         char *model;
163         char *model_version;
164         int num_probes;
165         char *firmware;
166 };
167
168 struct context {
169         struct dso_profile *profile;
170         struct sr_usb_dev_inst *usb;
171         void *cb_data;
172         /* We can't keep track of an FX2-based device after upgrading
173          * the firmware (it re-enumerates into a different device address
174          * after the upgrade) this is like a global lock. No device will open
175          * until a proper delay after the last device was upgraded.
176          */
177         GTimeVal fw_updated;
178         int epin_maxpacketsize;
179         int capture_empty_count;
180         int current_transfer;
181         int dev_state;
182
183         int timebase;
184         gboolean ch1_enabled;
185         gboolean ch2_enabled;
186         int voltage_ch1;
187         int voltage_ch2;
188         int coupling_ch1;
189         int coupling_ch2;
190         // voltage offset (vertical position)
191         float voffset_ch1;
192         float voffset_ch2;
193         float voffset_trigger;
194         uint16_t channel_levels[2][9][2];
195         int selected_channel;
196         int framesize;
197         gboolean filter_ch1;
198         gboolean filter_ch2;
199         gboolean filter_trigger;
200         int triggerslope;
201         int triggersource;
202         int triggerposition;
203         int triggermode;
204 };
205
206 SR_PRIV int dso_open(int dev_index);
207 SR_PRIV void dso_close(struct sr_dev_inst *sdi);
208 SR_PRIV int dso_enable_trigger(struct context *ctx);
209 SR_PRIV int dso_force_trigger(struct context *ctx);
210 SR_PRIV int dso_init(struct context *ctx);
211 SR_PRIV uint8_t dso_get_capturestate(struct context *ctx);
212 SR_PRIV uint8_t dso_capture_start(struct context *ctx);
213 SR_PRIV int dso_get_channeldata(struct context *ctx, libusb_transfer_cb_fn cb);
214
215 #endif