X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fbrymen-bm86x%2Fapi.c;h=23b42e1390cddee7c0baee502e50d8c2d9fe47db;hb=f1ba6b4b2c9a8ecf90bb31efb218752aa7e49d1a;hp=eb41b845fdfc3f6d8bbf60679548169986b1ce03;hpb=dd5c48a6d567a3cac62c4b0058588273bbeea171;p=libsigrok.git diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index eb41b845..23b42e13 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -44,7 +44,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) const char *conn; drvc = di->context; - drvc->instances = NULL; conn = BRYMEN_BC86X; for (l = options; l; l = l->next) { @@ -71,7 +70,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->model = g_strdup("BM869"); devc = g_malloc0(sizeof(struct dev_context)); sdi->priv = devc; - sdi->driver = di; sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P2"); @@ -80,11 +78,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sr_sw_limits_init(&devc->sw_limits); - drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); } - return devices; + return std_scan_complete(di, devices); } static int dev_open(struct sr_dev_inst *sdi) @@ -98,9 +95,7 @@ static int dev_open(struct sr_dev_inst *sdi) usb = sdi->conn; devc = sdi->priv; - if ((ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb)) == SR_OK) - sdi->status = SR_ST_ACTIVE; - else + if ((ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb)) < 0) return SR_ERR; /* Detach kernel drivers which grabbed this device (if any). */ @@ -125,7 +120,7 @@ static int dev_open(struct sr_dev_inst *sdi) } sr_dbg("Successfully claimed interface 0."); - return ret; + return SR_OK; } static int dev_close(struct sr_dev_inst *sdi) @@ -134,32 +129,23 @@ static int dev_close(struct sr_dev_inst *sdi) struct dev_context *devc; int ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - usb = sdi->conn; devc = sdi->priv; if ((ret = libusb_release_interface(usb->devhdl, 0))) sr_err("Failed to release interface 0: %s.\n", libusb_error_name(ret)); - else - sr_dbg("Successfully released interface 0.\n"); if (!ret && devc->detached_kernel_driver) { - if ((ret = libusb_attach_kernel_driver(usb->devhdl, 0))) { + if ((ret = libusb_attach_kernel_driver(usb->devhdl, 0))) sr_err("Failed to attach kernel driver: %s.\n", libusb_error_name(ret)); - } else { + else devc->detached_kernel_driver = 0; - sr_dbg("Successfully attached kernel driver.\n"); - } } libusb_close(usb->devhdl); - sdi->status = SR_ST_INACTIVE; - - return ret; + return (ret == 0) ? SR_OK : SR_ERR; } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -179,9 +165,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd (void)cg; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; return sr_sw_limits_config_set(&devc->sw_limits, key, data); @@ -213,14 +196,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) { struct dev_context *devc; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->sw_limits); - std_session_send_df_header(sdi, LOG_PREFIX); + std_session_send_df_header(sdi); sr_session_source_add(sdi->session, -1, 0, 10, brymen_bm86x_receive_data, (void *)sdi); @@ -230,10 +210,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - - std_session_send_df_end(sdi, LOG_PREFIX); + std_session_send_df_end(sdi); sr_session_source_remove(sdi->session, -1);