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
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
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?
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
Eeprom24xconstructor expects an
u8slave address parameter. The configurable address bits can be configured through:
SlaveAddr::Alternative(true, false, true)for
- [SOLVED] device address as
u8parameter 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+2and then copying the data, as the array size must be known at compile time.
This leads to repeated implementations of the
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
- 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
I created an implementation for a generic At24cx for each IC and provide
new methods which contain the IC name. e.g.
This will need to change together with the project name.
What do you think of methods like
- 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.