X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Flascar-el-usb%2Fapi.c;h=1ab2a68fdb3e7f6a0fc6f23401e1d417dc4c93a4;hb=063e7aef6d41d4c44591ff93672079998bf9622f;hp=210480cc727fc95a2dc5ea31f9c97bec3373bc57;hpb=6b8d6f93bb8df26ea04624009e2715cb6766b4f5;p=libsigrok.git diff --git a/hardware/lascar-el-usb/api.c b/hardware/lascar-el-usb/api.c index 210480cc..1ab2a68f 100644 --- a/hardware/lascar-el-usb/api.c +++ b/hardware/lascar-el-usb/api.c @@ -29,14 +29,14 @@ static struct sr_dev_driver *di = &lascar_el_usb_driver_info; static int hw_dev_close(struct sr_dev_inst *sdi); static const int hwopts[] = { - SR_HWOPT_CONN, + SR_CONF_CONN, 0, }; static const int hwcaps[] = { - SR_HWCAP_THERMOMETER, - SR_HWCAP_HYGROMETER, - SR_HWCAP_LIMIT_SAMPLES, + SR_CONF_THERMOMETER, + SR_CONF_HYGROMETER, + SR_CONF_LIMIT_SAMPLES, 0 }; @@ -70,17 +70,7 @@ static int clear_instances(void) static int hw_init(struct sr_context *sr_ctx) { - struct drv_context *drvc; - - if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) { - sr_err("Driver context malloc failed."); - return SR_ERR_MALLOC; - } - - drvc->sr_ctx = sr_ctx; - di->priv = drvc; - - return SR_OK; + return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN); } static GSList *hw_scan(GSList *options) @@ -89,26 +79,23 @@ static GSList *hw_scan(GSList *options) struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_usb_dev_inst *usb; - struct sr_hwopt *opt; + struct sr_config *src; GSList *usb_devices, *devices, *l; const char *conn; (void)options; - if (!(drvc = di->priv)) { - sr_err("Driver was not initialized."); - return NULL; - } + drvc = di->priv; /* USB scan is always authoritative. */ clear_instances(); conn = NULL; for (l = options; l; l = l->next) { - opt = l->data; - switch (opt->hwopt) { - case SR_HWOPT_CONN: - conn = opt->value; + src = l->data; + switch (src->key) { + case SR_CONF_CONN: + conn = src->value; break; } } @@ -213,29 +200,7 @@ static int hw_cleanup(void) return SR_OK; } -static int hw_info_get(int info_id, const void **data, - const struct sr_dev_inst *sdi) -{ - - (void)sdi; - - switch (info_id) { - case SR_DI_HWOPTS: - *data = hwopts; - break; - case SR_DI_HWCAPS: - *data = hwcaps; - break; - default: - sr_err("Unknown info_id: %d.", info_id); - return SR_ERR_ARG; - } - - return SR_OK; -} - -static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, - const void *value) +static int config_set(int id, const void *value, const struct sr_dev_inst *sdi) { struct dev_context *devc; int ret; @@ -251,20 +216,39 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, devc = sdi->priv; ret = SR_OK; - switch (hwcap) { - case SR_HWCAP_LIMIT_SAMPLES: + switch (id) { + case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = *(const uint64_t *)value; sr_dbg("Setting sample limit to %" PRIu64 ".", devc->limit_samples); break; default: - sr_err("Unknown hardware capability: %d.", hwcap); + sr_err("Unknown hardware capability: %d.", id); ret = SR_ERR_ARG; } return ret; } +static int config_list(int key, const void **data, const struct sr_dev_inst *sdi) +{ + + (void)sdi; + + switch (key) { + case SR_CONF_SCAN_OPTIONS: + *data = hwopts; + break; + case SR_CONF_DEVICE_OPTIONS: + *data = hwcaps; + break; + default: + return SR_ERR_ARG; + } + + return SR_OK; +} + static void mark_xfer(struct libusb_transfer *xfer) { @@ -337,7 +321,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, { struct sr_datafeed_packet packet; struct sr_datafeed_header header; - struct sr_datafeed_meta_analog meta; struct dev_context *devc; struct drv_context *drvc = di->priv; struct libusb_transfer *xfer_in, *xfer_out; @@ -431,12 +414,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, devc->log_size = xfer_in->buffer[1] + (xfer_in->buffer[2] << 8); libusb_free_transfer(xfer_out); - /* Send metadata about the SR_DF_ANALOG packets to come. */ - packet.type = SR_DF_META_ANALOG; - packet.payload = &meta; - meta.num_probes = 1; - sr_session_send(devc->cb_data, &packet); - pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); for (i = 0; pfd[i]; i++) { /* Handle USB events every 100ms, for decent latency. */ @@ -489,10 +466,10 @@ SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info = { .scan = hw_scan, .dev_list = hw_dev_list, .dev_clear = clear_instances, + .config_set = config_set, + .config_list = config_list, .dev_open = hw_dev_open, .dev_close = hw_dev_close, - .info_get = hw_info_get, - .dev_config_set = hw_dev_config_set, .dev_acquisition_start = hw_dev_acquisition_start, .dev_acquisition_stop = hw_dev_acquisition_stop, .priv = NULL,