X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=ftdi_eeprom%2Fmain.c;h=c19d1113bb3b8118991f65b64fb0964e687024f8;hp=931045f8cbb978e20bd8247303a204aa9f1b8600;hb=add00ad60e3d942f23233a0a25a39cebfced5c15;hpb=4359228aaa6840b20f4cf6b61bf156b9354a0f80 diff --git a/ftdi_eeprom/main.c b/ftdi_eeprom/main.c index 931045f..c19d111 100644 --- a/ftdi_eeprom/main.c +++ b/ftdi_eeprom/main.c @@ -2,7 +2,7 @@ main.c - description ------------------- begin : Mon Apr 7 12:05:22 CEST 2003 - copyright : (C) 2003-2011 by Intra2net AG and the libftdi developers + copyright : (C) 2003-2014 by Intra2net AG and the libftdi developers email : opensource@intra2net.com ***************************************************************************/ @@ -16,7 +16,6 @@ /* TODO: - - Remove 128 bytes limit - Merge Uwe's eeprom tool. Current features: - Init eeprom defaults based upon eeprom type - Read -> Already there @@ -38,26 +37,76 @@ #include #include +#include #include #include -static int str_to_cbus(char *str, int max_allowed) +static int parse_cbus(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result) { - #define MAX_OPTION 14 - const char* options[MAX_OPTION] = { - "TXDEN", "PWREN", "RXLED", "TXLED", "TXRXLED", "SLEEP", - "CLK48", "CLK24", "CLK12", "CLK6", - "IO_MODE", "BITBANG_WR", "BITBANG_RD", "SPECIAL"}; + static const char* options[] = + { + "TXDEN", "PWREN", "RXLED", "TXLED", "TXRXLED", "SLEEP", "CLK48", + "CLK24", "CLK12", "CLK6", "IOMODE", "BB_WR", "BB_RD" + }; + int i; - max_allowed += 1; - if (max_allowed > MAX_OPTION) max_allowed = MAX_OPTION; - for (i=0; i 0) { - - ftdi_eeprom_decode(ftdi, 0); - /* Debug output */ - /* - const char* chip_types[] = {"other", "BM", "R"}; - printf("vendor_id = \"%04x\"\n", eeprom->vendor_id); - printf("product_id = \"%04x\"\n", eeprom->product_id); - printf("chip_type = \"%s\"\n", - (eeprom->chip_type > 0x06) || (eeprom->chip_type & 0x01) ? "unknown": - chip_types[eeprom->chip_type>>1]); - printf("self_powered = \"%s\"\n", eeprom->self_powered?"true":"false"); - printf("remote_wakeup = \"%s\"\n", eeprom->remote_wakeup?"true":"false"); - printf("max_power = \"%d\"\n", eeprom->max_power); - printf("in_is_isochronous = \"%s\"\n", eeprom->in_is_isochronous?"true":"false"); - printf("out_is_isochronous = \"%s\"\n", eeprom->out_is_isochronous?"true":"false"); - printf("suspend_pull_downs = \"%s\"\n", eeprom->suspend_pull_downs?"true":"false"); - printf("use_serial = \"%s\"\n", eeprom->use_serial?"true":"false"); - printf("change_usb_version = \"%s\"\n", eeprom->change_usb_version?"true":"false"); - printf("usb_version = \"%d\"\n", eeprom->usb_version); - printf("manufacturer = \"%s\"\n", eeprom->manufacturer); - printf("product = \"%s\"\n", eeprom->product); - printf("serial = \"%s\"\n", eeprom->serial); - */ + ftdi_eeprom_decode(ftdi, 0 /* debug: 1 */); eeprom_buf = malloc(my_eeprom_size); ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size); @@ -301,14 +342,58 @@ int main(int argc, char *argv[]) eeprom_set_value(ftdi, USE_SERIAL, cfg_getbool(cfg, "use_serial")); eeprom_set_value(ftdi, USE_USB_VERSION, cfg_getbool(cfg, "change_usb_version")); eeprom_set_value(ftdi, USB_VERSION, cfg_getint(cfg, "usb_version")); - + eeprom_set_value(ftdi, CHIP_TYPE, cfg_getint(cfg, "eeprom_type")); eeprom_set_value(ftdi, HIGH_CURRENT, cfg_getbool(cfg, "high_current")); - eeprom_set_value(ftdi, CBUS_FUNCTION_0, str_to_cbus(cfg_getstr(cfg, "cbus0"), 13)); - eeprom_set_value(ftdi, CBUS_FUNCTION_1, str_to_cbus(cfg_getstr(cfg, "cbus1"), 13)); - eeprom_set_value(ftdi, CBUS_FUNCTION_2, str_to_cbus(cfg_getstr(cfg, "cbus2"), 13)); - eeprom_set_value(ftdi, CBUS_FUNCTION_3, str_to_cbus(cfg_getstr(cfg, "cbus3"), 13)); - eeprom_set_value(ftdi, CBUS_FUNCTION_4, str_to_cbus(cfg_getstr(cfg, "cbus4"), 9)); + + if (ftdi->type == TYPE_R) + { + if (cfg_getint(cfg, "cbus0") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_0, cfg_getint(cfg, "cbus0")); + if (cfg_getint(cfg, "cbus1") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_1, cfg_getint(cfg, "cbus1")); + if (cfg_getint(cfg, "cbus2") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_2, cfg_getint(cfg, "cbus2")); + if (cfg_getint(cfg, "cbus3") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_3, cfg_getint(cfg, "cbus3")); + if (cfg_getint(cfg, "cbus4") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_4, cfg_getint(cfg, "cbus4")); + } + else if (ftdi->type == TYPE_232H) + { + if (cfg_getint(cfg, "cbush0") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_0, cfg_getint(cfg, "cbush0")); + if (cfg_getint(cfg, "cbush1") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_1, cfg_getint(cfg, "cbush1")); + if (cfg_getint(cfg, "cbush2") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_2, cfg_getint(cfg, "cbush2")); + if (cfg_getint(cfg, "cbush3") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_3, cfg_getint(cfg, "cbush3")); + if (cfg_getint(cfg, "cbush4") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_4, cfg_getint(cfg, "cbush4")); + if (cfg_getint(cfg, "cbush5") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_5, cfg_getint(cfg, "cbush5")); + if (cfg_getint(cfg, "cbush6") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_6, cfg_getint(cfg, "cbush6")); + if (cfg_getint(cfg, "cbush7") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_7, cfg_getint(cfg, "cbush7")); + if (cfg_getint(cfg, "cbush8") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_8, cfg_getint(cfg, "cbush8")); + if (cfg_getint(cfg, "cbush9") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_9, cfg_getint(cfg, "cbush9")); + } + else if (ftdi->type == TYPE_230X) + { + if (cfg_getint(cfg, "cbusx0") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_0, cfg_getint(cfg, "cbusx0")); + if (cfg_getint(cfg, "cbusx1") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_1, cfg_getint(cfg, "cbusx1")); + if (cfg_getint(cfg, "cbusx2") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_2, cfg_getint(cfg, "cbusx2")); + if (cfg_getint(cfg, "cbusx3") != -1) + eeprom_set_value(ftdi, CBUS_FUNCTION_3, cfg_getint(cfg, "cbusx3")); + } + int invert = 0; if (cfg_getbool(cfg, "invert_rxd")) invert |= INVERT_RXD; if (cfg_getbool(cfg, "invert_txd")) invert |= INVERT_TXD; @@ -320,19 +405,31 @@ int main(int argc, char *argv[]) if (cfg_getbool(cfg, "invert_ri")) invert |= INVERT_RI; eeprom_set_value(ftdi, INVERT, invert); + eeprom_set_value(ftdi, CHANNEL_A_DRIVER, DRIVER_VCP); + eeprom_set_value(ftdi, CHANNEL_B_DRIVER, DRIVER_VCP); + eeprom_set_value(ftdi, CHANNEL_C_DRIVER, DRIVER_VCP); + eeprom_set_value(ftdi, CHANNEL_D_DRIVER, DRIVER_VCP); + eeprom_set_value(ftdi, CHANNEL_A_RS485, 0); + eeprom_set_value(ftdi, CHANNEL_B_RS485, 0); + eeprom_set_value(ftdi, CHANNEL_C_RS485, 0); + eeprom_set_value(ftdi, CHANNEL_D_RS485, 0); + if (_erase > 0) { printf("FTDI erase eeprom: %d\n", ftdi_erase_eeprom(ftdi)); } size_check = ftdi_eeprom_build(ftdi); + eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size); if (size_check == -1) { printf ("Sorry, the eeprom can only contain 128 bytes (100 bytes for your strings).\n"); printf ("You need to short your string by: %d bytes\n", size_check); goto cleanup; - } else if (size_check < 0) { + } + else if (size_check < 0) + { printf ("ftdi_eeprom_build(): error: %d\n", size_check); } else @@ -346,14 +443,26 @@ int main(int argc, char *argv[]) { if (filename != NULL && strlen(filename) > 0) { + eeprom_buf = malloc(max_eeprom_size); FILE *fp = fopen(filename, "rb"); - fread(eeprom_buf, 1, my_eeprom_size, fp); + if (fp == NULL) + { + printf ("Can't open eeprom file %s.\n", filename); + exit (-1); + } + my_eeprom_size = fread(eeprom_buf, 1, max_eeprom_size, fp); fclose(fp); + if (my_eeprom_size < 128) + { + printf ("Can't read eeprom file %s.\n", filename); + exit (-1); + } ftdi_set_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size); } } printf ("FTDI write eeprom: %d\n", ftdi_write_eeprom(ftdi)); + libusb_reset_device(ftdi->usb_dev); } // Write to file? @@ -368,6 +477,8 @@ int main(int argc, char *argv[]) else printf ("Writing to file: %s\n", filename); + if (eeprom_buf == NULL) + eeprom_buf = malloc(my_eeprom_size); ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size); fwrite(eeprom_buf, my_eeprom_size, 1, fp); @@ -383,6 +494,7 @@ cleanup: } ftdi_deinit (ftdi); + ftdi_free (ftdi); cfg_free(cfg);