X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fvictor-dmm%2Fapi.c;h=8e8f0276e60c8a97b8fd7f0083966004da19e10c;hb=62974b235a5c5aeaacad5d28a50aef39f528dccd;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..8e8f0276 100644
--- a/src/hardware/victor-dmm/api.c
+++ b/src/hardware/victor-dmm/api.c
@@ -17,11 +17,12 @@
* along with this program. If not, see .
*/
+#include
#include
#include
#include
#include
-#include "libsigrok.h"
+#include
#include "libsigrok-internal.h"
#include "protocol.h"
@@ -29,15 +30,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 +50,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;
@@ -62,21 +63,17 @@ static GSList *scan(GSList *options)
struct libusb_device_descriptor des;
libusb_device **devlist;
GSList *devices;
- int ret, i;
+ int i;
char connection_id[64];
(void)options;
- drvc = di->priv;
+ drvc = di->context;
devices = NULL;
libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
for (i = 0; devlist[i]; i++) {
- if ((ret = libusb_get_device_descriptor(devlist[i], &des)) != 0) {
- sr_warn("Failed to get device descriptor: %s",
- libusb_error_name(ret));
- continue;
- }
+ libusb_get_device_descriptor(devlist[i], &des);
if (des.idVendor != VICTOR_VID || des.idProduct != VICTOR_PID)
continue;
@@ -92,7 +89,6 @@ static GSList *scan(GSList *options)
sdi->priv = devc;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
-
sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
sdi->inst_type = SR_INST_USB;
@@ -105,20 +101,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 +161,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 +183,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 +224,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 +282,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 +326,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 +338,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 +365,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 +376,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 +391,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 +412,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 +446,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,
};