I want to modify only some bits (invert_rx) in the eeprom. The current
implementation expects the whole eeprom to be build from a configuration
file. I think it should be possible to read the eeprom, make the
modifications and write the eeprom back, without touching the other
bits.
Therefore I suggest two changes:
1) Add the "device release number" (bytes 6 and 7) to ftdi_eeprom and
initialise it in ftdi_eeprom_initdefaults and ftdi_eeprom_decode. The
current implementation forces a new value in ftdi_eeprom_build.
2) Change the behaviour of eeprom->initialized_for_connected_device
flag so that will tell if the eeprom buffer is ready to be written.
Currently is only set in ftdi_eeprom_initdefaults, but I suggest that it
would be set ftdi_eeprom_build.
- Jarkko Sonninen
Date: Tue, 26 Feb 2013 05:34:41 +0200
Subject: [PATCH 1/3] Save device release number.
---
src/ftdi.c | 67
++++++++++++++++++++++++++++++++--------------------------
src/ftdi.h | 1 +
src/ftdi_i.h | 2 ++
3 files changed, 40 insertions(+), 30 deletions(-)
diff --git a/src/ftdi.c b/src/ftdi.c
index 5570bd4..9816cf9 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -2392,6 +2392,32 @@ int ftdi_eeprom_initdefaults(struct ftdi_context
*ftdi, char * manufacturer,
}
eeprom->size = -1;
}
+ switch (ftdi->type)
+ {
+ case TYPE_AM:
+ eeprom->release_number = 0x0200;
+ break;
+ case TYPE_BM:
+ eeprom->release_number = 0x0400;
+ break;
+ case TYPE_2232C:
+ eeprom->release_number = 0x0500;
+ break;
+ case TYPE_R:
+ eeprom->release_number = 0x0600;
+ break;
+ case TYPE_2232H:
+ eeprom->release_number = 0x0700;
+ break;
+ case TYPE_4232H:
+ eeprom->release_number = 0x0800;
+ break;
+ case TYPE_232H:
+ eeprom->release_number = 0x0900;
+ break;
+ default:
+ eeprom->release_number = 0x00;
+ }
eeprom->initialized_for_connected_device = 1;
return 0;
}
@@ -2539,33 +2565,8 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi)
output[0x05] = eeprom->product_id >> 8;
// Addr 06: Device release number (0400h for BM features)
- output[0x06] = 0x00;
- switch (ftdi->type)
- {
- case TYPE_AM:
- output[0x07] = 0x02;
- break;
- case TYPE_BM:
- output[0x07] = 0x04;
- break;
- case TYPE_2232C:
- output[0x07] = 0x05;
- break;
- case TYPE_R:
- output[0x07] = 0x06;
- break;
- case TYPE_2232H:
- output[0x07] = 0x07;
- break;
- case TYPE_4232H:
- output[0x07] = 0x08;
- break;
- case TYPE_232H:
- output[0x07] = 0x09;
- break;
- default:
- output[0x07] = 0x00;
- }
+ output[0x06] = eeprom->release_number;
+ output[0x07] = eeprom->release_number >> 8;
// Addr 08: Config descriptor
// Bit 7: always 1
@@ -3025,7 +3026,6 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi,
int verbose)
int eeprom_size;
struct ftdi_eeprom *eeprom;
unsigned char *buf = ftdi->eeprom->buf;
- int release;
if (ftdi == NULL)
ftdi_error_return(-1,"No context");
@@ -3041,7 +3041,8 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi,
int verbose)
// Addr 04: Product ID
eeprom->product_id = buf[0x04] + (buf[0x05] << 8);
- release = buf[0x06] + (buf[0x07]<<8);
+ // Addr 06: Device release number
+ eeprom->release_number = buf[0x06] + (buf[0x07]<<8);
// Addr 08: Config descriptor
// Bit 7: always 1
@@ -3262,7 +3263,7 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi,
int verbose)
char *channel_mode[] = {"UART", "FIFO", "CPU", "OPTO",
"FT1284"};
fprintf(stdout, "VID: 0x%04x\n",eeprom->vendor_id);
fprintf(stdout, "PID: 0x%04x\n",eeprom->product_id);
- fprintf(stdout, "Release: 0x%04x\n",release);
+ fprintf(stdout, "Release: 0x%04x\n",eeprom->release_number);
if (eeprom->self_powered)
fprintf(stdout, "Self-Powered%s",
(eeprom->remote_wakeup)?", USB Remote Wake Up\n":"\n");
@@ -3417,6 +3418,9 @@ int ftdi_get_eeprom_value(struct ftdi_context
*ftdi, enum ftdi_eeprom_value valu
case PRODUCT_ID:
*value = ftdi->eeprom->product_id;
break;
+ case RELEASE_NUMBER:
+ *value = ftdi->eeprom->release_number;
+ break;
case SELF_POWERED:
*value = ftdi->eeprom->self_powered;
break;
@@ -3604,6 +3608,9 @@ int ftdi_set_eeprom_value(struct ftdi_context
*ftdi, enum ftdi_eeprom_value valu
case PRODUCT_ID:
ftdi->eeprom->product_id = value;
break;
+ case RELEASE_NUMBER:
+ ftdi->eeprom->release_number = value;
+ break;
case SELF_POWERED:
ftdi->eeprom->self_powered = value;
break;
diff --git a/src/ftdi.h b/src/ftdi.h
index 141a795..c1d74f1 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -309,6 +309,7 @@ enum ftdi_eeprom_value
CHANNEL_B_RS485 = 52,
CHANNEL_C_RS485 = 53,
CHANNEL_D_RS485 = 54,
+ RELEASE_NUMBER = 55,
};
/**
diff --git a/src/ftdi_i.h b/src/ftdi_i.h
index 1d52df1..0a434d1 100644
--- a/src/ftdi_i.h
+++ b/src/ftdi_i.h
@@ -38,6 +38,8 @@ struct ftdi_eeprom
connected device? **/
int initialized_for_connected_device;
+ /** device release number */
+ int release_number;
/** self powered */
int self_powered;
/** remote wakeup */
--
1.7.9.5
Date: Tue, 26 Feb 2013 05:53:31 +0200
Subject: [PATCH 2/3] Move setting of flag
initialized_for_connected_device to
ftdi_eeprom_build.
---
src/ftdi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ftdi.c b/src/ftdi.c
index 9816cf9..7ae4fab 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -2418,7 +2418,6 @@ int ftdi_eeprom_initdefaults(struct ftdi_context
*ftdi, char * manufacturer,
default:
eeprom->release_number = 0x00;
}
- eeprom->initialized_for_connected_device = 1;
return 0;
}
/*FTD2XX doesn't check for values not fitting in the ACBUS Signal
oprtions*/
@@ -2984,6 +2983,7 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi)
output[eeprom->size-2] = checksum;
output[eeprom->size-1] = checksum >> 8;
+ eeprom->initialized_for_connected_device = 1;
return user_area_size;
}
/* Decode the encoded EEPROM field for the FTDI Mode into a value for
the abstracted
--
1.7.9.5
Date: Fri, 1 Mar 2013 18:28:12 +0200
Subject: [PATCH 3/3] squash! Move setting of flag
initialized_for_connected_device to ftdi_eeprom_build.
---
src/ftdi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/ftdi.c b/src/ftdi.c
index 7ae4fab..6d4a64b 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -3772,6 +3772,7 @@ int ftdi_set_eeprom_value(struct ftdi_context
*ftdi, enum ftdi_eeprom_value valu
default :
ftdi_error_return(-1, "Request to unknown EEPROM value");
}
+ eeprom->initialized_for_connected_device = 0;
return 0;
}
--
1.7.9.5
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|