Skip to content

Commit 86a5017

Browse files
authored
fix #83, update readme.md (#85)
- fix #83, update readme.md (thanks to TonyRiddiough) - add calculatePageSize(deviceSize) to replace getPageSize(deviceSize) prep. - update GitHub actions - minor update examples - minor edits
1 parent 86228c5 commit 86a5017

File tree

23 files changed

+169
-81
lines changed

23 files changed

+169
-81
lines changed

.github/workflows/arduino-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ jobs:
66
runs-on: ubuntu-latest
77
timeout-minutes: 5
88
steps:
9-
- uses: actions/checkout@v4
10-
- uses: arduino/arduino-lint-action@v1
9+
- uses: actions/checkout@v5
10+
- uses: arduino/arduino-lint-action@v2
1111
with:
1212
library-manager: update
1313
compliance: strict

.github/workflows/arduino_test_runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
timeout-minutes: 20
99

1010
steps:
11-
- uses: actions/checkout@v4
11+
- uses: actions/checkout@v5
1212
- uses: ruby/setup-ruby@v1
1313
with:
1414
ruby-version: 2.6

.github/workflows/jsoncheck.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ on:
55
paths:
66
- '**.json'
77
pull_request:
8+
paths:
9+
- '**.json'
810

911
jobs:
1012
test:
1113
runs-on: ubuntu-latest
1214
timeout-minutes: 5
1315
steps:
14-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v5
1517
- name: json-syntax-check
1618
uses: limitusus/json-syntax-check@v2
1719
with:

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [1.9.4] - 2025-08-27
10+
- fix #83, update readme.md (thanks to TonyRiddiough)
11+
- add calculatePageSize(deviceSize) to replace getPageSize(deviceSize) prep.
12+
- update GitHub actions
13+
- minor update examples
14+
- minor edits
15+
916
## [1.9.3] - 2025-08-01
1017
- update readme.md
1118

12-
1319
## [1.9.2] - 2024-11-25
1420
- fix #79, wrong default in constructor - kudos to ekinohito
1521

I2C_eeprom.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, T
4545
{
4646
_deviceAddress = deviceAddress;
4747
_deviceSize = setDeviceSize(deviceSize);
48-
_pageSize = getPageSize(_deviceSize);
48+
_pageSize = calculatePageSize(_deviceSize);
4949
_wire = wire;
5050

5151
// Chips 16 Kbit (2048 Bytes) or smaller only have one-word addresses.
@@ -296,7 +296,7 @@ bool I2C_eeprom::updateBlockVerify(const uint16_t memoryAddress, const uint8_t *
296296
// 24LC01 128 B YES
297297
uint32_t I2C_eeprom::determineSize(const bool debug)
298298
{
299-
// try to read a byte to see if connected
299+
// try to read a byte to see if connected
300300
if (! isConnected()) return 0;
301301

302302
uint8_t patAA = 0xAA;
@@ -308,7 +308,7 @@ uint32_t I2C_eeprom::determineSize(const bool debug)
308308

309309
// store old values
310310
bool addressSize = _isAddressSizeTwoWords;
311-
_isAddressSizeTwoWords = size > I2C_DEVICESIZE_24LC16; // 2048
311+
_isAddressSizeTwoWords = size > I2C_DEVICESIZE_24LC16; // 2048
312312
uint8_t buf = readByte(size);
313313

314314
// test folding
@@ -338,7 +338,7 @@ uint32_t I2C_eeprom::determineSize(const bool debug)
338338
// new 1.8.1 #61
339339
// updated 1.8.2 #63
340340
//
341-
// Returns:
341+
// Returns:
342342
// 0 if device size cannot be determined or device is not online
343343
// 1 if device has default bytes in first dataFirstBytes bytes [0-BUFSIZE]
344344
// Write some dataFirstBytes to the first bytes and retry or use the determineSize method
@@ -402,14 +402,14 @@ uint32_t I2C_eeprom::determineSizeNoWrite()
402402
_isAddressSizeTwoWords = (size >= I2C_DEVICESIZE_24LC16); // == 2048
403403

404404
// Try to read last byte of the block, should return length of 0 when fails for single byte devices
405-
// Will return the same dataFirstBytes as initially read on other devices
405+
// Will return the same dataFirstBytes as initially read on other devices
406406
// as the data pointer could not be moved to the requested position
407407
delay(2);
408408
uint16_t bSize = readBlock(size, dataMatch, BUFSIZE);
409409

410410
if (bSize == BUFSIZE && memcmp(dataFirstBytes, dataMatch, BUFSIZE) != 0)
411411
{
412-
// Read is performed just over size (size + BUFSIZE),
412+
// Read is performed just over size (size + BUFSIZE),
413413
// this will only work for devices with mem > size;
414414
// therefore return size * 2
415415
_isAddressSizeTwoWords = addressSize;
@@ -433,16 +433,23 @@ uint8_t I2C_eeprom::getPageSize()
433433
}
434434

435435

436-
uint8_t I2C_eeprom::getPageSize(uint32_t deviceSize)
436+
uint8_t I2C_eeprom::calculatePageSize(uint32_t deviceSize)
437437
{
438438
// determine page size from device size
439439
// based on Microchip 24LCXX data sheets.
440440
if (deviceSize <= I2C_DEVICESIZE_24LC02) return 8;
441441
if (deviceSize <= I2C_DEVICESIZE_24LC16) return 16;
442442
if (deviceSize <= I2C_DEVICESIZE_24LC64) return 32;
443443
if (deviceSize <= I2C_DEVICESIZE_24LC256) return 64;
444-
// I2C_DEVICESIZE_24LC512
445-
return 128;
444+
if (deviceSize <= I2C_DEVICESIZE_24LC512) return 128;
445+
// Error.
446+
return 0;
447+
}
448+
449+
450+
uint8_t I2C_eeprom::getPageSize(uint32_t deviceSize)
451+
{
452+
return calculatePageSize(deviceSize);
446453
}
447454

448455

@@ -469,7 +476,7 @@ uint32_t I2C_eeprom::setDeviceSize(uint32_t deviceSize)
469476

470477
uint8_t I2C_eeprom::setPageSize(uint8_t pageSize)
471478
{
472-
// force power of 2.
479+
// force power of 2.
473480
if (pageSize >= 128) {
474481
_pageSize = 128;
475482
}
@@ -616,7 +623,7 @@ int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer
616623

617624
_lastWrite = micros();
618625

619-
yield(); // For OS scheduling
626+
yield(); // For OS scheduling
620627

621628
// if (rv != 0)
622629
// {
@@ -627,7 +634,7 @@ int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer
627634
// SPRN("\t");
628635
// SPRNL(rv);
629636
// }
630-
// return -(abs(rv)); // error
637+
// return -(abs(rv)); // error
631638
// }
632639
return rv;
633640
}
@@ -728,9 +735,9 @@ void I2C_eeprom::_waitEEReady()
728735
{
729736
if (isConnected()) return;
730737
// TODO remove pre 1.7.4 code
731-
// _wire->beginTransmission(_deviceAddress);
732-
// int x = _wire->endTransmission();
733-
// if (x == 0) return;
738+
// _wire->beginTransmission(_deviceAddress);
739+
// int x = _wire->endTransmission();
740+
// if (x == 0) return;
734741
yield(); // For OS scheduling
735742
}
736743
return;

I2C_eeprom.h

Lines changed: 8 additions & 6 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.9.3
5+
// VERSION: 1.9.4
66
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
77
// URL: https://github.com/RobTillaart/I2C_EEPROM
88

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

1313

14-
#define I2C_EEPROM_VERSION (F("1.9.3"))
14+
#define I2C_EEPROM_VERSION (F("1.9.4"))
1515

1616
#define I2C_DEVICESIZE_24LC512 65536
1717
#define I2C_DEVICESIZE_24LC256 32768
@@ -74,17 +74,17 @@ class I2C_eeprom
7474
* It will try to guess page size and address word size based on the size of the device.
7575
*
7676
* @param deviceAddress Byte address of the device.
77-
* @param deviceSize Max size in bytes of the device (divide your device size in Kbits by 8)
77+
* @param deviceSize Max size in bytes of the device (divide your device size in Kbits by 8 to get Kbytes)
7878
* @param wire Select alternative Wire interface
7979
*/
8080
I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, TwoWire *wire = &Wire);
8181

82-
// use default I2C pins.
8382
bool begin(int8_t writeProtectPin = -1);
8483
bool isConnected();
8584
uint8_t getAddress();
8685

8786

87+
// user is responsible that address is in range of the EEPROM used.
8888
// writes a byte to memoryAddress
8989
// returns I2C status, 0 = OK
9090
int writeByte(const uint16_t memoryAddress, const uint8_t value);
@@ -123,11 +123,13 @@ class I2C_eeprom
123123

124124

125125
// Meta data functions
126-
uint32_t determineSize(const bool debug = false);
127-
uint32_t determineSizeNoWrite();
128126
uint32_t getDeviceSize();
129127
uint8_t getPageSize();
128+
uint8_t calculatePageSize(uint32_t deviceSize);
129+
[[deprecated("Use calculatePageSize(deviceSize) instead.")]]
130130
uint8_t getPageSize(uint32_t deviceSize);
131+
uint32_t determineSizeNoWrite();
132+
uint32_t determineSize(const bool debug = false);
131133
uint32_t getLastWrite();
132134

133135

I2C_eeprom_cyclic_store.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// VERSION: 1.0.0
66
// PURPOSE: Supplemental utility class for I2C_EEPROM library
77
//
8+
// URL: https://github.com/RobTillaart/I2C_EEPROM
89

910

1011
#include <I2C_eeprom.h>

0 commit comments

Comments
 (0)