X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fftdi-la%2Fapi.c;h=432f566f84ed71a00f38b077e065a0c28b926de7;hb=66e19f47f421db4ab1609519129ee786ea44af04;hp=27415ae3ec0389a08994497632cbaf6a7f516cb9;hpb=a9010323ddf4e479663e871386c05db05ea3522e;p=libsigrok.git diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index 27415ae3..432f566f 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -28,8 +28,11 @@ static const uint32_t scanopts[] = { SR_CONF_CONN, }; -static const uint32_t devopts[] = { +static const uint32_t drvopts[] = { SR_CONF_LOGIC_ANALYZER, +}; + +static const uint32_t devopts[] = { SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, @@ -47,14 +50,8 @@ static const struct ftdi_chip_desc ft2232h_desc = { .product = 0x6010, .samplerate_div = 20, .channel_names = { - "ADBUS0", - "ADBUS1", - "ADBUS2", - "ADBUS3", - "ADBUS4", - "ADBUS5", - "ADBUS6", - "ADBUS7", + "ADBUS0", "ADBUS1", "ADBUS2", "ADBUS3", + "ADBUS4", "ADBUS5", "ADBUS6", "ADBUS7", /* TODO: BDBUS[0..7] channels. */ NULL } @@ -65,14 +62,17 @@ static const struct ftdi_chip_desc ft232r_desc = { .product = 0x6001, .samplerate_div = 30, .channel_names = { - "TXD", - "RXD", - "RTS#", - "CTS#", - "DTR#", - "DSR#", - "DCD#", - "RI#", + "TXD", "RXD", "RTS#", "CTS#", "DTR#", "DSR#", "DCD#", "RI#", + NULL + } +}; + +static const struct ftdi_chip_desc ft232h_desc = { + .vendor = 0x0403, + .product = 0x6014, + .samplerate_div = 30, + .channel_names = { + "ADBUS0", "ADBUS1", "ADBUS2", "ADBUS3", "ADBUS4", "ADBUS5", "ADBUS6", "ADBUS7", NULL } }; @@ -80,6 +80,8 @@ static const struct ftdi_chip_desc ft232r_desc = { static const struct ftdi_chip_desc *chip_descs[] = { &ft2232h_desc, &ft232r_desc, + &ft232h_desc, + NULL, }; static void scan_device(struct ftdi_context *ftdic, @@ -97,18 +99,19 @@ static void scan_device(struct ftdi_context *ftdic, desc = NULL; for (unsigned long i = 0; i < ARRAY_SIZE(chip_descs); i++) { desc = chip_descs[i]; + if (!desc) + break; if (desc->vendor == usb_desc.idVendor && desc->product == usb_desc.idProduct) break; } if (!desc) { - sr_spew("Unsupported FTDI device 0x%4x:0x%4x.", + sr_spew("Unsupported FTDI device 0x%04x:0x%04x.", usb_desc.idVendor, usb_desc.idProduct); return; } - /* Allocate memory for our private device context. */ devc = g_malloc0(sizeof(struct dev_context)); /* Allocate memory for the incoming data. */ @@ -135,7 +138,6 @@ static void scan_device(struct ftdi_context *ftdic, } sr_dbg("Found an FTDI device: %s.", model); - /* Register the device with libsigrok. */ sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; sdi->vendor = vendor; @@ -211,7 +213,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) } } - /* Allocate memory for the FTDI context (ftdic) and initialize it. */ ftdic = ftdi_new(); if (!ftdic) { sr_err("Failed to initialize libftdi."); @@ -270,7 +271,6 @@ static int dev_open(struct sr_dev_inst *sdi) goto err_ftdi_free; } - /* Purge RX/TX buffers in the FTDI chip. */ ret = ftdi_usb_purge_buffers(devc->ftdic); if (ret < 0) { sr_err("Failed to purge FTDI RX/TX buffers (%d): %s.", @@ -278,7 +278,6 @@ static int dev_open(struct sr_dev_inst *sdi) goto err_dev_open_close_ftdic; } - /* Reset the FTDI bitmode. */ ret = ftdi_set_bitmode(devc->ftdic, 0x00, BITMODE_RESET); if (ret < 0) { sr_err("Failed to reset the FTDI chip bitmode (%d): %s.", @@ -325,7 +324,6 @@ static int config_get(uint32_t key, GVariant **data, { struct dev_context *devc; struct sr_usb_dev_inst *usb; - char str[128]; (void)cg; @@ -339,8 +337,7 @@ static int config_get(uint32_t key, GVariant **data, if (!sdi || !sdi->conn) return SR_ERR_ARG; usb = sdi->conn; - snprintf(str, 128, "%d.%d", usb->bus, usb->address); - *data = g_variant_new_string(str); + *data = g_variant_new_printf("%d.%d", usb->bus, usb->address); break; default: return SR_ERR_NA; @@ -363,10 +360,9 @@ static int config_set(uint32_t key, GVariant *data, case SR_CONF_LIMIT_MSEC: value = g_variant_get_uint64(data); /* TODO: Implement. */ + (void)value; return SR_ERR_NA; case SR_CONF_LIMIT_SAMPLES: - if (g_variant_get_uint64(data) == 0) - return SR_ERR_ARG; devc->limit_samples = g_variant_get_uint64(data); break; case SR_CONF_SAMPLERATE: @@ -385,27 +381,12 @@ static int config_set(uint32_t key, GVariant *data, static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { - GVariant *gvar; - GVariantBuilder gvb; - - (void)sdi; - (void)cg; - switch (key) { case SR_CONF_SCAN_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); - break; case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); - break; + return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); case SR_CONF_SAMPLERATE: - g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); - gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), - samplerates, ARRAY_SIZE(samplerates), sizeof(uint64_t)); - g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar); - *data = g_variant_builder_end(&gvb); + *data = std_gvar_samplerates_steps(ARRAY_AND_SIZE(samplerates)); break; default: return SR_ERR_NA;