Driver library for Microchip I2C EERAM (47x04 and 47x16) 4 kbit or 16 kbit EEPROM backed SRAM.

Dependents:   EERAM_example

Files at this revision

API Documentation at this revision

Comitter:
vargham
Date:
Fri Aug 04 05:19:38 2017 +0000
Parent:
5:9444f29f3429
Child:
7:038c52e2268b
Commit message:
Removed I2C object copy.

Changed in this revision

EERAM.cpp Show annotated file Show diff for this revision Revisions of this file
EERAM.h Show annotated file Show diff for this revision Revisions of this file
--- a/EERAM.cpp	Tue May 09 07:01:45 2017 +0000
+++ b/EERAM.cpp	Fri Aug 04 05:19:38 2017 +0000
@@ -55,17 +55,17 @@
     int index = 0;
     while (index < length && success)
     {
-        success = _i2c.write(data[index]) == 1;
+        success = _i2c->write(data[index]) == 1;
         index++;
     }
-    _i2c.stop();
+    _i2c->stop();
     return success;
 }
 
 bool EERAM::writeBytes(char *data, int length)
 {
     bool success = false;
-    success = _i2c.write(_sramAddressWrite, data, length) == 0;
+    success = _i2c->write(_sramAddressWrite, data, length) == 0;
     return success;
 }
 
@@ -75,9 +75,9 @@
     if (success) success = setMemoryPointer(address, true);
     if (success)
     {
-        success = _i2c.read(_sramAddressRead, data, length, false) == 0;
+        success = _i2c->read(_sramAddressRead, data, length, false) == 0;
     }
-    _i2c.stop();
+    _i2c->stop();
     return success;
 }
 
@@ -86,19 +86,19 @@
     bool success = setMemoryPointer((uint8_t)data[1], (uint8_t)data[0], true);
     if (success)
     {
-        success = _i2c.read(_sramAddressRead, data + 2, length - 2, false) == 0;
+        success = _i2c->read(_sramAddressRead, data + 2, length - 2, false) == 0;
     }
-    _i2c.stop();
+    _i2c->stop();
     return success;
 }
 
 bool EERAM::writeRegister(uint8_t registerAddress, uint8_t data)
 {
-    _i2c.start();
-    bool success = _i2c.write(_controlAddressWrite) == 1;
-    if (success) success = _i2c.write(registerAddress) == 1;
-    if (success) success = _i2c.write(data) == 1;
-    _i2c.stop();
+    _i2c->start();
+    bool success = _i2c->write(_controlAddressWrite) == 1;
+    if (success) success = _i2c->write(registerAddress) == 1;
+    if (success) success = _i2c->write(data) == 1;
+    _i2c->stop();
     return success;
 }
 
@@ -124,14 +124,14 @@
 
 bool EERAM::readStatus()
 {
-    _i2c.start();
-    bool success = _i2c.write(_controlAddressRead) == 1;
+    _i2c->start();
+    bool success = _i2c->write(_controlAddressRead) == 1;
     if (success)
     {
-        _status = _i2c.read(false);
+        _status = _i2c->read(false);
         _statusToWrite = _status;
     }
-    _i2c.stop();
+    _i2c->stop();
     return success;
 }
 
@@ -193,9 +193,9 @@
 bool EERAM::isReady()
 {
     bool ready = false;
-    _i2c.start();
-    ready = _i2c.write(_controlAddressWrite) == 1;
-    _i2c.stop();
+    _i2c->start();
+    ready = _i2c->write(_controlAddressWrite) == 1;
+    _i2c->stop();
     return ready;
 }
 
@@ -235,7 +235,7 @@
     for (int i = 0; i < segments; i++)
     {
         serial.printf("%.4X", start + lineSize * i);
-        _i2c.read(_sramAddressRead, buffer, lineSize, false);
+        _i2c->read(_sramAddressRead, buffer, lineSize, false);
         for (int j = 0; j < (i == segments - 1 ? lastLineLength : lineSize); j++)
         {
             serial.printf(" %.2X", buffer[j]);
@@ -257,11 +257,11 @@
 bool EERAM::setMemoryPointer(uint8_t address_0, uint8_t address_1, bool stop)
 {
     int result = 0;
-    _i2c.start();
-    result = _i2c.write(_sramAddressWrite);
-    if (result == 1) result = _i2c.write(address_1);
-    if (result == 1) result = _i2c.write(address_0);
-    if (stop) _i2c.stop();
+    _i2c->start();
+    result = _i2c->write(_sramAddressWrite);
+    if (result == 1) result = _i2c->write(address_1);
+    if (result == 1) result = _i2c->write(address_0);
+    if (stop) _i2c->stop();
     return result == 1;
 }
 
@@ -272,10 +272,10 @@
     int index = 0;
     while (index < length && result == 1)
     {
-        result = _i2c.write(data);
+        result = _i2c->write(data);
         index++;
     }
-    _i2c.stop();
+    _i2c->stop();
     return result == 1;
 }
 
--- a/EERAM.h	Tue May 09 07:01:45 2017 +0000
+++ b/EERAM.h	Fri Aug 04 05:19:38 2017 +0000
@@ -91,12 +91,12 @@
     * @param A1 EERAM A1 pin state (true = high, false = low)
     * @param A2 EERAM A2 pin state (true = high, false = low)
     */
-    EERAM(PinName SDA, PinName SCL, uint16_t memorySize, bool A1 = false, bool A2 = false) :
-        _i2c(SDA, SCL),
-        _memorySize(memorySize)
-    {
-        initialize(A1, A2);
-    };
+//    EERAM(PinName SDA, PinName SCL, uint16_t memorySize, bool A1 = false, bool A2 = false) :
+//        _i2c(SDA, SCL),
+//        _memorySize(memorySize)
+//    {
+//        initialize(A1, A2);
+//    };
 
     /** Create an I2C EERAM interface, connected to the I2C, with specified size and with the specified address pins.
     * @param 12c I2C
@@ -104,7 +104,7 @@
     * @param A1 EERAM A1 pin state (true = high, false = low)
     * @param A2 EERAM A2 pin state (true = high, false = low)
     */
-    EERAM(I2C &i2c, uint16_t memorySize, bool A1 = false, bool A2 = false) :
+    EERAM(I2C *i2c, uint16_t memorySize, bool A1 = false, bool A2 = false) :
         _i2c(i2c),
         _memorySize(memorySize)
     {
@@ -219,7 +219,7 @@
         {
             if (direct)
             {
-                success = _i2c.read(_sramAddressRead, destinationAsBytes, readLength) == 0;
+                success = _i2c->read(_sramAddressRead, destinationAsBytes, readLength) == 0;
             }
             else
             {
@@ -454,7 +454,7 @@
     static const int TIME_STORE_16_MS = 25;
     static const int TIME_STORE_04_MS = 8;
     static const int TIME_STORE_STATUS_MS = 1;
-    I2C _i2c;
+    I2C *_i2c;
     uint16_t _memorySize;
     uint8_t _sramAddressWrite;
     uint8_t _sramAddressRead;