X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fbaylibre-acme%2Fapi.c;h=6827a16bfe5da763756f34318856411f0f220ee8;hb=a93086528e5b476812e42b423f7a8a53812af6f4;hp=b4ef69ddf3c1372f84fe809295e2decb4bccccff;hpb=5fabeeac6af940b52f67ac8c925952accc9b39b3;p=libsigrok.git diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index b4ef69dd..6827a16b 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -20,7 +20,6 @@ #include "protocol.h" SR_PRIV struct sr_dev_driver baylibre_acme_driver_info; -static struct sr_dev_driver *di = &baylibre_acme_driver_info; static const uint32_t devopts[] = { SR_CONF_CONTINUOUS | SR_CONF_SET, @@ -29,10 +28,19 @@ static const uint32_t devopts[] = { SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, }; -static const uint32_t devopts_cg[] = { - SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET, - SR_CONF_POWER_OFF | SR_CONF_GET | SR_CONF_SET, -}; +/* + * Currently there are two channel-group/probe options for ACME: + * - SR_CONF_PROBE_FACTOR - allows to modify current shunt resistance + * calibration + * - SR_CONF_POWER_OFF - allows to remotely cut-off/restore power to + * measured devices + * + * They are not static - we have to check each probe's capabilities in + * config_list(). + */ +#define MAX_DEVOPTS_CG 2 +#define HAS_PROBE_FACTOR (SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET) +#define HAS_POWER_OFF (SR_CONF_POWER_OFF | SR_CONF_GET | SR_CONF_SET) #define MAX_SAMPLE_RATE 500 /* In Hz */ @@ -42,12 +50,12 @@ static const uint64_t samplerates[] = { SR_HZ(1), }; -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); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; @@ -116,7 +124,7 @@ static GSList *scan(GSList *options) * Let's assume there's no ACME device present if no probe * has been registered. */ - if (sdi->channel_groups == NULL) + if (!sdi->channel_groups) goto err_out; devices = g_slist_append(devices, sdi); @@ -131,12 +139,12 @@ err_out: return NULL; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } @@ -161,9 +169,9 @@ 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) { - dev_clear(); + dev_clear(di); return SR_OK; } @@ -229,12 +237,10 @@ static int config_set(uint32_t key, GVariant *data, case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); devc->limit_msec = 0; - sr_dbg("Setting sample limit to %" PRIu64, devc->limit_samples); break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data) * 1000; devc->limit_samples = 0; - sr_dbg("Setting time limit to %" PRIu64"ms", devc->limit_msec); break; case SR_CONF_SAMPLERATE: samplerate = g_variant_get_uint64(data); @@ -244,7 +250,7 @@ static int config_set(uint32_t key, GVariant *data, break; } devc->samplerate = samplerate; - sr_dbg("Setting samplerate to %" PRIu64, devc->samplerate); + bl_acme_maybe_set_update_interval(sdi, samplerate); break; case SR_CONF_PROBE_FACTOR: if (!cg) @@ -267,9 +273,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { + uint32_t devopts_cg[MAX_DEVOPTS_CG]; GVariant *gvar; GVariantBuilder gvb; - int ret; + int ret, num_devopts_cg = 0; (void)sdi; (void)cg; @@ -295,8 +302,13 @@ static int config_list(uint32_t key, GVariant **data, } else { switch (key) { case SR_CONF_DEVICE_OPTIONS: + if (bl_acme_get_probe_type(cg) == PROBE_ENRG) + devopts_cg[num_devopts_cg++] = HAS_PROBE_FACTOR; + 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, ARRAY_SIZE(devopts_cg), sizeof(uint32_t)); + devopts_cg, num_devopts_cg, sizeof(uint32_t)); break; default: return SR_ERR_NA;