]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/yokogawa-dlm/api.c
drivers: Consistently use same indentation for config_*() API calls.
[libsigrok.git] / src / hardware / yokogawa-dlm / api.c
index cc0cacbd3737201255f9e1b1e50cda6f8f607c29..f6f0ce8a6d7c756e993470fadda51c40c974208e 100644 (file)
 static struct sr_dev_driver yokogawa_dlm_driver_info;
 
 static const char *MANUFACTURER_ID = "YOKOGAWA";
-static const char *MANUFACTURER_NAME = "Yokogawa";
 
-static const uint32_t dlm_scanopts[] = {
+static const uint32_t scanopts[] = {
        SR_CONF_CONN,
 };
 
-static const uint32_t dlm_drvopts[] = {
+static const uint32_t drvopts[] = {
        SR_CONF_LOGIC_ANALYZER,
        SR_CONF_OSCILLOSCOPE,
 };
 
-static const uint32_t dlm_devopts[] = {
+static const uint32_t devopts[] = {
        SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_SAMPLERATE | SR_CONF_GET,
        SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
@@ -47,13 +46,13 @@ static const uint32_t dlm_devopts[] = {
        SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
 };
 
-static const uint32_t dlm_analog_devopts[] = {
+static const uint32_t devopts_cg_analog[] = {
        SR_CONF_NUM_VDIV | SR_CONF_GET,
        SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
 };
 
-static const uint32_t dlm_digital_devopts[] = {
+static const uint32_t devopts_cg_digital[] = {
 };
 
 enum {
@@ -87,7 +86,7 @@ static struct sr_dev_inst *probe_usbtmc_device(struct sr_scpi_dev_inst *scpi)
                goto fail;
 
        sdi = g_malloc0(sizeof(struct sr_dev_inst));
-       sdi->vendor = g_strdup(MANUFACTURER_NAME);
+       sdi->vendor = g_strdup("Yokogawa");
        sdi->model = g_strdup(model_name);
        sdi->version = g_strdup(hw_info->firmware_version);
 
@@ -183,8 +182,8 @@ static int check_channel_group(struct dev_context *devc,
        return CG_INVALID;
 }
 
-static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
-               const struct sr_channel_group *cg)
+static int config_get(uint32_t key, GVariant **data,
+       const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
        int ret, cg_type;
        unsigned int i;
@@ -283,27 +282,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
        return ret;
 }
 
-static GVariant *build_tuples(const uint64_t (*array)[][2], unsigned int n)
-{
-       unsigned int i;
-       GVariant *rational[2];
-       GVariantBuilder gvb;
-
-       g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
-
-       for (i = 0; i < n; i++) {
-               rational[0] = g_variant_new_uint64((*array)[i][0]);
-               rational[1] = g_variant_new_uint64((*array)[i][1]);
-
-               /* FIXME: Valgrind reports a memory leak here. */
-               g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
-       }
-
-       return g_variant_builder_end(&gvb);
-}
-
-static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
-               const struct sr_channel_group *cg)
+static int config_set(uint32_t key, GVariant *data,
+       const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
        int ret, cg_type;
        unsigned int i, j;
@@ -457,7 +437,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 }
 
 static int config_channel_set(const struct sr_dev_inst *sdi,
-                       struct sr_channel *ch, unsigned int changes)
+       struct sr_channel *ch, unsigned int changes)
 {
        /* Currently we only handle SR_CHANNEL_SET_ENABLED. */
        if (changes != SR_CHANNEL_SET_ENABLED)
@@ -466,8 +446,8 @@ static int config_channel_set(const struct sr_dev_inst *sdi,
        return dlm_channel_state_set(sdi, ch->index, ch->enabled);
 }
 
-static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
-               const struct sr_channel_group *cg)
+static int config_list(uint32_t key, GVariant **data,
+       const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
        int cg_type = CG_NONE;
        struct dev_context *devc;
@@ -480,9 +460,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                switch (key) {
                case SR_CONF_SCAN_OPTIONS:
                case SR_CONF_DEVICE_OPTIONS:
-                       return STD_CONFIG_LIST(key, data, sdi, cg, dlm_scanopts, dlm_drvopts, dlm_devopts);
+                       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
                case SR_CONF_TIMEBASE:
-                       *data = build_tuples(&dlm_timebases, ARRAY_SIZE(dlm_timebases));
+                       *data = std_gvar_tuple_array(ARRAY_AND_SIZE(dlm_timebases));
                        return SR_OK;
                case SR_CONF_TRIGGER_SOURCE:
                        if (!model)
@@ -507,16 +487,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               if (cg_type == CG_ANALOG) {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               dlm_analog_devopts, ARRAY_SIZE(dlm_analog_devopts), sizeof(uint32_t));
-               } else if (cg_type == CG_DIGITAL) {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               dlm_digital_devopts, ARRAY_SIZE(dlm_digital_devopts), sizeof(uint32_t));
-               } else {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               NULL, 0, sizeof(uint32_t));
-               }
+               if (cg_type == CG_ANALOG)
+                       *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog));
+               else if (cg_type == CG_DIGITAL)
+                       *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_digital));
+               else
+                       *data = std_gvar_array_u32(NULL, 0);
                break;
        case SR_CONF_COUPLING:
                if (cg_type == CG_NONE)
@@ -527,7 +503,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        case SR_CONF_VDIV:
                if (cg_type == CG_NONE)
                        return SR_ERR_CHANNEL_GROUP;
-               *data = build_tuples(&dlm_vdivs, ARRAY_SIZE(dlm_vdivs));
+               *data = std_gvar_tuple_array(ARRAY_AND_SIZE(dlm_vdivs));
                break;
        default:
                return SR_ERR_NA;