X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fdevantech-eth008%2Fapi.c;h=9bace4eaa4dc938eb55fdcbf0f910f1ed57852ce;hb=1ebdf6406682edb25cd4929638c24391bec8e5f6;hp=a40a1fd98b581ece1721f51db8c884edad407eb2;hpb=8712c7833fdc1e33363807b094ad998df1b97463;p=libsigrok.git diff --git a/src/hardware/devantech-eth008/api.c b/src/hardware/devantech-eth008/api.c index a40a1fd9..9bace4ea 100644 --- a/src/hardware/devantech-eth008/api.c +++ b/src/hardware/devantech-eth008/api.c @@ -42,12 +42,25 @@ static const uint32_t devopts_cg_do[] = { SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET, }; +static const uint32_t devopts_cg_di[] = { + SR_CONF_ENABLED | SR_CONF_GET, +}; + static const uint32_t devopts_cg_ai[] = { SR_CONF_VOLTAGE | SR_CONF_GET, }; +/* List of supported devices. Sorted by model ID. */ static const struct devantech_eth008_model models[] = { - { 19, "ETH008", 8, 0, 1, }, + { 18, "ETH002", 2, 0, 0, 0, 1, 0, 0, }, + { 19, "ETH008", 8, 0, 0, 0, 1, 0, 0, }, + { 20, "ETH484", 16, 8, 4, 0, 2, 2, 0x00f0, }, + { 21, "ETH8020", 20, 8, 8, 0, 3, 4, 0, }, + { 22, "WIFI484", 16, 8, 4, 0, 2, 2, 0x00f0, }, + { 24, "WIFI8020", 20, 8, 8, 0, 3, 4, 0, }, + { 26, "WIFI002", 2, 0, 0, 0, 1, 0, 0, }, + { 28, "WIFI008", 8, 0, 0, 0, 1, 0, 0, }, + { 52, "ETH1610", 10, 16, 16, 0, 2, 2, 0, }, }; static const struct devantech_eth008_model *find_model(uint8_t code) @@ -77,7 +90,7 @@ static struct sr_dev_inst *probe_device_conn(const char *conn) gboolean has_serno_cmd; char snr_txt[16]; struct channel_group_context *cgc; - size_t ch_idx, nr, do_idx; + size_t ch_idx, nr, do_idx, di_idx, ai_idx; struct sr_channel_group *cg; char cg_name[24]; int ret; @@ -127,8 +140,11 @@ static struct sr_dev_inst *probe_device_conn(const char *conn) ch_idx = 0; devc->mask_do = (1UL << devc->model->ch_count_do) - 1; + devc->mask_do &= ~devc->model->mask_do_missing; for (do_idx = 0; do_idx < devc->model->ch_count_do; do_idx++) { nr = do_idx + 1; + if (devc->model->mask_do_missing & (1UL << do_idx)) + continue; snprintf(cg_name, sizeof(cg_name), "DO%zu", nr); cgc = g_malloc0(sizeof(*cgc)); cg = sr_channel_group_new(sdi, cg_name, cgc); @@ -138,6 +154,28 @@ static struct sr_dev_inst *probe_device_conn(const char *conn) (void)cg; ch_idx++; } + for (di_idx = 0; di_idx < devc->model->ch_count_di; di_idx++) { + nr = di_idx + 1; + snprintf(cg_name, sizeof(cg_name), "DI%zu", nr); + cgc = g_malloc0(sizeof(*cgc)); + cg = sr_channel_group_new(sdi, cg_name, cgc); + cgc->index = di_idx; + cgc->number = nr; + cgc->ch_type = DV_CH_DIGITAL_INPUT; + (void)cg; + ch_idx++; + } + for (ai_idx = 0; ai_idx < devc->model->ch_count_ai; ai_idx++) { + nr = ai_idx + 1; + snprintf(cg_name, sizeof(cg_name), "AI%zu", nr); + cgc = g_malloc0(sizeof(*cgc)); + cg = sr_channel_group_new(sdi, cg_name, cgc); + cgc->index = ai_idx; + cgc->number = nr; + cgc->ch_type = DV_CH_ANALOG_INPUT; + (void)cg; + ch_idx++; + } if (1) { /* Create an analog channel for the supply voltage. */ snprintf(cg_name, sizeof(cg_name), "Vsupply"); @@ -225,8 +263,22 @@ static int config_get(uint32_t key, GVariant **data, *data = g_variant_new_boolean(on); return SR_OK; } + if (cgc->ch_type == DV_CH_DIGITAL_INPUT) { + ret = devantech_eth008_query_di(sdi, cg, &on); + if (ret != SR_OK) + return ret; + *data = g_variant_new_boolean(on); + return SR_OK; + } return SR_ERR_NA; case SR_CONF_VOLTAGE: + if (cgc->ch_type == DV_CH_ANALOG_INPUT) { + ret = devantech_eth008_query_ai(sdi, cg, &vin); + if (ret != SR_OK) + return ret; + *data = g_variant_new_uint32(vin); + return SR_OK; + } if (cgc->ch_type == DV_CH_SUPPLY_VOLTAGE) { ret = devantech_eth008_query_supply(sdi, cg, &vin); if (ret != SR_OK) @@ -271,9 +323,6 @@ static int config_set(uint32_t key, GVariant *data, default: return SR_ERR_NA; } - - /* XXX Is this actually UNREACH? */ - return SR_OK; } static int config_list(uint32_t key, GVariant **data, @@ -301,6 +350,14 @@ static int config_list(uint32_t key, GVariant **data, *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_do)); return SR_OK; } + if (cgc->ch_type == DV_CH_DIGITAL_INPUT) { + *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_di)); + return SR_OK; + } + if (cgc->ch_type == DV_CH_ANALOG_INPUT) { + *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_ai)); + return SR_OK; + } if (cgc->ch_type == DV_CH_SUPPLY_VOLTAGE) { *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_ai)); return SR_OK;