SR_CONF_VOLTAGE_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
};
+static const char *cg_names[] = {
+ "A", "B",
+};
+
static const char *signal_edges[] = {
[H4032L_CLOCK_EDGE_TYPE_RISE] = "rising",
[H4032L_CLOCK_EDGE_TYPE_FALL] = "falling",
SR_MHZ(320),
};
-SR_PRIV struct sr_dev_driver hantek_4032l_driver_info;
+static struct sr_dev_driver hantek_4032l_driver_info;
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct sr_channel_group *channel_groups[2];
for (int j = 0; j < 2; j++) {
- cg = g_malloc0(sizeof(struct sr_channel_group));
+ cg = sr_channel_group_new(sdi, NULL, NULL);
cg->name = g_strdup_printf("%c", 'A' + j);
channel_groups[j] = cg;
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
/* Assemble channel list and add channel to channel groups. */
/* Initialize command packet. */
devc->cmd_pkt.magic = H4032L_CMD_PKT_MAGIC;
- devc->cmd_pkt.sample_size = 16384;
+ devc->cmd_pkt.sample_size = 16 * 1024;
devc->sample_rate = 0;
devc->status = H4032L_STATUS_IDLE;
devc->external_clock = FALSE;
devc->clock_edge = H4032L_CLOCK_EDGE_TYPE_RISE;
- devc->cur_threshold[0] = 2.5;
- devc->cur_threshold[1] = 2.5;
+ /* Create array of thresholds from min to max. */
+ GVariant *thresholds = std_gvar_min_max_step_thresholds(
+ H4032L_THR_VOLTAGE_MIN, H4032L_THR_VOLTAGE_MAX,
+ H4032L_THR_VOLTAGE_STEP);
+ /* Take default threshold value from array (FP workaround). */
+ g_variant_get_child(thresholds, H4032L_THR_VOLTAGE_DEFAULT,
+ "(dd)", &devc->cur_threshold[0], &devc->cur_threshold[1]);
sdi->priv = devc;
devices = g_slist_append(devices, sdi);
{
struct dev_context *devc = sdi->priv;
struct sr_usb_dev_inst *usb;
- unsigned int idx;
+ int idx;
switch (key) {
case SR_CONF_VOLTAGE_THRESHOLD:
if (!cg)
return SR_ERR_CHANNEL_GROUP;
- if (!strcmp(cg->name, "A"))
- *data = std_gvar_tuple_double(
- devc->cur_threshold[0], devc->cur_threshold[0]);
- else if (!strcmp(cg->name, "B"))
- *data = std_gvar_tuple_double(
- devc->cur_threshold[1], devc->cur_threshold[1]);
- else
+ if ((idx = std_str_idx_s(cg->name, ARRAY_AND_SIZE(cg_names))) < 0)
return SR_ERR_CHANNEL_GROUP;
+ *data = std_gvar_tuple_double(
+ devc->cur_threshold[idx], devc->cur_threshold[idx]);
break;
case SR_CONF_SAMPLERATE:
*data = g_variant_new_uint64(samplerates_hw[devc->sample_rate]);
*data = g_variant_new_boolean(devc->external_clock);
break;
case SR_CONF_EXTERNAL_CLOCK_SOURCE:
- idx = devc->external_clock_source;
- if (idx >= ARRAY_SIZE(ext_clock_sources))
- return SR_ERR_BUG;
- *data = g_variant_new_string(ext_clock_sources[idx]);
+ *data = g_variant_new_string(ext_clock_sources[devc->external_clock_source]);
break;
case SR_CONF_CONN:
if (!sdi || !(usb = sdi->conn))
*data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
break;
case SR_CONF_CLOCK_EDGE:
- idx = devc->clock_edge;
- if (idx >= ARRAY_SIZE(signal_edges))
- return SR_ERR_BUG;
- *data = g_variant_new_string(signal_edges[idx]);
+ *data = g_variant_new_string(signal_edges[devc->clock_edge]);
break;
default:
return SR_ERR_NA;
int idx;
struct dev_context *devc = sdi->priv;
struct h4032l_cmd_pkt *cmd_pkt = &devc->cmd_pkt;
- uint64_t sample_rate, capture_ratio, number_samples;
- double low, high, threshold;
+ uint64_t sample_rate, num_samples;
+ double low, high;
switch (key) {
case SR_CONF_SAMPLERATE:
idx = 0;
sample_rate = g_variant_get_uint64(data);
- while (idx < ARRAY_SIZE(samplerates_hw) && samplerates_hw[idx] != sample_rate)
+ while (idx < (int)ARRAY_SIZE(samplerates_hw) && samplerates_hw[idx] != sample_rate)
idx++;
if (idx == ARRAY_SIZE(samplerates_hw) || sample_rate == 0) {
sr_err("Invalid sample rate.");
devc->sample_rate = idx;
break;
case SR_CONF_CAPTURE_RATIO:
- capture_ratio = g_variant_get_uint64(data);
- if (capture_ratio > 99) {
- sr_err("Invalid capture ratio.");
- return SR_ERR;
- }
- devc->capture_ratio = capture_ratio;
+ devc->capture_ratio = g_variant_get_uint64(data);
break;
case SR_CONF_LIMIT_SAMPLES:
- number_samples = g_variant_get_uint64(data);
- number_samples += 511;
- number_samples &= 0xfffffe00;
- if (number_samples < H4043L_NUM_SAMPLES_MIN ||
- number_samples > H4032L_NUM_SAMPLES_MAX) {
+ num_samples = g_variant_get_uint64(data);
+ num_samples += 511;
+ num_samples &= 0xfffffe00;
+ if (num_samples < H4043L_NUM_SAMPLES_MIN ||
+ num_samples > H4032L_NUM_SAMPLES_MAX) {
sr_err("Invalid sample range 2k...64M: %"
- PRIu64 ".", number_samples);
+ PRIu64 ".", num_samples);
return SR_ERR;
}
- cmd_pkt->sample_size = number_samples;
+ cmd_pkt->sample_size = num_samples;
break;
case SR_CONF_VOLTAGE_THRESHOLD:
if (!cg)
return SR_ERR_CHANNEL_GROUP;
- g_variant_get(data, "(dd)", &low, &high);
- threshold = (low + high) / 2.0;
- if (!strcmp(cg->name, "A"))
- devc->cur_threshold[0] = threshold;
- else if (!strcmp(cg->name, "B"))
- devc->cur_threshold[1] = threshold;
- else
+ if ((idx = std_str_idx_s(cg->name, ARRAY_AND_SIZE(cg_names))) < 0)
return SR_ERR_CHANNEL_GROUP;
+ g_variant_get(data, "(dd)", &low, &high);
+ devc->cur_threshold[idx] = (low + high) / 2.0;
break;
case SR_CONF_EXTERNAL_CLOCK:
devc->external_clock = g_variant_get_boolean(data);
*data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
break;
case SR_CONF_VOLTAGE_THRESHOLD:
- *data = std_gvar_min_max_step_thresholds(-6.0, 6.0, 0.1);
+ *data = std_gvar_min_max_step_thresholds(H4032L_THR_VOLTAGE_MIN,
+ H4032L_THR_VOLTAGE_MAX, H4032L_THR_VOLTAGE_STEP);
break;
case SR_CONF_LIMIT_SAMPLES:
*data = std_gvar_tuple_u64(H4043L_NUM_SAMPLES_MIN, H4032L_NUM_SAMPLES_MAX);
else
cmd_pkt->sample_rate = devc->sample_rate;
- /* Set pwm channel values. */
+ /* Set PWM channel values. */
devc->cmd_pkt.pwm_a = h4032l_voltage2pwm(devc->cur_threshold[0]);
devc->cmd_pkt.pwm_b = h4032l_voltage2pwm(devc->cur_threshold[1]);
channel = channel->next;
}
- /* Compress range mask value and apply range settings. */
- if (range_mask) {
- cmd_pkt->trigger[0].flags.data_range_enabled = 1;
- cmd_pkt->trigger[0].data_range_mask |= (range_mask);
-
- uint32_t new_range_value = 0;
- uint32_t bit_mask = 1;
- while (range_mask) {
- if ((range_mask & 1) != 0) {
- new_range_value <<= 1;
- if ((range_value & 1) != 0)
- new_range_value |= bit_mask;
- bit_mask <<= 1;
- }
- range_mask >>= 1;
- range_value >>= 1;
- }
- cmd_pkt->trigger[0].data_range_max |= range_value;
- }
+ cmd_pkt->trigger[0].flags.data_range_enabled = 1;
+ cmd_pkt->trigger[0].data_range_mask |= range_mask;
+ cmd_pkt->trigger[0].data_range_max = range_value;
}
usb_source_add(sdi->session, drvc->sr_ctx, 1000,
return h4032l_stop(sdi);
}
-SR_PRIV struct sr_dev_driver hantek_4032l_driver_info = {
+static struct sr_dev_driver hantek_4032l_driver_info = {
.name = "hantek-4032l",
.longname = "Hantek 4032L",
.api_version = 1,