2012-04-22 23:05:58 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the sigrok project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
|
|
|
|
* With protocol information from the hantekdso project,
|
|
|
|
* Copyright (C) 2008 Oleg Khudyakov <prcoder@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LIBSIGROK_HARDWARE_HANTEK_DSO_H
|
|
|
|
#define LIBSIGROK_HARDWARE_HANTEK_DSO_H
|
|
|
|
|
2013-01-29 11:05:00 +00:00
|
|
|
/* Message logging helpers with driver-specific prefix string. */
|
|
|
|
#define DRIVER_LOG_DOMAIN "hantek-dso: "
|
|
|
|
#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
|
2013-04-02 12:33:17 +00:00
|
|
|
#define USB_INTERFACE 0
|
|
|
|
#define USB_CONFIGURATION 1
|
|
|
|
#define DSO_EP_IN 0x86
|
|
|
|
#define DSO_EP_OUT 0x02
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
/* FX2 renumeration delay in ms */
|
2013-04-02 12:33:17 +00:00
|
|
|
#define MAX_RENUM_DELAY_MS 3000
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-02 12:33:17 +00:00
|
|
|
#define MAX_CAPTURE_EMPTY 3
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-02 12:33:17 +00:00
|
|
|
#define DEFAULT_VOLTAGE VDIV_500MV
|
|
|
|
#define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
|
|
|
|
#define DEFAULT_TIMEBASE TIME_100us
|
|
|
|
#define DEFAULT_TRIGGER_SOURCE "CH1"
|
|
|
|
#define DEFAULT_COUPLING COUPLING_DC
|
|
|
|
#define DEFAULT_HORIZ_TRIGGERPOS 0.5
|
|
|
|
#define DEFAULT_VERT_OFFSET 0.5
|
|
|
|
#define DEFAULT_VERT_TRIGGERPOS 0.5
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-02 12:33:17 +00:00
|
|
|
#define MAX_VERT_TRIGGER 0xfe
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
/* Hantek DSO-specific protocol values */
|
2013-04-02 12:33:17 +00:00
|
|
|
#define EEPROM_CHANNEL_OFFSETS 0x08
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-02 18:54:44 +00:00
|
|
|
/* All models have this for their "fast" mode. */
|
2013-04-02 12:33:17 +00:00
|
|
|
#define FRAMESIZE_SMALL 10240
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
enum control_requests {
|
|
|
|
CTRL_READ_EEPROM = 0xa2,
|
|
|
|
CTRL_GETSPEED = 0xb2,
|
|
|
|
CTRL_BEGINCOMMAND = 0xb3,
|
|
|
|
CTRL_SETOFFSET = 0xb4,
|
2012-11-10 17:19:30 +00:00
|
|
|
CTRL_SETRELAYS = 0xb5,
|
2012-04-22 23:05:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum dso_commands {
|
|
|
|
CMD_SET_FILTERS = 0,
|
|
|
|
CMD_SET_TRIGGER_SAMPLERATE,
|
|
|
|
CMD_FORCE_TRIGGER,
|
|
|
|
CMD_CAPTURE_START,
|
|
|
|
CMD_ENABLE_TRIGGER,
|
|
|
|
CMD_GET_CHANNELDATA,
|
|
|
|
CMD_GET_CAPTURESTATE,
|
|
|
|
CMD_SET_VOLTAGE,
|
2012-05-17 00:03:12 +00:00
|
|
|
/* unused */
|
2012-04-22 23:05:58 +00:00
|
|
|
cmdSetLogicalData,
|
2012-11-10 17:19:30 +00:00
|
|
|
cmdGetLogicalData,
|
2012-04-22 23:05:58 +00:00
|
|
|
};
|
|
|
|
|
2012-05-17 01:17:09 +00:00
|
|
|
/* Must match the coupling table. */
|
2012-04-22 23:05:58 +00:00
|
|
|
enum couplings {
|
|
|
|
COUPLING_AC = 0,
|
|
|
|
COUPLING_DC,
|
2012-05-19 23:14:37 +00:00
|
|
|
/* TODO not used, how to enable? */
|
2012-11-10 17:19:30 +00:00
|
|
|
COUPLING_GND,
|
2012-04-22 23:05:58 +00:00
|
|
|
};
|
|
|
|
|
2012-05-17 01:17:09 +00:00
|
|
|
/* Must match the timebases table. */
|
2012-04-22 23:05:58 +00:00
|
|
|
enum time_bases {
|
|
|
|
TIME_10us = 0,
|
|
|
|
TIME_20us,
|
|
|
|
TIME_40us,
|
|
|
|
TIME_100us,
|
|
|
|
TIME_200us,
|
|
|
|
TIME_400us,
|
|
|
|
TIME_1ms,
|
|
|
|
TIME_2ms,
|
|
|
|
TIME_4ms,
|
|
|
|
TIME_10ms,
|
|
|
|
TIME_20ms,
|
|
|
|
TIME_40ms,
|
|
|
|
TIME_100ms,
|
|
|
|
TIME_200ms,
|
2012-11-10 17:19:30 +00:00
|
|
|
TIME_400ms,
|
2012-04-22 23:05:58 +00:00
|
|
|
};
|
|
|
|
|
2012-05-17 01:17:09 +00:00
|
|
|
/* Must match the vdivs table. */
|
2012-05-17 00:03:12 +00:00
|
|
|
enum {
|
|
|
|
VDIV_10MV,
|
|
|
|
VDIV_20MV,
|
|
|
|
VDIV_50MV,
|
|
|
|
VDIV_100MV,
|
|
|
|
VDIV_200MV,
|
|
|
|
VDIV_500MV,
|
|
|
|
VDIV_1V,
|
|
|
|
VDIV_2V,
|
|
|
|
VDIV_5V,
|
|
|
|
};
|
|
|
|
|
2012-04-22 23:05:58 +00:00
|
|
|
enum trigger_slopes {
|
|
|
|
SLOPE_POSITIVE = 0,
|
2012-11-10 17:19:30 +00:00
|
|
|
SLOPE_NEGATIVE,
|
2012-04-22 23:05:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum trigger_sources {
|
|
|
|
TRIGGER_CH2 = 0,
|
|
|
|
TRIGGER_CH1,
|
|
|
|
TRIGGER_EXT,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum capturestates {
|
|
|
|
CAPTURE_EMPTY = 0,
|
|
|
|
CAPTURE_FILLING = 1,
|
|
|
|
CAPTURE_READY_8BIT = 2,
|
|
|
|
CAPTURE_READY_9BIT = 7,
|
|
|
|
CAPTURE_TIMEOUT = 127,
|
2012-11-10 17:19:30 +00:00
|
|
|
CAPTURE_UNKNOWN = 255,
|
2012-04-22 23:05:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum triggermodes {
|
|
|
|
TRIGGERMODE_AUTO,
|
|
|
|
TRIGGERMODE_NORMAL,
|
2012-11-10 17:19:30 +00:00
|
|
|
TRIGGERMODE_SINGLE,
|
2012-04-22 23:05:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum states {
|
|
|
|
IDLE,
|
|
|
|
NEW_CAPTURE,
|
|
|
|
CAPTURE,
|
2012-08-02 23:05:40 +00:00
|
|
|
FETCH_DATA,
|
|
|
|
STOPPING,
|
2012-04-22 23:05:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct dso_profile {
|
|
|
|
/* VID/PID after cold boot */
|
|
|
|
uint16_t orig_vid;
|
|
|
|
uint16_t orig_pid;
|
|
|
|
/* VID/PID after firmware upload */
|
|
|
|
uint16_t fw_vid;
|
|
|
|
uint16_t fw_pid;
|
|
|
|
char *vendor;
|
|
|
|
char *model;
|
2013-04-02 18:54:44 +00:00
|
|
|
const uint64_t *buffersizes;
|
2012-04-22 23:05:58 +00:00
|
|
|
char *firmware;
|
|
|
|
};
|
|
|
|
|
2012-07-29 22:24:26 +00:00
|
|
|
struct dev_context {
|
2012-05-31 23:12:09 +00:00
|
|
|
const struct dso_profile *profile;
|
2012-04-22 23:05:58 +00:00
|
|
|
void *cb_data;
|
2012-04-30 20:29:31 +00:00
|
|
|
uint64_t limit_frames;
|
|
|
|
uint64_t num_frames;
|
2013-01-23 02:40:44 +00:00
|
|
|
GSList *enabled_probes;
|
2012-04-22 23:05:58 +00:00
|
|
|
/* We can't keep track of an FX2-based device after upgrading
|
|
|
|
* the firmware (it re-enumerates into a different device address
|
|
|
|
* after the upgrade) this is like a global lock. No device will open
|
|
|
|
* until a proper delay after the last device was upgraded.
|
|
|
|
*/
|
2012-06-26 22:55:15 +00:00
|
|
|
int64_t fw_updated;
|
2012-04-22 23:05:58 +00:00
|
|
|
int epin_maxpacketsize;
|
|
|
|
int capture_empty_count;
|
|
|
|
int dev_state;
|
|
|
|
|
2012-06-26 21:26:55 +00:00
|
|
|
/* Oscilloscope settings. */
|
2012-04-22 23:05:58 +00:00
|
|
|
int timebase;
|
|
|
|
gboolean ch1_enabled;
|
|
|
|
gboolean ch2_enabled;
|
|
|
|
int voltage_ch1;
|
|
|
|
int voltage_ch2;
|
|
|
|
int coupling_ch1;
|
|
|
|
int coupling_ch2;
|
|
|
|
// voltage offset (vertical position)
|
|
|
|
float voffset_ch1;
|
|
|
|
float voffset_ch2;
|
|
|
|
float voffset_trigger;
|
|
|
|
uint16_t channel_levels[2][9][2];
|
2012-06-26 21:26:55 +00:00
|
|
|
unsigned int framesize;
|
2012-04-22 23:05:58 +00:00
|
|
|
gboolean filter_ch1;
|
|
|
|
gboolean filter_ch2;
|
|
|
|
gboolean filter_trigger;
|
|
|
|
int triggerslope;
|
2012-05-15 18:56:29 +00:00
|
|
|
char *triggersource;
|
2012-05-14 00:33:37 +00:00
|
|
|
float triggerposition;
|
2012-04-22 23:05:58 +00:00
|
|
|
int triggermode;
|
2012-06-26 21:26:55 +00:00
|
|
|
|
|
|
|
/* Frame transfer */
|
|
|
|
unsigned int samp_received;
|
|
|
|
unsigned int samp_buffered;
|
|
|
|
unsigned int trigger_offset;
|
|
|
|
unsigned char *framebuf;
|
2012-04-22 23:05:58 +00:00
|
|
|
};
|
|
|
|
|
2012-07-21 20:04:47 +00:00
|
|
|
SR_PRIV int dso_open(struct sr_dev_inst *sdi);
|
2012-04-22 23:05:58 +00:00
|
|
|
SR_PRIV void dso_close(struct sr_dev_inst *sdi);
|
2013-04-16 21:15:34 +00:00
|
|
|
SR_PRIV int dso_enable_trigger(const struct sr_dev_inst *sdi);
|
|
|
|
SR_PRIV int dso_force_trigger(const struct sr_dev_inst *sdi);
|
|
|
|
SR_PRIV int dso_init(const struct sr_dev_inst *sdi);
|
|
|
|
SR_PRIV int dso_get_capturestate(const struct sr_dev_inst *sdi,
|
2012-11-10 17:19:30 +00:00
|
|
|
uint8_t *capturestate, uint32_t *trigger_offset);
|
2013-04-16 21:15:34 +00:00
|
|
|
SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi);
|
2013-01-23 02:40:44 +00:00
|
|
|
SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
|
2012-11-10 17:19:30 +00:00
|
|
|
libusb_transfer_cb_fn cb);
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
#endif
|