static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) { GVariant *gvar; GVariantBuilder gvb; (void)sdi; switch (key) { case SR_CONF_DEVICE_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, chronovu_la8_hwcaps, ARRAY_SIZE(chronovu_la8_hwcaps), sizeof(int32_t)); break; case SR_CONF_SAMPLERATE: fill_supported_samplerates_if_needed(); g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), chronovu_la8_samplerates, ARRAY_SIZE(chronovu_la8_samplerates), sizeof(uint64_t)); g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); *data = g_variant_builder_end(&gvb); break; case SR_CONF_TRIGGER_TYPE: *data = g_variant_new_string(TRIGGER_TYPE); break; default: return SR_ERR_NA; } return SR_OK; }
/** * Check if the given samplerate is supported by the LA8 hardware. * * @param samplerate The samplerate (in Hz) to check. * @return 1 if the samplerate is supported/valid, 0 otherwise. */ SR_PRIV int is_valid_samplerate(uint64_t samplerate) { int i; fill_supported_samplerates_if_needed(); for (i = 0; i < 255; i++) { if (supported_samplerates[i] == samplerate) return 1; } sr_err("Invalid samplerate (%" PRIu64 "Hz).", samplerate); return 0; }
SR_PRIV int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate) { struct dev_context *devc; /* Note: Caller checked that sdi and sdi->priv != NULL. */ devc = sdi->priv; sr_spew("Trying to set samplerate to %" PRIu64 "Hz.", samplerate); fill_supported_samplerates_if_needed(); /* Check if this is a samplerate supported by the hardware. */ if (!is_valid_samplerate(samplerate)) return SR_ERR; /* Set the new samplerate. */ devc->cur_samplerate = samplerate; sr_dbg("Samplerate set to %" PRIu64 "Hz.", devc->cur_samplerate); return SR_OK; }