Fork of 24LCxx_I2C. Works for Renesas EEPROMs. Fixes problems with PageWrites over page boundaries.

Fork of 24LCxx_I2C by Yann Garcia

Revision:
4:2add27250e69
Parent:
2:16ce7dae9019
--- a/24LCxx_I2C.h	Wed May 21 19:58:39 2014 +0000
+++ b/24LCxx_I2C.h	Tue Dec 23 17:21:25 2014 +0000
@@ -76,7 +76,11 @@
          * - If A1 and A2 pins are tired to Vdd and A0 is tired to Vss, address shall '00000110'B
          * - If A0 and A1 pins are tired to Vss and A2 is tired to Vdd, address shall '00000100'B
          */
-        C24LCXX_I2C(const PinName p_sda, const PinName p_scl, const unsigned char p_address, const PinName p_wp = NC, const unsigned int p_frequency = 400000);
+        //C24LCXX_I2C(const PinName p_sda, const PinName p_scl, const unsigned char p_address, const PinName p_wp = NC, const unsigned int p_frequency = 400000);
+        
+        /* defaults to a 24LC256: 256 kbit, 64Bytes PageSize */
+        C24LCXX_I2C(const PinName p_sda, const PinName p_scl, const unsigned char p_address, const PinName p_wp = NC, const unsigned int p_frequency = 400000,
+                    const uint32_t deviceSize = 256, const uint8_t pageSize = 64);
     
         /** Destructor
          */
@@ -187,7 +191,6 @@
     
         /** Write a buffer of characters at the specified memory address (from 0 to N - 1, N is the number of cells of the memory)
          *
-         * Note that the length of the buffer is not saved and the string is saved in Big Endian mode
          * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
          * @param p_datas The string to save
          * @param p_storeLength If true, store also the length of the string in Big Endian mode, otherwise the length will be provided by p_length2write parameter. Default value: true.
@@ -277,6 +280,23 @@
          */
         bool Read(const short p_address, std::string & p_string, bool p_readLengthFirst = true, int p_length2write = -1);
     
+        /** Read a buffer of characters from the specified memory address and store it into char array
+         *
+         * @param p_address The memory address (from 0 to N - 1, N is the number of cells of the memory)
+         * @param p_datas The string buffer to fill
+         * @param p_readLengthFirst If true, read the length first and p_length2write parameter is ignored, otherwise the length is provided by p_length2write parameter. Default value: true
+         * @param p_length2write The number of character to write, -1 to use the size of the string buffer
+         * @return true on success, false otherwise
+         * Exemple:
+         * @code
+         * char[255] readtext;
+         * ...
+         * myEEPROM.Read(memoryAddress, readtext);
+         * ...
+         * @endcode
+         */
+        bool Read(const short p_address, unsigned char * p_datas, bool p_readLengthFirst = true, int p_length2write = -1);
+
         /** Activate or deactivate write protect (pin 7)
          *
          * Note that a voltage of 3.3V apply to WP input of 24LCxx device is enough to enable write protect
@@ -309,9 +329,22 @@
 #endif // _DEBUG
         
     private:
+    
+        /* write to EEPROM. Take care of pageBoundaries */
+        int i2cWrite(short address, const char *data, int length);
+        
         /** Internal reference identifier
          */
         std::string _internalId;
+        
+        /** pageSize of device in Bytes
+        */
+        uint8_t _pageSize;
+        
+        /** Device Size of Device in Kbits
+        */
+        uint32_t _deviceSize;
+        
 
     }; // End of class C24LCXX_I2C