]> sigrok.org Git - libsigrok.git/blobdiff - hardware/chronovu-la8/chronovu-la8.c
sr/cli/gtk: Remove analog left-overs from API.
[libsigrok.git] / hardware / chronovu-la8 / chronovu-la8.c
index 05af43b96c52cc6613724a02402ed36b4a78467a..4560d69f47ed68f9539bb0a1892aad7722218da5 100644 (file)
@@ -21,8 +21,8 @@
 #include <ftdi.h>
 #include <glib.h>
 #include <string.h>
-#include <sigrok.h>
-#include <sigrok-internal.h>
+#include "sigrok.h"
+#include "sigrok-internal.h"
 
 #define USB_VENDOR_ID                  0x0403
 #define USB_PRODUCT_ID                 0x6001
 
 static GSList *device_instances = NULL;
 
+static const char *probe_names[NUM_PROBES + 1] = {
+       "0",
+       "1",
+       "2",
+       "3",
+       "4",
+       "5",
+       "6",
+       "7",
+       NULL,
+};
+
 struct la8 {
        /** FTDI device context (used by libftdi). */
        struct ftdi_context *ftdic;
@@ -48,9 +60,6 @@ struct la8 {
        /** The currently configured samplerate of the device. */
        uint64_t cur_samplerate;
 
-       /** period in picoseconds corresponding to the samplerate */
-       uint64_t period_ps;
-
        /** The current sampling limit (in ms). */
        uint64_t limit_msec;
 
@@ -470,19 +479,17 @@ static int hw_init(const char *deviceinfo)
        sr_spew("la8: entering %s", __func__);
 
        /* Avoid compiler errors. */
-       deviceinfo = deviceinfo;
+       (void)deviceinfo;
 
        /* Allocate memory for our private driver context. */
        if (!(la8 = g_try_malloc(sizeof(struct la8)))) {
                sr_err("la8: %s: struct la8 malloc failed", __func__);
-               ret = SR_ERR_MALLOC;
                goto err_free_nothing;
        }
 
        /* Set some sane defaults. */
        la8->ftdic = NULL;
        la8->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */
-       la8->period_ps = 10000;
        la8->limit_msec = 0;
        la8->limit_samples = 0;
        la8->session_id = NULL;
@@ -499,24 +506,21 @@ static int hw_init(const char *deviceinfo)
        /* Allocate memory where we'll store the de-mangled data. */
        if (!(la8->final_buf = g_try_malloc(SDRAM_SIZE))) {
                sr_err("la8: %s: final_buf malloc failed", __func__);
-               ret = SR_ERR_MALLOC;
                goto err_free_la8;
        }
 
        /* Allocate memory for the FTDI context (ftdic) and initialize it. */
        if (!(la8->ftdic = ftdi_new())) {
                sr_err("la8: %s: ftdi_new failed", __func__);
-               ret = SR_ERR; /* TODO: More specific error? */
                goto err_free_final_buf;
        }
 
        /* Check for the device and temporarily open it. */
        if ((ret = ftdi_usb_open_desc(la8->ftdic, USB_VENDOR_ID,
                        USB_PRODUCT_ID, USB_DESCRIPTION, NULL)) < 0) {
-               sr_err("la8: %s: ftdi_usb_open_desc: (%d) %s",
+               sr_dbg("la8: %s: ftdi_usb_open_desc: (%d) %s",
                       __func__, ret, ftdi_get_error_string(la8->ftdic));
                (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
-               ret = SR_ERR; /* TODO: More specific error? */
                goto err_free_ftdic;
        }
        sr_dbg("la8: found device");
@@ -526,7 +530,6 @@ static int hw_init(const char *deviceinfo)
                        USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION);
        if (!sdi) {
                sr_err("la8: %s: sr_device_instance_new failed", __func__);
-               ret = SR_ERR; /* TODO: More specific error? */
                goto err_close_ftdic;
        }
 
@@ -539,7 +542,6 @@ static int hw_init(const char *deviceinfo)
        /* Close device. We'll reopen it again when we need it. */
        (void) la8_close(la8); /* Log, but ignore errors. */
 
-       // return SR_OK; /* TODO */
        return 1;
 
 err_close_ftdic:
@@ -551,7 +553,7 @@ err_free_final_buf:
 err_free_la8:
        g_free(la8);
 err_free_nothing:
-       // return ret; /* TODO */
+
        return 0;
 }
 
@@ -637,7 +639,6 @@ static int set_samplerate(struct sr_device_instance *sdi, uint64_t samplerate)
 
        /* Set the new samplerate. */
        la8->cur_samplerate = samplerate;
-       la8->period_ps = 1000000000000 / samplerate;
 
        sr_dbg("la8: samplerate set to %" PRIu64 "Hz", la8->cur_samplerate);
 
@@ -690,11 +691,17 @@ static void hw_cleanup(void)
                        sr_warn("la8: %s: sdi was NULL, continuing", __func__);
                        continue;
                }
+#if 0
+               /*
+                * Fixes a segfault as it's free()d elsewhere already.
+                * TODO: Document who is supposed to free this, and when.
+                */
                if (sdi->priv != NULL)
                        free(sdi->priv);
                else
                        sr_warn("la8: %s: sdi->priv was NULL, nothing "
                                "to do", __func__);
+#endif
                sr_device_instance_free(sdi); /* Returns void. */
        }
        g_slist_free(device_instances); /* Returns void. */
@@ -726,6 +733,9 @@ static void *hw_get_device_info(int device_index, int device_info_id)
        case SR_DI_NUM_PROBES:
                info = GINT_TO_POINTER(NUM_PROBES);
                break;
+       case SR_DI_PROBE_NAMES:
+               info = probe_names;
+               break;
        case SR_DI_SAMPLERATES:
                fill_supported_samplerates_if_needed();
                info = &samplerates;
@@ -920,8 +930,6 @@ static void send_block_to_session_bus(struct la8 *la8, int block)
                sr_spew("la8: sending SR_DF_LOGIC packet (%d bytes) for "
                        "block %d", BS, block);
                packet.type = SR_DF_LOGIC;
-               packet.timeoffset = block * BS * la8->period_ps;
-               packet.duration = BS * la8->period_ps;
                packet.payload = &logic;
                logic.length = BS;
                logic.unitsize = 1;
@@ -945,8 +953,6 @@ static void send_block_to_session_bus(struct la8 *la8, int block)
                sr_spew("la8: sending pre-trigger SR_DF_LOGIC packet, "
                        "start = %d, length = %d", block * BS, trigger_point);
                packet.type = SR_DF_LOGIC;
-               packet.timeoffset = block * BS * la8->period_ps;
-               packet.duration = trigger_point * la8->period_ps;
                packet.payload = &logic;
                logic.length = trigger_point;
                logic.unitsize = 1;
@@ -958,8 +964,6 @@ static void send_block_to_session_bus(struct la8 *la8, int block)
        sr_spew("la8: sending SR_DF_TRIGGER packet, sample = %d",
                (block * BS) + trigger_point);
        packet.type = SR_DF_TRIGGER;
-       packet.timeoffset = (block * BS + trigger_point) * la8->period_ps;
-       packet.duration = 0;
        packet.payload = NULL;
        sr_session_bus(la8->session_id, &packet);
 
@@ -970,8 +974,6 @@ static void send_block_to_session_bus(struct la8 *la8, int block)
                        "start = %d, length = %d",
                        (block * BS) + trigger_point, BS - trigger_point);
                packet.type = SR_DF_LOGIC;
-               packet.timeoffset = (block * BS + trigger_point) * la8->period_ps;
-               packet.duration = (BS - trigger_point) * la8->period_ps;
                packet.payload = &logic;
                logic.length = BS - trigger_point;
                logic.unitsize = 1;
@@ -987,11 +989,11 @@ static int receive_data(int fd, int revents, void *session_data)
        struct la8 *la8;
 
        /* Avoid compiler errors. */
-       fd = fd;
-       revents = revents;
+       (void)fd;
+       (void)revents;
 
        if (!(sdi = session_data)) {
-               sr_err("la8: %s: user_data was NULL", __func__);
+               sr_err("la8: %s: session_data was NULL", __func__);
                return FALSE;
        }
 
@@ -1086,7 +1088,6 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        gettimeofday(&header.starttime, NULL);
        header.samplerate = la8->cur_samplerate;
        header.num_logic_probes = NUM_PROBES;
-       header.num_analog_probes = 0;
        sr_session_bus(session_data, &packet);
 
        /* Time when we should be done (for detecting trigger timeouts). */
@@ -1125,7 +1126,7 @@ static void hw_stop_acquisition(int device_index, gpointer session_data)
        sr_session_bus(session_data, &packet);
 }
 
-struct sr_device_plugin chronovu_la8_plugin_info = {
+SR_PRIV struct sr_device_plugin chronovu_la8_plugin_info = {
        .name = "chronovu-la8",
        .longname = "ChronoVu LA8",
        .api_version = 1,