diff --git a/ftdi_eeprom/main.c b/ftdi_eeprom/main.c index c7db6e8..7b44540 100644 --- a/ftdi_eeprom/main.c +++ b/ftdi_eeprom/main.c @@ -107,6 +107,7 @@ int main(int argc, char *argv[]) */ cfg_opt_t opts[] = { + CFG_STR("description", "", 0), CFG_INT("vendor_id", 0, 0), CFG_INT("product_id", 0, 0), CFG_BOOL("self_powered", cfg_true, 0), @@ -214,15 +215,33 @@ int main(int argc, char *argv[]) if (_read > 0 || _erase > 0 || _flash > 0) { - int vendor_id = cfg_getint(cfg, "vendor_id"); - int product_id = cfg_getint(cfg, "product_id"); + char *description = cfg_getstr(cfg, "description"); - i = ftdi_usb_open(ftdi, vendor_id, product_id); + if (description != NULL && strlen(description) > 0) + { + i = ftdi_usb_open_string(ftdi, description); + + if (i != 0) + { + printf("Unable to find FTDI devices under given description: %s\n", description); + } + } + else + { + int vendor_id = cfg_getint(cfg, "vendor_id"); + int product_id = cfg_getint(cfg, "product_id"); + + i = ftdi_usb_open(ftdi, vendor_id, product_id); + if (i != 0) + { + printf("Unable to find FTDI devices under given vendor/product id: 0x%X/0x%X\n", vendor_id, product_id); + } + } if (i != 0) { int default_pid = cfg_getint(cfg, "default_pid"); - printf("Unable to find FTDI devices under given vendor/product id: 0x%X/0x%X\n", vendor_id, product_id); + printf("Error code: %d (%s)\n", i, ftdi_get_error_string(ftdi)); printf("Retrying with default FTDI pid=%#04x.\n", default_pid);