]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/chronovu-la/api.c
Fix #442 by renaming sr_dev_driver.priv to .context
[libsigrok.git] / src / hardware / chronovu-la / api.c
index 5a8a3d36c959a1c4b06c7411a07e01508d6907fe..c4cc2ab097e4a33b6d5ac110c7f0e3694911dc7c 100644 (file)
 SR_PRIV struct sr_dev_driver chronovu_la_driver_info;
 static struct sr_dev_driver *di = &chronovu_la_driver_info;
 
-static const int32_t hwcaps[] = {
+static const uint32_t devopts[] = {
        SR_CONF_LOGIC_ANALYZER,
-       SR_CONF_SAMPLERATE,
-       SR_CONF_TRIGGER_MATCH,
-       SR_CONF_LIMIT_MSEC, /* TODO: Not yet implemented. */
-       SR_CONF_LIMIT_SAMPLES, /* TODO: Not yet implemented. */
+       SR_CONF_LIMIT_MSEC | SR_CONF_SET,
+       SR_CONF_LIMIT_SAMPLES | SR_CONF_SET | SR_CONF_LIST,
+       SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+       SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
 };
 
 static const int32_t trigger_matches[] = {
@@ -39,7 +39,7 @@ static const int32_t trigger_matches[] = {
 };
 
 /* The ChronoVu LA8/LA16 can have multiple VID/PID pairs. */
-static struct {
+static const struct {
        uint16_t vid;
        uint16_t pid;
        int model;
@@ -63,12 +63,12 @@ static void clear_helper(void *priv)
        g_free(devc->final_buf);
 }
 
-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);
 }
@@ -80,14 +80,13 @@ static int add_device(int idx, int model, GSList **devices)
        struct sr_dev_inst *sdi;
        struct drv_context *drvc;
        struct dev_context *devc;
-       struct sr_channel *ch;
 
        ret = SR_OK;
 
-       drvc = di->priv;
+       drvc = di->context;
 
        /* Allocate memory for our private device context. */
-       devc = g_try_malloc(sizeof(struct dev_context));
+       devc = g_malloc0(sizeof(struct dev_context));
 
        /* Set some sane defaults. */
        devc->prof = &cv_profiles[model];
@@ -120,47 +119,37 @@ static int add_device(int idx, int model, GSList **devices)
        devc->cur_samplerate = devc->prof->max_samplerate;
 
        /* Register the device with libsigrok. */
-       sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING,
-                             "ChronoVu", devc->prof->modelname, NULL);
-       if (!sdi) {
-               sr_err("Failed to create device instance.");
-               ret = SR_ERR;
-               goto err_free_final_buf;
-       }
+       sdi = g_malloc0(sizeof(struct sr_dev_inst));
+       sdi->status = SR_ST_INITIALIZING;
+       sdi->vendor = g_strdup("ChronoVu");
+       sdi->model = g_strdup(devc->prof->modelname);
        sdi->driver = di;
        sdi->priv = devc;
 
-       for (i = 0; i < devc->prof->num_channels; i++) {
-               if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE,
-                                         cv_channel_names[i]))) {
-                       ret = SR_ERR;
-                       goto err_free_dev_inst;
-               }
-               sdi->channels = g_slist_append(sdi->channels, ch);
-       }
+       for (i = 0; i < devc->prof->num_channels; i++)
+               sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
+                               cv_channel_names[i]);
 
        *devices = g_slist_append(*devices, sdi);
        drvc->instances = g_slist_append(drvc->instances, sdi);
 
-       return SR_OK;
+       if (ret == SR_OK)
+               return SR_OK;
 
-err_free_dev_inst:
-       sr_dev_inst_free(sdi);
-err_free_final_buf:
-       g_free(devc->final_buf);
 err_free_devc:
        g_free(devc);
 
        return ret;
 }
 
-static GSList *scan(GSList *options)
+static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        int ret;
        unsigned int i;
        GSList *devices;
        struct ftdi_context *ftdic;
 
+       (void)di;
        (void)options;
 
        devices = NULL;
@@ -200,9 +189,9 @@ static GSList *scan(GSList *options)
        return devices;
 }
 
-static GSList *dev_list(void)
+static GSList *dev_list(const struct sr_dev_driver *di)
 {
-       return ((struct drv_context *)(di->priv))->instances;
+       return ((struct drv_context *)(di->context))->instances;
 }
 
 static int dev_open(struct sr_dev_inst *sdi)
@@ -210,8 +199,6 @@ static int dev_open(struct sr_dev_inst *sdi)
        struct dev_context *devc;
        int ret;
 
-       ret = SR_ERR;
-
        if (!(devc = sdi->priv))
                return SR_ERR_BUG;
 
@@ -254,7 +241,8 @@ static int dev_open(struct sr_dev_inst *sdi)
 
        sdi->status = SR_ST_ACTIVE;
 
-       return SR_OK;
+       if (ret == SR_OK)
+               return SR_OK;
 
 err_ftdi_free:
        ftdi_free(devc->ftdic); /* Close device (if open), free FTDI context. */
@@ -280,19 +268,19 @@ 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(int id, GVariant **data, const struct sr_dev_inst *sdi,
+static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
 
        (void)cg;
 
-       switch (id) {
+       switch (key) {
        case SR_CONF_SAMPLERATE:
                if (!sdi || !(devc = sdi->priv))
                        return SR_ERR_BUG;
@@ -305,7 +293,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
        return SR_OK;
 }
 
-static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
+static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
@@ -318,7 +306,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
        if (!(devc = sdi->priv))
                return SR_ERR_BUG;
 
-       switch (id) {
+       switch (key) {
        case SR_CONF_SAMPLERATE:
                if (cv_set_samplerate(sdi, g_variant_get_uint64(data)) < 0)
                        return SR_ERR;
@@ -340,7 +328,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
        return SR_OK;
 }
 
-static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
+static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
        GVariant *gvar, *grange[2];
@@ -351,8 +339,8 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
-                               hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
                break;
        case SR_CONF_SAMPLERATE:
                if (!sdi || !sdi->priv || !(devc = sdi->priv))
@@ -554,5 +542,5 @@ SR_PRIV struct sr_dev_driver chronovu_la_driver_info = {
        .dev_close = dev_close,
        .dev_acquisition_start = dev_acquisition_start,
        .dev_acquisition_stop = dev_acquisition_stop,
-       .priv = NULL,
+       .context = NULL,
 };