drivers: Replace struct voltage_threshold with an array.
This makes the code-base more consistent and will allow for wider usage of upcoming array helper functions.
This commit is contained in:
parent
87dc541027
commit
94e64a0b89
|
@ -72,7 +72,7 @@ static const char *const signal_edge_names[] = {
|
||||||
[DS_EDGE_FALLING] = "falling",
|
[DS_EDGE_FALLING] = "falling",
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct voltage_threshold voltage_thresholds[] = {
|
static const double voltage_thresholds[][2] = {
|
||||||
{ 0.7, 1.4 },
|
{ 0.7, 1.4 },
|
||||||
{ 1.4, 3.6 },
|
{ 1.4, 3.6 },
|
||||||
};
|
};
|
||||||
|
@ -405,12 +405,12 @@ static int config_get(uint32_t key, GVariant **data,
|
||||||
voltage_range = 0;
|
voltage_range = 0;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(voltage_thresholds); i++)
|
for (i = 0; i < ARRAY_SIZE(voltage_thresholds); i++)
|
||||||
if (voltage_thresholds[i].low == devc->cur_threshold) {
|
if (voltage_thresholds[i][0] == devc->cur_threshold) {
|
||||||
voltage_range = i;
|
voltage_range = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*data = std_gvar_tuple_double(voltage_thresholds[voltage_range].low,
|
*data = std_gvar_tuple_double(voltage_thresholds[voltage_range][0],
|
||||||
voltage_thresholds[voltage_range].high);
|
voltage_thresholds[voltage_range][1]);
|
||||||
} else {
|
} else {
|
||||||
*data = std_gvar_tuple_double(devc->cur_threshold, devc->cur_threshold);
|
*data = std_gvar_tuple_double(devc->cur_threshold, devc->cur_threshold);
|
||||||
}
|
}
|
||||||
|
@ -505,10 +505,10 @@ static int config_set(uint32_t key, GVariant *data,
|
||||||
g_variant_get(data, "(dd)", &low, &high);
|
g_variant_get(data, "(dd)", &low, &high);
|
||||||
if (!strcmp(devc->profile->model, "DSLogic")) {
|
if (!strcmp(devc->profile->model, "DSLogic")) {
|
||||||
for (i = 0; (unsigned int)i < ARRAY_SIZE(voltage_thresholds); i++) {
|
for (i = 0; (unsigned int)i < ARRAY_SIZE(voltage_thresholds); i++) {
|
||||||
if (fabs(voltage_thresholds[i].low - low) < 0.1 &&
|
if (fabs(voltage_thresholds[i][0] - low) < 0.1 &&
|
||||||
fabs(voltage_thresholds[i].high - high) < 0.1) {
|
fabs(voltage_thresholds[i][1] - high) < 0.1) {
|
||||||
devc->cur_threshold =
|
devc->cur_threshold =
|
||||||
voltage_thresholds[i].low;
|
voltage_thresholds[i][0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ static const struct {
|
||||||
{ VOLTAGE_RANGE_5_V, },
|
{ VOLTAGE_RANGE_5_V, },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct voltage_threshold volt_thresholds[] = {
|
static const double volt_thresholds[][2] = {
|
||||||
{ 0.7, 1.4 },
|
{ 0.7, 1.4 },
|
||||||
{ 1.4, 3.6 },
|
{ 1.4, 3.6 },
|
||||||
};
|
};
|
||||||
|
@ -441,7 +441,7 @@ static int config_get(uint32_t key, GVariant **data,
|
||||||
if (devc->selected_voltage_range !=
|
if (devc->selected_voltage_range !=
|
||||||
volt_thresholds_ranges[i].range)
|
volt_thresholds_ranges[i].range)
|
||||||
continue;
|
continue;
|
||||||
*data = std_gvar_tuple_double(volt_thresholds[i].low, volt_thresholds[i].high);
|
*data = std_gvar_tuple_double(volt_thresholds[i][0], volt_thresholds[i][1]);
|
||||||
ret = SR_OK;
|
ret = SR_OK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -481,8 +481,8 @@ static int config_set(uint32_t key, GVariant *data,
|
||||||
g_variant_get(data, "(dd)", &low, &high);
|
g_variant_get(data, "(dd)", &low, &high);
|
||||||
ret = SR_ERR_ARG;
|
ret = SR_ERR_ARG;
|
||||||
for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++) {
|
for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++) {
|
||||||
if (fabs(volt_thresholds[i].low - low) < 0.1 &&
|
if (fabs(volt_thresholds[i][0] - low) < 0.1 &&
|
||||||
fabs(volt_thresholds[i].high - high) < 0.1) {
|
fabs(volt_thresholds[i][1] - high) < 0.1) {
|
||||||
devc->selected_voltage_range =
|
devc->selected_voltage_range =
|
||||||
volt_thresholds_ranges[i].range;
|
volt_thresholds_ranges[i].range;
|
||||||
ret = SR_OK;
|
ret = SR_OK;
|
||||||
|
|
|
@ -971,12 +971,7 @@ SR_PRIV GVariant *std_gvar_array_i32(const int32_t *a, unsigned int n);
|
||||||
SR_PRIV GVariant *std_gvar_array_u32(const uint32_t *a, unsigned int n);
|
SR_PRIV GVariant *std_gvar_array_u32(const uint32_t *a, unsigned int n);
|
||||||
SR_PRIV GVariant *std_gvar_array_u64(const uint64_t *a, unsigned int n);
|
SR_PRIV GVariant *std_gvar_array_u64(const uint64_t *a, unsigned int n);
|
||||||
|
|
||||||
struct voltage_threshold {
|
SR_PRIV GVariant *std_gvar_thresholds(const double a[][2], unsigned int n);
|
||||||
double low;
|
|
||||||
double high;
|
|
||||||
};
|
|
||||||
|
|
||||||
SR_PRIV GVariant *std_gvar_thresholds(const struct voltage_threshold a[], unsigned int n);
|
|
||||||
|
|
||||||
/*--- resource.c ------------------------------------------------------------*/
|
/*--- resource.c ------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
|
@ -685,7 +685,7 @@ SR_PRIV GVariant *std_gvar_array_u64(const uint64_t *a, unsigned int n)
|
||||||
a, n, sizeof(uint64_t));
|
a, n, sizeof(uint64_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV GVariant *std_gvar_thresholds(const struct voltage_threshold a[], unsigned int n)
|
SR_PRIV GVariant *std_gvar_thresholds(const double a[][2], unsigned int n)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
GVariant *gvar, *range[2];
|
GVariant *gvar, *range[2];
|
||||||
|
@ -694,8 +694,8 @@ SR_PRIV GVariant *std_gvar_thresholds(const struct voltage_threshold a[], unsign
|
||||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
range[0] = g_variant_new_double(a[i].low);
|
range[0] = g_variant_new_double(a[i][0]);
|
||||||
range[1] = g_variant_new_double(a[i].high);
|
range[1] = g_variant_new_double(a[i][1]);
|
||||||
gvar = g_variant_new_tuple(range, 2);
|
gvar = g_variant_new_tuple(range, 2);
|
||||||
g_variant_builder_add_value(&gvb, gvar);
|
g_variant_builder_add_value(&gvb, gvar);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue