]>
Commit | Line | Data |
---|---|---|
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_PROTOCOL_H | |
23 | #define LIBSIGROK_HARDWARE_HANTEK_DSO_PROTOCOL_H | |
24 | ||
25 | #define LOG_PREFIX "hantek-dso" | |
26 | ||
27 | #define USB_INTERFACE 0 | |
28 | #define USB_CONFIGURATION 1 | |
29 | #define DSO_EP_IN 0x86 | |
30 | #define DSO_EP_OUT 0x02 | |
31 | ||
32 | /* FX2 renumeration delay in ms */ | |
33 | #define MAX_RENUM_DELAY_MS 3000 | |
34 | ||
35 | #define MAX_CAPTURE_EMPTY 3 | |
36 | ||
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_HORIZ_TRIGGERPOS 0.5 | |
44 | #define DEFAULT_VERT_OFFSET 0.5 | |
45 | #define DEFAULT_VERT_TRIGGERPOS 0.5 | |
46 | ||
47 | #define MAX_VERT_TRIGGER 0xfe | |
48 | ||
49 | /* Hantek DSO-specific protocol values */ | |
50 | #define EEPROM_CHANNEL_OFFSETS 0x08 | |
51 | ||
52 | /* All models have this for their "fast" mode. */ | |
53 | #define FRAMESIZE_SMALL (10 * 1024) | |
54 | ||
55 | #define NUM_CHANNELS 2 | |
56 | ||
57 | enum control_requests { | |
58 | CTRL_READ_EEPROM = 0xa2, | |
59 | CTRL_GETSPEED = 0xb2, | |
60 | CTRL_BEGINCOMMAND = 0xb3, | |
61 | CTRL_SETOFFSET = 0xb4, | |
62 | CTRL_SETRELAYS = 0xb5, | |
63 | }; | |
64 | ||
65 | enum dso_commands { | |
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, | |
74 | /* unused */ | |
75 | CMD_SET_LOGICALDATA = 0x8, | |
76 | CMD_GET_LOGICALDATA = 0x9, | |
77 | CMD__UNUSED1 = 0xa, | |
78 | /* For the following and other specials please see | |
79 | * http://openhantek.sourceforge.net/doc/namespaceHantek.html#ac1cd181814cf3da74771c29800b39028 */ | |
80 | CMD_2250_SET_CHANNELS = 0xb, | |
81 | CMD_2250_SET_TRIGGERSOURCE = 0xc, | |
82 | CMD_2250_SET_RECORD_LENGTH = 0xd, | |
83 | CMD_2250_SET_SAMPLERATE = 0xe, | |
84 | CMD_2250_SET_TRIGGERPOS_AND_BUFFER = 0xf, | |
85 | }; | |
86 | ||
87 | /* Must match the coupling table. */ | |
88 | enum couplings { | |
89 | COUPLING_AC = 0, | |
90 | COUPLING_DC, | |
91 | /* TODO not used, how to enable? */ | |
92 | COUPLING_GND, | |
93 | }; | |
94 | ||
95 | /* Must match the timebases table. */ | |
96 | enum time_bases { | |
97 | TIME_10us = 0, | |
98 | TIME_20us, | |
99 | TIME_40us, | |
100 | TIME_100us, | |
101 | TIME_200us, | |
102 | TIME_400us, | |
103 | TIME_1ms, | |
104 | TIME_2ms, | |
105 | TIME_4ms, | |
106 | TIME_10ms, | |
107 | TIME_20ms, | |
108 | TIME_40ms, | |
109 | TIME_100ms, | |
110 | TIME_200ms, | |
111 | TIME_400ms, | |
112 | }; | |
113 | ||
114 | /* Must match the vdivs table. */ | |
115 | enum { | |
116 | VDIV_10MV, | |
117 | VDIV_20MV, | |
118 | VDIV_50MV, | |
119 | VDIV_100MV, | |
120 | VDIV_200MV, | |
121 | VDIV_500MV, | |
122 | VDIV_1V, | |
123 | VDIV_2V, | |
124 | VDIV_5V, | |
125 | }; | |
126 | ||
127 | enum trigger_slopes { | |
128 | SLOPE_POSITIVE = 0, | |
129 | SLOPE_NEGATIVE, | |
130 | }; | |
131 | ||
132 | enum trigger_sources { | |
133 | TRIGGER_CH2 = 0, | |
134 | TRIGGER_CH1, | |
135 | TRIGGER_EXT, | |
136 | }; | |
137 | ||
138 | enum capturestates { | |
139 | CAPTURE_EMPTY = 0, | |
140 | CAPTURE_FILLING = 1, | |
141 | CAPTURE_READY_8BIT = 2, | |
142 | CAPTURE_READY2250 = 3, | |
143 | CAPTURE_READY_9BIT = 7, | |
144 | CAPTURE_TIMEOUT = 127, | |
145 | CAPTURE_UNKNOWN = 255, | |
146 | }; | |
147 | ||
148 | enum triggermodes { | |
149 | TRIGGERMODE_AUTO, | |
150 | TRIGGERMODE_NORMAL, | |
151 | TRIGGERMODE_SINGLE, | |
152 | }; | |
153 | ||
154 | enum states { | |
155 | IDLE, | |
156 | NEW_CAPTURE, | |
157 | CAPTURE, | |
158 | FETCH_DATA, | |
159 | STOPPING, | |
160 | }; | |
161 | ||
162 | struct dso_profile { | |
163 | /* VID/PID after cold boot */ | |
164 | uint16_t orig_vid; | |
165 | uint16_t orig_pid; | |
166 | /* VID/PID after firmware upload */ | |
167 | uint16_t fw_vid; | |
168 | uint16_t fw_pid; | |
169 | const char *vendor; | |
170 | const char *model; | |
171 | const uint64_t *buffersizes; | |
172 | const char *firmware; | |
173 | }; | |
174 | ||
175 | struct dev_context { | |
176 | const struct dso_profile *profile; | |
177 | uint64_t limit_frames; | |
178 | uint64_t num_frames; | |
179 | GSList *enabled_channels; | |
180 | /* We can't keep track of an FX2-based device after upgrading | |
181 | * the firmware (it re-enumerates into a different device address | |
182 | * after the upgrade) this is like a global lock. No device will open | |
183 | * until a proper delay after the last device was upgraded. | |
184 | */ | |
185 | int64_t fw_updated; | |
186 | int epin_maxpacketsize; | |
187 | int capture_empty_count; | |
188 | int dev_state; | |
189 | ||
190 | /* Oscilloscope settings. */ | |
191 | int samplerate; | |
192 | int timebase; | |
193 | gboolean ch_enabled[2]; | |
194 | int voltage[2]; | |
195 | int coupling[2]; | |
196 | // voltage offset (vertical position) | |
197 | float voffset_ch1; | |
198 | float voffset_ch2; | |
199 | float voffset_trigger; | |
200 | uint16_t channel_levels[2][9][2]; | |
201 | unsigned int framesize; | |
202 | gboolean filter[2]; | |
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 | ||
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); | |
225 | SR_PRIV int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi); | |
226 | ||
227 | #endif |