X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Flascar-el-usb%2Fapi.c;h=40a4164943282cd90e076a0b3cf8865b1169a798;hb=41812aca436805b0614f2a8f31cf2f8ce494aea0;hp=5c615cceb2eafb37fc4f753340685d94e5dfb6da;hpb=a0e0bb4149081eda06714f1158639f2dadcfa9d8;p=libsigrok.git diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index 5c615cce..40a41649 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -24,7 +24,6 @@ #include "protocol.h" SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info; -static struct sr_dev_driver *di = &lascar_el_usb_driver_info; static const uint32_t scanopts[] = { SR_CONF_CONN, @@ -33,16 +32,17 @@ static const uint32_t scanopts[] = { static const uint32_t devopts[] = { SR_CONF_THERMOMETER, SR_CONF_HYGROMETER, - SR_CONF_DATALOG, - SR_CONF_LIMIT_SAMPLES, + SR_CONF_CONN | SR_CONF_GET, + SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, + SR_CONF_DATALOG | SR_CONF_GET | SR_CONF_SET, }; -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 sr_dev_inst *sdi; @@ -51,7 +51,7 @@ static GSList *scan(GSList *options) GSList *usb_devices, *devices, *l; const char *conn; - drvc = di->priv; + drvc = di->context; conn = NULL; for (l = options; l; l = l->next) { @@ -88,18 +88,19 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { - return ((struct drv_context *)(di->priv))->instances; + return ((struct drv_context *)(di->context))->instances; } static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc; struct sr_usb_dev_inst *usb; int ret; - if (!(drvc = di->priv)) { + if (!(drvc = di->context)) { sr_err("Driver was not initialized."); return SR_ERR; } @@ -120,9 +121,10 @@ static int dev_open(struct sr_dev_inst *sdi) 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) { + if (!di->context) { sr_err("Driver was not initialized."); return SR_ERR; } @@ -141,19 +143,17 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { int ret; struct drv_context *drvc; - if (!(drvc = di->priv)) + if (!(drvc = di->context)) /* Can get called on an unused driver, doesn't matter. */ return SR_OK; - ret = std_dev_clear(di, NULL); g_free(drvc); - di->priv = NULL; return ret; } @@ -197,6 +197,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; int ret; @@ -205,7 +206,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!di->priv) { + if (!di->context) { sr_err("Driver was not initialized."); return SR_ERR; } @@ -214,18 +215,13 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd ret = SR_OK; switch (key) { case SR_CONF_DATALOG: - if (g_variant_get_boolean(data)) { - /* Start logging. */ + if (g_variant_get_boolean(data)) ret = lascar_start_logging(sdi); - } else { - /* Stop logging. */ + else ret = lascar_stop_logging(sdi); - } break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); - sr_dbg("Setting sample limit to %" PRIu64 ".", - devc->limit_samples); break; default: ret = SR_ERR_NA; @@ -256,7 +252,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * return SR_OK; } -static void mark_xfer(struct libusb_transfer *xfer) +static void LIBUSB_CALL mark_xfer(struct libusb_transfer *xfer) { if (xfer->status == LIBUSB_TRANSFER_COMPLETED) @@ -304,11 +300,11 @@ static int lascar_proc_config(const struct sr_dev_inst *sdi) devc->temp_unit = devc->config[0x2e] | (devc->config[0x2f] << 8); if (devc->temp_unit != 0 && devc->temp_unit != 1) { sr_dbg("invalid temperature unit %d", devc->temp_unit); - /* Default to Celcius, we're all adults here. */ + /* Default to Celsius, we're all adults here. */ devc->temp_unit = 0; } else sr_dbg("temperature unit is %s", devc->temp_unit - ? "Fahrenheit" : "Celcius"); + ? "Fahrenheit" : "Celsius"); break; case LOG_CO: devc->sample_size = 2; @@ -328,6 +324,7 @@ static int lascar_proc_config(const struct sr_dev_inst *sdi) static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; struct sr_datafeed_packet packet; struct sr_datafeed_meta meta; struct sr_config *src; @@ -343,12 +340,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - if (!di->priv) { + if (!di->context) { sr_err("Driver was not initialized."); return SR_ERR; } - drvc = di->priv; + drvc = di->context; devc = sdi->priv; usb = sdi->conn; devc->cb_data = cb_data; @@ -387,14 +384,13 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) libusb_control_transfer(usb->devhdl, LIBUSB_REQUEST_TYPE_VENDOR, 0x02, 0x0001, 0x00, NULL, 0, 50); - /* Flush input. The F321 requires this. */ while (libusb_bulk_transfer(usb->devhdl, LASCAR_EP_IN, resp, 256, &ret, 5) == 0 && ret > 0) ; libusb_fill_bulk_transfer(xfer_in, usb->devhdl, LASCAR_EP_IN, - resp, sizeof(resp), mark_xfer, 0, 10000); + resp, sizeof(resp), mark_xfer, 0, BULK_XFER_TIMEOUT); if (libusb_submit_transfer(xfer_in) != 0) { libusb_free_transfer(xfer_in); libusb_free_transfer(xfer_out); @@ -415,7 +411,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) tv.tv_sec = 0; tv.tv_usec = 0; while (!xfer_in->user_data || !xfer_out->user_data) { - g_usleep(5000); + g_usleep(SLEEP_US_LONG); libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); } if (xfer_in->user_data != GINT_TO_POINTER(1) || @@ -437,7 +433,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) usb_source_add(sdi->session, drvc->sr_ctx, 100, lascar_el_usb_handle_events, (void *)sdi); - buf = g_try_malloc(4096); + buf = g_malloc(4096); libusb_fill_bulk_transfer(xfer_in, usb->devhdl, LASCAR_EP_IN, buf, 4096, lascar_el_usb_receive_transfer, cb_data, 100); if ((ret = libusb_submit_transfer(xfer_in) != 0)) { @@ -452,9 +448,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) SR_PRIV int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; (void)cb_data; - if (!di->priv) { + if (!di->context) { sr_err("Driver was not initialized."); return SR_ERR; } @@ -486,5 +483,5 @@ SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, };