};
static const char *channel_names[] = {
- "0", "1", "2", "3", "4", "5", "6", "7",
- "8", "9", "10", "11", "12", "13", "14", "15",
- NULL,
+ "0", "1", "2", "3", "4", "5", "6", "7",
+ "8", "9", "10", "11", "12", "13", "14", "15",
};
static const int32_t soft_trigger_matches[] = {
};
SR_PRIV struct sr_dev_driver fx2lafw_driver_info;
-static struct sr_dev_driver *di = &fx2lafw_driver_info;
-static int init(struct sr_context *sr_ctx)
+static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
{
return std_init(sr_ctx, di, LOG_PREFIX);
}
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct drv_context *drvc;
struct dev_context *devc;
struct sr_dev_inst *sdi;
struct sr_usb_dev_inst *usb;
- struct sr_channel *ch;
struct sr_config *src;
const struct fx2lafw_profile *prof;
GSList *l, *devices, *conn_devices;
/* Fill in channellist according to this device's profile. */
num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8;
- for (j = 0; j < num_logic_channels; j++) {
- ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE,
+ for (j = 0; j < num_logic_channels; j++)
+ sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE,
channel_names[j]);
- sdi->channels = g_slist_append(sdi->channels, ch);
- }
devc = fx2lafw_dev_new();
devc->profile = prof;
return devices;
}
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
{
return ((struct drv_context *)(di->priv))->instances;
}
static int dev_open(struct sr_dev_inst *sdi)
{
+ struct sr_dev_driver *di = sdi->driver;
struct sr_usb_dev_inst *usb;
struct dev_context *devc;
int ret;
struct sr_usb_dev_inst *usb;
usb = sdi->conn;
- if (usb->devhdl == NULL)
+ if (!usb->devhdl)
return SR_ERR;
sr_info("fx2lafw: Closing device on %d.%d (logical) / %s (physical) interface %d.",
return SR_OK;
}
-static int cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
{
int ret;
struct drv_context *drvc;
ret = std_dev_clear(di, NULL);
g_free(drvc);
- di->priv = NULL;
return ret;
}
ret = SR_OK;
switch (key) {
- case SR_CONF_SAMPLERATE:
- arg = g_variant_get_uint64(data);
- for (i = 0; i < ARRAY_SIZE(samplerates); i++) {
- if (samplerates[i] == arg) {
- devc->cur_samplerate = arg;
- break;
- }
+ case SR_CONF_SAMPLERATE:
+ arg = g_variant_get_uint64(data);
+ for (i = 0; i < ARRAY_SIZE(samplerates); i++) {
+ if (samplerates[i] == arg) {
+ devc->cur_samplerate = arg;
+ break;
}
- if (i == ARRAY_SIZE(samplerates))
- ret = SR_ERR_ARG;
- break;
- case SR_CONF_LIMIT_SAMPLES:
- devc->limit_samples = g_variant_get_uint64(data);
- break;
- case SR_CONF_CAPTURE_RATIO:
- devc->capture_ratio = g_variant_get_uint64(data);
- if (devc->capture_ratio > 100) {
- devc->capture_ratio = 0;
- ret = SR_ERR;
- } else
- ret = SR_OK;
- break;
- default:
- ret = SR_ERR_NA;
+ }
+ if (i == ARRAY_SIZE(samplerates))
+ ret = SR_ERR_ARG;
+ break;
+ case SR_CONF_LIMIT_SAMPLES:
+ devc->limit_samples = g_variant_get_uint64(data);
+ break;
+ case SR_CONF_CAPTURE_RATIO:
+ devc->capture_ratio = g_variant_get_uint64(data);
+ if (devc->capture_ratio > 100) {
+ devc->capture_ratio = 0;
+ ret = SR_ERR;
+ } else
+ ret = SR_OK;
+ break;
+ default:
+ ret = SR_ERR_NA;
}
return ret;
(void)fd;
(void)revents;
- (void)cb_data;
- drvc = di->priv;
+ drvc = (struct drv_context *)cb_data;
tv.tv_sec = tv.tv_usec = 0;
libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
devc = sdi->priv;
usb = sdi->conn;
- devc->cb_data = cb_data;
devc->sent_samples = 0;
devc->acq_aborted = FALSE;
devc->empty_transfer_count = 0;
if (devc->limit_samples > 0)
pre_trigger_samples = devc->capture_ratio * devc->limit_samples/100;
devc->stl = soft_trigger_logic_new(sdi, trigger, pre_trigger_samples);
- if (devc->stl == NULL)
+ if (!devc->stl)
return SR_ERR_MALLOC;
devc->trigger_fired = FALSE;
} else
}
/* Send header packet to the session bus. */
- std_session_send_df_header(devc->cb_data, LOG_PREFIX);
-
- usb_source_add(sdi->session, devc->ctx, timeout, receive_data, NULL);
+ std_session_send_df_header(sdi, LOG_PREFIX);
return SR_OK;
}
-static void dslogic_trigger_receive(struct libusb_transfer *transfer)
+static void LIBUSB_CALL dslogic_trigger_receive(struct libusb_transfer *transfer)
{
const struct sr_dev_inst *sdi;
struct dslogic_trigger_pos *tpos;
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
{
+ struct sr_dev_driver *di;
struct drv_context *drvc;
struct dev_context *devc;
int timeout, ret;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
+ di = sdi->driver;
drvc = di->priv;
devc = sdi->priv;
- /* Configures devc->trigger_* and devc->sample_wide */
- if (fx2lafw_configure_channels(sdi) != SR_OK) {
- sr_err("Failed to configure channels.");
- return SR_ERR;
- }
-
devc->ctx = drvc->sr_ctx;
devc->cb_data = cb_data;
devc->sent_samples = 0;
devc->acq_aborted = FALSE;
timeout = fx2lafw_get_timeout(devc);
- usb_source_add(devc->ctx, timeout, receive_data, NULL);
+ usb_source_add(sdi->session, devc->ctx, timeout, receive_data, drvc);
if (devc->dslogic) {
dslogic_trigger_request(sdi);