]> sigrok.org Git - libsigrok.git/commitdiff
baylibre-acme: Dynamically check per probe config options.
authorBartosz Golaszewski <redacted>
Fri, 3 Apr 2015 12:58:11 +0000 (14:58 +0200)
committerUwe Hermann <redacted>
Sun, 12 Apr 2015 15:16:32 +0000 (17:16 +0200)
PROBE_FACTOR and POWER_OFF options are advertised for all ACME probes
(channel groups) regardless of whether they actually have given capability.

Check these options in config_list() at runtime and only advertise them
for probes which support them.

Signed-off-by: Bartosz Golaszewski <redacted>
src/hardware/baylibre-acme/api.c
src/hardware/baylibre-acme/protocol.c
src/hardware/baylibre-acme/protocol.h

index def373d1e2a34d4c682d14e6c4d286eba615aa26..85f474cf3ca66fcda15c30aa56dbc18c74a33d09 100644 (file)
@@ -28,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 */
 
@@ -263,9 +272,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;
@@ -291,8 +301,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;
index 656e89fec6c3e140a5bbb7909ce6203d64344422..ca09eba069c51a0c017f851b53b31d5779346d58 100644 (file)
@@ -245,6 +245,20 @@ SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type,
        return TRUE;
 }
 
+SR_PRIV int bl_acme_get_probe_type(const struct sr_channel_group *cg)
+{
+       struct channel_group_priv *cgp = cg->priv;
+
+       return cgp->probe_type;
+}
+
+SR_PRIV int bl_acme_probe_has_pws(const struct sr_channel_group *cg)
+{
+       struct channel_group_priv *cgp = cg->priv;
+
+       return sr_gpio_getval_export(pws_info_gpios[cgp->index]);
+}
+
 /*
  * Sets path to the hwmon attribute if this channel group
  * supports shunt resistance setting. The caller has to supply
@@ -348,8 +362,7 @@ SR_PRIV int bl_acme_read_power_state(const struct sr_channel_group *cg,
 
        cgp = cg->priv;
 
-       val = sr_gpio_getval_export(pws_info_gpios[cgp->index]);
-       if (val != 1) {
+       if (!bl_acme_probe_has_pws(cg)) {
                sr_err("Probe has no power-switch");
                return SR_ERR_ARG;
        }
@@ -368,8 +381,7 @@ SR_PRIV int bl_acme_set_power_off(const struct sr_channel_group *cg,
 
        cgp = cg->priv;
 
-       val = sr_gpio_getval_export(pws_info_gpios[cgp->index]);
-       if (val != 1) {
+       if (!bl_acme_probe_has_pws(cg)) {
                sr_err("Probe has no power-switch");
                return SR_ERR_ARG;
        }
index 3972aa2cc6da6326fb1d5905a40e958dd7ed9668..baa91cac33745a251cd23a6e799ee58971d79d77 100644 (file)
@@ -81,6 +81,9 @@ SR_PRIV gboolean bl_acme_detect_probe(unsigned int addr,
 SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type,
                                        unsigned int addr, int prb_num);
 
+SR_PRIV int bl_acme_get_probe_type(const struct sr_channel_group *cg);
+SR_PRIV int bl_acme_probe_has_pws(const struct sr_channel_group *cg);
+
 SR_PRIV int bl_acme_get_shunt(const struct sr_channel_group *cg,
                              uint64_t *shunt);
 SR_PRIV int bl_acme_set_shunt(const struct sr_channel_group *cg,