]> sigrok.org Git - libsigrok.git/blame - src/hardware/hantek-6xxx/protocol.h
hantek-6xxx: Initial driver implementation.
[libsigrok.git] / src / hardware / hantek-6xxx / protocol.h
CommitLineData
6c6bc80a
C
1/*
2 * This file is part of the libsigrok project.
3 *
f2a66a8e 4 * Copyright (C) 2015 Christer Ekholm <christerekholm@gmail.com>
6c6bc80a
C
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20#ifndef LIBSIGROK_HARDWARE_HANTEK_6XXX_PROTOCOL_H
21#define LIBSIGROK_HARDWARE_HANTEK_6XXX_PROTOCOL_H
22
23#include <stdint.h>
f2a66a8e 24#include <string.h>
6c6bc80a
C
25#include <glib.h>
26#include <libsigrok/libsigrok.h>
27#include "libsigrok-internal.h"
28
29#define LOG_PREFIX "hantek-6xxx"
30
f2a66a8e
C
31#define MAX_RENUM_DELAY_MS 3000
32
33#define DEFAULT_VOLTAGE 2
34#define DEFAULT_SAMPLERATE SR_MHZ(8)
35
36#define NUM_CHANNELS 2
37
38#define SAMPLERATE_VALUES \
39 SR_MHZ(48), SR_MHZ(30), SR_MHZ(24), \
40 SR_MHZ(16), SR_MHZ(8), SR_MHZ(4), \
41 SR_MHZ(1), SR_KHZ(500), SR_KHZ(200), \
42 SR_KHZ(100),
43
44#define SAMPLERATE_REGS \
45 48, 30, 24, 16, 8, 4, 1, 50, 20, 10,
46
47#define VDIV_VALUES \
48 { 100, 1000 }, \
49 { 250, 1000 }, \
50 { 500, 1000 }, \
51 { 1, 1 },
52
53#define VDIV_REG \
54 10, 5, 2, 1,
55
56#define VDIV_MULTIPLIER 10
57
58/* Weird flushing needed for filtering glitch away. */
59#define FLUSH_PACKET_SIZE 2600
60
61#define MIN_PACKET_SIZE 600
62#define MAX_PACKET_SIZE (12 * 1024 * 1024)
63
64#define HANTEK_EP_IN 0x86
65#define USB_INTERFACE 0
66#define USB_CONFIGURATION 1
67
68enum control_requests {
69 VDIV_CH1_REG = 0xe0,
70 VDIV_CH2_REG = 0xe1,
71 SAMPLERATE_REG = 0xe2,
72 TRIGGER_REG = 0xe3,
73 CHANNELS_REG = 0xe4,
74};
75
76enum states {
77 IDLE,
78 FLUSH,
79 CAPTURE,
80 STOPPING,
81};
82
83struct hantek_6xxx_profile {
84 /* VID/PID after cold boot */
85 uint16_t orig_vid;
86 uint16_t orig_pid;
87 /* VID/PID after firmware upload */
88 uint16_t fw_vid;
89 uint16_t fw_pid;
90 const char *vendor;
91 const char *model;
92 const char *firmware;
93};
94
6c6bc80a 95struct dev_context {
f2a66a8e
C
96 const struct hantek_6xxx_profile *profile;
97 void *cb_data;
98 GSList *enabled_channels;
99 /*
100 * We can't keep track of an FX2-based device after upgrading
101 * the firmware (it re-enumerates into a different device address
102 * after the upgrade) this is like a global lock. No device will open
103 * until a proper delay after the last device was upgraded.
104 */
105 int64_t fw_updated;
106 int dev_state;
107 uint64_t samp_received;
108 uint64_t aq_started;
6c6bc80a 109
f2a66a8e
C
110 uint64_t read_start_ts;
111 uint32_t read_data_amount;
6c6bc80a 112
f2a66a8e
C
113 struct libusb_transfer **sample_buf;
114 uint32_t sample_buf_write;
115 uint32_t sample_buf_size;
6c6bc80a 116
f2a66a8e
C
117 gboolean ch_enabled[NUM_CHANNELS];
118 int voltage[NUM_CHANNELS];
119 uint64_t samplerate;
6c6bc80a 120
f2a66a8e
C
121 uint64_t limit_msec;
122 uint64_t limit_samples;
6c6bc80a
C
123};
124
f2a66a8e
C
125SR_PRIV int hantek_6xxx_open(struct sr_dev_inst *sdi);
126SR_PRIV void hantek_6xxx_close(struct sr_dev_inst *sdi);
127SR_PRIV int hantek_6xxx_get_channeldata(const struct sr_dev_inst *sdi,
128 libusb_transfer_cb_fn cb, uint32_t data_amount);
129
130SR_PRIV int hantek_6xxx_start_data_collecting(const struct sr_dev_inst *sdi);
131SR_PRIV int hantek_6xxx_stop_data_collecting(const struct sr_dev_inst *sdi);
132
133SR_PRIV int hantek_6xxx_update_samplerate(const struct sr_dev_inst *sdi);
134SR_PRIV int hantek_6xxx_update_vdiv(const struct sr_dev_inst *sdi);
135SR_PRIV int hantek_6xxx_update_channels(const struct sr_dev_inst *sdi);
136SR_PRIV int hantek_6xxx_init(const struct sr_dev_inst *sdi);
6c6bc80a
C
137
138#endif