From: Uwe Hermann Date: Thu, 20 Jul 2017 21:43:53 +0000 (+0200) Subject: drivers: Factor out std_gvar_array_*(). X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=105df67463b84683a35f3474eccc871e5aa4ed0e;p=libsigrok.git drivers: Factor out std_gvar_array_*(). --- diff --git a/src/hardware/arachnid-labs-re-load-pro/api.c b/src/hardware/arachnid-labs-re-load-pro/api.c index 48d3cb8f..91b086aa 100644 --- a/src/hardware/arachnid-labs-re-load-pro/api.c +++ b/src/hardware/arachnid-labs-re-load-pro/api.c @@ -155,8 +155,7 @@ static int config_list(uint32_t key, GVariant **data, } else { switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg, ARRAY_SIZE(devopts_cg)); break; case SR_CONF_CURRENT_LIMIT: *data = std_gvar_min_max_step(0.0, 6.0, 0.001); diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index aaefb450..5b169d56 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -243,9 +243,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * break; #if ASIX_SIGMA_WITH_TRIGGER case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - trigger_matches, ARRAY_SIZE(trigger_matches), - sizeof(int32_t)); + *data = std_gvar_array_i32(trigger_matches, ARRAY_SIZE(trigger_matches)); break; #endif default: diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 0f27b4f8..d4ab7f89 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -360,8 +360,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg, ARRAY_SIZE(devopts_cg)); break; case SR_CONF_VOLTAGE_TARGET: *data = std_gvar_min_max_step_array(devc->model->channels[channel].voltage); diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index 44169a1b..4438c642 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -240,8 +240,7 @@ static int config_list(uint32_t key, GVariant **data, if (bl_acme_probe_has_pws(cg)) devopts_cg[num_devopts_cg++] = HAS_POWER_OFF; - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg, num_devopts_cg, sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg, num_devopts_cg); break; default: return SR_ERR_NA; diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index e904833d..b570c112 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -248,9 +248,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates)); break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches), - sizeof(int32_t)); + *data = std_gvar_array_i32(soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches)); break; default: return SR_ERR_NA; diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 95aee39e..47d34927 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -372,9 +372,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * case SR_CONF_TRIGGER_MATCH: if (!devc->prof) return SR_ERR_BUG; - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - trigger_matches, devc->prof->num_trigger_matches, - sizeof(int32_t)); + *data = std_gvar_array_i32(trigger_matches, devc->prof->num_trigger_matches); break; default: return SR_ERR_NA; diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index e9c504a2..a2d39736 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -372,18 +372,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * switch (key) { case SR_CONF_DEVICE_OPTIONS: if (ch->type == SR_CHANNEL_LOGIC) - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_logic, ARRAY_SIZE(devopts_cg_logic), - sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg_logic, ARRAY_SIZE(devopts_cg_logic)); else if (ch->type == SR_CHANNEL_ANALOG) { if (strcmp(cg->name, "Analog") == 0) - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_analog_group, ARRAY_SIZE(devopts_cg_analog_group), - sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg_analog_group, ARRAY_SIZE(devopts_cg_analog_group)); else - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_analog_channel, ARRAY_SIZE(devopts_cg_analog_channel), - sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg_analog_channel, ARRAY_SIZE(devopts_cg_analog_channel)); } else return SR_ERR_BUG; diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index b1909428..ec0ee480 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -543,9 +543,7 @@ static int config_list(uint32_t key, GVariant **data, *data = std_gvar_samplerates(devc->samplerates, devc->num_samplerates); break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches), - sizeof(int32_t)); + *data = std_gvar_array_i32(soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches)); break; default: return SR_ERR_NA; diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 83e7e040..bb066dc2 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -460,24 +460,18 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * switch (key) { case SR_CONF_SCAN_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); + *data = std_gvar_array_u32(scanopts, ARRAY_SIZE(scanopts)); break; case SR_CONF_DEVICE_OPTIONS: if (cg_type == CG_NONE) { if (model) - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - model->devopts, model->num_devopts, sizeof(uint32_t)); + *data = std_gvar_array_u32((const uint32_t *)model->devopts, model->num_devopts); else - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); + *data = std_gvar_array_u32(drvopts, ARRAY_SIZE(drvopts)); } else if (cg_type == CG_ANALOG) { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - model->devopts_cg_analog, model->num_devopts_cg_analog, - sizeof(uint32_t)); + *data = std_gvar_array_u32((const uint32_t *)model->devopts_cg_analog, model->num_devopts_cg_analog); } else { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - NULL, 0, sizeof(uint32_t)); + *data = std_gvar_array_u32(NULL, 0); } break; case SR_CONF_COUPLING: diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index 4f8e0112..5e19ccc4 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -476,8 +476,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * } else { switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg, ARRAY_SIZE(devopts_cg)); break; case SR_CONF_COUPLING: *data = g_variant_new_strv(devc->coupling_vals, devc->coupling_tab_size); diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index 09053273..65f11bfc 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -605,8 +605,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * if (!sdi) return SR_ERR_ARG; devc = sdi->priv; - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64, - devc->profile->buffersizes, NUM_BUFFER_SIZES, sizeof(uint64_t)); + *data = std_gvar_array_u64(devc->profile->buffersizes, NUM_BUFFER_SIZES); break; case SR_CONF_TIMEBASE: *data = std_gvar_tuple_array(&timebases, ARRAY_SIZE(timebases)); @@ -625,8 +624,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * } else { switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg, ARRAY_SIZE(devopts_cg)); break; case SR_CONF_COUPLING: *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling)); diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index 7ddc8787..8b268e21 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -592,8 +592,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * case SR_CONF_DEVICE_OPTIONS: if (!cg) return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg, ARRAY_SIZE(devopts_cg)); break; case SR_CONF_SAMPLERATE: *data = std_gvar_samplerates(samplerates, ARRAY_SIZE(samplerates)); @@ -605,8 +604,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = g_variant_new_strv(trigger_slopes, ARRAY_SIZE(trigger_slopes)); break; case SR_CONF_BUFFERSIZE: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64, - buffersizes, ARRAY_SIZE(buffersizes), sizeof(uint64_t)); + *data = std_gvar_array_u64(buffersizes, ARRAY_SIZE(buffersizes)); break; case SR_CONF_VDIV: *data = std_gvar_tuple_array(&vdivs, ARRAY_SIZE(vdivs)); diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 3b832866..7e3c21c3 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -309,9 +309,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = std_gvar_samplerates(sl2_samplerates, ARRAY_SIZE(sl2_samplerates)); break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - trigger_matches, ARRAY_SIZE(trigger_matches), - sizeof(int32_t)); + *data = std_gvar_array_i32(trigger_matches, ARRAY_SIZE(trigger_matches)); break; case SR_CONF_LIMIT_SAMPLES: grange[0] = g_variant_new_uint64(0); diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index 6f7eec94..2682f7bd 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -413,9 +413,7 @@ static int config_list(uint32_t key, GVariant **data, *data = std_gvar_samplerates(samplerates, ARRAY_SIZE(samplerates)); break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - trigger_matches, ARRAY_SIZE(trigger_matches), - sizeof(int32_t)); + *data = std_gvar_array_i32(trigger_matches, ARRAY_SIZE(trigger_matches)); break; default: return SR_ERR_NA; diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index 033299f5..f5139702 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -381,9 +381,7 @@ static int config_list(uint32_t key, GVariant **data, case SR_CONF_DEVICE_OPTIONS: if (!cg) return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_analog, ARRAY_SIZE(devopts_cg_analog), - sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg_analog, ARRAY_SIZE(devopts_cg_analog)); break; case SR_CONF_COUPLING: *data = g_variant_new_strv(*model->coupling_options, diff --git a/src/hardware/maynuo-m97/api.c b/src/hardware/maynuo-m97/api.c index 9d0ddbe4..c2083f7b 100644 --- a/src/hardware/maynuo-m97/api.c +++ b/src/hardware/maynuo-m97/api.c @@ -368,8 +368,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * } else { switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg, ARRAY_SIZE(devopts_cg)); break; case SR_CONF_VOLTAGE_TARGET: *data = std_gvar_min_max_step(0.0, devc->model->max_voltage, 0.001); diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index 464ce7db..be5d7256 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -682,11 +682,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * switch (key) { case SR_CONF_DEVICE_OPTIONS: if ((ch_idx == 0) || (ch_idx == 1)) /* CH1, CH2 */ - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_ch12, ARRAY_SIZE(devopts_cg_ch12), sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg_ch12, ARRAY_SIZE(devopts_cg_ch12)); else /* Must be CH3 */ - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_ch3, ARRAY_SIZE(devopts_cg_ch3), sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg_ch3, ARRAY_SIZE(devopts_cg_ch3)); break; case SR_CONF_VOLTAGE_TARGET: *data = std_gvar_min_max_step_array(devc->model->channels[ch_idx].voltage); diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index 3fd34c6d..dccd025d 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -334,9 +334,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates)); break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - trigger_matches, ARRAY_SIZE(trigger_matches), - sizeof(int32_t)); + *data = std_gvar_array_i32(trigger_matches, ARRAY_SIZE(trigger_matches)); break; case SR_CONF_PATTERN_MODE: *data = g_variant_new_strv(patterns, ARRAY_SIZE(patterns)); diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 4923d677..5006380b 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -344,9 +344,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates)); break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - trigger_matches, ARRAY_SIZE(trigger_matches), - sizeof(int32_t)); + *data = std_gvar_array_i32(trigger_matches, ARRAY_SIZE(trigger_matches)); break; case SR_CONF_PATTERN_MODE: *data = g_variant_new_strv(patterns, ARRAY_SIZE(patterns)); diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index ee0fd8c6..8bf40c5e 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -851,14 +851,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * if (!cg) return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); if (cg == devc->digital_group) { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - NULL, 0, sizeof(uint32_t)); + *data = std_gvar_array_u32(NULL, 0); return SR_OK; } else { for (i = 0; i < devc->model->analog_channels; i++) { if (cg == devc->analog_groups[i]) { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_analog, ARRAY_SIZE(devopts_cg_analog), sizeof(uint32_t)); + *data = std_gvar_array_u32(devopts_cg_analog, ARRAY_SIZE(devopts_cg_analog)); return SR_OK; } } @@ -873,8 +871,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * case SR_CONF_PROBE_FACTOR: if (!cg) return SR_ERR_CHANNEL_GROUP; - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64, - probe_factor, ARRAY_SIZE(probe_factor), sizeof(uint64_t)); + *data = std_gvar_array_u64(probe_factor, ARRAY_SIZE(probe_factor)); break; case SR_CONF_VDIV: if (!devc) diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index 9d28a9b3..9bbe169f 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -524,9 +524,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = g_variant_builder_end(&gvb); break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches), - sizeof(int32_t)); + *data = std_gvar_array_i32(soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches)); break; default: return SR_ERR_NA; diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 3ac44a3c..5a847eb2 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -562,9 +562,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devc->device->devopts_cg, devc->device->num_devopts_cg, - sizeof(uint32_t)); + *data = std_gvar_array_u32(devc->device->devopts_cg, devc->device->num_devopts_cg); break; case SR_CONF_VOLTAGE_TARGET: *data = std_gvar_min_max_step_array(ch_spec->voltage); diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 3d8f0979..4e4fc3a5 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -621,9 +621,7 @@ static int config_list(uint32_t key, GVariant **data, *data = std_gvar_samplerates(devc->model->samplerates, devc->model->num_samplerates); break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - trigger_matches, ARRAY_SIZE(trigger_matches), - sizeof(trigger_matches[0])); + *data = std_gvar_array_i32(trigger_matches, ARRAY_SIZE(trigger_matches)); break; case SR_CONF_TRIGGER_SOURCE: *data = g_variant_new_strv(trigger_source_names, diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 6364d104..5bba8d9b 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -488,16 +488,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, - devopts_cg_analog, ARRAY_SIZE(devopts_cg_analog), sizeof(uint32_t)); - } else if (cg_type == CG_DIGITAL) { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_cg_digital, ARRAY_SIZE(devopts_cg_digital), 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(devopts_cg_analog, ARRAY_SIZE(devopts_cg_analog)); + else if (cg_type == CG_DIGITAL) + *data = std_gvar_array_u32(devopts_cg_digital, ARRAY_SIZE(devopts_cg_digital)); + else + *data = std_gvar_array_u32(NULL, 0); break; case SR_CONF_COUPLING: if (cg_type == CG_NONE) diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index dd0e66d5..af8e6203 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -409,9 +409,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * } break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - trigger_matches, ARRAY_SIZE(trigger_matches), - sizeof(int32_t)); + *data = std_gvar_array_i32(trigger_matches, ARRAY_SIZE(trigger_matches)); break; case SR_CONF_VOLTAGE_THRESHOLD: *data = std_gvar_min_max_step_thresholds(-6.0, 6.0, 0.1); diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 112ee460..cb0e38f3 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -964,6 +964,9 @@ SR_PRIV GVariant *std_gvar_min_max_step(double min, double max, double step); SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3]); SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double dmin, const double dmax, const double dstep); +SR_PRIV GVariant *std_gvar_array_i32(const int32_t *a, unsigned int n); +SR_PRIV GVariant *std_gvar_array_u32(const uint32_t *a, unsigned int n); +SR_PRIV GVariant *std_gvar_array_u64(const uint64_t *a, unsigned int n); /*--- resource.c ------------------------------------------------------------*/ diff --git a/src/std.c b/src/std.c index 45cc3a49..119b301e 100644 --- a/src/std.c +++ b/src/std.c @@ -646,3 +646,21 @@ SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double min, const doubl return g_variant_builder_end(&gvb); } + +SR_PRIV GVariant *std_gvar_array_i32(const int32_t *a, unsigned int n) +{ + return g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + a, n, sizeof(int32_t)); +} + +SR_PRIV GVariant *std_gvar_array_u32(const uint32_t *a, unsigned int n) +{ + return g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + a, n, sizeof(uint32_t)); +} + +SR_PRIV GVariant *std_gvar_array_u64(const uint64_t *a, unsigned int n) +{ + return g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64, + a, n, sizeof(uint64_t)); +}