X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Fhardware%2Fhung-chang-dso-2100%2Fapi.c;h=88423357592dd6eeefa230abf980ddab09015fbf;hp=4386053d3d2f8a4639a6c6b52446a452d73945c2;hb=HEAD;hpb=697fb6ddfc2522b2e6d35511c7837e2c61d8ae73 diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index 4386053d..88423357 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -138,11 +138,9 @@ static GSList *scan_port(GSList *devices, struct parport *port) ieee1284_ref(port); for (i = 0; i < NUM_CHANNELS; i++) { - cg = g_malloc0(sizeof(struct sr_channel_group)); - cg->name = g_strdup(trigger_sources[i]); + cg = sr_channel_group_new(sdi, trigger_sources[i], NULL); ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, FALSE, trigger_sources[i]); cg->channels = g_slist_append(cg->channels, ch); - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } devc = g_malloc0(sizeof(struct dev_context)); @@ -312,35 +310,29 @@ static int config_get(uint32_t key, GVariant **data, case SR_CONF_TRIGGER_SLOPE: if (devc->edge >= ARRAY_SIZE(trigger_slopes)) return SR_ERR; - else - *data = g_variant_new_string(trigger_slopes[devc->edge]); + *data = g_variant_new_string(trigger_slopes[devc->edge]); break; case SR_CONF_BUFFERSIZE: *data = g_variant_new_uint64(buffersizes[devc->last_step]); break; case SR_CONF_VDIV: - if (ch == -1) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else { - if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x33, ARRAY_AND_SIZE(vdivs_map))) < 0) - return SR_ERR_BUG; - *data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]); - } + if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x33, ARRAY_AND_SIZE(vdivs_map))) < 0) + return SR_ERR_BUG; + *data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]); break; case SR_CONF_COUPLING: - if (ch == -1) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else { - if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x0C, ARRAY_AND_SIZE(coupling_map))) < 0) - return SR_ERR_BUG; - *data = g_variant_new_string(coupling[idx]); - } + if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x0C, ARRAY_AND_SIZE(coupling_map))) < 0) + return SR_ERR_BUG; + *data = g_variant_new_string(coupling[idx]); break; case SR_CONF_PROBE_FACTOR: - if (ch == -1) + if (!cg) return SR_ERR_CHANNEL_GROUP; - else - *data = g_variant_new_uint64(devc->probe[ch]); + *data = g_variant_new_uint64(devc->probe[ch]); break; default: return SR_ERR_NA; @@ -384,35 +376,28 @@ static int config_set(uint32_t key, GVariant *data, devc->last_step = idx; break; case SR_CONF_VDIV: - if (ch == -1) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else if (!g_variant_is_of_type(data, G_VARIANT_TYPE("(tt)"))) { + if (!g_variant_is_of_type(data, G_VARIANT_TYPE("(tt)"))) return SR_ERR_ARG; - } else { - if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0) - return SR_ERR_ARG; - devc->cctl[ch] = (devc->cctl[ch] & 0xCC) | vdivs_map[idx]; - } + if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0) + return SR_ERR_ARG; + devc->cctl[ch] = (devc->cctl[ch] & 0xCC) | vdivs_map[idx]; break; case SR_CONF_COUPLING: - if (ch == -1) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else { - if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0) - return SR_ERR_ARG; - devc->cctl[ch] = (devc->cctl[ch] & 0xF3) | coupling_map[idx]; - } + if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0) + return SR_ERR_ARG; + devc->cctl[ch] = (devc->cctl[ch] & 0xF3) | coupling_map[idx]; break; case SR_CONF_PROBE_FACTOR: - if (ch == -1) { + if (!cg) return SR_ERR_CHANNEL_GROUP; - } else { - u = g_variant_get_uint64(data); - if (!u) - return SR_ERR_ARG; - else - devc->probe[ch] = u; - } + u = g_variant_get_uint64(data); + if (!u) + return SR_ERR_ARG; + devc->probe[ch] = u; break; default: return SR_ERR_NA; @@ -427,17 +412,19 @@ static int config_channel_set(const struct sr_dev_inst *sdi, struct dev_context *devc = sdi->priv; uint8_t v; - if (changes & SR_CHANNEL_SET_ENABLED) { - if (ch->enabled) { - v = devc->channel | (1 << ch->index); - if (v & (v - 1)) - return SR_ERR; - devc->channel = v; - devc->enabled_channel->data = ch; - } else { - devc->channel &= ~(1 << ch->index); - } + if (!(changes & SR_CHANNEL_SET_ENABLED)) + return SR_OK; + + if (ch->enabled) { + v = devc->channel | (1 << ch->index); + if (v & (v - 1)) + return SR_ERR; + devc->channel = v; + devc->enabled_channel->data = ch; + } else { + devc->channel &= ~(1 << ch->index); } + return SR_OK; } @@ -501,10 +488,10 @@ static int config_list(uint32_t key, GVariant **data, switch (key) { case SR_CONF_SCAN_OPTIONS: - return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, NULL); + return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NO_OPTS, NO_OPTS); case SR_CONF_DEVICE_OPTIONS: if (!cg) - return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); + return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts); *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg)); break; case SR_CONF_SAMPLERATE: