mFS file system library for EEPROM memory chips.
i2c_eeprom.h@13:142b6be3e3c8, 2011-02-24 (annotated)
- Committer:
- HBP
- Date:
- Thu Feb 24 09:28:32 2011 +0000
- Revision:
- 13:142b6be3e3c8
- Parent:
- 9:52c01cb100ac
- Better handling of empty files
- doesn\t write EOF on AWRITE if EOF is not reached
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HBP | 0:cbf45dde2b49 | 1 | /*H**************************************************************************** |
HBP | 7:5ac5121bb4e0 | 2 | * FILENAME : i2c_eeprom.h * |
HBP | 7:5ac5121bb4e0 | 3 | * * |
HBP | 7:5ac5121bb4e0 | 4 | * DESCRIPTION : * |
HBP | 7:5ac5121bb4e0 | 5 | * Simple library for external I2C EEEPROM. * |
HBP | 7:5ac5121bb4e0 | 6 | * * |
HBP | 7:5ac5121bb4e0 | 7 | * AUTHOR : Olli Vanhoja START DATE : 2011-02-17 * |
HBP | 7:5ac5121bb4e0 | 8 | ****************************************************************************** |
HBP | 7:5ac5121bb4e0 | 9 | * |
HBP | 7:5ac5121bb4e0 | 10 | * CHANGES : |
HBP | 7:5ac5121bb4e0 | 11 | * |
HBP | 7:5ac5121bb4e0 | 12 | * VERSION DATE WHO DETAIL |
HBP | 7:5ac5121bb4e0 | 13 | * 0.1 2011-02-21 Olli Vanhoja Initial release version |
HBP | 7:5ac5121bb4e0 | 14 | * 0.2 2011-02-21 Olli Vanhoja *Added possibility change I2C speed |
HBP | 7:5ac5121bb4e0 | 15 | * *Added external reset pin and autoreset |
HBP | 7:5ac5121bb4e0 | 16 | * for read function. Thanks to Jon Ward. |
HBP | 7:5ac5121bb4e0 | 17 | * *Documentational comments added. |
HBP | 7:5ac5121bb4e0 | 18 | * 0.3 2011-02-21 Olli Vanhoja *Auto-reset for all error conditions |
HBP | 7:5ac5121bb4e0 | 19 | * |
HBP | 7:5ac5121bb4e0 | 20 | *H*/ |
HBP | 0:cbf45dde2b49 | 21 | |
HBP | 0:cbf45dde2b49 | 22 | #ifndef I2C_EEPROM_H |
HBP | 0:cbf45dde2b49 | 23 | #define I2C_EEPROM_H |
HBP | 0:cbf45dde2b49 | 24 | |
HBP | 5:a0fe74dce80d | 25 | /** I2C EEPROM access class |
HBP | 5:a0fe74dce80d | 26 | * |
HBP | 5:a0fe74dce80d | 27 | * This class is used for communication with I2C EEPROM chip. |
HBP | 5:a0fe74dce80d | 28 | */ |
HBP | 0:cbf45dde2b49 | 29 | class i2c_eeprom { |
HBP | 0:cbf45dde2b49 | 30 | private: |
HBP | 0:cbf45dde2b49 | 31 | int i_i2c_address; // I2C harware address |
HBP | 7:5ac5121bb4e0 | 32 | void autoreset(); |
HBP | 0:cbf45dde2b49 | 33 | public: |
HBP | 5:a0fe74dce80d | 34 | /** Initialize communication |
HBP | 5:a0fe74dce80d | 35 | * |
HBP | 5:a0fe74dce80d | 36 | * @param hwAddr Harware address of the I2C EEPROM chip. |
HBP | 5:a0fe74dce80d | 37 | * @param speed I2C bus speed. |
HBP | 5:a0fe74dce80d | 38 | */ |
HBP | 5:a0fe74dce80d | 39 | i2c_eeprom(int hwAddr, int speed); |
HBP | 5:a0fe74dce80d | 40 | |
HBP | 5:a0fe74dce80d | 41 | /** Write to I2C EEPROM |
HBP | 5:a0fe74dce80d | 42 | * |
HBP | 5:a0fe74dce80d | 43 | * Write any length of bytes to external EEPROM. |
HBP | 5:a0fe74dce80d | 44 | * |
HBP | 5:a0fe74dce80d | 45 | * @param *data Array of bytes. |
HBP | 5:a0fe74dce80d | 46 | * @param iAddr Memory address. |
HBP | 5:a0fe74dce80d | 47 | * @param n Write n bytes. |
HBP | 5:a0fe74dce80d | 48 | */ |
HBP | 9:52c01cb100ac | 49 | void write(char *data, uint16_t iAddr, unsigned int n); |
HBP | 5:a0fe74dce80d | 50 | |
HBP | 5:a0fe74dce80d | 51 | /** Read from I2C EEPROM |
HBP | 5:a0fe74dce80d | 52 | * |
HBP | 5:a0fe74dce80d | 53 | * Read any length of bytes from external EEPROM. |
HBP | 5:a0fe74dce80d | 54 | * |
HBP | 5:a0fe74dce80d | 55 | * @param iAddr Memory address. |
HBP | 5:a0fe74dce80d | 56 | * @param n Read n bytes. |
HBP | 5:a0fe74dce80d | 57 | * @param *out Returns array of bytes. |
HBP | 5:a0fe74dce80d | 58 | */ |
HBP | 9:52c01cb100ac | 59 | void read(uint16_t iAddr, uint16_t n, char *out); |
HBP | 0:cbf45dde2b49 | 60 | }; |
HBP | 0:cbf45dde2b49 | 61 | |
HBP | 0:cbf45dde2b49 | 62 | #endif |