Hi,
I have written an embedded-hal-based driver for serial EEPROM ICs of the 24x series (I2C).
You can find the crate here.
It would be nice if some of you could provide feedback, with special attention to this:
-
Project / crate name: [SOLVED] The project is now called
eeprom24x
.
Summary
I wrote it for an AT24C256 but it is compatible with AT24C32...AT24C512 although it could be trivially extended for other ICs and hence the at24cx
name.
However, the naming has changed: Microchip (formerly Atmel) 24xxxx.
There are also several other vendors that have their own versions that seem compatible and they appear to be named "24
": e.g. OnSemi CAT24xxx, ST M24xxx.
Do you have any suggestions for a better crate name? eeprom-24x
? serial-eeprom-24x
? 24x-eeprom
? 24x-serial-eeprom
? 24x-eeprom-driver
? 24x-driver
?
24x
seems too short.
-
Interface: driver interface
-
Alternative addresses: The lowest 3 bits of the 7-bit device address can be configured for these ICs. The
Eeprom24x
constructor expects anu8
slave address parameter. The configurable address bits can be configured through:SlaveAddr::Alternative(true, false, true)
forA2
,A1
,A0
.- [SOLVED] device address as
u8
parameter but actually I2C device addresses are 7-bit. Still, 7 boolean parameters would be worse. - What do you think about specifying an alternative address like this? (syntax, bools for all configurable address bits,...)
- [SOLVED] device address as
-
Support for several ICs
-
Duplicated code: Depending on the memory size, the page size changes per IC. When writing a (variable size) page to the memory, I need to prepend the target address to the data. I solved this by creating a new array with a size of
PAGE_SIZE+2
and then copying the data, as the array size must be known at compile time.
This leads to repeated implementations of thewrite_page()
method.
This code and documentation duplication can only get worse as I add support for more ICs.
As suggested below, this could be solved using a trait with an associated constant but this is blocked by this upstream issue at the moment.
Do you have any better idea? -
Constructors: [SOLVED] There are methods like
Eeprom24x::new_24x32(...)
andEeprom24x::new_24x256(...)
-
Duplicated code: Depending on the memory size, the page size changes per IC. When writing a (variable size) page to the memory, I need to prepend the target address to the data. I solved this by creating a new array with a size of
-
Alternative addresses: The lowest 3 bits of the 7-bit device address can be configured for these ICs. The
Summary
I created an implementation for a generic At24cx for each IC and provide new
methods which contain the IC name. e.g. At24cx::new_at24c32(...)
At24cx::new_at24c256(...)
.
This will need to change together with the project name.
What do you think of methods like At24cx::new_32kbit(...)
, At24cx::new_256kbit(...)
,...?
- General feedback
- Further improvements
I understand that this is a big post containing lots of requests but some discussion would be very interesting for me and also for other device drivers I may write in the future. I can also split this topic into separate ones if you want.
I look forward to your feedback.