hantek-4032l: Set new pwm threshold handling.

Calculate threshold values from <-6.0;6.0> range.

Signed-off-by: Andrej Valek <andy@skyrain.eu>
This commit is contained in:
Andrej Valek 2018-05-22 22:33:12 +02:00 committed by Uwe Hermann
parent 3dc976fe9f
commit caad0024fb
2 changed files with 14 additions and 8 deletions

View File

@ -39,7 +39,7 @@ static const uint32_t devopts[] = {
SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
SR_CONF_TRIGGER_MATCH | SR_CONF_LIST, SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
SR_CONF_CONN | SR_CONF_GET, SR_CONF_CONN | SR_CONF_GET,
SR_CONF_VOLTAGE_THRESHOLD | SR_CONF_SET | SR_CONF_LIST, SR_CONF_VOLTAGE_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
}; };
static const int32_t trigger_matches[] = { static const int32_t trigger_matches[] = {
@ -210,13 +210,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
/* Initialize command packet. */ /* Initialize command packet. */
devc->cmd_pkt.magic = H4032L_CMD_PKT_MAGIC; devc->cmd_pkt.magic = H4032L_CMD_PKT_MAGIC;
devc->cmd_pkt.pwm_a = h4032l_voltage2pwm(2.5);
devc->cmd_pkt.pwm_b = h4032l_voltage2pwm(2.5);
devc->cmd_pkt.sample_size = 16384; devc->cmd_pkt.sample_size = 16384;
devc->status = H4032L_STATUS_IDLE; devc->status = H4032L_STATUS_IDLE;
devc->capture_ratio = 5; devc->capture_ratio = 5;
devc->cur_threshold = 2.5;
sdi->priv = devc; sdi->priv = devc;
devices = g_slist_append(devices, sdi); devices = g_slist_append(devices, sdi);
@ -298,6 +297,9 @@ static int config_get(uint32_t key, GVariant **data,
(void)cg; (void)cg;
switch (key) { switch (key) {
case SR_CONF_VOLTAGE_THRESHOLD:
*data = std_gvar_tuple_double(devc->cur_threshold, devc->cur_threshold);
break;
case SR_CONF_SAMPLERATE: case SR_CONF_SAMPLERATE:
*data = g_variant_new_uint64(samplerates_hw[devc->cmd_pkt.sample_rate]); *data = g_variant_new_uint64(samplerates_hw[devc->cmd_pkt.sample_rate]);
break; break;
@ -364,10 +366,9 @@ static int config_set(uint32_t key, GVariant *data,
break; break;
} }
case SR_CONF_VOLTAGE_THRESHOLD: { case SR_CONF_VOLTAGE_THRESHOLD: {
double d1, d2; double low, high;
g_variant_get(data, "(dd)", &d1, &d2); g_variant_get(data, "(dd)", &low, &high);
devc->cmd_pkt.pwm_a = h4032l_voltage2pwm(d1); devc->cur_threshold = (low+high)/2.0;
devc->cmd_pkt.pwm_b = h4032l_voltage2pwm(d2);
break; break;
} }
default: default:
@ -391,7 +392,7 @@ static int config_list(uint32_t key, GVariant **data,
*data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches)); *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
break; break;
case SR_CONF_VOLTAGE_THRESHOLD: case SR_CONF_VOLTAGE_THRESHOLD:
*data = std_gvar_tuple_double(2.5, 2.5); *data = std_gvar_min_max_step_thresholds(-6.0, 6.0, 0.1);
break; break;
case SR_CONF_LIMIT_SAMPLES: case SR_CONF_LIMIT_SAMPLES:
*data = std_gvar_tuple_u64(H4043L_NUM_SAMPLES_MIN, H4032L_NUM_SAMPLES_MAX); *data = std_gvar_tuple_u64(H4043L_NUM_SAMPLES_MIN, H4032L_NUM_SAMPLES_MAX);
@ -420,6 +421,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
cmd_pkt->pre_trigger_size = (cmd_pkt->sample_size * devc->capture_ratio) / 100; cmd_pkt->pre_trigger_size = (cmd_pkt->sample_size * devc->capture_ratio) / 100;
devc->trigger_pos = cmd_pkt->pre_trigger_size; devc->trigger_pos = cmd_pkt->pre_trigger_size;
/* Set pwm channel values. */
devc->cmd_pkt.pwm_a = h4032l_voltage2pwm(devc->cur_threshold);
devc->cmd_pkt.pwm_b = devc->cmd_pkt.pwm_a;
cmd_pkt->trig_flags.enable_trigger1 = 0; cmd_pkt->trig_flags.enable_trigger1 = 0;
cmd_pkt->trig_flags.enable_trigger2 = 0; cmd_pkt->trig_flags.enable_trigger2 = 0;
cmd_pkt->trig_flags.trigger_and_logic = 0; cmd_pkt->trig_flags.trigger_and_logic = 0;

View File

@ -136,6 +136,7 @@ struct dev_context {
uint8_t buffer[512]; uint8_t buffer[512];
uint64_t capture_ratio; uint64_t capture_ratio;
uint32_t trigger_pos; uint32_t trigger_pos;
double cur_threshold;
uint32_t fpga_version; uint32_t fpga_version;
}; };