]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/beaglelogic/api.c
hantek-4032l: Initial driver skeleton.
[libsigrok.git] / src / hardware / beaglelogic / api.c
index 5527dcea46a28354e6fc984a740e406cba9101ed..5a7068c4407020297543d0c56726a2941f7bbac1 100644 (file)
@@ -59,20 +59,6 @@ static const uint64_t samplerates[] = {
        SR_HZ(1),
 };
 
-static struct dev_context *beaglelogic_devc_alloc(void)
-{
-       struct dev_context *devc;
-
-       devc = g_malloc0(sizeof(struct dev_context));
-
-       /* Default non-zero values (if any) */
-       devc->fd = -1;
-       devc->limit_samples = (uint64_t)10000000;
-       devc->tcp_buffer = 0;
-
-       return devc;
-}
-
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        GSList *l;
@@ -93,7 +79,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        }
 
        /* Probe for /dev/beaglelogic if not connecting via TCP */
-       if (conn == NULL) {
+       if (!conn) {
                if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS))
                        return NULL;
        } else {
@@ -110,19 +96,21 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                }
        }
 
-       if (maxch > 8)
-               maxch = NUM_CHANNELS;
-       else
-               maxch = 8;
+       maxch = (maxch > 8) ? NUM_CHANNELS : 8;
 
        sdi = g_new0(struct sr_dev_inst, 1);
        sdi->status = SR_ST_INACTIVE;
        sdi->model = g_strdup("BeagleLogic");
        sdi->version = g_strdup("1.0");
 
-       devc = beaglelogic_devc_alloc();
+       devc = g_malloc0(sizeof(struct dev_context));
 
-       if (conn == NULL) {
+       /* Default non-zero values (if any) */
+       devc->fd = -1;
+       devc->limit_samples = (uint64_t)10000000;
+       devc->tcp_buffer = 0;
+
+       if (!conn) {
                devc->beaglelogic = &beaglelogic_native_ops;
                sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE);
        } else {
@@ -141,6 +129,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                sr_info("BeagleLogic device found at %s : %s",
                        devc->address, devc->port);
        }
+
        /* Fill the channels */
        for (i = 0; i < maxch; i++)
                sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
@@ -149,6 +138,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        sdi->priv = devc;
 
        return std_scan_complete(di, g_slist_append(NULL, sdi));
+
 err_free:
        g_free(sdi->model);
        g_free(sdi->version);
@@ -337,9 +327,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        devc->beaglelogic->set_sampleunit(devc);
 
        /* If continuous sampling, set the limit_samples to max possible value */
-       if (devc->triggerflags == BL_TRIGGERFLAGS_CONTINUOUS) {
+       if (devc->triggerflags == BL_TRIGGERFLAGS_CONTINUOUS)
                devc->limit_samples = (uint64_t)-1;
-       }
 
        /* Configure triggers & send header packet */
        if ((trigger = sr_session_trigger_get(sdi->session))) {