sr: fx2lafw: Consistency fixes.
This commit is contained in:
parent
01c3e9dbd5
commit
da68656857
|
@ -53,7 +53,7 @@ static const struct fx2lafw_profile supported_fx2[] = {
|
||||||
{ 0, 0, 0, 0, 0, 0, 0 }
|
{ 0, 0, 0, 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int fx2lafw_capabilities[] = {
|
static int hwcaps[] = {
|
||||||
SR_HWCAP_LOGIC_ANALYZER,
|
SR_HWCAP_LOGIC_ANALYZER,
|
||||||
SR_HWCAP_SAMPLERATE,
|
SR_HWCAP_SAMPLERATE,
|
||||||
|
|
||||||
|
@ -63,7 +63,10 @@ static int fx2lafw_capabilities[] = {
|
||||||
0,
|
0,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *fx2lafw_probe_names[] = {
|
/*
|
||||||
|
* TODO: Different probe_names[] for each supported device.
|
||||||
|
*/
|
||||||
|
static const char *probe_names[] = {
|
||||||
"0",
|
"0",
|
||||||
"1",
|
"1",
|
||||||
"2",
|
"2",
|
||||||
|
@ -98,7 +101,7 @@ static GSList *dev_insts = NULL;
|
||||||
static libusb_context *usb_context = NULL;
|
static libusb_context *usb_context = NULL;
|
||||||
|
|
||||||
static int hw_dev_config_set(int dev_index, int hwcap, void *value);
|
static int hw_dev_config_set(int dev_index, int hwcap, void *value);
|
||||||
static int hw_dev_acquisition_stop(int dev_index, void *session_dev_id);
|
static int hw_dev_acquisition_stop(int dev_index, void *cb_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the USB configuration to determine if this is an fx2lafw device.
|
* Check the USB configuration to determine if this is an fx2lafw device.
|
||||||
|
@ -114,39 +117,37 @@ static gboolean check_conf_profile(libusb_device *dev)
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
while (!ret) {
|
while (!ret) {
|
||||||
/* Assume the firmware has not been loaded, unless proven wrong. */
|
/* Assume the FW has not been loaded, unless proven wrong. */
|
||||||
ret = 0;
|
ret = FALSE;
|
||||||
|
|
||||||
if (libusb_get_device_descriptor(dev, &des) != 0)
|
if (libusb_get_device_descriptor(dev, &des) != 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (des.bNumConfigurations != 1)
|
|
||||||
/* Need exactly 1 configuration. */
|
/* Need exactly 1 configuration. */
|
||||||
|
if (des.bNumConfigurations != 1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (libusb_get_config_descriptor(dev, 0, &conf_dsc) != 0)
|
if (libusb_get_config_descriptor(dev, 0, &conf_dsc) != 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (conf_dsc->bNumInterfaces != 1)
|
|
||||||
/* Need exactly 1 interface. */
|
/* Need exactly 1 interface. */
|
||||||
|
if (conf_dsc->bNumInterfaces != 1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (conf_dsc->interface[0].num_altsetting != 1)
|
|
||||||
/* Need just one alternate setting. */
|
/* Need just one alternate setting. */
|
||||||
|
if (conf_dsc->interface[0].num_altsetting != 1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* Need exactly 2 endpoints. */
|
||||||
intf_dsc = &(conf_dsc->interface[0].altsetting[0]);
|
intf_dsc = &(conf_dsc->interface[0].altsetting[0]);
|
||||||
if (intf_dsc->bNumEndpoints != 2)
|
if (intf_dsc->bNumEndpoints != 2)
|
||||||
/* Need exactly 2 end points. */
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ((intf_dsc->endpoint[0].bEndpointAddress & 0x8f) !=
|
|
||||||
(2 | LIBUSB_ENDPOINT_IN)) // 0x82
|
|
||||||
/* The first endpoint should be 2 (inbound). */
|
/* The first endpoint should be 2 (inbound). */
|
||||||
|
if ((intf_dsc->endpoint[0].bEndpointAddress & 0x8f) !=
|
||||||
|
(2 | LIBUSB_ENDPOINT_IN))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* TODO: Check the debug channel... */
|
|
||||||
|
|
||||||
/* If we made it here, it must be an fx2lafw. */
|
/* If we made it here, it must be an fx2lafw. */
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +158,7 @@ static gboolean check_conf_profile(libusb_device *dev)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fx2lafw_open_dev(int dev_index)
|
static int fx2lafw_dev_open(int dev_index)
|
||||||
{
|
{
|
||||||
libusb_device **devlist;
|
libusb_device **devlist;
|
||||||
struct libusb_device_descriptor des;
|
struct libusb_device_descriptor des;
|
||||||
|
@ -291,7 +292,7 @@ static int configure_probes(struct context *ctx, GSList *probes)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct context *fx2lafw_device_new(void)
|
static struct context *fx2lafw_dev_new(void)
|
||||||
{
|
{
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
|
|
||||||
|
@ -309,11 +310,11 @@ static struct context *fx2lafw_device_new(void)
|
||||||
* API callbacks
|
* API callbacks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int hw_init(const char *deviceinfo)
|
static int hw_init(const char *devinfo)
|
||||||
{
|
{
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct libusb_device_descriptor des;
|
struct libusb_device_descriptor des;
|
||||||
const struct fx2lafw_profile *fx2lafw_prof;
|
const struct fx2lafw_profile *prof;
|
||||||
struct context *ctx;
|
struct context *ctx;
|
||||||
libusb_device **devlist;
|
libusb_device **devlist;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -321,7 +322,7 @@ static int hw_init(const char *deviceinfo)
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
/* Avoid compiler warnings. */
|
/* Avoid compiler warnings. */
|
||||||
(void)deviceinfo;
|
(void)devinfo;
|
||||||
|
|
||||||
if (libusb_init(&usb_context) != 0) {
|
if (libusb_init(&usb_context) != 0) {
|
||||||
sr_warn("fx2lafw: Failed to initialize libusb.");
|
sr_warn("fx2lafw: Failed to initialize libusb.");
|
||||||
|
@ -338,26 +339,25 @@ static int hw_init(const char *deviceinfo)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
fx2lafw_prof = NULL;
|
prof = NULL;
|
||||||
for (j = 0; supported_fx2[j].vid; j++) {
|
for (j = 0; supported_fx2[j].vid; j++) {
|
||||||
if (des.idVendor == supported_fx2[j].vid &&
|
if (des.idVendor == supported_fx2[j].vid &&
|
||||||
des.idProduct == supported_fx2[j].pid) {
|
des.idProduct == supported_fx2[j].pid) {
|
||||||
fx2lafw_prof = &supported_fx2[j];
|
prof = &supported_fx2[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip if the device was not found */
|
/* Skip if the device was not found */
|
||||||
if (!fx2lafw_prof)
|
if (!prof)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING,
|
sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING,
|
||||||
fx2lafw_prof->vendor, fx2lafw_prof->model,
|
prof->vendor, prof->model, prof->model_version);
|
||||||
fx2lafw_prof->model_version);
|
|
||||||
if (!sdi)
|
if (!sdi)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ctx = fx2lafw_device_new();
|
ctx = fx2lafw_dev_new();
|
||||||
ctx->profile = fx2lafw_prof;
|
ctx->profile = prof;
|
||||||
sdi->priv = ctx;
|
sdi->priv = ctx;
|
||||||
dev_insts = g_slist_append(dev_insts, sdi);
|
dev_insts = g_slist_append(dev_insts, sdi);
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ static int hw_init(const char *deviceinfo)
|
||||||
libusb_get_device_address(devlist[i]), NULL);
|
libusb_get_device_address(devlist[i]), NULL);
|
||||||
} else {
|
} else {
|
||||||
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
|
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
|
||||||
fx2lafw_prof->firmware) == SR_OK)
|
prof->firmware) == SR_OK)
|
||||||
/* Remember when the firmware on this device was updated */
|
/* Remember when the firmware on this device was updated */
|
||||||
g_get_current_time(&ctx->fw_updated);
|
g_get_current_time(&ctx->fw_updated);
|
||||||
else
|
else
|
||||||
|
@ -409,7 +409,7 @@ static int hw_dev_open(int dev_index)
|
||||||
g_usleep(300 * 1000);
|
g_usleep(300 * 1000);
|
||||||
timediff = 0;
|
timediff = 0;
|
||||||
while (timediff < MAX_RENUM_DELAY) {
|
while (timediff < MAX_RENUM_DELAY) {
|
||||||
if ((ret = fx2lafw_open_dev(dev_index)) == SR_OK)
|
if ((ret = fx2lafw_dev_open(dev_index)) == SR_OK)
|
||||||
break;
|
break;
|
||||||
g_usleep(100 * 1000);
|
g_usleep(100 * 1000);
|
||||||
g_get_current_time(&cur_time);
|
g_get_current_time(&cur_time);
|
||||||
|
@ -417,7 +417,7 @@ static int hw_dev_open(int dev_index)
|
||||||
}
|
}
|
||||||
sr_info("fx2lafw: Device came back after %d ms.", timediff);
|
sr_info("fx2lafw: Device came back after %d ms.", timediff);
|
||||||
} else {
|
} else {
|
||||||
ret = fx2lafw_open_dev(dev_index);
|
ret = fx2lafw_dev_open(dev_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != SR_OK) {
|
if (ret != SR_OK) {
|
||||||
|
@ -509,7 +509,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id)
|
||||||
case SR_DI_NUM_PROBES:
|
case SR_DI_NUM_PROBES:
|
||||||
return GINT_TO_POINTER(ctx->profile->num_probes);
|
return GINT_TO_POINTER(ctx->profile->num_probes);
|
||||||
case SR_DI_PROBE_NAMES:
|
case SR_DI_PROBE_NAMES:
|
||||||
return fx2lafw_probe_names;
|
return probe_names;
|
||||||
case SR_DI_SAMPLERATES:
|
case SR_DI_SAMPLERATES:
|
||||||
return &samplerates;
|
return &samplerates;
|
||||||
case SR_DI_TRIGGER_TYPES:
|
case SR_DI_TRIGGER_TYPES:
|
||||||
|
@ -534,7 +534,7 @@ static int hw_dev_status_get(int dev_index)
|
||||||
|
|
||||||
static int *hw_hwcap_get_all(void)
|
static int *hw_hwcap_get_all(void)
|
||||||
{
|
{
|
||||||
return fx2lafw_capabilities;
|
return hwcaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hw_dev_config_set(int dev_index, int hwcap, void *value)
|
static int hw_dev_config_set(int dev_index, int hwcap, void *value)
|
||||||
|
|
Loading…
Reference in New Issue