X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fpipistrello-ols%2Fapi.c;h=8aca1ed12f844c30cec2aadabbe26013dc116712;hb=a162eeb2e8f23da99d1a7ca7d62dc6ad0981afc6;hp=f16b659e1aabad0bdc66e605e9e22a249874f3c1;hpb=05199c0ac9f15f229d43e50e86c4c1eadc55deac;p=libsigrok.git diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index f16b659e..8aca1ed1 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -91,31 +91,24 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; - /* Allocate memory for our private device context. */ devc = g_malloc0(sizeof(struct dev_context)); - /* Device-specific settings */ devc->max_samplebytes = devc->max_samplerate = devc->protocol_version = 0; - /* Acquisition settings */ devc->limit_samples = devc->capture_ratio = 0; devc->trigger_at = -1; devc->channel_mask = 0xffffffff; devc->flag_reg = 0; - /* Allocate memory for the incoming ftdi data. */ devc->ftdi_buf = g_malloc0(FTDI_BUF_SIZE); - /* Allocate memory for the FTDI context (ftdic) and initialize it. */ if (!(devc->ftdic = ftdi_new())) { sr_err("Failed to initialize libftdi."); goto err_free_ftdi_buf;; } - /* Try to open the FTDI device */ - if (p_ols_open(devc) != SR_OK) { + if (p_ols_open(devc) != SR_OK) goto err_free_ftdic; - } /* The discovery procedure is like this: first send the Reset * command (0x00) 5 times, since the device could be anywhere @@ -166,7 +159,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) goto err_close_ftdic; } - /* Close device. We'll reopen it again when we need it. */ p_ols_close(devc); /* Parse the metadata. */ @@ -184,7 +176,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) err_close_ftdic: p_ols_close(devc); err_free_ftdic: - ftdi_free(devc->ftdic); /* NOT free() or g_free()! */ + ftdi_free(devc->ftdic); err_free_ftdi_buf: g_free(devc->ftdi_buf); g_free(devc); @@ -203,8 +195,8 @@ static int dev_clear(const struct sr_dev_driver *di) return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper); } -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) { struct dev_context *devc; @@ -245,8 +237,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s return SR_OK; } -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) { struct dev_context *devc; uint16_t flag; @@ -338,31 +330,23 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd return ret; } -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) { struct dev_context *devc; - GVariant *gvar, *grange[2]; - GVariantBuilder gvb; int num_pols_changrp, i; switch (key) { case SR_CONF_DEVICE_OPTIONS: return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); case SR_CONF_SAMPLERATE: - g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); - gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates, - ARRAY_SIZE(samplerates), sizeof(uint64_t)); - g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar); - *data = g_variant_builder_end(&gvb); + *data = std_gvar_samplerates_steps(ARRAY_AND_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(ARRAY_AND_SIZE(trigger_matches)); break; case SR_CONF_PATTERN_MODE: - *data = g_variant_new_strv(patterns, ARRAY_SIZE(patterns)); + *data = g_variant_new_strv(ARRAY_AND_SIZE(patterns)); break; case SR_CONF_LIMIT_SAMPLES: if (!sdi) @@ -386,12 +370,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * /* 3 channel groups takes as many bytes as 4 channel groups */ if (num_pols_changrp == 3) num_pols_changrp = 4; - grange[0] = g_variant_new_uint64(MIN_NUM_SAMPLES); - if (num_pols_changrp) - grange[1] = g_variant_new_uint64(devc->max_samplebytes / num_pols_changrp); - else - grange[1] = g_variant_new_uint64(MIN_NUM_SAMPLES); - *data = g_variant_new_tuple(grange, 2); + + *data = std_gvar_tuple_u64(MIN_NUM_SAMPLES, + (num_pols_changrp) ? devc->max_samplebytes / num_pols_changrp : MIN_NUM_SAMPLES); break; default: return SR_ERR_NA;