]> sigrok.org Git - libsigrok.git/commitdiff
cem-dt-885x: Support for max/min hold modes
authorBert Vermeulen <redacted>
Sun, 16 Jun 2013 10:14:09 +0000 (12:14 +0200)
committerBert Vermeulen <redacted>
Mon, 17 Jun 2013 14:17:39 +0000 (16:17 +0200)
hardware/cem-dt-885x/api.c
hardware/cem-dt-885x/protocol.c
hardware/cem-dt-885x/protocol.h

index 834e4290d24a153dc0442927e3dfa98326e93c3d..f2329c38c229de7ca33ce1fc56114bf742155a35 100644 (file)
@@ -35,6 +35,8 @@ static const int32_t hwcaps[] = {
        SR_CONF_DATALOG,
        SR_CONF_SPL_WEIGHT_FREQ,
        SR_CONF_SPL_WEIGHT_TIME,
+       SR_CONF_HOLD_MAX,
+       SR_CONF_HOLD_MIN,
 };
 
 static const char *weight_freq[] = {
@@ -171,12 +173,13 @@ static int cleanup(void)
 static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
-       int tmp;
+       int tmp, ret;
 
        if (!sdi)
                return SR_ERR_ARG;
 
        devc = sdi->priv;
+       ret = SR_OK;
        switch (key) {
        case SR_CONF_LIMIT_SAMPLES:
                *data = g_variant_new_uint64(devc->limit_samples);
@@ -202,18 +205,26 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
                else
                        return SR_ERR;
                break;
+       case SR_CONF_HOLD_MAX:
+               if ((ret = cem_dt_885x_holdmode_get(sdi, &tmp)) == SR_OK)
+                       *data = g_variant_new_boolean(tmp == SR_MQFLAG_MAX);
+               break;
+       case SR_CONF_HOLD_MIN:
+               if ((ret = cem_dt_885x_holdmode_get(sdi, &tmp)) == SR_OK)
+                       *data = g_variant_new_boolean(tmp == SR_MQFLAG_MIN);
+               break;
        default:
                return SR_ERR_NA;
        }
 
-       return SR_OK;
+       return ret;
 }
 
 static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        uint64_t tmp_u64;
-       int ret;
+       int tmp, ret;
        const char *tmp_str;
 
        if (sdi->status != SR_ST_ACTIVE)
@@ -262,6 +273,14 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
                else
                        return SR_ERR_ARG;
                break;
+       case SR_CONF_HOLD_MAX:
+               tmp = g_variant_get_boolean(data) ? SR_MQFLAG_MAX : 0;
+               ret = cem_dt_885x_holdmode_set(sdi, tmp);
+               break;
+       case SR_CONF_HOLD_MIN:
+               tmp = g_variant_get_boolean(data) ? SR_MQFLAG_MIN : 0;
+               ret = cem_dt_885x_holdmode_set(sdi, tmp);
+               break;
        default:
                ret = SR_ERR_NA;
        }
index e9a92bc95fa4697fc68a23088381c5c33709827e..173117b606c76faaa8018ed5b38b6bf5697c29c1 100644 (file)
@@ -523,3 +523,72 @@ SR_PRIV int cem_dt_885x_weight_time_set(const struct sr_dev_inst *sdi, int timew
 
        return ret;
 }
+
+SR_PRIV int cem_dt_885x_holdmode_get(const struct sr_dev_inst *sdi,
+               gboolean *holdmode)
+{
+       struct dev_context *devc;
+       char tokens[5];
+
+       devc = sdi->priv;
+
+       if (devc->cur_mqflags == 0) {
+               tokens[0] = TOKEN_HOLD_MAX;
+               tokens[1] = TOKEN_HOLD_MIN;
+               tokens[2] = TOKEN_HOLD_NONE;
+               tokens[3] = -1;
+               if (wait_for_token(sdi, tokens, 0) != SR_OK)
+                       return SR_ERR;
+               if (devc->token == TOKEN_HOLD_MAX)
+                       devc->cur_mqflags = SR_MQFLAG_MAX;
+               else if (devc->token == TOKEN_HOLD_MIN)
+                       devc->cur_mqflags = SR_MQFLAG_MIN;
+       }
+       *holdmode = devc->cur_mqflags & (SR_MQFLAG_MAX | SR_MQFLAG_MIN);
+
+       return SR_OK;
+}
+
+SR_PRIV int cem_dt_885x_holdmode_set(const struct sr_dev_inst *sdi, int holdmode)
+{
+       struct dev_context *devc;
+       int cur_setting, ret;
+       char tokens[5];
+
+       devc = sdi->priv;
+
+       /* The toggle below needs the desired state in first position. */
+       if (holdmode == SR_MQFLAG_MAX) {
+               tokens[0] = TOKEN_HOLD_MAX;
+               tokens[1] = TOKEN_HOLD_MIN;
+               tokens[2] = TOKEN_HOLD_NONE;
+       } else if (holdmode == SR_MQFLAG_MIN) {
+               tokens[0] = TOKEN_HOLD_MIN;
+               tokens[1] = TOKEN_HOLD_MAX;
+               tokens[2] = TOKEN_HOLD_NONE;
+       } else {
+               tokens[0] = TOKEN_HOLD_NONE;
+               tokens[1] = TOKEN_HOLD_MAX;
+               tokens[2] = TOKEN_HOLD_MIN;
+       }
+       tokens[3] = -1;
+
+       if (devc->cur_mqflags == 0) {
+               /* Didn't pick up device state yet. */
+               if (wait_for_token(sdi, tokens, 0) != SR_OK)
+                       return SR_ERR;
+               if (devc->token == tokens[0])
+                       /* Nothing to do. */
+                       return SR_OK;
+       } else {
+               cur_setting = devc->cur_mqflags & (SR_MQFLAG_MAX | SR_MQFLAG_MIN);
+               if (cur_setting == holdmode)
+                       /* Already set correctly. */
+                       return SR_OK;
+       }
+
+       /* 51ms timeout seems to work best for this. */
+       ret = cem_dt_885x_toggle(sdi, CMD_TOGGLE_HOLD_MAX_MIN, tokens, 51);
+
+       return ret;
+}
index a2e77e758fbc3d1eb59ceb2e8e9f6d90eaeebc55..49fe55d3aab3111f1dca469de749a12a39da93ec 100644 (file)
@@ -70,6 +70,7 @@ enum {
        CMD_TOGGLE_RECORDING = 0x55,
        CMD_TOGGLE_WEIGHT_FREQ = 0x99,
        CMD_TOGGLE_WEIGHT_TIME = 0x77,
+       CMD_TOGGLE_HOLD_MAX_MIN = 0x11,
 };
 
 /** Private, per-device-instance driver context. */
@@ -110,5 +111,8 @@ SR_PRIV int cem_dt_885x_weight_freq_get(const struct sr_dev_inst *sdi);
 SR_PRIV int cem_dt_885x_weight_freq_set(const struct sr_dev_inst *sdi, int freqw);
 SR_PRIV int cem_dt_885x_weight_time_get(const struct sr_dev_inst *sdi);
 SR_PRIV int cem_dt_885x_weight_time_set(const struct sr_dev_inst *sdi, int timew);
+SR_PRIV int cem_dt_885x_holdmode_get(const struct sr_dev_inst *sdi,
+               gboolean *holdmode);
+SR_PRIV int cem_dt_885x_holdmode_set(const struct sr_dev_inst *sdi, int holdmode);
 
 #endif