]> sigrok.org Git - libsigrok.git/blobdiff - hardware/zeroplus-logic-cube/api.c
drivers: return SR_ERR_NA on unsupported config key
[libsigrok.git] / hardware / zeroplus-logic-cube / api.c
index eca4bea483cf530df2217762c9506bf436ef0f6d..78036892a00ea3f8cbf51256b7b52872a9a73a60 100644 (file)
@@ -42,6 +42,7 @@ struct zp_model {
  * same 128K sample depth.
  */
 static const struct zp_model zeroplus_models[] = {
+       {0x0c12, 0x7002, "LAP-16128U",    16, 128,  200},
        {0x0c12, 0x7009, "LAP-C(16064)",  16, 64,   100},
        {0x0c12, 0x700a, "LAP-C(16128)",  16, 128,  200},
        /* TODO: We don't know anything about these.
@@ -210,6 +211,33 @@ static int configure_probes(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
+SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate)
+{
+       int i;
+
+       for (i = 0; ARRAY_SIZE(samplerates_200); i++)
+               if (samplerate == samplerates_200[i])
+                       break;
+
+       if (i == ARRAY_SIZE(samplerates_200) || samplerate > devc->max_samplerate) {
+               sr_err("Unsupported samplerate: %" PRIu64 "Hz.", samplerate);
+               return SR_ERR_ARG;
+       }
+
+       sr_info("Setting samplerate to %" PRIu64 "Hz.", samplerate);
+
+       if (samplerate >= SR_MHZ(1))
+               analyzer_set_freq(samplerate / SR_MHZ(1), FREQ_SCALE_MHZ);
+       else if (samplerate >= SR_KHZ(1))
+               analyzer_set_freq(samplerate / SR_KHZ(1), FREQ_SCALE_KHZ);
+       else
+               analyzer_set_freq(samplerate, FREQ_SCALE_HZ);
+
+       devc->cur_samplerate = samplerate;
+
+       return SR_OK;
+}
+
 static int clear_instances(void)
 {
        GSList *l;
@@ -483,7 +511,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
                        return SR_ERR;
                break;
        default:
-               return SR_ERR_ARG;
+               return SR_ERR_NA;
        }
 
        return SR_OK;
@@ -511,7 +539,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
        case SR_CONF_CAPTURE_RATIO:
                return set_capture_ratio(devc, g_variant_get_uint64(data));
        default:
-               return SR_ERR;
+               return SR_ERR_NA;
        }
 
        return SR_OK;
@@ -551,7 +579,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
                *data = g_variant_new_string(TRIGGER_TYPE);
                break;
        default:
-               return SR_ERR_ARG;
+               return SR_ERR_NA;
        }
 
        return SR_OK;