SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
#if WITH_THRESHOLD_DEVCFG
SR_CONF_VOLTAGE_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
-#if !WITH_THRESHOLD_SIMPLE
- SR_CONF_LOGIC_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
- SR_CONF_LOGIC_THRESHOLD_CUSTOM | SR_CONF_GET | SR_CONF_SET,
-#endif
#endif
SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
SR_MHZ(100),
};
-#if WITH_THRESHOLD_SIMPLE
-
/*
* Only list a few discrete voltages, to form a useful set which covers
* most logic families. Too many choices can make some applications use
return voltage;
}
-#else /* WITH_THRESHOLD_SIMPLE */
-
-static const float logic_threshold_value[] = {
- 1.58,
- 2.5,
- 1.165,
- 1.5,
- 1.25,
- 0.9,
- 0.75,
- 0.60,
- 0.45,
-};
-
-static const char *logic_threshold[] = {
- "TTL 5V",
- "CMOS 5V",
- "CMOS 3.3V",
- "CMOS 3.0V",
- "CMOS 2.5V",
- "CMOS 1.8V",
- "CMOS 1.5V",
- "CMOS 1.2V",
- "CMOS 0.9V",
- "USER",
-};
-
-#define LOGIC_THRESHOLD_IDX_USER (ARRAY_SIZE(logic_threshold) - 1)
-
-static double threshold_voltage(const struct sr_dev_inst *sdi, double *high)
-{
- struct dev_context *devc;
- size_t idx;
- double voltage;
-
- devc = sdi->priv;
- idx = devc->threshold_voltage_idx;
- if (idx == LOGIC_THRESHOLD_IDX_USER)
- voltage = devc->threshold_voltage;
- else
- voltage = logic_threshold_value[idx];
- if (high)
- *high = voltage;
-
- return voltage;
-}
-
-#endif /* WITH_THRESHOLD_SIMPLE */
-
/* Convenience. Release an allocated devc from error paths. */
static void kingst_la2016_free_devc(struct dev_context *devc)
{
devc->sw_limits.limit_samples = 0;
devc->capture_ratio = 50;
devc->cur_samplerate = devc->model->samplerate;
-#if WITH_THRESHOLD_SIMPLE
devc->threshold_voltage_idx = LOGIC_THRESHOLD_IDX_DFLT;
-#else /* WITH_THRESHOLD_SIMPLE */
- devc->threshold_voltage_idx = 0;
- devc->threshold_voltage = logic_threshold_value[devc->threshold_voltage_idx];
-#endif /* WITH_THRESHOLD_SIMPLE */
if (ARRAY_SIZE(devc->pwm_setting) >= 1) {
devc->pwm_setting[0].enabled = FALSE;
devc->pwm_setting[0].freq = SR_KHZ(1);
struct pwm_setting *pwm;
struct sr_usb_dev_inst *usb;
double voltage, rounded;
- const char *label;
(void)rounded;
(void)voltage;
if (cg && cg_type == SR_CHANNEL_LOGIC) {
switch (key) {
#if !WITH_THRESHOLD_DEVCFG
-#if WITH_THRESHOLD_SIMPLE
case SR_CONF_VOLTAGE_THRESHOLD:
voltage = threshold_voltage(sdi, NULL);
*data = std_gvar_tuple_double(voltage, voltage);
break;
-#endif /* WITH_THRESHOLD_SIMPLE */
#endif /* WITH_THRESHOLD_DEVCFG */
default:
return SR_ERR_NA;
*data = g_variant_new_uint64(devc->capture_ratio);
break;
#if WITH_THRESHOLD_DEVCFG
-#if WITH_THRESHOLD_SIMPLE
case SR_CONF_VOLTAGE_THRESHOLD:
voltage = threshold_voltage(sdi, NULL);
*data = std_gvar_tuple_double(voltage, voltage);
break;
-#else /* WITH_THRESHOLD_SIMPLE */
- case SR_CONF_VOLTAGE_THRESHOLD:
- rounded = (int)(devc->threshold_voltage / 0.1) * 0.1;
- *data = std_gvar_tuple_double(rounded, rounded + 0.1);
- break;
- case SR_CONF_LOGIC_THRESHOLD:
- label = logic_threshold[devc->threshold_voltage_idx];
- *data = g_variant_new_string(label);
- break;
- case SR_CONF_LOGIC_THRESHOLD_CUSTOM:
- *data = g_variant_new_double(devc->threshold_voltage);
- break;
-#endif /* WITH_THRESHOLD_SIMPLE */
#endif /* WITH_THRESHOLD_DEVCFG */
default:
return SR_ERR_NA;
size_t logic_idx, analog_idx;
struct pwm_setting *pwm;
double value_f;
- double low, high, voltage;
int idx;
devc = sdi->priv;
if (cg && cg_type == SR_CHANNEL_LOGIC) {
switch (key) {
#if !WITH_THRESHOLD_DEVCFG
-#if WITH_THRESHOLD_SIMPLE
case SR_CONF_LOGIC_THRESHOLD:
idx = std_double_tuple_idx(data,
ARRAY_AND_SIZE(threshold_ranges));
return SR_ERR_ARG;
devc->threshold_voltage_idx = idx;
break;
-#endif /* WITH_THRESHOLD_SIMPLE */
#endif /* WITH_THRESHOLD_DEVCFG */
default:
return SR_ERR_NA;
devc->capture_ratio = g_variant_get_uint64(data);
break;
#if WITH_THRESHOLD_DEVCFG
-#if WITH_THRESHOLD_SIMPLE
case SR_CONF_VOLTAGE_THRESHOLD:
idx = std_double_tuple_idx(data,
ARRAY_AND_SIZE(threshold_ranges));
return SR_ERR_ARG;
devc->threshold_voltage_idx = idx;
break;
-#else /* WITH_THRESHOLD_SIMPLE */
- case SR_CONF_VOLTAGE_THRESHOLD:
- g_variant_get(data, "(dd)", &low, &high);
- devc->threshold_voltage = (low + high) / 2.0;
- devc->threshold_voltage_idx = LOGIC_THRESHOLD_IDX_USER;
- break;
- case SR_CONF_LOGIC_THRESHOLD: {
- idx = std_str_idx(data, ARRAY_AND_SIZE(logic_threshold));
- if (idx < 0)
- return SR_ERR_ARG;
- if (idx != LOGIC_THRESHOLD_IDX_USER) {
- devc->threshold_voltage = logic_threshold_value[idx];
- }
- devc->threshold_voltage_idx = idx;
- break;
- }
- case SR_CONF_LOGIC_THRESHOLD_CUSTOM:
- devc->threshold_voltage = g_variant_get_double(data);
- break;
-#endif /* WITH_THRESHOLD_SIMPLE */
#endif /* WITH_THRESHOLD_DEVCFG */
default:
return SR_ERR_NA;
sizeof(devopts_cg_logic[0]));
break;
#if !WITH_THRESHOLD_DEVCFG
-#if WITH_THRESHOLD_SIMPLE
case SR_CONF_VOLTAGE_THRESHOLD:
*data = std_gvar_thresholds(ARRAY_AND_SIZE(threshold_ranges));
break;
-#endif /* WITH_THRESHOLD_SIMPLE */
#endif /* WITH_THRESHOLD_DEVCFG */
default:
return SR_ERR_NA;
*data = std_gvar_tuple_u64(0, LA2016_NUM_SAMPLES_MAX);
break;
#if WITH_THRESHOLD_DEVCFG
-#if WITH_THRESHOLD_SIMPLE
case SR_CONF_VOLTAGE_THRESHOLD:
*data = std_gvar_thresholds(ARRAY_AND_SIZE(threshold_ranges));
break;
-#else /* WITH_THRESHOLD_SIMPLE */
- case SR_CONF_VOLTAGE_THRESHOLD:
- *data = std_gvar_min_max_step_thresholds(
- LA2016_THR_VOLTAGE_MIN,
- LA2016_THR_VOLTAGE_MAX, 0.1);
- break;
- case SR_CONF_LOGIC_THRESHOLD:
- *data = g_variant_new_strv(ARRAY_AND_SIZE(logic_threshold));
- break;
-#endif /* WITH_THRESHOLD_SIMPLE */
#endif /* WITH_THRESHOLD_DEVCFG */
case SR_CONF_TRIGGER_MATCH:
*data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
#define LA2016_EP2_PADDING 2048
/*
- * The complex logic input threshold voltage support with a custom level
- * is not operational yet. Ideally we could support the set of pre-made
- * voltages with their pretty text labels, and one of them referencing
- * a voltage which is user specified. But not all applications support
- * this setup equally well, or present it most appropriately to users.
- * So let's implement something simpler for the moment until the more
- * complex approach becomes accessible in all applications.
- *
- * Strictly speaking the logic input threshold voltage is a property of
- * the "Logic" channel group. Again not all applications support such
- * an approach, and like to see them as global device properties.
+ * Whether the logic input threshold voltage is a config item of the
+ * "Logic" channel group or a global config item of the device. Ideally
+ * it would be the former (being strictly related to the Logic channels)
+ * but mainline applications work better with the latter, and many other
+ * device drivers implement it that way, too.
*/
#define WITH_THRESHOLD_DEVCFG 1
-#define WITH_THRESHOLD_SIMPLE 1
-#if !WITH_THRESHOLD_DEVCFG && !WITH_THRESHOLD_SIMPLE
-# error "Custom threshold in Logic group is not implemented."
-#endif
#define LA2016_THR_VOLTAGE_MIN 0.40
#define LA2016_THR_VOLTAGE_MAX 4.00
float duty;
} pwm_setting[LA2016_NUM_PWMCH_MAX];
size_t threshold_voltage_idx;
-#if !WITH_THRESHOLD_SIMPLE
- float threshold_voltage;
-#endif
uint64_t cur_samplerate;
struct sr_sw_limits sw_limits;
uint64_t capture_ratio;