]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/asix-sigma/asix-sigma.c
Channel names consistency fixes and simplifications.
[libsigrok.git] / src / hardware / asix-sigma / asix-sigma.c
index 3a15b2817531742ad590d9627ebb51f176e46e6a..1ca841e9aade53c7dc960c3e407b4a5b07c71d48 100644 (file)
@@ -39,7 +39,6 @@
 #define USB_MODEL_NAME                 "SIGMA"
 
 SR_PRIV struct sr_dev_driver asix_sigma_driver_info;
-static struct sr_dev_driver *di = &asix_sigma_driver_info;
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data);
 
 /*
@@ -71,13 +70,13 @@ static const char *channel_names[] = {
        "9", "10", "11", "12", "13", "14", "15", "16",
 };
 
-static const uint32_t devopts[] = {
+static const uint32_t drvopts[] = {
        SR_CONF_LOGIC_ANALYZER,
-       SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
-       SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
 };
 
-static const uint32_t devopts_global[] = {
+static const uint32_t devopts[] = {
+       SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
        SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
        SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
@@ -312,20 +311,19 @@ static void clear_helper(void *priv)
        ftdi_deinit(&devc->ftdic);
 }
 
-static int dev_clear(void)
+static int dev_clear(const struct sr_dev_driver *di)
 {
        return std_dev_clear(di, clear_helper);
 }
 
-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 sr_dev_inst *sdi;
-       struct sr_channel *ch;
        struct drv_context *drvc;
        struct dev_context *devc;
        GSList *devices;
@@ -341,10 +339,7 @@ static GSList *scan(GSList *options)
 
        devices = NULL;
 
-       if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
-               sr_err("%s: devc malloc failed", __func__);
-               return NULL;
-       }
+       devc = g_malloc0(sizeof(struct dev_context));
 
        ftdi_init(&devc->ftdic);
 
@@ -380,20 +375,14 @@ static GSList *scan(GSList *options)
        devc->use_triggers = 0;
 
        /* Register SIGMA device. */
-       if (!(sdi = sr_dev_inst_new(SR_ST_INITIALIZING, USB_VENDOR_NAME,
-                                   USB_MODEL_NAME, NULL))) {
-               sr_err("%s: sdi was NULL", __func__);
-               goto free;
-       }
+       sdi = g_malloc0(sizeof(struct sr_dev_inst));
+       sdi->status = SR_ST_INITIALIZING;
+       sdi->vendor = g_strdup(USB_VENDOR_NAME);
+       sdi->model = g_strdup(USB_MODEL_NAME);
        sdi->driver = di;
 
-       for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
-               ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE,
-                                   channel_names[i]);
-               if (!ch)
-                       return NULL;
-               sdi->channels = g_slist_append(sdi->channels, ch);
-       }
+       for (i = 0; i < ARRAY_SIZE(channel_names); i++)
+               sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]);
 
        devices = g_slist_append(devices, sdi);
        drvc->instances = g_slist_append(drvc->instances, sdi);
@@ -410,7 +399,7 @@ free:
        return NULL;
 }
 
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
 {
        return ((struct drv_context *)(di->priv))->instances;
 }
@@ -452,7 +441,7 @@ static int sigma_fpga_init_bitbang(struct dev_context *devc)
                if (data & (1 << 5))
                        return 0;
                /* The D6 was not asserted yet, wait a bit. */
-               usleep(10000);
+               g_usleep(10000);
        }
 
        return SR_ERR_TIMEOUT;
@@ -793,7 +782,6 @@ static int convert_trigger(const struct sr_dev_inst *sdi)
                }
        }
 
-
        return SR_OK;
 }
 
@@ -812,9 +800,9 @@ 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)
 {
-       return dev_clear();
+       return dev_clear(di);
 }
 
 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
@@ -895,17 +883,16 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       (void)sdi;
        (void)cg;
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
                if (!sdi)
                        *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
+                                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
                else
                        *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts_global, ARRAY_SIZE(devopts_global), sizeof(uint32_t));
+                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
                break;
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
@@ -959,7 +946,6 @@ static int get_trigger_offset(uint8_t *samples, uint16_t last_sample,
        return i & 0x7;
 }
 
-
 /*
  * Return the timestamp of "DRAM cluster".
  */