]> sigrok.org Git - libsigrok.git/blobdiff - hardware/link-mso19/link-mso19.c
Shorten probe_names[] arrays everywhere.
[libsigrok.git] / hardware / link-mso19 / link-mso19.c
index 30449e08265ec8e722c004be6bec4c5d909b2dc3..40e8d9e3ed802456cce81902494cb8be7465ee63 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"
@@ -54,18 +54,11 @@ static const int hwcaps[] = {
  * See also: http://www.linkinstruments.com/images/mso19_1113.gif
  */
 static const char *probe_names[NUM_PROBES + 1] = {
-       "0",
-       "1",
-       "2",
-       "3",
-       "4",
-       "5",
-       "6",
-       "7",
+       "0", "1", "2", "3", "4", "5", "6", "7",
        NULL,
 };
 
-static uint64_t supported_samplerates[] = {
+static const uint64_t supported_samplerates[] = {
        SR_HZ(100),
        SR_HZ(200),
        SR_HZ(500),
@@ -89,7 +82,7 @@ static uint64_t supported_samplerates[] = {
        0,
 };
 
-static struct sr_samplerates samplerates = {
+static const struct sr_samplerates samplerates = {
        0,
        0,
        0,
@@ -111,7 +104,7 @@ static int mso_send_control_message(struct sr_dev_inst *sdi,
                goto ret;
 
        if (!(buf = g_try_malloc(s))) {
-               sr_err("mso19: %s: buf malloc failed", __func__);
+               sr_err("Failed to malloc message buffer.");
                ret = SR_ERR_MALLOC;
                goto ret;
        }
@@ -151,7 +144,7 @@ static int mso_reset_adc(struct sr_dev_inst *sdi)
        ops[1] = mso_trans(REG_CTL1, ctx->ctlbase1);
        ctx->ctlbase1 |= BIT_CTL1_ADC_UNKNOWN4;
 
-       sr_dbg("mso19: Requesting ADC reset");
+       sr_dbg("Requesting ADC reset.");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -163,7 +156,7 @@ static int mso_reset_fsm(struct sr_dev_inst *sdi)
        ctx->ctlbase1 |= BIT_CTL1_RESETFSM;
        ops[0] = mso_trans(REG_CTL1, ctx->ctlbase1);
 
-       sr_dbg("mso19: Requesting ADC reset");
+       sr_dbg("Requesting ADC reset.");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -177,7 +170,7 @@ static int mso_toggle_led(struct sr_dev_inst *sdi, int state)
                ctx->ctlbase1 |= BIT_CTL1_LED;
        ops[0] = mso_trans(REG_CTL1, ctx->ctlbase1);
 
-       sr_dbg("mso19: Requesting LED toggle");
+       sr_dbg("Requesting LED toggle.");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -187,7 +180,7 @@ static int mso_check_trigger(struct sr_dev_inst *sdi, uint8_t *info)
        char buf[1];
        int ret;
 
-       sr_dbg("mso19: Requesting trigger state");
+       sr_dbg("Requesting trigger state.");
        ret = mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
        if (info == NULL || ret != SR_OK)
                return ret;
@@ -197,7 +190,7 @@ static int mso_check_trigger(struct sr_dev_inst *sdi, uint8_t *info)
                ret = SR_ERR;
        *info = buf[0];
 
-       sr_dbg("mso19: Trigger state is: 0x%x", *info);
+       sr_dbg("Trigger state is: 0x%x.", *info);
        return ret;
 }
 
@@ -205,7 +198,7 @@ static int mso_read_buffer(struct sr_dev_inst *sdi)
 {
        uint16_t ops[] = { mso_trans(REG_BUFFER, 0) };
 
-       sr_dbg("mso19: Requesting buffer dump");
+       sr_dbg("Requesting buffer dump.");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -218,7 +211,7 @@ static int mso_arm(struct sr_dev_inst *sdi)
                mso_trans(REG_CTL1, ctx->ctlbase1),
        };
 
-       sr_dbg("mso19: Requesting trigger arm");
+       sr_dbg("Requesting trigger arm.");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -230,7 +223,7 @@ static int mso_force_capture(struct sr_dev_inst *sdi)
                mso_trans(REG_CTL1, ctx->ctlbase1),
        };
 
-       sr_dbg("mso19: Requesting forced capture");
+       sr_dbg("Requesting forced capture.");
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -243,7 +236,7 @@ static int mso_dac_out(struct sr_dev_inst *sdi, uint16_t val)
                mso_trans(REG_CTL1, ctx->ctlbase1 | BIT_CTL1_RESETADC),
        };
 
-       sr_dbg("mso19: Setting dac word to 0x%x", val);
+       sr_dbg("Setting dac word to 0x%x.", val);
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -254,7 +247,7 @@ static int mso_clkrate_out(struct sr_dev_inst *sdi, uint16_t val)
                mso_trans(REG_CLKRATE2, val & 0xff),
        };
 
-       sr_dbg("mso19: Setting clkrate word to 0x%x", val);
+       sr_dbg("Setting clkrate word to 0x%x.", val);
        return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops));
 }
 
@@ -401,7 +394,14 @@ static int mso_parse_serial(const char *iSerial, const char *iProduct,
        return SR_OK;
 }
 
-static int hw_init(const char *devinfo)
+static int hw_init(struct sr_context *sr_ctx)
+{
+       /* Nothing to do. */
+
+       return SR_OK;
+}
+
+static int hw_scan(void)
 {
        struct sr_dev_inst *sdi;
        int devcnt = 0;
@@ -410,8 +410,6 @@ static int hw_init(const char *devinfo)
        struct udev_list_entry *devs, *dev_list_entry;
        struct context *ctx;
 
-       devinfo = devinfo;
-
        /* It's easier to map usb<->serial using udev */
        /*
         * FIXME: On windows we can get the same information from the
@@ -419,7 +417,7 @@ static int hw_init(const char *devinfo)
         */
        udev = udev_new();
        if (!udev) {
-               sr_err("mso19: Failed to initialize udev.");
+               sr_err("Failed to initialize udev.");
                goto ret;
        }
        enumerate = udev_enumerate_new(udev);
@@ -439,7 +437,7 @@ static int hw_init(const char *devinfo)
                parent = udev_device_get_parent_with_subsystem_devtype(
                                dev, "usb", "usb_device");
                if (!parent) {
-                       sr_err("mso19: Unable to find parent usb device for %s",
+                       sr_err("Unable to find parent usb device for %s",
                               sysname);
                        continue;
                }
@@ -458,7 +456,7 @@ static int hw_init(const char *devinfo)
                s = strcspn(iProduct, " ");
                if (s > sizeof(product) ||
                                strlen(iProduct) - s > sizeof(manufacturer)) {
-                       sr_err("mso19: Could not parse iProduct: %s", iProduct);
+                       sr_err("Could not parse iProduct: %s.", iProduct);
                        continue;
                }
                strncpy(product, iProduct, s);
@@ -466,12 +464,12 @@ static int hw_init(const char *devinfo)
                strcpy(manufacturer, iProduct + s);
 
                if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
-                       sr_err("mso19: %s: ctx malloc failed", __func__);
+                       sr_err("Context malloc failed.");
                        continue; /* TODO: Errors handled correctly? */
                }
 
                if (mso_parse_serial(iSerial, iProduct, ctx) != SR_OK) {
-                       sr_err("mso19: Invalid iSerial: %s", iSerial);
+                       sr_err("Invalid iSerial: %s.", iSerial);
                        goto err_free_ctx;
                }
                sprintf(hwrev, "r%d", ctx->hwrev);
@@ -491,7 +489,7 @@ static int hw_init(const char *devinfo)
                sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING,
                                      manufacturer, product, hwrev);
                if (!sdi) {
-                       sr_err("mso19: Unable to create device instance for %s",
+                       sr_err("Unable to create device instance for %s",
                               sysname);
                        goto err_free_ctx;
                }
@@ -531,7 +529,7 @@ static int hw_cleanup(void)
        for (l = dev_insts; l; l = l->next) {
                if (!(sdi = l->data)) {
                        /* Log error, but continue cleaning up the rest. */
-                       sr_err("mso19: %s: sdi was NULL, continuing", __func__);
+                       sr_err("%s: sdi was NULL, continuing", __func__);
                        ret = SR_ERR_BUG;
                        continue;
                }
@@ -555,7 +553,7 @@ static int hw_dev_open(int dev_index)
                return ret;
 
        ctx = sdi->priv;
-       sdi->serial->fd = serial_open(sdi->serial->port, O_RDWR);
+       sdi->serial->fd = serial_open(sdi->serial->port, SERIAL_RDWR);
        if (sdi->serial->fd == -1)
                return ret;
 
@@ -568,21 +566,19 @@ static int hw_dev_open(int dev_index)
        /* FIXME: discard serial buffer */
 
        mso_check_trigger(sdi, &ctx->trigger_state);
-       sr_dbg("mso19: trigger state: 0x%x", ctx->trigger_state);
+       sr_dbg("Trigger state: 0x%x.", ctx->trigger_state);
 
        ret = mso_reset_adc(sdi);
        if (ret != SR_OK)
                return ret;
 
        mso_check_trigger(sdi, &ctx->trigger_state);
-       sr_dbg("mso19: trigger state: 0x%x", ctx->trigger_state);
+       sr_dbg("Trigger state: 0x%x.", ctx->trigger_state);
 
 //     ret = mso_reset_fsm(sdi);
 //     if (ret != SR_OK)
 //             return ret;
 
-       sr_dbg("mso19: Finished %s", __func__);
-
 //     return SR_ERR;
        return SR_OK;
 }
@@ -592,7 +588,7 @@ static int hw_dev_close(int dev_index)
        struct sr_dev_inst *sdi;
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
-               sr_err("mso19: %s: sdi was NULL", __func__);
+               sr_err("%s: sdi was NULL", __func__);
                return SR_ERR_BUG;
        }
 
@@ -603,7 +599,6 @@ static int hw_dev_close(int dev_index)
                sdi->status = SR_ST_INACTIVE;
        }
 
-       sr_dbg("mso19: finished %s", __func__);
        return SR_OK;
 }
 
@@ -655,7 +650,7 @@ 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;
 
@@ -664,7 +659,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:
@@ -691,7 +686,6 @@ static int receive_data(int fd, int revents, void *cb_data)
        double analog_out[1024];
        size_t i, s;
 
-       /* Avoid compiler warnings. */
        (void)revents;
 
        s = serial_read(fd, in, sizeof(in));
@@ -827,7 +821,6 @@ static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
 {
        struct sr_datafeed_packet packet;
 
-       /* Avoid compiler warnings. */
        (void)dev_index;
 
        packet.type = SR_DF_END;
@@ -842,6 +835,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,