X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fvictor-dmm%2Fapi.c;h=e82302618693c76f09de61eb89e847c9063785c8;hb=41812aca436805b0614f2a8f31cf2f8ce494aea0;hp=2552027cec4284f6c2bb382d7257b44997575495;hpb=5e23fcab889c62864b92aa3ad6902ce3e9f5be49;p=libsigrok.git diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 2552027c..e8230261 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -29,15 +29,15 @@ #define VICTOR_PID 0xd237 #define VICTOR_VENDOR "Victor" #define VICTOR_INTERFACE 0 -#define VICTOR_ENDPOINT LIBUSB_ENDPOINT_IN | 1 +#define VICTOR_ENDPOINT (LIBUSB_ENDPOINT_IN | 1) SR_PRIV struct sr_dev_driver victor_dmm_driver_info; -static struct sr_dev_driver *di = &victor_dmm_driver_info; static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static const uint32_t drvopts[] = { SR_CONF_MULTIMETER, }; + static const uint32_t scanopts[] = { SR_CONF_CONN, }; @@ -49,12 +49,12 @@ static const uint32_t devopts[] = { SR_CONF_CONN | SR_CONF_GET, }; -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 dev_context *devc; @@ -67,7 +67,7 @@ static GSList *scan(GSList *options) (void)options; - drvc = di->priv; + drvc = di->context; devices = NULL; libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); @@ -105,20 +105,21 @@ 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 drv_context *drvc = di->priv; + struct sr_dev_driver *di = sdi->driver; + struct drv_context *drvc = di->context; struct sr_usb_dev_inst *usb; libusb_device **devlist; int ret, i; char connection_id[64]; - if (!di->priv) { + if (!di->context) { sr_err("Driver was not initialized."); return SR_ERR; } @@ -164,9 +165,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; } @@ -185,19 +187,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; } @@ -228,40 +228,36 @@ 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; gint64 now; - int ret; (void)cg; 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; } devc = sdi->priv; - ret = SR_OK; + switch (key) { case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); now = g_get_monotonic_time() / 1000; devc->end_time = now + devc->limit_msec; - sr_dbg("Setting time limit to %" PRIu64 "ms.", - devc->limit_msec); 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; + return SR_ERR_NA; } - return ret; + return SR_OK; } static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -290,7 +286,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * return SR_OK; } -static void receive_transfer(struct libusb_transfer *transfer) +static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) { struct dev_context *devc; struct sr_dev_inst *sdi; @@ -334,9 +330,10 @@ static void receive_transfer(struct libusb_transfer *transfer) static int handle_events(int fd, int revents, void *cb_data) { struct dev_context *devc; - struct drv_context *drvc = di->priv; + struct drv_context *drvc; struct sr_datafeed_packet packet; struct sr_dev_inst *sdi; + struct sr_dev_driver *di; struct timeval tv; gint64 now; @@ -345,6 +342,8 @@ static int handle_events(int fd, int revents, void *cb_data) sdi = cb_data; devc = sdi->priv; + di = sdi->driver; + drvc = di->context; if (devc->limit_msec) { now = g_get_monotonic_time() / 1000; @@ -370,8 +369,9 @@ static int handle_events(int fd, int revents, void *cb_data) static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { + struct sr_dev_driver *di = sdi->driver; struct dev_context *devc; - struct drv_context *drvc = di->priv; + struct drv_context *drvc = di->context; struct sr_usb_dev_inst *usb; struct libusb_transfer *transfer; int ret; @@ -380,7 +380,7 @@ 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; } @@ -395,7 +395,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) usb_source_add(sdi->session, drvc->sr_ctx, 100, handle_events, (void *)sdi); - buf = g_try_malloc(DMM_DATA_SIZE); + buf = g_malloc(DMM_DATA_SIZE); transfer = libusb_alloc_transfer(0); /* Each transfer request gets 100ms to arrive before it's restarted. * The device only sends 1 transfer/second no matter how many @@ -416,9 +416,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) static 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; } @@ -449,5 +450,5 @@ SR_PRIV struct sr_dev_driver victor_dmm_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, };