X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fftdi-la%2Fapi.c;h=8bb67121cc6c71051b279b200ffc6a6d95e2372d;hb=968b1a23f23e1f22f7e438a39e3235b4f21b8b14;hp=b22e57f1a883f07572dd232c7c8534366c786f88;hpb=f6051b9eca164319131ada85c3f82f75dca460cf;p=libsigrok.git diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index b22e57f1..8bb67121 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -57,6 +57,28 @@ static const struct ftdi_chip_desc ft2232h_desc = { } }; +static const struct ftdi_chip_desc ft2232h_tumpa_desc = { + .vendor = 0x0403, + .product = 0x8a98, + .samplerate_div = 20, + /* 20 pin JTAG header */ + .channel_names = { + "TCK", "TDI", "TDO", "TMS", "RST", "nTRST", "DBGRQ", "RTCK", + NULL + } +}; + +static const struct ftdi_chip_desc ft4232h_desc = { + .vendor = 0x0403, + .product = 0x6011, + .samplerate_div = 20, + .channel_names = { + "ADBUS0", "ADBUS1", "ADBUS2", "ADBUS3", "ADBUS4", "ADBUS5", "ADBUS6", "ADBUS7", + /* TODO: BDBUS[0..7], CDBUS[0..7], DDBUS[0..7] channels. */ + NULL + } +}; + static const struct ftdi_chip_desc ft232r_desc = { .vendor = 0x0403, .product = 0x6001, @@ -67,14 +89,30 @@ static const struct ftdi_chip_desc ft232r_desc = { } }; +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 + } +}; + static const struct ftdi_chip_desc *chip_descs[] = { &ft2232h_desc, + &ft2232h_tumpa_desc, + &ft4232h_desc, &ft232r_desc, + &ft232h_desc, + NULL, }; static void scan_device(struct ftdi_context *ftdic, struct libusb_device *dev, GSList **devices) { + static const int usb_str_maxlen = 32; + struct libusb_device_descriptor usb_desc; const struct ftdi_chip_desc *desc; struct dev_context *devc; @@ -87,13 +125,15 @@ 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; } @@ -105,14 +145,42 @@ static void scan_device(struct ftdi_context *ftdic, devc->desc = desc; - vendor = g_malloc(32); - model = g_malloc(32); - serial_num = g_malloc(32); - rv = ftdi_usb_get_strings(ftdic, dev, vendor, 32, - model, 32, serial_num, 32); + vendor = g_malloc(usb_str_maxlen); + model = g_malloc(usb_str_maxlen); + serial_num = g_malloc(usb_str_maxlen); + rv = ftdi_usb_get_strings(ftdic, dev, vendor, usb_str_maxlen, + model, usb_str_maxlen, serial_num, usb_str_maxlen); switch (rv) { case 0: break; + /* ftdi_usb_get_strings() fails on first miss, hence fall through. */ + case -7: + sr_dbg("The device lacks a manufacturer descriptor."); + g_snprintf(vendor, usb_str_maxlen, "Generic"); + /* FALLTHROUGH */ + case -8: + sr_dbg("The device lacks a product descriptor."); + switch (usb_desc.idProduct) { + case 0x6001: + g_snprintf(model, usb_str_maxlen, "FT232R"); + break; + case 0x6010: + g_snprintf(model, usb_str_maxlen, "FT2232H"); + break; + case 0x6011: + g_snprintf(model, usb_str_maxlen, "FT4232H"); + break; + case 0x6014: + g_snprintf(model, usb_str_maxlen, "FT232H"); + break; + case 0x8a98: + g_snprintf(model, usb_str_maxlen, "FT2232H-TUMPA"); + break; + default: + g_snprintf(model, usb_str_maxlen, "Unknown"); + break; + } + /* FALLTHROUGH */ case -9: sr_dbg("The device lacks a serial number."); g_free(serial_num);