hantek-dso: Store USB connection in sr_dev_inst

This commit is contained in:
Bert Vermeulen 2013-04-16 23:15:34 +02:00
parent 9bb2f327a9
commit c118080b1d
3 changed files with 134 additions and 98 deletions

View File

@ -251,7 +251,7 @@ static int clear_instances(void)
continue; continue;
} }
dso_close(sdi); dso_close(sdi);
sr_usb_dev_inst_free(devc->usb); sr_usb_dev_inst_free(sdi->conn);
g_free(devc->triggersource); g_free(devc->triggersource);
g_slist_free(devc->enabled_probes); g_slist_free(devc->enabled_probes);
@ -317,7 +317,7 @@ static GSList *hw_scan(GSList *options)
sr_err("Firmware upload failed for " sr_err("Firmware upload failed for "
"device %d.", devcnt); "device %d.", devcnt);
/* Dummy USB address of 0xff will get overwritten later. */ /* Dummy USB address of 0xff will get overwritten later. */
devc->usb = sr_usb_dev_inst_new( sdi->conn = sr_usb_dev_inst_new(
libusb_get_bus_number(devlist[i]), 0xff, NULL); libusb_get_bus_number(devlist[i]), 0xff, NULL);
devcnt++; devcnt++;
break; break;
@ -330,7 +330,7 @@ static GSList *hw_scan(GSList *options)
sdi->status = SR_ST_INACTIVE; sdi->status = SR_ST_INACTIVE;
devices = g_slist_append(devices, sdi); devices = g_slist_append(devices, sdi);
devc = sdi->priv; devc = sdi->priv;
devc->usb = sr_usb_dev_inst_new( sdi->conn = sr_usb_dev_inst_new(
libusb_get_bus_number(devlist[i]), libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL); libusb_get_device_address(devlist[i]), NULL);
devcnt++; devcnt++;
@ -354,10 +354,12 @@ static GSList *hw_dev_list(void)
static int hw_dev_open(struct sr_dev_inst *sdi) static int hw_dev_open(struct sr_dev_inst *sdi)
{ {
struct dev_context *devc; struct dev_context *devc;
struct sr_usb_dev_inst *usb;
int64_t timediff_us, timediff_ms; int64_t timediff_us, timediff_ms;
int err; int err;
devc = sdi->priv; devc = sdi->priv;
usb = sdi->conn;
/* /*
* If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS * If the firmware was recently uploaded, wait up to MAX_RENUM_DELAY_MS
@ -387,7 +389,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
return SR_ERR; return SR_ERR;
} }
err = libusb_claim_interface(devc->usb->devhdl, USB_INTERFACE); err = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
if (err != 0) { if (err != 0) {
sr_err("Unable to claim interface: %s.", sr_err("Unable to claim interface: %s.",
libusb_error_name(err)); libusb_error_name(err));
@ -814,11 +816,11 @@ static int handle_event(int fd, int revents, void *cb_data)
/* TODO: ugh */ /* TODO: ugh */
if (devc->dev_state == NEW_CAPTURE) { if (devc->dev_state == NEW_CAPTURE) {
if (dso_capture_start(devc) != SR_OK) if (dso_capture_start(sdi) != SR_OK)
return TRUE; return TRUE;
if (dso_enable_trigger(devc) != SR_OK) if (dso_enable_trigger(sdi) != SR_OK)
return TRUE; return TRUE;
// if (dso_force_trigger(devc) != SR_OK) // if (dso_force_trigger(sdi) != SR_OK)
// return TRUE; // return TRUE;
sr_dbg("Successfully requested next chunk."); sr_dbg("Successfully requested next chunk.");
devc->dev_state = CAPTURE; devc->dev_state = CAPTURE;
@ -827,7 +829,7 @@ static int handle_event(int fd, int revents, void *cb_data)
if (devc->dev_state != CAPTURE) if (devc->dev_state != CAPTURE)
return TRUE; return TRUE;
if ((dso_get_capturestate(devc, &capturestate, &trigger_offset)) != SR_OK) if ((dso_get_capturestate(sdi, &capturestate, &trigger_offset)) != SR_OK)
return TRUE; return TRUE;
sr_dbg("Capturestate %d.", capturestate); sr_dbg("Capturestate %d.", capturestate);
@ -836,11 +838,11 @@ static int handle_event(int fd, int revents, void *cb_data)
case CAPTURE_EMPTY: case CAPTURE_EMPTY:
if (++devc->capture_empty_count >= MAX_CAPTURE_EMPTY) { if (++devc->capture_empty_count >= MAX_CAPTURE_EMPTY) {
devc->capture_empty_count = 0; devc->capture_empty_count = 0;
if (dso_capture_start(devc) != SR_OK) if (dso_capture_start(sdi) != SR_OK)
break; break;
if (dso_enable_trigger(devc) != SR_OK) if (dso_enable_trigger(sdi) != SR_OK)
break; break;
// if (dso_force_trigger(devc) != SR_OK) // if (dso_force_trigger(sdi) != SR_OK)
// break; // break;
sr_dbg("Successfully requested next chunk."); sr_dbg("Successfully requested next chunk.");
} }
@ -905,10 +907,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
return SR_ERR; return SR_ERR;
} }
if (dso_init(devc) != SR_OK) if (dso_init(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if (dso_capture_start(devc) != SR_OK) if (dso_capture_start(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
devc->dev_state = CAPTURE; devc->dev_state = CAPTURE;

View File

@ -28,15 +28,17 @@
extern struct sr_dev_driver hantek_dso_driver_info; extern struct sr_dev_driver hantek_dso_driver_info;
static int send_begin(struct dev_context *devc) static int send_begin(const struct sr_dev_inst *sdi)
{ {
struct sr_usb_dev_inst *usb;
int ret; int ret;
unsigned char buffer[] = {0x0f, 0x03, 0x03, 0x03, 0x68, 0xac, 0xfe, unsigned char buffer[] = {0x0f, 0x03, 0x03, 0x03, 0x68, 0xac, 0xfe,
0x00, 0x01, 0x00}; 0x00, 0x01, 0x00};
sr_dbg("Sending CTRL_BEGINCOMMAND."); sr_dbg("Sending CTRL_BEGINCOMMAND.");
if ((ret = libusb_control_transfer(devc->usb->devhdl, usb = sdi->conn;
if ((ret = libusb_control_transfer(usb->devhdl,
LIBUSB_REQUEST_TYPE_VENDOR, CTRL_BEGINCOMMAND, LIBUSB_REQUEST_TYPE_VENDOR, CTRL_BEGINCOMMAND,
0, 0, buffer, sizeof(buffer), 200)) != sizeof(buffer)) { 0, 0, buffer, sizeof(buffer), 200)) != sizeof(buffer)) {
sr_err("Failed to send begincommand: %s.", sr_err("Failed to send begincommand: %s.",
@ -47,16 +49,18 @@ static int send_begin(struct dev_context *devc)
return SR_OK; return SR_OK;
} }
static int send_bulkcmd(struct dev_context *devc, uint8_t *cmdstring, int cmdlen) static int send_bulkcmd(const struct sr_dev_inst *sdi, uint8_t *cmdstring, int cmdlen)
{ {
struct sr_usb_dev_inst *usb;
int ret, tmp; int ret, tmp;
if (send_begin(devc) != SR_OK) usb = sdi->conn;
if (send_begin(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if ((ret = libusb_bulk_transfer(devc->usb->devhdl, if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT, cmdstring,
DSO_EP_OUT | LIBUSB_ENDPOINT_OUT, cmdlen, &tmp, 200)) != 0)
cmdstring, cmdlen, &tmp, 200)) != 0)
return SR_ERR; return SR_ERR;
return SR_OK; return SR_OK;
@ -104,13 +108,15 @@ err:
SR_PRIV int dso_open(struct sr_dev_inst *sdi) SR_PRIV int dso_open(struct sr_dev_inst *sdi)
{ {
libusb_device **devlist;
struct libusb_device_descriptor des;
struct dev_context *devc; struct dev_context *devc;
struct drv_context *drvc = hantek_dso_driver_info.priv; struct drv_context *drvc = hantek_dso_driver_info.priv;
struct sr_usb_dev_inst *usb;
struct libusb_device_descriptor des;
libusb_device **devlist;
int err, skip, i; int err, skip, i;
devc = sdi->priv; devc = sdi->priv;
usb = sdi->conn;
if (sdi->status == SR_ST_ACTIVE) if (sdi->status == SR_ST_ACTIVE)
/* already in use */ /* already in use */
@ -140,27 +146,27 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi)
* This device is fully enumerated, so we need to find * This device is fully enumerated, so we need to find
* this device by vendor, product, bus and address. * this device by vendor, product, bus and address.
*/ */
if (libusb_get_bus_number(devlist[i]) != devc->usb->bus if (libusb_get_bus_number(devlist[i]) != usb->bus
|| libusb_get_device_address(devlist[i]) != devc->usb->address) || libusb_get_device_address(devlist[i]) != usb->address)
/* this is not the one */ /* this is not the one */
continue; continue;
} }
if (!(err = libusb_open(devlist[i], &devc->usb->devhdl))) { if (!(err = libusb_open(devlist[i], &usb->devhdl))) {
if (devc->usb->address == 0xff) if (usb->address == 0xff)
/* /*
* first time we touch this device after firmware upload, * first time we touch this device after firmware upload,
* so we don't know the address yet. * so we don't know the address yet.
*/ */
devc->usb->address = libusb_get_device_address(devlist[i]); usb->address = libusb_get_device_address(devlist[i]);
if (!(devc->epin_maxpacketsize = dso_getmps(devlist[i]))) if (!(devc->epin_maxpacketsize = dso_getmps(devlist[i])))
sr_err("Wrong endpoint profile."); sr_err("Wrong endpoint profile.");
else { else {
sdi->status = SR_ST_ACTIVE; sdi->status = SR_ST_ACTIVE;
sr_info("Opened device %d on %d.%d interface %d.", sr_info("Opened device %d on %d.%d interface %d.",
sdi->index, devc->usb->bus, sdi->index, usb->bus,
devc->usb->address, USB_INTERFACE); usb->address, USB_INTERFACE);
} }
} else { } else {
sr_err("Failed to open device: %s.", sr_err("Failed to open device: %s.",
@ -180,30 +186,35 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi)
SR_PRIV void dso_close(struct sr_dev_inst *sdi) SR_PRIV void dso_close(struct sr_dev_inst *sdi)
{ {
struct dev_context *devc; struct sr_usb_dev_inst *usb;
devc = sdi->priv; usb = sdi->conn;
if (devc->usb->devhdl == NULL) if (usb->devhdl == NULL)
return; return;
sr_info("Closing device %d on %d.%d interface %d.", sdi->index, sr_info("Closing device %d on %d.%d interface %d.", sdi->index,
devc->usb->bus, devc->usb->address, USB_INTERFACE); usb->bus, usb->address, USB_INTERFACE);
libusb_release_interface(devc->usb->devhdl, USB_INTERFACE); libusb_release_interface(usb->devhdl, USB_INTERFACE);
libusb_close(devc->usb->devhdl); libusb_close(usb->devhdl);
devc->usb->devhdl = NULL; usb->devhdl = NULL;
sdi->status = SR_ST_INACTIVE; sdi->status = SR_ST_INACTIVE;
} }
static int get_channel_offsets(struct dev_context *devc) static int get_channel_offsets(const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
GString *gs; GString *gs;
int chan, v, ret; int chan, v, ret;
sr_dbg("Getting channel offsets."); sr_dbg("Getting channel offsets.");
ret = libusb_control_transfer(devc->usb->devhdl, devc = sdi->priv;
usb = sdi->conn;
ret = libusb_control_transfer(usb->devhdl,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR,
CTRL_READ_EEPROM, EEPROM_CHANNEL_OFFSETS, 0, CTRL_READ_EEPROM, EEPROM_CHANNEL_OFFSETS, 0,
(unsigned char *)&devc->channel_levels, (unsigned char *)&devc->channel_levels,
@ -245,8 +256,10 @@ static int get_channel_offsets(struct dev_context *devc)
return SR_OK; return SR_OK;
} }
SR_PRIV int dso_set_trigger_samplerate(struct dev_context *devc) SR_PRIV int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
int ret, tmp; int ret, tmp;
uint8_t cmdstring[12]; uint8_t cmdstring[12];
uint16_t timebase_small[] = { 0xffff, 0xfffc, 0xfff7, 0xffe8, 0xffce, uint16_t timebase_small[] = { 0xffff, 0xfffc, 0xfff7, 0xffe8, 0xffce,
@ -256,6 +269,9 @@ SR_PRIV int dso_set_trigger_samplerate(struct dev_context *devc)
sr_dbg("Preparing CMD_SET_TRIGGER_SAMPLERATE."); sr_dbg("Preparing CMD_SET_TRIGGER_SAMPLERATE.");
devc = sdi->priv;
usb = sdi->conn;
memset(cmdstring, 0, sizeof(cmdstring)); memset(cmdstring, 0, sizeof(cmdstring));
/* Command */ /* Command */
cmdstring[0] = CMD_SET_TRIGGER_SAMPLERATE; cmdstring[0] = CMD_SET_TRIGGER_SAMPLERATE;
@ -343,13 +359,11 @@ SR_PRIV int dso_set_trigger_samplerate(struct dev_context *devc)
cmdstring[7] = (tmp >> 8) & 0xff; cmdstring[7] = (tmp >> 8) & 0xff;
cmdstring[10] = (tmp >> 16) & 0xff; cmdstring[10] = (tmp >> 16) & 0xff;
if (send_begin(devc) != SR_OK) if (send_begin(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if ((ret = libusb_bulk_transfer(devc->usb->devhdl, if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT,
DSO_EP_OUT | LIBUSB_ENDPOINT_OUT, cmdstring, sizeof(cmdstring), &tmp, 100)) != 0) {
cmdstring, sizeof(cmdstring),
&tmp, 100)) != 0) {
sr_err("Failed to set trigger/samplerate: %s.", sr_err("Failed to set trigger/samplerate: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
return SR_ERR; return SR_ERR;
@ -359,13 +373,18 @@ SR_PRIV int dso_set_trigger_samplerate(struct dev_context *devc)
return SR_OK; return SR_OK;
} }
SR_PRIV int dso_set_filters(struct dev_context *devc) SR_PRIV int dso_set_filters(const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
int ret, tmp; int ret, tmp;
uint8_t cmdstring[8]; uint8_t cmdstring[8];
sr_dbg("Preparing CMD_SET_FILTERS."); sr_dbg("Preparing CMD_SET_FILTERS.");
devc = sdi->priv;
usb = sdi->conn;
memset(cmdstring, 0, sizeof(cmdstring)); memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_SET_FILTERS; cmdstring[0] = CMD_SET_FILTERS;
cmdstring[1] = 0x0f; cmdstring[1] = 0x0f;
@ -383,13 +402,11 @@ SR_PRIV int dso_set_filters(struct dev_context *devc)
cmdstring[2] |= 0x20; cmdstring[2] |= 0x20;
} }
if (send_begin(devc) != SR_OK) if (send_begin(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if ((ret = libusb_bulk_transfer(devc->usb->devhdl, if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT,
DSO_EP_OUT | LIBUSB_ENDPOINT_OUT, cmdstring, sizeof(cmdstring), &tmp, 100)) != 0) {
cmdstring, sizeof(cmdstring),
&tmp, 100)) != 0) {
sr_err("Failed to set filters: %s.", libusb_error_name(ret)); sr_err("Failed to set filters: %s.", libusb_error_name(ret));
return SR_ERR; return SR_ERR;
} }
@ -398,13 +415,18 @@ SR_PRIV int dso_set_filters(struct dev_context *devc)
return SR_OK; return SR_OK;
} }
SR_PRIV int dso_set_voltage(struct dev_context *devc) SR_PRIV int dso_set_voltage(const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
int ret, tmp; int ret, tmp;
uint8_t cmdstring[8]; uint8_t cmdstring[8];
sr_dbg("Preparing CMD_SET_VOLTAGE."); sr_dbg("Preparing CMD_SET_VOLTAGE.");
devc = sdi->priv;
usb = sdi->conn;
memset(cmdstring, 0, sizeof(cmdstring)); memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_SET_VOLTAGE; cmdstring[0] = CMD_SET_VOLTAGE;
cmdstring[1] = 0x0f; cmdstring[1] = 0x0f;
@ -450,13 +472,11 @@ SR_PRIV int dso_set_voltage(struct dev_context *devc)
break; break;
} }
if (send_begin(devc) != SR_OK) if (send_begin(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if ((ret = libusb_bulk_transfer(devc->usb->devhdl, if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT,
DSO_EP_OUT | LIBUSB_ENDPOINT_OUT, cmdstring, sizeof(cmdstring), &tmp, 100)) != 0) {
cmdstring, sizeof(cmdstring),
&tmp, 100)) != 0) {
sr_err("Failed to set voltage: %s.", libusb_error_name(ret)); sr_err("Failed to set voltage: %s.", libusb_error_name(ret));
return SR_ERR; return SR_ERR;
} }
@ -465,8 +485,10 @@ SR_PRIV int dso_set_voltage(struct dev_context *devc)
return SR_OK; return SR_OK;
} }
SR_PRIV int dso_set_relays(struct dev_context *devc) SR_PRIV int dso_set_relays(const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
GString *gs; GString *gs;
int ret, i; int ret, i;
uint8_t relays[17] = { 0x00, 0x04, 0x08, 0x02, 0x20, 0x40, 0x10, 0x01, uint8_t relays[17] = { 0x00, 0x04, 0x08, 0x02, 0x20, 0x40, 0x10, 0x01,
@ -474,6 +496,9 @@ SR_PRIV int dso_set_relays(struct dev_context *devc)
sr_dbg("Preparing CTRL_SETRELAYS."); sr_dbg("Preparing CTRL_SETRELAYS.");
devc = sdi->priv;
usb = sdi->conn;
if (devc->voltage_ch1 < VDIV_1V) if (devc->voltage_ch1 < VDIV_1V)
relays[1] = ~relays[1]; relays[1] = ~relays[1];
@ -506,7 +531,7 @@ SR_PRIV int dso_set_relays(struct dev_context *devc)
g_string_free(gs, TRUE); g_string_free(gs, TRUE);
} }
if ((ret = libusb_control_transfer(devc->usb->devhdl, if ((ret = libusb_control_transfer(usb->devhdl,
LIBUSB_REQUEST_TYPE_VENDOR, CTRL_SETRELAYS, LIBUSB_REQUEST_TYPE_VENDOR, CTRL_SETRELAYS,
0, 0, relays, 17, 100)) != sizeof(relays)) { 0, 0, relays, 17, 100)) != sizeof(relays)) {
sr_err("Failed to set relays: %s.", libusb_error_name(ret)); sr_err("Failed to set relays: %s.", libusb_error_name(ret));
@ -517,14 +542,19 @@ SR_PRIV int dso_set_relays(struct dev_context *devc)
return SR_OK; return SR_OK;
} }
SR_PRIV int dso_set_voffsets(struct dev_context *devc) SR_PRIV int dso_set_voffsets(const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
int offset, ret; int offset, ret;
uint16_t *ch_levels; uint16_t *ch_levels;
uint8_t offsets[17]; uint8_t offsets[17];
sr_dbg("Preparing CTRL_SETOFFSET."); sr_dbg("Preparing CTRL_SETOFFSET.");
devc = sdi->priv;
usb = sdi->conn;
memset(offsets, 0, sizeof(offsets)); memset(offsets, 0, sizeof(offsets));
/* Channel 1 */ /* Channel 1 */
ch_levels = devc->channel_levels[0][devc->voltage_ch1]; ch_levels = devc->channel_levels[0][devc->voltage_ch1];
@ -549,7 +579,7 @@ SR_PRIV int dso_set_voffsets(struct dev_context *devc)
sr_dbg("Trigger offset: %3.2f (%.2x%.2x).", devc->voffset_trigger, sr_dbg("Trigger offset: %3.2f (%.2x%.2x).", devc->voffset_trigger,
offsets[4], offsets[5]); offsets[4], offsets[5]);
if ((ret = libusb_control_transfer(devc->usb->devhdl, if ((ret = libusb_control_transfer(usb->devhdl,
LIBUSB_REQUEST_TYPE_VENDOR, CTRL_SETOFFSET, LIBUSB_REQUEST_TYPE_VENDOR, CTRL_SETOFFSET,
0, 0, offsets, sizeof(offsets), 100)) != sizeof(offsets)) { 0, 0, offsets, sizeof(offsets), 100)) != sizeof(offsets)) {
sr_err("Failed to set offsets: %s.", libusb_error_name(ret)); sr_err("Failed to set offsets: %s.", libusb_error_name(ret));
@ -560,24 +590,25 @@ SR_PRIV int dso_set_voffsets(struct dev_context *devc)
return SR_OK; return SR_OK;
} }
SR_PRIV int dso_enable_trigger(struct dev_context *devc) SR_PRIV int dso_enable_trigger(const struct sr_dev_inst *sdi)
{ {
struct sr_usb_dev_inst *usb;
int ret, tmp; int ret, tmp;
uint8_t cmdstring[2]; uint8_t cmdstring[2];
sr_dbg("Sending CMD_ENABLE_TRIGGER."); sr_dbg("Sending CMD_ENABLE_TRIGGER.");
usb = sdi->conn;
memset(cmdstring, 0, sizeof(cmdstring)); memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_ENABLE_TRIGGER; cmdstring[0] = CMD_ENABLE_TRIGGER;
cmdstring[1] = 0x00; cmdstring[1] = 0x00;
if (send_begin(devc) != SR_OK) if (send_begin(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if ((ret = libusb_bulk_transfer(devc->usb->devhdl, if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT,
DSO_EP_OUT | LIBUSB_ENDPOINT_OUT, cmdstring, sizeof(cmdstring), &tmp, 100)) != 0) {
cmdstring, sizeof(cmdstring),
&tmp, 100)) != 0) {
sr_err("Failed to enable trigger: %s.", libusb_error_name(ret)); sr_err("Failed to enable trigger: %s.", libusb_error_name(ret));
return SR_ERR; return SR_ERR;
} }
@ -585,24 +616,25 @@ SR_PRIV int dso_enable_trigger(struct dev_context *devc)
return SR_OK; return SR_OK;
} }
SR_PRIV int dso_force_trigger(struct dev_context *devc) SR_PRIV int dso_force_trigger(const struct sr_dev_inst *sdi)
{ {
struct sr_usb_dev_inst *usb;
int ret, tmp; int ret, tmp;
uint8_t cmdstring[2]; uint8_t cmdstring[2];
sr_dbg("Sending CMD_FORCE_TRIGGER."); sr_dbg("Sending CMD_FORCE_TRIGGER.");
usb = sdi->conn;
memset(cmdstring, 0, sizeof(cmdstring)); memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_FORCE_TRIGGER; cmdstring[0] = CMD_FORCE_TRIGGER;
cmdstring[1] = 0x00; cmdstring[1] = 0x00;
if (send_begin(devc) != SR_OK) if (send_begin(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if ((ret = libusb_bulk_transfer(devc->usb->devhdl, if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_OUT,
DSO_EP_OUT | LIBUSB_ENDPOINT_OUT, cmdstring, sizeof(cmdstring), &tmp, 100)) != 0) {
cmdstring, sizeof(cmdstring),
&tmp, 100)) != 0) {
sr_err("Failed to force trigger: %s.", libusb_error_name(ret)); sr_err("Failed to force trigger: %s.", libusb_error_name(ret));
return SR_ERR; return SR_ERR;
} }
@ -610,56 +642,57 @@ SR_PRIV int dso_force_trigger(struct dev_context *devc)
return SR_OK; return SR_OK;
} }
SR_PRIV int dso_init(struct dev_context *devc) SR_PRIV int dso_init(const struct sr_dev_inst *sdi)
{ {
sr_dbg("Initializing DSO."); sr_dbg("Initializing DSO.");
if (get_channel_offsets(devc) != SR_OK) if (get_channel_offsets(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if (dso_set_trigger_samplerate(devc) != SR_OK) if (dso_set_trigger_samplerate(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if (dso_set_filters(devc) != SR_OK) if (dso_set_filters(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if (dso_set_voltage(devc) != SR_OK) if (dso_set_voltage(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if (dso_set_relays(devc) != SR_OK) if (dso_set_relays(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if (dso_set_voffsets(devc) != SR_OK) if (dso_set_voffsets(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
if (dso_enable_trigger(devc) != SR_OK) if (dso_enable_trigger(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
return SR_OK; return SR_OK;
} }
SR_PRIV int dso_get_capturestate(struct dev_context *devc, SR_PRIV int dso_get_capturestate(const struct sr_dev_inst *sdi,
uint8_t *capturestate, uint8_t *capturestate, uint32_t *trigger_offset)
uint32_t *trigger_offset)
{ {
struct sr_usb_dev_inst *usb;
int ret, tmp, i; int ret, tmp, i;
unsigned int bitvalue, toff; unsigned int bitvalue, toff;
uint8_t cmdstring[2], inbuf[512]; uint8_t cmdstring[2], inbuf[512];
sr_dbg("Sending CMD_GET_CAPTURESTATE."); sr_dbg("Sending CMD_GET_CAPTURESTATE.");
usb = sdi->conn;
cmdstring[0] = CMD_GET_CAPTURESTATE; cmdstring[0] = CMD_GET_CAPTURESTATE;
cmdstring[1] = 0; cmdstring[1] = 0;
if ((ret = send_bulkcmd(devc, cmdstring, sizeof(cmdstring))) != SR_OK) { if ((ret = send_bulkcmd(sdi, cmdstring, sizeof(cmdstring))) != SR_OK) {
sr_dbg("Failed to send get_capturestate command: %s.", sr_dbg("Failed to send get_capturestate command: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
return SR_ERR; return SR_ERR;
} }
if ((ret = libusb_bulk_transfer(devc->usb->devhdl, if ((ret = libusb_bulk_transfer(usb->devhdl, DSO_EP_IN,
DSO_EP_IN | LIBUSB_ENDPOINT_IN,
inbuf, 512, &tmp, 100)) != 0) { inbuf, 512, &tmp, 100)) != 0) {
sr_dbg("Failed to get capturestate: %s.", sr_dbg("Failed to get capturestate: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
@ -685,7 +718,7 @@ SR_PRIV int dso_get_capturestate(struct dev_context *devc,
return SR_OK; return SR_OK;
} }
SR_PRIV int dso_capture_start(struct dev_context *devc) SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi)
{ {
int ret; int ret;
uint8_t cmdstring[2]; uint8_t cmdstring[2];
@ -695,7 +728,7 @@ SR_PRIV int dso_capture_start(struct dev_context *devc)
cmdstring[0] = CMD_CAPTURE_START; cmdstring[0] = CMD_CAPTURE_START;
cmdstring[1] = 0; cmdstring[1] = 0;
if ((ret = send_bulkcmd(devc, cmdstring, sizeof(cmdstring))) != SR_OK) { if ((ret = send_bulkcmd(sdi, cmdstring, sizeof(cmdstring))) != SR_OK) {
sr_err("Failed to send capture_start command: %s.", sr_err("Failed to send capture_start command: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
return SR_ERR; return SR_ERR;
@ -708,18 +741,21 @@ SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
libusb_transfer_cb_fn cb) libusb_transfer_cb_fn cb)
{ {
struct dev_context *devc; struct dev_context *devc;
struct sr_usb_dev_inst *usb;
struct libusb_transfer *transfer; struct libusb_transfer *transfer;
int num_transfers, ret, i; int num_transfers, ret, i;
uint8_t cmdstring[2]; uint8_t cmdstring[2];
unsigned char *buf; unsigned char *buf;
devc = sdi->priv;
sr_dbg("Sending CMD_GET_CHANNELDATA."); sr_dbg("Sending CMD_GET_CHANNELDATA.");
devc = sdi->priv;
usb = sdi->conn;
cmdstring[0] = CMD_GET_CHANNELDATA; cmdstring[0] = CMD_GET_CHANNELDATA;
cmdstring[1] = 0; cmdstring[1] = 0;
if ((ret = send_bulkcmd(devc, cmdstring, sizeof(cmdstring))) != SR_OK) { if ((ret = send_bulkcmd(sdi, cmdstring, sizeof(cmdstring))) != SR_OK) {
sr_err("Failed to get channel data: %s.", sr_err("Failed to get channel data: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
return SR_ERR; return SR_ERR;
@ -735,8 +771,7 @@ SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
} }
transfer = libusb_alloc_transfer(0); transfer = libusb_alloc_transfer(0);
libusb_fill_bulk_transfer(transfer, devc->usb->devhdl, libusb_fill_bulk_transfer(transfer, usb->devhdl, DSO_EP_IN, buf,
DSO_EP_IN | LIBUSB_ENDPOINT_IN, buf,
devc->epin_maxpacketsize, cb, (void *)sdi, 40); devc->epin_maxpacketsize, cb, (void *)sdi, 40);
if ((ret = libusb_submit_transfer(transfer)) != 0) { if ((ret = libusb_submit_transfer(transfer)) != 0) {
sr_err("Failed to submit transfer: %s.", sr_err("Failed to submit transfer: %s.",

View File

@ -169,7 +169,6 @@ struct dso_profile {
struct dev_context { struct dev_context {
const struct dso_profile *profile; const struct dso_profile *profile;
struct sr_usb_dev_inst *usb;
void *cb_data; void *cb_data;
uint64_t limit_frames; uint64_t limit_frames;
uint64_t num_frames; uint64_t num_frames;
@ -215,12 +214,12 @@ struct dev_context {
SR_PRIV int dso_open(struct sr_dev_inst *sdi); SR_PRIV int dso_open(struct sr_dev_inst *sdi);
SR_PRIV void dso_close(struct sr_dev_inst *sdi); SR_PRIV void dso_close(struct sr_dev_inst *sdi);
SR_PRIV int dso_enable_trigger(struct dev_context *devc); SR_PRIV int dso_enable_trigger(const struct sr_dev_inst *sdi);
SR_PRIV int dso_force_trigger(struct dev_context *devc); SR_PRIV int dso_force_trigger(const struct sr_dev_inst *sdi);
SR_PRIV int dso_init(struct dev_context *devc); SR_PRIV int dso_init(const struct sr_dev_inst *sdi);
SR_PRIV int dso_get_capturestate(struct dev_context *devc, SR_PRIV int dso_get_capturestate(const struct sr_dev_inst *sdi,
uint8_t *capturestate, uint32_t *trigger_offset); uint8_t *capturestate, uint32_t *trigger_offset);
SR_PRIV int dso_capture_start(struct dev_context *devc); SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi);
SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi, SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
libusb_transfer_cb_fn cb); libusb_transfer_cb_fn cb);