2 * This file is part of the libsigrok project.
4 * Copyright (C) 2015 Christer Ekholm <christerekholm@gmail.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef LIBSIGROK_HARDWARE_HANTEK_6XXX_PROTOCOL_H
21 #define LIBSIGROK_HARDWARE_HANTEK_6XXX_PROTOCOL_H
26 #include <libsigrok/libsigrok.h>
27 #include "libsigrok-internal.h"
29 #define LOG_PREFIX "hantek-6xxx"
31 #define MAX_RENUM_DELAY_MS 3000
33 #define DEFAULT_VOLTAGE 2
34 #define DEFAULT_COUPLING COUPLING_DC
35 #define DEFAULT_SAMPLERATE SR_MHZ(8)
37 #define NUM_CHANNELS 2
39 #define SAMPLERATE_VALUES \
40 SR_MHZ(48), SR_MHZ(30), SR_MHZ(24), \
41 SR_MHZ(16), SR_MHZ(8), SR_MHZ(4), \
42 SR_MHZ(1), SR_KHZ(500), SR_KHZ(200), \
45 #define SAMPLERATE_REGS \
46 48, 30, 24, 16, 8, 4, 1, 50, 20, 10,
57 #define VDIV_MULTIPLIER 10
59 /* Weird flushing needed for filtering glitch away. */
60 #define FLUSH_PACKET_SIZE 1024
62 #define MIN_PACKET_SIZE 512
63 #define MAX_PACKET_SIZE (12 * 1024 * 1024)
65 #define HANTEK_EP_IN 0x86
66 #define USB_INTERFACE 0
67 #define USB_CONFIGURATION 1
69 enum control_requests {
72 SAMPLERATE_REG = 0xe2,
90 struct hantek_6xxx_profile {
91 /* VID/PID after cold boot */
94 /* VID/PID after firmware upload */
103 const struct hantek_6xxx_profile *profile;
104 GSList *enabled_channels;
106 * We can't keep track of an FX2-based device after upgrading
107 * the firmware (it re-enumerates into a different device address
108 * after the upgrade) this is like a global lock. No device will open
109 * until a proper delay after the last device was upgraded.
113 uint64_t samp_received;
116 uint64_t read_start_ts;
117 uint32_t read_data_amount;
119 struct libusb_transfer **sample_buf;
120 uint32_t sample_buf_write;
121 uint32_t sample_buf_size;
123 gboolean ch_enabled[NUM_CHANNELS];
124 int voltage[NUM_CHANNELS];
125 int coupling[NUM_CHANNELS];
129 uint64_t limit_samples;
132 SR_PRIV int hantek_6xxx_open(struct sr_dev_inst *sdi);
133 SR_PRIV void hantek_6xxx_close(struct sr_dev_inst *sdi);
134 SR_PRIV int hantek_6xxx_get_channeldata(const struct sr_dev_inst *sdi,
135 libusb_transfer_cb_fn cb, uint32_t data_amount);
137 SR_PRIV int hantek_6xxx_start_data_collecting(const struct sr_dev_inst *sdi);
138 SR_PRIV int hantek_6xxx_stop_data_collecting(const struct sr_dev_inst *sdi);
140 SR_PRIV int hantek_6xxx_update_coupling(const struct sr_dev_inst *sdi);
141 SR_PRIV int hantek_6xxx_update_samplerate(const struct sr_dev_inst *sdi);
142 SR_PRIV int hantek_6xxx_update_vdiv(const struct sr_dev_inst *sdi);
143 SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi);
144 SR_PRIV int hantek_6xxx_init(const struct sr_dev_inst *sdi);