From: Gerhard Sittig Date: Mon, 25 Sep 2023 12:18:55 +0000 (+0200) Subject: devantech-eth008: declare more models, still digital-output only X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6af128b64262914c45475376c0590354a003b6ed;p=libsigrok.git devantech-eth008: declare more models, still digital-output only Add the ETH002, ETH484, and ETH8020 items to the list of supported models. Adjust driver code paths for the differing DO image sizes of these models (up to 20 relays which span up to three bytes width). Support the R5..R8 gap for ETH484. This was written without access to the hardware, and is untested. --- diff --git a/src/hardware/devantech-eth008/api.c b/src/hardware/devantech-eth008/api.c index a40a1fd9..3eadb1fb 100644 --- a/src/hardware/devantech-eth008/api.c +++ b/src/hardware/devantech-eth008/api.c @@ -47,7 +47,10 @@ static const uint32_t devopts_cg_ai[] = { }; static const struct devantech_eth008_model models[] = { - { 19, "ETH008", 8, 0, 1, }, + { 18, "ETH002", 2, 0, 1, 0, }, + { 19, "ETH008", 8, 0, 1, 0, }, + { 20, "ETH484", 16, 0, 2, 0x00f0, }, + { 21, "ETH8020", 20, 0, 3, 0, }, }; static const struct devantech_eth008_model *find_model(uint8_t code) @@ -127,8 +130,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 &= ~model->mask_do_missing; for (do_idx = 0; do_idx < devc->model->ch_count_do; do_idx++) { nr = do_idx + 1; + if (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); diff --git a/src/hardware/devantech-eth008/protocol.c b/src/hardware/devantech-eth008/protocol.c index 87ac7244..8c436ea3 100644 --- a/src/hardware/devantech-eth008/protocol.c +++ b/src/hardware/devantech-eth008/protocol.c @@ -256,7 +256,7 @@ SR_PRIV int devantech_eth008_cache_state(const struct sr_dev_inst *sdi) struct dev_context *devc; size_t rx_size; uint8_t req[1], *wrptr; - uint8_t rsp[1]; + uint8_t rsp[3]; const uint8_t *rdptr; uint32_t have; int ret; @@ -283,6 +283,12 @@ SR_PRIV int devantech_eth008_cache_state(const struct sr_dev_inst *sdi) case 1: have = read_u8_inc(&rdptr); break; + case 2: + have = read_u16le_inc(&rdptr); + break; + case 3: + have = read_u24le_inc(&rdptr); + break; default: return SR_ERR_NA; } @@ -343,7 +349,7 @@ SR_PRIV int devantech_eth008_setup_do(const struct sr_dev_inst *sdi, struct channel_group_context *cgc; size_t number; uint32_t reg; - uint8_t req[3], *wrptr, cmd; + uint8_t req[4], *wrptr, cmd; uint8_t rsp[1], v8; const uint8_t *rdptr; int ret; @@ -378,6 +384,12 @@ SR_PRIV int devantech_eth008_setup_do(const struct sr_dev_inst *sdi, case 1: write_u8_inc(&wrptr, reg & 0xff); break; + case 2: + write_u16le_inc(&wrptr, reg & 0xffff); + break; + case 3: + write_u24le_inc(&wrptr, reg & 0xffffff); + break; default: return SR_ERR_NA; } diff --git a/src/hardware/devantech-eth008/protocol.h b/src/hardware/devantech-eth008/protocol.h index 5834a4c9..074a1b2e 100644 --- a/src/hardware/devantech-eth008/protocol.h +++ b/src/hardware/devantech-eth008/protocol.h @@ -35,7 +35,8 @@ * length. Getting relay state takes a variable number of bytes to carry * the bit fields. Response length depends on the model's relay count. * As does request length for setting the state of several relays at the - * same time. + * same time. Some models have gaps in their relay channel numbers + * (ETH484 misses R5..R8). * * Some models have digital inputs and analog inputs. These features * currently are not supported in this implementation. @@ -46,6 +47,7 @@ struct devantech_eth008_model { size_t ch_count_do; uint8_t min_serno_fw; size_t width_do; + uint32_t mask_do_missing; }; enum devantech_eth008_channel_type {