From: Bert Vermeulen Date: Thu, 5 Jul 2012 09:27:48 +0000 (+0200) Subject: sr: add new driver API call: scan() X-Git-Tag: dsupstream~851 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=61136ea6035778f2894a1e32b78f94a0640a5a91;p=libsigrok.git sr: add new driver API call: scan() This changes the semantics of the init() call as well. That now only initializes the driver -- an administrative affair, no hardware gets touched during this call. It returns a standard SR_OK or SR_ERR* code. The scan() call does a discovery run for devices it knows, and returns the number found. It can be called at any time. --- diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 4884afde..097a5648 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -406,6 +406,14 @@ static int bin2bitbang(const char *filename, } static int hw_init(void) +{ + + /* Nothing to do. */ + + return SR_OK; +} + +static int hw_scan(void) { struct sr_dev_inst *sdi; struct context *ctx; @@ -1437,6 +1445,7 @@ SR_PRIV struct sr_dev_driver asix_sigma_driver_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, + .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .dev_info_get = hw_dev_info_get, diff --git a/hardware/chronovu-la8/api.c b/hardware/chronovu-la8/api.c index 5a4ddbbe..08348e72 100644 --- a/hardware/chronovu-la8/api.c +++ b/hardware/chronovu-la8/api.c @@ -40,6 +40,14 @@ static const uint16_t usb_pids[] = { static int hw_dev_acquisition_stop(int dev_index, void *cb_data); static int hw_init(void) +{ + + /* Nothing to do. */ + + return SR_OK; +} + +static int hw_scan(void) { int ret; struct sr_dev_inst *sdi; @@ -542,6 +550,7 @@ SR_PRIV struct sr_dev_driver chronovu_la8_driver_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, + .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .dev_info_get = hw_dev_info_get, diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index ed8c6f4b..175e7263 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -141,6 +141,14 @@ static int thread_running; static int hw_dev_acquisition_stop(int dev_index, void *cb_data); static int hw_init(void) +{ + + /* Nothing to do. */ + + return SR_OK; +} + +static int hw_scan(void) { struct sr_dev_inst *sdi; @@ -510,6 +518,7 @@ SR_PRIV struct sr_dev_driver demo_driver_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, + .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .dev_info_get = hw_dev_info_get, diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index 736490fe..4344cf24 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -383,22 +383,27 @@ static struct context *fx2lafw_dev_new(void) */ static int hw_init(void) +{ + + if (libusb_init(&usb_context) != 0) { + sr_warn("fx2lafw: Failed to initialize libusb."); + return SR_ERR; + } + + return SR_OK; +} + +static int hw_scan(void) { struct sr_dev_inst *sdi; struct libusb_device_descriptor des; const struct fx2lafw_profile *prof; struct context *ctx; libusb_device **devlist; - int ret; - int devcnt = 0; - int i, j; - - if (libusb_init(&usb_context) != 0) { - sr_warn("fx2lafw: Failed to initialize libusb."); - return 0; - } + int devcnt, ret, i, j; /* Find all fx2lafw compatible devices and upload firmware to them. */ + devcnt = 0; libusb_get_device_list(usb_context, &devlist); for (i = 0; devlist[i]; i++) { @@ -1009,6 +1014,7 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, + .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .dev_info_get = hw_dev_info_get, diff --git a/hardware/genericdmm/api.c b/hardware/genericdmm/api.c index ca50a728..4a5da744 100644 --- a/hardware/genericdmm/api.c +++ b/hardware/genericdmm/api.c @@ -58,15 +58,22 @@ SR_PRIV libusb_context *genericdmm_usb_context = NULL; static int hw_init(void) { - struct sr_dev_inst *sdi; - struct context *ctx; - int devcnt = 0; if (libusb_init(&genericdmm_usb_context) != 0) { sr_err("genericdmm: Failed to initialize USB."); - return 0; + return SR_ERR; } + + return SR_OK; +} + +static int hw_scan(void) +{ + struct sr_dev_inst *sdi; + struct context *ctx; + int devcnt = 0; + if (!(ctx = g_try_malloc0(sizeof(struct context)))) { sr_err("genericdmm: ctx malloc failed."); return 0; @@ -610,6 +617,7 @@ SR_PRIV struct sr_dev_driver genericdmm_driver_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, + .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .dev_info_get = hw_dev_info_get, diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index dc8dbef8..40303fee 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -201,25 +201,31 @@ static int configure_probes(struct context *ctx, const GSList *probes) } static int hw_init(void) +{ + + if (libusb_init(&usb_context) != 0) { + sr_err("hantek-dso: Failed to initialize USB."); + return SR_ERR; + } + + return SR_OK; +} + +static int hw_scan(void) { struct sr_dev_inst *sdi; struct libusb_device_descriptor des; const struct dso_profile *prof; struct context *ctx; libusb_device **devlist; - int err, devcnt, i, j; - - if (libusb_init(&usb_context) != 0) { - sr_err("hantek-dso: Failed to initialize USB."); - return 0; - } + int devcnt, ret, i, j; /* Find all Hantek DSO devices and upload firmware to all of them. */ devcnt = 0; libusb_get_device_list(usb_context, &devlist); for (i = 0; devlist[i]; i++) { - if ((err = libusb_get_device_descriptor(devlist[i], &des))) { - sr_err("hantek-dso: failed to get device descriptor: %d", err); + if ((ret = libusb_get_device_descriptor(devlist[i], &des))) { + sr_err("hantek-dso: failed to get device descriptor: %d", ret); continue; } @@ -856,6 +862,7 @@ SR_PRIV struct sr_dev_driver hantek_dso_driver_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, + .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .dev_info_get = hw_dev_info_get, diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index 4b3d9218..c264b3cc 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -402,6 +402,14 @@ static int mso_parse_serial(const char *iSerial, const char *iProduct, } static int hw_init(void) +{ + + /* Nothing to do. */ + + return SR_OK; +} + +static int hw_scan(void) { struct sr_dev_inst *sdi; int devcnt = 0; @@ -840,6 +848,7 @@ SR_PRIV struct sr_dev_driver link_mso19_driver_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, + .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .dev_info_get = hw_dev_info_get, diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index 02afff33..bcbba5df 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -349,6 +349,14 @@ static struct sr_dev_inst *get_metadata(int fd) } static int hw_init(void) +{ + + /* Nothing to do. */ + + return SR_OK; +} + +static int hw_scan(void) { struct sr_dev_inst *sdi; struct context *ctx; @@ -1047,6 +1055,7 @@ SR_PRIV struct sr_dev_driver ols_driver_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, + .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .dev_info_get = hw_dev_info_get, diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index 25660af0..ac396ded 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -328,6 +328,14 @@ static int configure_probes(struct sr_dev_inst *sdi, const GSList *probes) */ static int hw_init(void) +{ + + /* Nothing to do. */ + + return SR_OK; +} + +static int hw_scan(void) { struct sr_dev_inst *sdi; struct libusb_device_descriptor des; @@ -737,6 +745,7 @@ SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, + .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .dev_info_get = hw_dev_info_get, diff --git a/libsigrok.h b/libsigrok.h index 695b360b..ccad393c 100644 --- a/libsigrok.h +++ b/libsigrok.h @@ -472,6 +472,7 @@ struct sr_dev_driver { int api_version; int (*init) (void); int (*cleanup) (void); + int (*scan) (void); /* Device-specific */ int (*dev_open) (int dev_index); diff --git a/session_driver.c b/session_driver.c index ed397a96..0b8c1ed2 100644 --- a/session_driver.c +++ b/session_driver.c @@ -151,7 +151,7 @@ static int hw_cleanup(void); static int hw_init(void) { - return 0; + return SR_OK; } /**