* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
#include "protocol.h"
-static const uint32_t devopts[] = {
+static const uint32_t drvopts[] = {
SR_CONF_LOGIC_ANALYZER,
+};
+
+static const uint32_t devopts[] = {
SR_CONF_LIMIT_SAMPLES | SR_CONF_SET | SR_CONF_LIST,
SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
SR_MHZ(20),
};
-static const char *channel_names[NUM_CHANNELS + 1] = {
+static const char *channel_names[] = {
"0", "1", "2", "3",
- NULL,
};
-SR_PRIV struct sr_dev_driver ikalogic_scanalogic2_driver_info;
-
-static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
-{
- return std_init(sr_ctx, di, LOG_PREFIX);
-}
-
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
GSList *usb_devices, *devices, *l;
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
struct device_info dev_info;
- int ret, i;
+ unsigned int i;
+ int ret;
(void)options;
devices = NULL;
- drvc = di->priv;
- drvc->instances = NULL;
+ drvc = di->context;
usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, USB_VID_PID);
- if (usb_devices == NULL)
+ if (!usb_devices)
return NULL;
for (l = usb_devices; l; l = l->next) {
usb = l->data;
- if ((ret = sl2_get_device_info(*usb, &dev_info)) < 0) {
+ if ((ret = sl2_get_device_info(di, *usb, &dev_info)) < 0) {
sr_warn("Failed to get device information: %d.", ret);
sr_usb_dev_inst_free(usb);
continue;
sdi->version = g_strdup_printf("%u.%u", dev_info.fw_ver_major, dev_info.fw_ver_minor);
sdi->serial_num = g_strdup_printf("%d", dev_info.serial);
sdi->priv = devc;
- sdi->driver = di;
sdi->inst_type = SR_INST_USB;
sdi->conn = usb;
- for (i = 0; channel_names[i]; i++)
- devc->channels[i] = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC,
- TRUE, channel_names[i]);
+ for (i = 0; i < ARRAY_SIZE(channel_names); i++)
+ devc->channels[i] = sr_channel_new(sdi, i,
+ SR_CHANNEL_LOGIC, TRUE, channel_names[i]);
devc->state = STATE_IDLE;
devc->next_state = STATE_IDLE;
devc->xfer_data_out = devc->xfer_buf_out +
LIBUSB_CONTROL_SETUP_SIZE;
- drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
}
g_slist_free(usb_devices);
- return devices;
-}
-
-static GSList *dev_list(const struct sr_dev_driver *di)
-{
- return ((struct drv_context *)(di->priv))->instances;
+ return std_scan_complete(di, devices);
}
-static void clear_dev_context(void *priv)
+static void clear_helper(struct dev_context *devc)
{
- struct dev_context *devc;
-
- devc = priv;
-
- sr_dbg("Device context cleared.");
-
libusb_free_transfer(devc->xfer_in);
libusb_free_transfer(devc->xfer_out);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
{
- return std_dev_clear(di, &clear_dev_context);
+ return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
}
static int dev_open(struct sr_dev_inst *sdi)
{
struct sr_dev_driver *di = sdi->driver;
- struct drv_context *drvc;
+ struct drv_context *drvc = di->context;
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
uint8_t buffer[PACKET_LENGTH];
int ret;
- if (!(drvc = di->priv)) {
- sr_err("Driver was not initialized.");
- return SR_ERR;
- }
-
usb = sdi->conn;
devc = sdi->priv;
if (sr_usb_open(drvc->sr_ctx->libusb_ctx, usb) != SR_OK)
return SR_ERR;
- /*
- * Determine if a kernel driver is active on this interface and, if so,
- * detach it.
- */
if (libusb_kernel_driver_active(usb->devhdl, USB_INTERFACE) == 1) {
ret = libusb_detach_kernel_driver(usb->devhdl, USB_INTERFACE);
if (ret < 0) {
libusb_fill_control_transfer(devc->xfer_in, usb->devhdl,
devc->xfer_buf_in, sl2_receive_transfer_in,
- sdi, USB_TIMEOUT);
+ sdi, USB_TIMEOUT_MS);
libusb_fill_control_transfer(devc->xfer_out, usb->devhdl,
devc->xfer_buf_out, sl2_receive_transfer_out,
- sdi, USB_TIMEOUT);
+ sdi, USB_TIMEOUT_MS);
memset(buffer, 0, sizeof(buffer));
return SR_ERR;
}
- sdi->status = SR_ST_ACTIVE;
-
return SR_OK;
}
static int dev_close(struct sr_dev_inst *sdi)
{
- struct sr_dev_driver *di = sdi->driver;
struct sr_usb_dev_inst *usb;
- if (!di->priv) {
- sr_err("Driver was not initialized.");
- return SR_ERR;
- }
-
usb = sdi->conn;
if (!usb->devhdl)
- return SR_OK;
+ return SR_ERR_BUG;
libusb_release_interface(usb->devhdl, USB_INTERFACE);
libusb_close(usb->devhdl);
usb->devhdl = NULL;
- sdi->status = SR_ST_INACTIVE;
return SR_OK;
}
-static int cleanup(const struct sr_dev_driver *di)
-{
- return dev_clear(di);
-}
-
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)cg;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
- ret = SR_OK;
-
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
limit_samples = g_variant_get_uint64(data);
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
- GVariant *gvar, *grange[2];
- GVariantBuilder gvb;
- int ret;
-
- (void)sdi;
- (void)cg;
-
- ret = SR_OK;
+ GVariant *grange[2];
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
- *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
- break;
+ return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts);
case SR_CONF_SAMPLERATE:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
- gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
- sl2_samplerates, ARRAY_SIZE(sl2_samplerates),
- sizeof(uint64_t));
- g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_samplerates(sl2_samplerates, ARRAY_SIZE(sl2_samplerates));
break;
case SR_CONF_TRIGGER_MATCH:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
return SR_ERR_NA;
}
- return ret;
+ return SR_OK;
}
-static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_start(const struct sr_dev_inst *sdi)
{
struct sr_dev_driver *di = sdi->driver;
struct drv_context *drvc;
unsigned int i, j;
int ret;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
devc = sdi->priv;
- drvc = di->priv;
+ drvc = di->context;
- devc->cb_data = cb_data;
devc->wait_data_ready_locked = TRUE;
devc->stopping_in_progress = FALSE;
devc->transfer_error = FALSE;
usb_source_add(sdi->session, drvc->sr_ctx, 100,
ikalogic_scanalogic2_receive_data, (void *)sdi);
- sr_dbg("Acquisition started successfully.");
-
- /* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi);
devc->next_state = STATE_SAMPLE;
return SR_OK;
}
-static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
+static int dev_acquisition_stop(struct sr_dev_inst *sdi)
{
- (void)cb_data;
-
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
- sr_dbg("Stopping acquisition.");
-
sdi->status = SR_ST_STOPPING;
return SR_OK;
}
-SR_PRIV struct sr_dev_driver ikalogic_scanalogic2_driver_info = {
+static struct sr_dev_driver ikalogic_scanalogic2_driver_info = {
.name = "ikalogic-scanalogic2",
.longname = "IKALOGIC Scanalogic-2",
.api_version = 1,
- .init = init,
- .cleanup = cleanup,
+ .init = std_init,
+ .cleanup = std_cleanup,
.scan = scan,
- .dev_list = dev_list,
+ .dev_list = std_dev_list,
.dev_clear = dev_clear,
.config_get = config_get,
.config_set = config_set,
.dev_close = dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .context = NULL,
};
+SR_REGISTER_DEV_DRIVER(ikalogic_scanalogic2_driver_info);