2012-04-22 23:05:58 +00:00
|
|
|
/*
|
2013-04-23 20:24:30 +00:00
|
|
|
* This file is part of the libsigrok project.
|
2012-04-22 23:05:58 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2012-07-04 22:55:07 +00:00
|
|
|
#include "libsigrok.h"
|
|
|
|
#include "libsigrok-internal.h"
|
2012-04-22 23:05:58 +00:00
|
|
|
#include "dso.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <libusb.h>
|
|
|
|
|
2012-07-13 20:18:01 +00:00
|
|
|
extern struct sr_dev_driver hantek_dso_driver_info;
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
static int send_begin(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-04-22 23:05:58 +00:00
|
|
|
int ret;
|
|
|
|
unsigned char buffer[] = {0x0f, 0x03, 0x03, 0x03, 0x68, 0xac, 0xfe,
|
|
|
|
0x00, 0x01, 0x00};
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sending CTRL_BEGINCOMMAND.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
usb = sdi->conn;
|
|
|
|
if ((ret = libusb_control_transfer(usb->devhdl,
|
2012-04-22 23:05:58 +00:00
|
|
|
LIBUSB_REQUEST_TYPE_VENDOR, CTRL_BEGINCOMMAND,
|
|
|
|
0, 0, buffer, sizeof(buffer), 200)) != sizeof(buffer)) {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_err("Failed to send begincommand: %s.",
|
|
|
|
libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
static int send_bulkcmd(const struct sr_dev_inst *sdi, uint8_t *cmdstring, int cmdlen)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-04-22 23:05:58 +00:00
|
|
|
int ret, tmp;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
usb = sdi->conn;
|
|
|
|
|
|
|
|
if (send_begin(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT, cmdstring,
|
|
|
|
cmdlen, &tmp, 200)) != 0)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:16:55 +00:00
|
|
|
static int dso_getmps(libusb_device *dev)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
|
|
|
struct libusb_device_descriptor des;
|
|
|
|
struct libusb_config_descriptor *conf_dsc;
|
|
|
|
const struct libusb_interface_descriptor *intf_dsc;
|
|
|
|
int mps;
|
|
|
|
|
|
|
|
if (libusb_get_device_descriptor(dev, &des) != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (des.bNumConfigurations != 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (libusb_get_config_descriptor(dev, 0, &conf_dsc) != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mps = 0;
|
|
|
|
intf_dsc = &(conf_dsc->interface[0].altsetting[0]);
|
|
|
|
if (intf_dsc->bNumEndpoints != 2)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if ((intf_dsc->endpoint[0].bEndpointAddress & 0x8f) !=
|
|
|
|
(2 | LIBUSB_ENDPOINT_OUT))
|
|
|
|
/* The first endpoint should be 2 (outbound). */
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if ((intf_dsc->endpoint[1].bEndpointAddress & 0x8f) !=
|
|
|
|
(6 | LIBUSB_ENDPOINT_IN))
|
|
|
|
/* The second endpoint should be 6 (inbound). */
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
mps = intf_dsc->endpoint[1].wMaxPacketSize;
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (conf_dsc)
|
|
|
|
libusb_free_config_descriptor(conf_dsc);
|
|
|
|
|
|
|
|
return mps;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-07-29 22:24:26 +00:00
|
|
|
struct dev_context *devc;
|
2012-12-03 02:33:24 +00:00
|
|
|
struct drv_context *drvc = hantek_dso_driver_info.priv;
|
2013-04-16 21:15:34 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
|
|
|
struct libusb_device_descriptor des;
|
|
|
|
libusb_device **devlist;
|
2012-04-22 23:05:58 +00:00
|
|
|
int err, skip, i;
|
|
|
|
|
2012-07-29 22:24:26 +00:00
|
|
|
devc = sdi->priv;
|
2013-04-16 21:15:34 +00:00
|
|
|
usb = sdi->conn;
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
if (sdi->status == SR_ST_ACTIVE)
|
|
|
|
/* already in use */
|
|
|
|
return SR_ERR;
|
|
|
|
|
|
|
|
skip = 0;
|
2012-12-03 02:33:24 +00:00
|
|
|
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
|
2012-04-22 23:05:58 +00:00
|
|
|
for (i = 0; devlist[i]; i++) {
|
|
|
|
if ((err = libusb_get_device_descriptor(devlist[i], &des))) {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_err("Failed to get device descriptor: %s.",
|
|
|
|
libusb_error_name(err));
|
2012-04-22 23:05:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-07-29 22:24:26 +00:00
|
|
|
if (des.idVendor != devc->profile->fw_vid
|
|
|
|
|| des.idProduct != devc->profile->fw_pid)
|
2012-04-22 23:05:58 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sdi->status == SR_ST_INITIALIZING) {
|
2012-07-21 20:04:47 +00:00
|
|
|
if (skip != sdi->index) {
|
2012-04-22 23:05:58 +00:00
|
|
|
/* Skip devices of this type that aren't the one we want. */
|
|
|
|
skip += 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (sdi->status == SR_ST_INACTIVE) {
|
|
|
|
/*
|
|
|
|
* This device is fully enumerated, so we need to find
|
|
|
|
* this device by vendor, product, bus and address.
|
|
|
|
*/
|
2013-04-16 21:15:34 +00:00
|
|
|
if (libusb_get_bus_number(devlist[i]) != usb->bus
|
|
|
|
|| libusb_get_device_address(devlist[i]) != usb->address)
|
2012-04-22 23:05:58 +00:00
|
|
|
/* this is not the one */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (!(err = libusb_open(devlist[i], &usb->devhdl))) {
|
|
|
|
if (usb->address == 0xff)
|
2012-04-22 23:05:58 +00:00
|
|
|
/*
|
|
|
|
* first time we touch this device after firmware upload,
|
|
|
|
* so we don't know the address yet.
|
|
|
|
*/
|
2013-04-16 21:15:34 +00:00
|
|
|
usb->address = libusb_get_device_address(devlist[i]);
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
if (!(devc->epin_maxpacketsize = dso_getmps(devlist[i])))
|
|
|
|
sr_err("Wrong endpoint profile.");
|
2012-04-22 23:05:58 +00:00
|
|
|
else {
|
|
|
|
sdi->status = SR_ST_ACTIVE;
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_info("Opened device %d on %d.%d interface %d.",
|
2013-04-16 21:15:34 +00:00
|
|
|
sdi->index, usb->bus,
|
|
|
|
usb->address, USB_INTERFACE);
|
2012-04-22 23:05:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_err("Failed to open device: %s.",
|
|
|
|
libusb_error_name(err));
|
2012-04-22 23:05:58 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
/* If we made it here, we handled the device (somehow). */
|
2012-04-22 23:05:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
libusb_free_device_list(devlist, 1);
|
|
|
|
|
|
|
|
if (sdi->status != SR_ST_ACTIVE)
|
|
|
|
return SR_ERR;
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
SR_PRIV void dso_close(struct sr_dev_inst *sdi)
|
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
usb = sdi->conn;
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (usb->devhdl == NULL)
|
2012-04-22 23:05:58 +00:00
|
|
|
return;
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_info("Closing device %d on %d.%d interface %d.", sdi->index,
|
2013-04-16 21:15:34 +00:00
|
|
|
usb->bus, usb->address, USB_INTERFACE);
|
|
|
|
libusb_release_interface(usb->devhdl, USB_INTERFACE);
|
|
|
|
libusb_close(usb->devhdl);
|
|
|
|
usb->devhdl = NULL;
|
2012-04-22 23:05:58 +00:00
|
|
|
sdi->status = SR_ST_INACTIVE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
static int get_channel_offsets(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-05-19 23:14:37 +00:00
|
|
|
GString *gs;
|
|
|
|
int chan, v, ret;
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Getting channel offsets.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
devc = sdi->priv;
|
|
|
|
usb = sdi->conn;
|
|
|
|
|
|
|
|
ret = libusb_control_transfer(usb->devhdl,
|
2012-04-22 23:05:58 +00:00
|
|
|
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR,
|
|
|
|
CTRL_READ_EEPROM, EEPROM_CHANNEL_OFFSETS, 0,
|
2012-07-29 22:24:26 +00:00
|
|
|
(unsigned char *)&devc->channel_levels,
|
|
|
|
sizeof(devc->channel_levels), 200);
|
|
|
|
if (ret != sizeof(devc->channel_levels)) {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_err("Failed to get channel offsets: %s.",
|
|
|
|
libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
2012-05-19 23:14:37 +00:00
|
|
|
/* Comes in as 16-bit numbers with the second byte always 0 on
|
|
|
|
* the DSO-2090. Guessing this is supposed to be big-endian,
|
|
|
|
* since that's how voltage offsets are submitted back to the DSO.
|
|
|
|
* Convert to host order now, so we can use them natively.
|
|
|
|
*/
|
|
|
|
for (chan = 0; chan < 2; chan++) {
|
|
|
|
for (v = 0; v < 9; v++) {
|
2012-11-10 17:19:30 +00:00
|
|
|
devc->channel_levels[chan][v][0] =
|
|
|
|
g_ntohs(devc->channel_levels[chan][v][0]);
|
|
|
|
devc->channel_levels[chan][v][1] =
|
|
|
|
g_ntohs(devc->channel_levels[chan][v][1]);
|
2012-05-19 23:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sr_log_loglevel_get() >= SR_LOG_DBG) {
|
|
|
|
gs = g_string_sized_new(128);
|
|
|
|
for (chan = 0; chan < 2; chan++) {
|
2012-11-10 17:19:30 +00:00
|
|
|
g_string_printf(gs, "CH%d:", chan + 1);
|
2012-05-19 23:14:37 +00:00
|
|
|
for (v = 0; v < 9; v++) {
|
|
|
|
g_string_append_printf(gs, " %.4x-%.4x",
|
2012-11-10 17:19:30 +00:00
|
|
|
devc->channel_levels[chan][v][0],
|
|
|
|
devc->channel_levels[chan][v][1]);
|
2012-05-19 23:14:37 +00:00
|
|
|
}
|
2013-01-29 11:05:00 +00:00
|
|
|
sr_dbg("%s", gs->str);
|
2012-05-19 23:14:37 +00:00
|
|
|
}
|
|
|
|
g_string_free(gs, TRUE);
|
|
|
|
}
|
|
|
|
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:16:55 +00:00
|
|
|
static int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-04-22 23:05:58 +00:00
|
|
|
int ret, tmp;
|
|
|
|
uint8_t cmdstring[12];
|
|
|
|
uint16_t timebase_small[] = { 0xffff, 0xfffc, 0xfff7, 0xffe8, 0xffce,
|
2012-11-10 17:19:30 +00:00
|
|
|
0xff9c, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79, 0xd8f1 };
|
2012-04-22 23:05:58 +00:00
|
|
|
uint16_t timebase_large[] = { 0xffff, 0x0000, 0xfffc, 0xfff7, 0xffe8,
|
2012-11-10 17:19:30 +00:00
|
|
|
0xffce, 0xff9d, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79 };
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Preparing CMD_SET_TRIGGER_SAMPLERATE.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
devc = sdi->priv;
|
|
|
|
usb = sdi->conn;
|
|
|
|
|
2012-04-22 23:05:58 +00:00
|
|
|
memset(cmdstring, 0, sizeof(cmdstring));
|
|
|
|
/* Command */
|
|
|
|
cmdstring[0] = CMD_SET_TRIGGER_SAMPLERATE;
|
|
|
|
|
|
|
|
/* Trigger source */
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Trigger source %s.", devc->triggersource);
|
2012-07-29 22:24:26 +00:00
|
|
|
if (!strcmp("CH2", devc->triggersource))
|
2012-05-15 18:56:29 +00:00
|
|
|
tmp = 0;
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (!strcmp("CH1", devc->triggersource))
|
2012-05-15 18:56:29 +00:00
|
|
|
tmp = 1;
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (!strcmp("EXT", devc->triggersource))
|
2012-05-15 18:56:29 +00:00
|
|
|
tmp = 2;
|
|
|
|
else {
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_err("Invalid trigger source: '%s'.", devc->triggersource);
|
2012-05-15 18:56:29 +00:00
|
|
|
return SR_ERR_ARG;
|
|
|
|
}
|
|
|
|
cmdstring[2] = tmp;
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
/* Frame size */
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Frame size: %d.", devc->framesize);
|
2012-07-29 22:24:26 +00:00
|
|
|
cmdstring[2] |= (devc->framesize == FRAMESIZE_SMALL ? 0x01 : 0x02) << 2;
|
2012-05-14 00:33:37 +00:00
|
|
|
|
|
|
|
/* Timebase fast */
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Time base index: %d.", devc->timebase);
|
2013-04-02 18:54:44 +00:00
|
|
|
if (devc->framesize == FRAMESIZE_SMALL) {
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->timebase < TIME_20us)
|
2012-05-14 00:33:37 +00:00
|
|
|
tmp = 0;
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (devc->timebase == TIME_20us)
|
2012-05-14 00:33:37 +00:00
|
|
|
tmp = 1;
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (devc->timebase == TIME_40us)
|
2012-05-14 00:33:37 +00:00
|
|
|
tmp = 2;
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (devc->timebase == TIME_100us)
|
2012-05-14 00:33:37 +00:00
|
|
|
tmp = 3;
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (devc->timebase >= TIME_200us)
|
2012-05-14 00:33:37 +00:00
|
|
|
tmp = 4;
|
2013-04-02 18:54:44 +00:00
|
|
|
} else {
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->timebase < TIME_40us) {
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_err("Timebase < 40us only supported with 10K buffer.");
|
2012-05-14 00:33:37 +00:00
|
|
|
return SR_ERR_ARG;
|
|
|
|
}
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (devc->timebase == TIME_40us)
|
2012-05-14 00:33:37 +00:00
|
|
|
tmp = 0;
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (devc->timebase == TIME_100us)
|
2012-05-14 00:33:37 +00:00
|
|
|
tmp = 2;
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (devc->timebase == TIME_200us)
|
2012-05-14 00:33:37 +00:00
|
|
|
tmp = 3;
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (devc->timebase >= TIME_400us)
|
2012-05-14 00:33:37 +00:00
|
|
|
tmp = 4;
|
2012-04-22 23:05:58 +00:00
|
|
|
}
|
2012-05-14 00:33:37 +00:00
|
|
|
cmdstring[2] |= (tmp & 0x07) << 5;
|
|
|
|
|
|
|
|
/* Enabled channels: 00=CH1 01=CH2 10=both */
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Channels CH1=%d CH2=%d", devc->ch1_enabled, devc->ch2_enabled);
|
2012-07-29 22:24:26 +00:00
|
|
|
tmp = (((devc->ch2_enabled ? 1 : 0) << 1) + (devc->ch1_enabled ? 1 : 0)) - 1;
|
2012-05-01 18:35:04 +00:00
|
|
|
cmdstring[3] = tmp;
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2012-05-14 00:33:37 +00:00
|
|
|
/* Fast rates channel */
|
2012-11-10 17:19:30 +00:00
|
|
|
/* TODO: Is this right? */
|
2012-07-29 22:24:26 +00:00
|
|
|
tmp = devc->timebase < TIME_10us ? 1 : 0;
|
2012-05-14 00:33:37 +00:00
|
|
|
cmdstring[3] |= tmp << 2;
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2012-05-14 00:33:37 +00:00
|
|
|
/* Trigger slope: 0=positive 1=negative */
|
2012-11-10 17:19:30 +00:00
|
|
|
/* TODO: Does this work? */
|
|
|
|
sr_dbg("Trigger slope: %d.", devc->triggerslope);
|
2012-07-29 22:24:26 +00:00
|
|
|
cmdstring[3] |= (devc->triggerslope == SLOPE_NEGATIVE ? 1 : 0) << 3;
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2012-05-15 18:56:29 +00:00
|
|
|
/* Timebase slow */
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->timebase < TIME_100us)
|
2012-04-22 23:05:58 +00:00
|
|
|
tmp = 0;
|
2012-07-29 22:24:26 +00:00
|
|
|
else if (devc->timebase > TIME_400ms)
|
2012-04-22 23:05:58 +00:00
|
|
|
tmp = 0xffed;
|
|
|
|
else {
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->framesize == FRAMESIZE_SMALL)
|
|
|
|
tmp = timebase_small[devc->timebase - 3];
|
2012-04-22 23:05:58 +00:00
|
|
|
else
|
2012-07-29 22:24:26 +00:00
|
|
|
tmp = timebase_large[devc->timebase - 3];
|
2012-04-22 23:05:58 +00:00
|
|
|
}
|
2012-05-14 00:33:37 +00:00
|
|
|
cmdstring[4] = tmp & 0xff;
|
|
|
|
cmdstring[5] = (tmp >> 8) & 0xff;
|
|
|
|
|
|
|
|
/* Horizontal trigger position */
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Trigger position: %3.2f.", devc->triggerposition);
|
2012-07-29 22:24:26 +00:00
|
|
|
tmp = 0x77fff + 0x8000 * devc->triggerposition;
|
2012-04-22 23:05:58 +00:00
|
|
|
cmdstring[6] = tmp & 0xff;
|
|
|
|
cmdstring[7] = (tmp >> 8) & 0xff;
|
|
|
|
cmdstring[10] = (tmp >> 16) & 0xff;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (send_begin(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT,
|
|
|
|
cmdstring, sizeof(cmdstring), &tmp, 100)) != 0) {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_err("Failed to set trigger/samplerate: %s.",
|
|
|
|
libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sent CMD_SET_TRIGGER_SAMPLERATE.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:16:55 +00:00
|
|
|
static int dso_set_filters(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-04-22 23:05:58 +00:00
|
|
|
int ret, tmp;
|
|
|
|
uint8_t cmdstring[8];
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Preparing CMD_SET_FILTERS.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
devc = sdi->priv;
|
|
|
|
usb = sdi->conn;
|
|
|
|
|
2012-04-22 23:05:58 +00:00
|
|
|
memset(cmdstring, 0, sizeof(cmdstring));
|
|
|
|
cmdstring[0] = CMD_SET_FILTERS;
|
|
|
|
cmdstring[1] = 0x0f;
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->filter_ch1) {
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Turning on CH1 filter.");
|
2012-04-22 23:05:58 +00:00
|
|
|
cmdstring[2] |= 0x80;
|
2012-05-15 20:41:00 +00:00
|
|
|
}
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->filter_ch2) {
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Turning on CH2 filter.");
|
2012-04-22 23:05:58 +00:00
|
|
|
cmdstring[2] |= 0x40;
|
2012-05-15 20:41:00 +00:00
|
|
|
}
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->filter_trigger) {
|
2012-05-15 20:41:00 +00:00
|
|
|
/* TODO: supported on the DSO-2090? */
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Turning on trigger filter.");
|
2012-04-22 23:05:58 +00:00
|
|
|
cmdstring[2] |= 0x20;
|
2012-05-15 20:41:00 +00:00
|
|
|
}
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (send_begin(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT,
|
|
|
|
cmdstring, sizeof(cmdstring), &tmp, 100)) != 0) {
|
2012-12-05 00:23:49 +00:00
|
|
|
sr_err("Failed to set filters: %s.", libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sent CMD_SET_FILTERS.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:16:55 +00:00
|
|
|
static int dso_set_voltage(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-04-22 23:05:58 +00:00
|
|
|
int ret, tmp;
|
|
|
|
uint8_t cmdstring[8];
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Preparing CMD_SET_VOLTAGE.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
devc = sdi->priv;
|
|
|
|
usb = sdi->conn;
|
|
|
|
|
2012-04-22 23:05:58 +00:00
|
|
|
memset(cmdstring, 0, sizeof(cmdstring));
|
|
|
|
cmdstring[0] = CMD_SET_VOLTAGE;
|
|
|
|
cmdstring[1] = 0x0f;
|
2012-05-17 00:03:12 +00:00
|
|
|
cmdstring[2] = 0x30;
|
|
|
|
|
|
|
|
/* CH1 volts/div is encoded in bits 0-1 */
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("CH1 vdiv index: %d.", devc->voltage_ch1);
|
2012-07-29 22:24:26 +00:00
|
|
|
switch (devc->voltage_ch1) {
|
2012-05-17 00:03:12 +00:00
|
|
|
case VDIV_1V:
|
|
|
|
case VDIV_100MV:
|
|
|
|
case VDIV_10MV:
|
|
|
|
cmdstring[2] |= 0x00;
|
|
|
|
break;
|
|
|
|
case VDIV_2V:
|
|
|
|
case VDIV_200MV:
|
|
|
|
case VDIV_20MV:
|
|
|
|
cmdstring[2] |= 0x01;
|
|
|
|
break;
|
|
|
|
case VDIV_5V:
|
|
|
|
case VDIV_500MV:
|
|
|
|
case VDIV_50MV:
|
|
|
|
cmdstring[2] |= 0x02;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CH2 volts/div is encoded in bits 2-3 */
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("CH2 vdiv index: %d.", devc->voltage_ch2);
|
2012-07-29 22:24:26 +00:00
|
|
|
switch (devc->voltage_ch2) {
|
2012-05-17 00:03:12 +00:00
|
|
|
case VDIV_1V:
|
|
|
|
case VDIV_100MV:
|
|
|
|
case VDIV_10MV:
|
|
|
|
cmdstring[2] |= 0x00;
|
|
|
|
break;
|
|
|
|
case VDIV_2V:
|
|
|
|
case VDIV_200MV:
|
|
|
|
case VDIV_20MV:
|
2012-06-05 16:15:58 +00:00
|
|
|
cmdstring[2] |= 0x04;
|
2012-05-17 00:03:12 +00:00
|
|
|
break;
|
|
|
|
case VDIV_5V:
|
|
|
|
case VDIV_500MV:
|
|
|
|
case VDIV_50MV:
|
2012-06-05 16:15:58 +00:00
|
|
|
cmdstring[2] |= 0x08;
|
2012-05-17 00:03:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (send_begin(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT,
|
|
|
|
cmdstring, sizeof(cmdstring), &tmp, 100)) != 0) {
|
2012-12-05 00:23:49 +00:00
|
|
|
sr_err("Failed to set voltage: %s.", libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sent CMD_SET_VOLTAGE.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:16:55 +00:00
|
|
|
static int dso_set_relays(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-06-18 21:05:02 +00:00
|
|
|
GString *gs;
|
|
|
|
int ret, i;
|
|
|
|
uint8_t relays[17] = { 0x00, 0x04, 0x08, 0x02, 0x20, 0x40, 0x10, 0x01,
|
2012-04-22 23:05:58 +00:00
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Preparing CTRL_SETRELAYS.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
devc = sdi->priv;
|
|
|
|
usb = sdi->conn;
|
|
|
|
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->voltage_ch1 < VDIV_1V)
|
2012-04-22 23:05:58 +00:00
|
|
|
relays[1] = ~relays[1];
|
|
|
|
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->voltage_ch1 < VDIV_100MV)
|
2012-04-22 23:05:58 +00:00
|
|
|
relays[2] = ~relays[2];
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("CH1 coupling: %d.", devc->coupling_ch1);
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->coupling_ch1 != COUPLING_AC)
|
2012-04-22 23:05:58 +00:00
|
|
|
relays[3] = ~relays[3];
|
|
|
|
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->voltage_ch2 < VDIV_1V)
|
2012-04-22 23:05:58 +00:00
|
|
|
relays[4] = ~relays[4];
|
|
|
|
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->voltage_ch2 < VDIV_100MV)
|
2012-04-22 23:05:58 +00:00
|
|
|
relays[5] = ~relays[5];
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("CH2 coupling: %d.", devc->coupling_ch1);
|
2012-07-29 22:24:26 +00:00
|
|
|
if (devc->coupling_ch2 != COUPLING_AC)
|
2012-04-22 23:05:58 +00:00
|
|
|
relays[6] = ~relays[6];
|
|
|
|
|
2012-07-29 22:24:26 +00:00
|
|
|
if (!strcmp(devc->triggersource, "EXT"))
|
2012-04-22 23:05:58 +00:00
|
|
|
relays[7] = ~relays[7];
|
|
|
|
|
2012-06-18 21:05:02 +00:00
|
|
|
if (sr_log_loglevel_get() >= SR_LOG_DBG) {
|
|
|
|
gs = g_string_sized_new(128);
|
2012-11-10 17:19:30 +00:00
|
|
|
g_string_printf(gs, "Relays:");
|
2012-06-18 21:05:02 +00:00
|
|
|
for (i = 0; i < 17; i++)
|
|
|
|
g_string_append_printf(gs, " %.2x", relays[i]);
|
2013-01-29 11:05:00 +00:00
|
|
|
sr_dbg("%s", gs->str);
|
2012-06-18 21:05:02 +00:00
|
|
|
g_string_free(gs, TRUE);
|
|
|
|
}
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = libusb_control_transfer(usb->devhdl,
|
2012-04-22 23:05:58 +00:00
|
|
|
LIBUSB_REQUEST_TYPE_VENDOR, CTRL_SETRELAYS,
|
2012-06-18 21:05:02 +00:00
|
|
|
0, 0, relays, 17, 100)) != sizeof(relays)) {
|
2012-12-05 00:23:49 +00:00
|
|
|
sr_err("Failed to set relays: %s.", libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sent CTRL_SETRELAYS.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-14 22:16:55 +00:00
|
|
|
static int dso_set_voffsets(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-04-22 23:05:58 +00:00
|
|
|
int offset, ret;
|
|
|
|
uint16_t *ch_levels;
|
2012-05-19 23:14:37 +00:00
|
|
|
uint8_t offsets[17];
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Preparing CTRL_SETOFFSET.");
|
2012-05-19 23:14:37 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
devc = sdi->priv;
|
|
|
|
usb = sdi->conn;
|
|
|
|
|
2012-05-19 23:14:37 +00:00
|
|
|
memset(offsets, 0, sizeof(offsets));
|
|
|
|
/* Channel 1 */
|
2012-07-29 22:24:26 +00:00
|
|
|
ch_levels = devc->channel_levels[0][devc->voltage_ch1];
|
|
|
|
offset = (ch_levels[1] - ch_levels[0]) * devc->voffset_ch1 + ch_levels[0];
|
2012-05-19 23:14:37 +00:00
|
|
|
offsets[0] = (offset >> 8) | 0x20;
|
|
|
|
offsets[1] = offset & 0xff;
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("CH1 offset: %3.2f (%.2x%.2x).", devc->voffset_ch1,
|
|
|
|
offsets[0], offsets[1]);
|
2012-05-19 23:14:37 +00:00
|
|
|
|
|
|
|
/* Channel 2 */
|
2012-07-29 22:24:26 +00:00
|
|
|
ch_levels = devc->channel_levels[1][devc->voltage_ch2];
|
|
|
|
offset = (ch_levels[1] - ch_levels[0]) * devc->voffset_ch2 + ch_levels[0];
|
2012-05-19 23:14:37 +00:00
|
|
|
offsets[2] = (offset >> 8) | 0x20;
|
|
|
|
offsets[3] = offset & 0xff;
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("CH2 offset: %3.2f (%.2x%.2x).", devc->voffset_ch2,
|
|
|
|
offsets[2], offsets[3]);
|
2012-05-19 23:14:37 +00:00
|
|
|
|
|
|
|
/* Trigger */
|
2012-07-29 22:24:26 +00:00
|
|
|
offset = MAX_VERT_TRIGGER * devc->voffset_trigger;
|
2012-05-19 23:14:37 +00:00
|
|
|
offsets[4] = (offset >> 8) | 0x20;
|
|
|
|
offsets[5] = offset & 0xff;
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Trigger offset: %3.2f (%.2x%.2x).", devc->voffset_trigger,
|
2012-05-19 23:14:37 +00:00
|
|
|
offsets[4], offsets[5]);
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = libusb_control_transfer(usb->devhdl,
|
2012-04-22 23:05:58 +00:00
|
|
|
LIBUSB_REQUEST_TYPE_VENDOR, CTRL_SETOFFSET,
|
|
|
|
0, 0, offsets, sizeof(offsets), 100)) != sizeof(offsets)) {
|
2012-12-05 00:23:49 +00:00
|
|
|
sr_err("Failed to set offsets: %s.", libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sent CTRL_SETOFFSET.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
SR_PRIV int dso_enable_trigger(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-04-22 23:05:58 +00:00
|
|
|
int ret, tmp;
|
|
|
|
uint8_t cmdstring[2];
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sending CMD_ENABLE_TRIGGER.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
usb = sdi->conn;
|
|
|
|
|
2012-04-22 23:05:58 +00:00
|
|
|
memset(cmdstring, 0, sizeof(cmdstring));
|
|
|
|
cmdstring[0] = CMD_ENABLE_TRIGGER;
|
|
|
|
cmdstring[1] = 0x00;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (send_begin(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT,
|
|
|
|
cmdstring, sizeof(cmdstring), &tmp, 100)) != 0) {
|
2012-12-05 00:23:49 +00:00
|
|
|
sr_err("Failed to enable trigger: %s.", libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
SR_PRIV int dso_force_trigger(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-04-22 23:05:58 +00:00
|
|
|
int ret, tmp;
|
|
|
|
uint8_t cmdstring[2];
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sending CMD_FORCE_TRIGGER.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
usb = sdi->conn;
|
|
|
|
|
2012-04-22 23:05:58 +00:00
|
|
|
memset(cmdstring, 0, sizeof(cmdstring));
|
|
|
|
cmdstring[0] = CMD_FORCE_TRIGGER;
|
|
|
|
cmdstring[1] = 0x00;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (send_begin(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT,
|
|
|
|
cmdstring, sizeof(cmdstring), &tmp, 100)) != 0) {
|
2012-12-05 00:23:49 +00:00
|
|
|
sr_err("Failed to force trigger: %s.", libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
SR_PRIV int dso_init(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Initializing DSO.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (get_channel_offsets(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (dso_set_trigger_samplerate(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (dso_set_filters(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (dso_set_voltage(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (dso_set_relays(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (dso_set_voffsets(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if (dso_enable_trigger(sdi) != SR_OK)
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
SR_PRIV int dso_get_capturestate(const struct sr_dev_inst *sdi,
|
|
|
|
uint8_t *capturestate, uint32_t *trigger_offset)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-04-16 21:15:34 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-06-24 16:57:37 +00:00
|
|
|
int ret, tmp, i;
|
|
|
|
unsigned int bitvalue, toff;
|
2012-04-22 23:05:58 +00:00
|
|
|
uint8_t cmdstring[2], inbuf[512];
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sending CMD_GET_CAPTURESTATE.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
usb = sdi->conn;
|
|
|
|
|
2012-04-22 23:05:58 +00:00
|
|
|
cmdstring[0] = CMD_GET_CAPTURESTATE;
|
|
|
|
cmdstring[1] = 0;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = send_bulkcmd(sdi, cmdstring, sizeof(cmdstring))) != SR_OK) {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_dbg("Failed to send get_capturestate command: %s.",
|
|
|
|
libusb_error_name(ret));
|
2012-06-18 21:09:37 +00:00
|
|
|
return SR_ERR;
|
2012-04-22 23:05:58 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_IN,
|
2012-04-22 23:05:58 +00:00
|
|
|
inbuf, 512, &tmp, 100)) != 0) {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_dbg("Failed to get capturestate: %s.",
|
|
|
|
libusb_error_name(ret));
|
2012-06-18 21:09:37 +00:00
|
|
|
return SR_ERR;
|
2012-04-22 23:05:58 +00:00
|
|
|
}
|
2012-06-18 21:09:37 +00:00
|
|
|
*capturestate = inbuf[0];
|
2012-06-24 16:57:37 +00:00
|
|
|
toff = (inbuf[1] << 16) | (inbuf[3] << 8) | inbuf[2];
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
/*
|
|
|
|
* This conversion comes from the openhantek project.
|
2012-06-24 16:57:37 +00:00
|
|
|
* Each set bit in the 24-bit value inverts all bits with a lower
|
|
|
|
* value. No idea why the device reports the trigger point this way.
|
|
|
|
*/
|
|
|
|
bitvalue = 1;
|
|
|
|
for (i = 0; i < 24; i++) {
|
2012-06-26 21:26:55 +00:00
|
|
|
/* Each set bit inverts all bits with a lower value. */
|
2012-06-24 16:57:37 +00:00
|
|
|
if(toff & bitvalue)
|
|
|
|
toff ^= bitvalue - 1;
|
|
|
|
bitvalue <<= 1;
|
|
|
|
}
|
|
|
|
*trigger_offset = toff;
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2012-06-18 21:09:37 +00:00
|
|
|
return SR_OK;
|
2012-04-22 23:05:58 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
uint8_t cmdstring[2];
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sending CMD_CAPTURE_START.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
|
|
|
cmdstring[0] = CMD_CAPTURE_START;
|
|
|
|
cmdstring[1] = 0;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = send_bulkcmd(sdi, cmdstring, sizeof(cmdstring))) != SR_OK) {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_err("Failed to send capture_start command: %s.",
|
|
|
|
libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-23 02:40:44 +00:00
|
|
|
SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
|
|
|
|
libusb_transfer_cb_fn cb)
|
2012-04-22 23:05:58 +00:00
|
|
|
{
|
2013-01-23 02:40:44 +00:00
|
|
|
struct dev_context *devc;
|
2013-04-16 21:15:34 +00:00
|
|
|
struct sr_usb_dev_inst *usb;
|
2012-04-22 23:05:58 +00:00
|
|
|
struct libusb_transfer *transfer;
|
|
|
|
int num_transfers, ret, i;
|
|
|
|
uint8_t cmdstring[2];
|
|
|
|
unsigned char *buf;
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_dbg("Sending CMD_GET_CHANNELDATA.");
|
2012-04-22 23:05:58 +00:00
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
devc = sdi->priv;
|
|
|
|
usb = sdi->conn;
|
|
|
|
|
2012-04-22 23:05:58 +00:00
|
|
|
cmdstring[0] = CMD_GET_CHANNELDATA;
|
|
|
|
cmdstring[1] = 0;
|
|
|
|
|
2013-04-16 21:15:34 +00:00
|
|
|
if ((ret = send_bulkcmd(sdi, cmdstring, sizeof(cmdstring))) != SR_OK) {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_err("Failed to get channel data: %s.",
|
|
|
|
libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
2012-11-10 17:19:30 +00:00
|
|
|
/* TODO: DSO-2xxx only. */
|
|
|
|
num_transfers = devc->framesize *
|
|
|
|
sizeof(unsigned short) / devc->epin_maxpacketsize;
|
|
|
|
sr_dbg("Queueing up %d transfers.", num_transfers);
|
2012-04-22 23:05:58 +00:00
|
|
|
for (i = 0; i < num_transfers; i++) {
|
2012-07-29 22:24:26 +00:00
|
|
|
if (!(buf = g_try_malloc(devc->epin_maxpacketsize))) {
|
2012-11-10 17:19:30 +00:00
|
|
|
sr_err("Failed to malloc USB endpoint buffer.");
|
2012-04-22 23:05:58 +00:00
|
|
|
return SR_ERR_MALLOC;
|
|
|
|
}
|
|
|
|
transfer = libusb_alloc_transfer(0);
|
2013-04-16 21:15:34 +00:00
|
|
|
libusb_fill_bulk_transfer(transfer, usb->devhdl, DSO_EP_IN, buf,
|
2013-01-23 02:40:44 +00:00
|
|
|
devc->epin_maxpacketsize, cb, (void *)sdi, 40);
|
2012-04-22 23:05:58 +00:00
|
|
|
if ((ret = libusb_submit_transfer(transfer)) != 0) {
|
2012-12-04 20:11:25 +00:00
|
|
|
sr_err("Failed to submit transfer: %s.",
|
|
|
|
libusb_error_name(ret));
|
2012-04-22 23:05:58 +00:00
|
|
|
/* TODO: Free them all. */
|
|
|
|
libusb_free_transfer(transfer);
|
|
|
|
g_free(buf);
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|