]> sigrok.org Git - libsigrok.git/blobdiff - hardware/link-mso19/link-mso19.c
sr: moved sigrok.h so libsigrok/libsigrok.h
[libsigrok.git] / hardware / link-mso19 / link-mso19.c
index c3dc19bd934865109902f7d1d39f57a60d646158..7c25817bebab29ab939ad7632d9547d919bddb61 100644 (file)
@@ -28,8 +28,8 @@
 #include <glib.h>
 #include <libudev.h>
 #include <arpa/inet.h>
-#include "sigrok.h"
-#include "sigrok-internal.h"
+#include "libsigrok.h"
+#include "libsigrok-internal.h"
 #include "link-mso19.h"
 
 #define USB_VENDOR "3195"
@@ -37,7 +37,7 @@
 
 #define NUM_PROBES 8
 
-static int hwcaps[] = {
+static const int hwcaps[] = {
        SR_HWCAP_LOGIC_ANALYZER,
 //     SR_HWCAP_OSCILLOSCOPE,
 //     SR_HWCAP_PAT_GENERATOR,
@@ -48,6 +48,11 @@ static int hwcaps[] = {
        0,
 };
 
+/*
+ * Probes are numbered 0 to 7.
+ *
+ * See also: http://www.linkinstruments.com/images/mso19_1113.gif
+ */
 static const char *probe_names[NUM_PROBES + 1] = {
        "0",
        "1",
@@ -60,7 +65,7 @@ static const char *probe_names[NUM_PROBES + 1] = {
        NULL,
 };
 
-static uint64_t supported_samplerates[] = {
+static const uint64_t supported_samplerates[] = {
        SR_HZ(100),
        SR_HZ(200),
        SR_HZ(500),
@@ -84,10 +89,10 @@ static uint64_t supported_samplerates[] = {
        0,
 };
 
-static struct sr_samplerates samplerates = {
-       SR_HZ(100),
-       SR_MHZ(200),
-       SR_HZ(0),
+static const struct sr_samplerates samplerates = {
+       0,
+       0,
+       0,
        supported_samplerates,
 };
 
@@ -588,7 +593,7 @@ static int hw_dev_close(int dev_index)
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
                sr_err("mso19: %s: sdi was NULL", __func__);
-               return SR_ERR; /* TODO: SR_ERR_ARG? */
+               return SR_ERR_BUG;
        }
 
        /* TODO */
@@ -602,11 +607,11 @@ static int hw_dev_close(int dev_index)
        return SR_OK;
 }
 
-static void *hw_dev_info_get(int dev_index, int dev_info_id)
+static const void *hw_dev_info_get(int dev_index, int dev_info_id)
 {
        struct sr_dev_inst *sdi;
        struct context *ctx;
-       void *info = NULL;
+       const void *info = NULL;
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
                return NULL;
@@ -645,12 +650,12 @@ static int hw_dev_status_get(int dev_index)
        return sdi->status;
 }
 
-static int *hw_hwcap_get_all(void)
+static const int *hw_hwcap_get_all(void)
 {
        return hwcaps;
 }
 
-static int hw_dev_config_set(int dev_index, int hwcap, void *value)
+static int hw_dev_config_set(int dev_index, int hwcap, const void *value)
 {
        struct sr_dev_inst *sdi;
 
@@ -659,7 +664,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value)
 
        switch (hwcap) {
        case SR_HWCAP_SAMPLERATE:
-               return mso_configure_rate(sdi, *(uint64_t *) value);
+               return mso_configure_rate(sdi, *(const uint64_t *) value);
        case SR_HWCAP_PROBECONFIG:
        case SR_HWCAP_LIMIT_SAMPLES:
        default:
@@ -676,9 +681,9 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value)
 #define MSO_TRIGGER_DATAREADY  '6'
 
 /* FIXME: Pass errors? */
-static int receive_data(int fd, int revents, void *user_data)
+static int receive_data(int fd, int revents, void *cb_data)
 {
-       struct sr_dev_inst *sdi = user_data;
+       struct sr_dev_inst *sdi = cb_data;
        struct context *ctx = sdi->priv;
        struct sr_datafeed_packet packet;
        struct sr_datafeed_logic logic;
@@ -686,7 +691,8 @@ static int receive_data(int fd, int revents, void *user_data)
        double analog_out[1024];
        size_t i, s;
 
-       revents = revents;
+       /* Avoid compiler warnings. */
+       (void)revents;
 
        s = serial_read(fd, in, sizeof(in));
        if (s <= 0)
@@ -726,7 +732,7 @@ static int receive_data(int fd, int revents, void *user_data)
        logic.length = 1024;
        logic.unitsize = 1;
        logic.data = logic_out;
-       sr_session_bus(ctx->session_id, &packet);
+       sr_session_send(ctx->session_dev_id, &packet);
 
        // Dont bother fixing this yet, keep it "old style"
        /*
@@ -734,16 +740,16 @@ static int receive_data(int fd, int revents, void *user_data)
        packet.length = 1024;
        packet.unitsize = sizeof(double);
        packet.payload = analog_out;
-       sr_session_bus(ctx->session_id, &packet);
+       sr_session_send(ctx->session_dev_id, &packet);
        */
 
        packet.type = SR_DF_END;
-       sr_session_bus(ctx->session_id, &packet);
+       sr_session_send(ctx->session_dev_id, &packet);
 
        return TRUE;
 }
 
-static int hw_dev_acquisition_start(int dev_index, gpointer session_dev_id)
+static int hw_dev_acquisition_start(int dev_index, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct context *ctx;
@@ -801,7 +807,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_dev_id)
        if (ret != SR_OK)
                return ret;
 
-       ctx->session_id = session_dev_id;
+       ctx->session_dev_id = cb_data;
        sr_source_add(sdi->serial->fd, G_IO_IN, -1, receive_data, sdi);
 
        packet.type = SR_DF_HEADER;
@@ -811,25 +817,26 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_dev_id)
        header.samplerate = ctx->cur_rate;
        // header.num_analog_probes = 1;
        header.num_logic_probes = 8;
-       sr_session_bus(session_dev_id, &packet);
+       sr_session_send(ctx->session_dev_id, &packet);
 
        return ret;
 }
 
-/* FIXME */
-static int hw_dev_acquisition_stop(int dev_index, gpointer session_dev_id)
+/* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
+static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
 {
        struct sr_datafeed_packet packet;
 
-       dev_index = dev_index;
+       /* Avoid compiler warnings. */
+       (void)dev_index;
 
        packet.type = SR_DF_END;
-       sr_session_bus(session_dev_id, &packet);
+       sr_session_send(cb_data, &packet);
 
        return SR_OK;
 }
 
-SR_PRIV struct sr_dev_plugin link_mso19_plugin_info = {
+SR_PRIV struct sr_dev_driver link_mso19_driver_info = {
        .name = "link-mso19",
        .longname = "Link Instruments MSO-19",
        .api_version = 1,