Skip to content

Commit 7c3a797

Browse files
committed
1.8.3 I2C_EEPROM
1 parent 6f2cc90 commit 7c3a797

File tree

14 files changed

+260
-28
lines changed

14 files changed

+260
-28
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# These are supported funding model platforms
22

33
github: RobTillaart
4+
custom: "https://www.paypal.me/robtillaart"
45

libraries/I2C_EEPROM/.github/workflows/arduino-lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ on: [push, pull_request]
55
jobs:
66
lint:
77
runs-on: ubuntu-latest
8+
timeout-minutes: 5
89
steps:
9-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v4
1011
- uses: arduino/arduino-lint-action@v1
1112
with:
1213
library-manager: update

libraries/I2C_EEPROM/.github/workflows/arduino_test_runner.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ on: [push, pull_request]
66
jobs:
77
runTest:
88
runs-on: ubuntu-latest
9+
timeout-minutes: 20
910

1011
steps:
11-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1213
- uses: ruby/setup-ruby@v1
1314
with:
1415
ruby-version: 2.6
1516
- run: |
17+
sudo sysctl vm.mmap_rnd_bits=28
1618
gem install arduino_ci
1719
arduino_ci.rb

libraries/I2C_EEPROM/.github/workflows/jsoncheck.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12+
timeout-minutes: 5
1213
steps:
13-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1415
- name: json-syntax-check
15-
uses: limitusus/json-syntax-check@v1
16+
uses: limitusus/json-syntax-check@v2
1617
with:
1718
pattern: "\\.json$"
1819

libraries/I2C_EEPROM/CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8-
## [1.8.2] - 2023-01-02
8+
9+
## [1.8.3] - 2024-03-28
10+
- Fix #64, compiler warning.
11+
- add **verifyBlock(memoryAddress, buffer, length)**
12+
- add example **I2C_eeprom_verifyBlock.ino**
13+
- update GitHub actions
14+
- update keywords.txt
15+
- update examples
16+
- update readme.md
17+
18+
19+
## [1.8.2] - 2024-01-02
920
- updated **uint32_t determineSizeNoWrite()**, kudos to roelandkluit
1021
- minor edits
1122

@@ -14,7 +25,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1425
- add example
1526
- minor edits
1627

17-
1828
## [1.8.0] - 2023-11-24 (breaking change)
1929
- simplify **begin()**, remove setting Wire pins from library.
2030
- add **getAddress()**

libraries/I2C_EEPROM/I2C_eeprom.cpp

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: I2C_eeprom.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 1.8.2
4+
// VERSION: 1.8.3
55
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
66
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
77

@@ -147,6 +147,27 @@ uint16_t I2C_eeprom::readBlock(const uint16_t memoryAddress, uint8_t * buffer, c
147147
}
148148

149149

150+
// returns true or false.
151+
bool I2C_eeprom::verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
152+
{
153+
uint16_t addr = memoryAddress;
154+
uint16_t len = length;
155+
while (len > 0)
156+
{
157+
uint8_t cnt = I2C_BUFFERSIZE;
158+
if (cnt > len) cnt = len;
159+
if (_verifyBlock(addr, buffer, cnt) == false)
160+
{
161+
return false;
162+
}
163+
addr += cnt;
164+
buffer += cnt;
165+
len -= cnt;
166+
}
167+
return true;
168+
}
169+
170+
150171
/////////////////////////////////////////////////////////////
151172
//
152173
// UPDATE SECTION
@@ -203,22 +224,26 @@ bool I2C_eeprom::writeByteVerify(const uint16_t memoryAddress, const uint8_t val
203224
bool I2C_eeprom::writeBlockVerify(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
204225
{
205226
if (writeBlock(memoryAddress, buffer, length) != 0) return false;
206-
uint8_t data[length];
207-
if (readBlock(memoryAddress, data, length) != length) return false;
208-
return memcmp(data, buffer, length) == 0;
227+
return verifyBlock(memoryAddress, buffer, length);
209228
}
210229

211230

212231
// return false if write or verify failed.
213232
bool I2C_eeprom::setBlockVerify(const uint16_t memoryAddress, const uint8_t value, const uint16_t length)
214233
{
215234
if (setBlock(memoryAddress, value, length) != 0) return false;
216-
uint8_t data[length];
235+
uint8_t * data = (uint8_t *) malloc(length);
236+
if (data == NULL) return false;
217237
if (readBlock(memoryAddress, data, length) != length) return false;
218238
for (uint16_t i = 0; i < length; i++)
219239
{
220-
if (data[i] != value) return false;
240+
if (data[i] != value)
241+
{
242+
free(data);
243+
return false;
244+
}
221245
}
246+
free(data);
222247
return true;
223248
}
224249

@@ -236,9 +261,7 @@ bool I2C_eeprom::updateByteVerify(const uint16_t memoryAddress, const uint8_t va
236261
bool I2C_eeprom::updateBlockVerify(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
237262
{
238263
if (updateBlock(memoryAddress, buffer, length) != length) return false;
239-
uint8_t data[length];
240-
if (readBlock(memoryAddress, data, length) != length) return false;
241-
return memcmp(data, buffer, length) == 0;
264+
return verifyBlock(memoryAddress, buffer, length);
242265
}
243266

244267

@@ -380,7 +403,7 @@ uint32_t I2C_eeprom::determineSizeNoWrite()
380403
//Read is perfomed just over size (size + BUFSIZE), this will only work for devices with mem > size; therefore return size * 2
381404
_isAddressSizeTwoWords = addressSize;
382405
return size * 2;
383-
}
406+
}
384407
}
385408
_isAddressSizeTwoWords = addressSize;
386409
return 0;
@@ -640,6 +663,50 @@ uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, c
640663
}
641664

642665

666+
// compares content of EEPROM with buffer.
667+
// returns true if equal.
668+
bool I2C_eeprom::_verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint8_t length)
669+
{
670+
_waitEEReady();
671+
672+
this->_beginTransmission(memoryAddress);
673+
int rv = _wire->endTransmission();
674+
if (rv != 0)
675+
{
676+
// if (_debug)
677+
// {
678+
// SPRN("mem addr r: ");
679+
// SPRNH(memoryAddress, HEX);
680+
// SPRN("\t");
681+
// SPRNL(rv);
682+
// }
683+
return false; // error
684+
}
685+
686+
// readBytes will always be equal or smaller to length
687+
uint8_t readBytes = 0;
688+
if (this->_isAddressSizeTwoWords)
689+
{
690+
readBytes = _wire->requestFrom(_deviceAddress, length);
691+
}
692+
else
693+
{
694+
uint8_t addr = _deviceAddress | ((memoryAddress >> 8) & 0x07);
695+
readBytes = _wire->requestFrom(addr, length);
696+
}
697+
yield(); // For OS scheduling
698+
uint8_t cnt = 0;
699+
while (cnt < readBytes)
700+
{
701+
if (buffer[cnt++] != _wire->read())
702+
{
703+
return false;
704+
}
705+
}
706+
return true;
707+
}
708+
709+
643710
void I2C_eeprom::_waitEEReady()
644711
{
645712
// Wait until EEPROM gives ACK again.

libraries/I2C_EEPROM/I2C_eeprom.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: I2C_eeprom.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 1.8.2
5+
// VERSION: 1.8.3
66
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
77
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
88

@@ -11,7 +11,7 @@
1111
#include "Wire.h"
1212

1313

14-
#define I2C_EEPROM_VERSION (F("1.8.2"))
14+
#define I2C_EEPROM_VERSION (F("1.8.3"))
1515

1616
#define I2C_DEVICESIZE_24LC512 65536
1717
#define I2C_DEVICESIZE_24LC256 32768
@@ -92,7 +92,7 @@ class I2C_eeprom
9292
// reads length bytes into buffer
9393
// returns bytes read.
9494
uint16_t readBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint16_t length);
95-
95+
bool verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length);
9696

9797
// updates a byte at memoryAddress, writes only if there is a new value.
9898
// return 0 if data is same or written OK, error code otherwise.
@@ -159,11 +159,14 @@ class I2C_eeprom
159159
void _beginTransmission(const uint16_t memoryAddress);
160160

161161
// returns I2C status, 0 = OK
162+
// TODO incrBuffer is an implementation name, not a functional name.
162163
int _pageBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length, const bool incrBuffer);
163164
// returns I2C status, 0 = OK
164165
int _WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint8_t length);
165166
// returns bytes read.
166167
uint8_t _ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint8_t length);
168+
// compare bytes in EEPROM.
169+
bool _verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint8_t length);
167170

168171
// to optimize the write latency of the EEPROM
169172
void _waitEEReady();

libraries/I2C_EEPROM/examples/I2C_eeprom_test/I2C_eeprom_test.ino

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ void setup()
3939
SERIAL_OUT.println("ERROR: Can't find eeprom\nstopped...");
4040
while (1);
4141
}
42-
43-
SERIAL_OUT.print("I2C eeprom library: ");
44-
SERIAL_OUT.print(I2C_EEPROM_VERSION);
45-
SERIAL_OUT.println("\n");
46-
4742
SERIAL_OUT.print("isConnected:\t");
4843
SERIAL_OUT.println(ee.isConnected());
4944

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
I2C_EEPROM_VERSION: 1.8.2
2+
3+
Testruns NN: 100
4+
5+
6+
TEST: NN x writeByte()
7+
DUR1: 466516
8+
9+
TEST: NN x writeByteVerify()
10+
DUR1: 542336
11+
12+
TEST: NN x updateByte() same data
13+
DUR2: 58616
14+
15+
TEST: NN x updateByteVerify() same data
16+
DUR2: 116896
17+
18+
TEST: NN x updateByteVerify() not same data
19+
DUR2: 596672
20+
21+
TEST: NN x writeBlock()
22+
DUR1: 1414432
23+
24+
TEST: NN x writeBlockVerify()
25+
DUR1: 2010844
26+
27+
TEST: NN x updateBlock() same data
28+
DUR2: 594796
29+
30+
TEST: NN x updateBlockVerify() same data
31+
DUR2: 1186644
32+
33+
TEST: NN x updateBlockVerify() not same data
34+
DUR2: 1204960
35+
36+
TEST: NN x setBlock() same data
37+
DUR2: 1415932
38+
39+
TEST: NN x setBlockVerify() same data
40+
DUR2: 2014048
41+
42+
TEST: NN x setBlockVerify() not same data
43+
DUR2: 2009780
44+
done...

0 commit comments

Comments
 (0)