Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 7:038c52e2268b, committed 2017-10-29
- Comitter:
- vargham
- Date:
- Sun Oct 29 18:31:47 2017 +0000
- Parent:
- 6:b3f9b29b07ba
- Commit message:
- Changed I2C pointer to reference.
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 Fri Aug 04 05:19:38 2017 +0000
+++ b/EERAM.cpp Sun Oct 29 18:31:47 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 Fri Aug 04 05:19:38 2017 +0000
+++ b/EERAM.h Sun Oct 29 18:31:47 2017 +0000
@@ -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;