add changelog.md + optimize yield() calls (#47)

* add changelog.md
* optimize yield() calls
* update readme.md
This commit is contained in:
Rob Tillaart
2022-10-31 16:51:06 +01:00
committed by GitHub
parent 9001ab38c7
commit 4db0ca9815
7 changed files with 239 additions and 101 deletions
+19 -2
View File
@@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile: compile:
# Choosing to run compilation tests on 2 different Arduino platforms # Choosing to run compilation tests on 2 different Arduino platforms
platforms: platforms:
@@ -7,5 +22,7 @@ compile:
# - leonardo # - leonardo
- m4 - m4
- esp32 - esp32
# - esp8266 - esp8266
# - mega2560 # - mega2560
- rpipico
+138
View File
@@ -0,0 +1,138 @@
# Change Log I2C_EEPROM
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [1.6.2] - 2022-10-30
- Add RP2040 support to build-CI.
- Add CHANGELOG.md
- remove **yield()** calls in writeBlock(), readBlock() and updateBlock()
as these are already handled on a lower level. See #46
- better explain **begin()** in readme.md
## [1.6.1] - 2022-06-11
- update documentation
- minor edits
- minor improvements / bug fixes
## [1.6.0] - 2022-06-02
- add verify functions.
----
## [1.5.2] - 2021-12-19
- update library.json
- update license
- minor edits
## [1.5.1] - 2021-10-14
- function to add extra for write cycle (experimental)
## [1.5.0] - 2021-06-30
- #28 fix addressing 24LC04/08/16
----
## [1.4.3] - 2021-05-05
- adjust buffer size AVR / ESP
- rename ?
## [1.4.2] - 2021-01-31
- add updateBlock()
## [1.4.1] - 2021-01-28
- fix addressing bug 24LC04/08/16 equivalents from ST e.g. m24c08w
- add Wire1..WireN;
## [1.4.0] - 2021-01-27
- rewrite addressing scheme
- fix determineSize() - See determineSize for all tested.
----
## [1.3.2] - 2021-01-18
- add cyclic store functionality (Thanks to Tomas Hübner)
## [1.3.1] - 2020-12-22
- add Arduino-CI + unit tests
- add updateByte()
## [1.3.0] - 2020-06-19
- refactor
- remove pre 1.0 support
- add ESP32 support.
----
## [1.2.7] - 2019-09-03
- fix issue #113 and #128
## [1.2.6] - 2019-02-01
- fix issue #121
## [1.2.5] - 2017-04-20
- refactor the removed timeout (Thanks to Koepel)
## [1.2.4] - 2017-04-19
- remove timeout - issue #63
## [1.2.03] - 2015-05-15
- fix in \_pageBlock & example (thanks ifreislich )
## [1.2.02] - 2015-03-06
- stricter interface
## [1.2.01] - 2014-05-21
- Refactoring
## [1.2.00] - 2014-05-21
- Add support for Arduino DUE ( thanks to Tyler F.)
----
## [1.1.00] - 2013-11-13
- added begin() function (Note breaking interface)
- use faster block Wire.write()
- int casting removed
----
## [1.0.05] - 2013-11-06
- improved waitEEReady(),
- add determineSize()
## [1.0.04] - 2013-11-03
- fix bug in readBlock
- moved waitEEReady() -> more efficient.
## [1.0.03] - 2013-11-03
- refactor 5 millis() write-latency
## [1.0.02] - 2013-11-03
- optimize internal buffers
- refactor
## [1.0.01] - 2013-11-01
- fixed writeBlock bug
- refactor
## [1.0.00] - 2013-06-09
- support for Arduino 1.0.x
----
## [0.2.01] - 2011-08-13
- \_readBlock made more robust + return value
## [0.2.00] - 2011-02-11
- fix 64 bit boundary bug
----
## [0.1.01] - 2011-02-07
- add setBlock function
## [0.1.00] - 2011-01-21
- initial version
+18 -56
View File
@@ -1,54 +1,17 @@
// //
// FILE: I2C_eeprom.cpp // FILE: I2C_eeprom.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 1.6.1 // VERSION: 1.6.2
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
// URL: https://github.com/RobTillaart/I2C_EEPROM.git // URL: https://github.com/RobTillaart/I2C_EEPROM.git
// //
// HISTORY: // HISTORY: see changelog.md
// 0.1.00 2011-01-21 initial version
// 0.1.01 2011-02-07 added setBlock function
// 0.2.00 2011-02-11 fixed 64 bit boundary bug
// 0.2.01 2011-08-13 _readBlock made more robust + return value
// 1.0.00 2013-06-09 support for Arduino 1.0.x
// 1.0.01 2013-11-01 fixed writeBlock bug, refactor
// 1.0.02 2013-11-03 optimize internal buffers, refactor
// 1.0.03 2013-11-03 refactor 5 millis() write-latency
// 1.0.04 2013-11-03 fix bug in readBlock, moved waitEEReady()
// -> more efficient.
// 1.0.05 2013-11-06 improved waitEEReady(),
// added determineSize()
// 1.1.00 2013-11-13 added begin() function (Note breaking interface)
// use faster block Wire.write()
// int casting removed
// 1.2.00 2014-05-21 Added support for Arduino DUE ( thanks to Tyler F.)
// 1.2.01 2014-05-21 Refactoring
// 1.2.02 2015-03-06 stricter interface
// 1.2.03 2015-05-15 bugfix in _pageBlock & example (thanks ifreislich )
// 1.2.4 2017-04-19 remove timeout - issue #63
// 1.2.5 2017-04-20 refactor the removed timeout (Thanks to Koepel)
// 1.2.6 2019-02-01 fix issue #121
// 1.2.7 2019-09-03 fix issue #113 and #128
// 1.3.0 2020-06-19 refactor; removed pre 1.0 support; added ESP32 support.
// 1.3.1 2020-12-22 Arduino-CI + unit tests + updateByte()
// 1.3.2 2021-01-18 cyclic store functionality (Thanks to Tomas Hübner)
// 1.4.0 2021-01-27 rewritten addressing scheme + determineSize
// See determineSize for all tested.
// 1.4.1 2021-01-28 fixed addressing bug 24LC04/08/16 equivalents from ST e.g. m24c08w
// add Wire1..WireN;
// 1.4.2 2021-01-31 add updateBlock()
// 1.4.3 2021-05-05 adjust buffer size AVR / ESP +rename
// 1.5.0 2021-06-30 #28 fix addressing 24LC04/08/16
// 1.5.1 2021-10-14 function to add extra for write cycle (experimental)
// 1.5.2 2021-12-19 update library.json, license, minor edits
// 1.6.0 2022-06-02 add verify functions.
// 1.6.1 2022-06-11 update documentation, minor edits
// minor improvements / bug fixes
#include "I2C_eeprom.h" #include "I2C_eeprom.h"
// Not used directly
// Not used directly
#define I2C_PAGESIZE_24LC512 128 #define I2C_PAGESIZE_24LC512 128
#define I2C_PAGESIZE_24LC256 64 #define I2C_PAGESIZE_24LC256 64
#define I2C_PAGESIZE_24LC128 64 #define I2C_PAGESIZE_24LC128 64
@@ -72,7 +35,7 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// //
// PUBLIC FUNCTIONS // PUBLIC FUNCTIONS
// //
I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, TwoWire * wire) I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, TwoWire * wire)
{ {
@@ -87,7 +50,7 @@ I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, T
_pageSize = getPageSize(_deviceSize); _pageSize = getPageSize(_deviceSize);
_wire = wire; _wire = wire;
// Chips 16Kbit (2048 Bytes) or smaller only have one-word addresses. // Chips 16Kbit (2048 Bytes) or smaller only have one-word addresses.
this->_isAddressSizeTwoWords = deviceSize > I2C_DEVICESIZE_24LC16; this->_isAddressSizeTwoWords = deviceSize > I2C_DEVICESIZE_24LC16;
} }
@@ -186,7 +149,6 @@ uint16_t I2C_eeprom::readBlock(const uint16_t memoryAddress, uint8_t * buffer, c
addr += cnt; addr += cnt;
buffer += cnt; buffer += cnt;
len -= cnt; len -= cnt;
yield(); // For OS scheduling
} }
return rv; return rv;
} }
@@ -225,7 +187,6 @@ uint16_t I2C_eeprom::updateBlock(const uint16_t memoryAddress, const uint8_t * b
addr += cnt; addr += cnt;
buffer += cnt; buffer += cnt;
len -= cnt; len -= cnt;
yield(); // For OS scheduling
} }
return rv; return rv;
} }
@@ -292,8 +253,8 @@ bool I2C_eeprom::updateBlockVerify(const uint16_t memoryAddress, const uint8_t *
// METADATA SECTION // METADATA SECTION
// //
// returns size in bytes // returns size in bytes
// returns 0 if not connected // returns 0 if not connected
// //
// tested for // tested for
// 2 byte address // 2 byte address
@@ -321,12 +282,12 @@ uint32_t I2C_eeprom::determineSize(const bool debug)
{ {
bool folded = false; bool folded = false;
// store old values // store old values
bool addressSize = _isAddressSizeTwoWords; bool addressSize = _isAddressSizeTwoWords;
_isAddressSizeTwoWords = size > I2C_DEVICESIZE_24LC16; // 2048 _isAddressSizeTwoWords = size > I2C_DEVICESIZE_24LC16; // 2048
uint8_t buf = readByte(size); uint8_t buf = readByte(size);
// test folding // test folding
uint8_t cnt = 0; uint8_t cnt = 0;
writeByte(size, pat55); writeByte(size, pat55);
if (readByte(0) == pat55) cnt++; if (readByte(0) == pat55) cnt++;
@@ -340,7 +301,7 @@ uint32_t I2C_eeprom::determineSize(const bool debug)
Serial.println(readByte(size), HEX); Serial.println(readByte(size), HEX);
} }
// restore old values // restore old values
writeByte(size, buf); writeByte(size, buf);
_isAddressSizeTwoWords = addressSize; _isAddressSizeTwoWords = addressSize;
@@ -352,19 +313,20 @@ uint32_t I2C_eeprom::determineSize(const bool debug)
uint8_t I2C_eeprom::getPageSize(uint32_t deviceSize) uint8_t I2C_eeprom::getPageSize(uint32_t deviceSize)
{ {
// determine page size from device size - based on Microchip 24LCXX data sheets. // determine page size from device size
// based on Microchip 24LCXX data sheets.
if (deviceSize <= I2C_DEVICESIZE_24LC02) return 8; if (deviceSize <= I2C_DEVICESIZE_24LC02) return 8;
if (deviceSize <= I2C_DEVICESIZE_24LC16) return 16; if (deviceSize <= I2C_DEVICESIZE_24LC16) return 16;
if (deviceSize <= I2C_DEVICESIZE_24LC64) return 32; if (deviceSize <= I2C_DEVICESIZE_24LC64) return 32;
if (deviceSize <= I2C_DEVICESIZE_24LC256) return 64; if (deviceSize <= I2C_DEVICESIZE_24LC256) return 64;
// I2C_DEVICESIZE_24LC512 // I2C_DEVICESIZE_24LC512
return 128; return 128;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// //
// PRIVATE // PRIVATE
// //
// _pageBlock aligns buffer to page boundaries for writing. // _pageBlock aligns buffer to page boundaries for writing.
@@ -424,7 +386,7 @@ int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer
int rv = _wire->endTransmission(); int rv = _wire->endTransmission();
_lastWrite = micros(); _lastWrite = micros();
yield(); yield(); // For OS scheduling
// if (rv != 0) // if (rv != 0)
// { // {
@@ -472,11 +434,11 @@ uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, c
uint8_t addr = _deviceAddress | ((memoryAddress >> 8) & 0x07); uint8_t addr = _deviceAddress | ((memoryAddress >> 8) & 0x07);
readBytes = _wire->requestFrom(addr, length); readBytes = _wire->requestFrom(addr, length);
} }
yield(); // For OS scheduling
uint8_t cnt = 0; uint8_t cnt = 0;
while (cnt < readBytes) while (cnt < readBytes)
{ {
buffer[cnt++] = _wire->read(); buffer[cnt++] = _wire->read();
yield();
} }
return readBytes; return readBytes;
} }
@@ -494,7 +456,7 @@ void I2C_eeprom::_waitEEReady()
_wire->beginTransmission(_deviceAddress); _wire->beginTransmission(_deviceAddress);
int x = _wire->endTransmission(); int x = _wire->endTransmission();
if (x == 0) return; if (x == 0) return;
yield(); yield(); // For OS scheduling
} }
return; return;
} }
+4 -2
View File
@@ -2,7 +2,7 @@
// //
// FILE: I2C_eeprom.h // FILE: I2C_eeprom.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 1.6.1 // VERSION: 1.6.2
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
// URL: https://github.com/RobTillaart/I2C_EEPROM.git // URL: https://github.com/RobTillaart/I2C_EEPROM.git
// //
@@ -13,7 +13,7 @@
#include "Wire.h" #include "Wire.h"
#define I2C_EEPROM_VERSION (F("1.6.1")) #define I2C_EEPROM_VERSION (F("1.6.2"))
#define I2C_DEVICESIZE_24LC512 65536 #define I2C_DEVICESIZE_24LC512 65536
@@ -53,8 +53,10 @@ public:
I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, TwoWire *wire = &Wire); I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, TwoWire *wire = &Wire);
#if defined (ESP8266) || defined(ESP32) #if defined (ESP8266) || defined(ESP32)
// set the I2C pins explicitly (overrule)
bool begin(uint8_t sda, uint8_t scl); bool begin(uint8_t sda, uint8_t scl);
#endif #endif
// use default I2C pins.
bool begin(); bool begin();
bool isConnected(); bool isConnected();
+58 -39
View File
@@ -45,35 +45,48 @@ Most important change is 32 bit memory addresses.
### Constructor ### Constructor
- **I2C_eeprom(uint8_t deviceAddress, TwoWire \*wire = &Wire)** constructor, optional Wire interface. - **I2C_eeprom(uint8_t deviceAddress, TwoWire \*wire = &Wire)** constructor,
- **I2C_eeprom(uint8_t deviceAddress, uint32_t deviceSize, TwoWire \*wire = &Wire)** constructor, with optional Wire interface. optional Wire interface.
- **bool begin()** initializes the I2C bus and checks if the device is available on the I2C bus. - **I2C_eeprom(uint8_t deviceAddress, uint32_t deviceSize, TwoWire \*wire = &Wire)**
- **bool begin(uint8_t sda, uint8_t scl)** idem for ESP32 / ESP8266 and alike. constructor, with optional Wire interface.
- **bool begin()** initializes the I2C bus with the default pins.
Furthermore it checks if the deviceAddress is available on the I2C bus.
Returns true if deviceAddress is found on the bus, false otherwise.
- **bool begin(uint8_t sda, uint8_t scl)** (ESP32 / ESP8266 only)
initializes the I2C bus with the specified pins, therby overruling the default pins.
Furthermore it checks if the deviceAddress is available on the I2C bus.
Returns true if deviceAddress is found on the bus, false otherwise.
- **bool isConnected()** test to see if deviceAddress is found on the bus. - **bool isConnected()** test to see if deviceAddress is found on the bus.
### Write functions ### Write functions
- **int writeByte(uint16_t memoryAddress, uint8_t value)** write a single byte to the specified memory address. - **int writeByte(uint16_t memoryAddress, uint8_t value)** write a single byte to
the specified memory address.
Returns I2C status, 0 = OK. Returns I2C status, 0 = OK.
- **int writeBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** write a buffer starting at the specified memory address. - **int writeBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)**
write a buffer starting at the specified memory address.
Returns I2C status, 0 = OK. Returns I2C status, 0 = OK.
- **int setBlock(uint16_t memoryAddress, uint8_t value, uint16_t length)** writes the same byte to length places starting at the specified memory address. - **int setBlock(uint16_t memoryAddress, uint8_t value, uint16_t length)** writes
the same byte to length places starting at the specified memory address.
Returns I2C status, 0 = OK. Returns I2C status, 0 = OK.
### Update functions ### Update functions
- **int updateByte(uint16_t memoryAddress, uint8_t value)** write a single byte, but only if changed. - **int updateByte(uint16_t memoryAddress, uint8_t value)** write a single byte,
but only if changed.
Returns 0 if value was same or write succeeded. Returns 0 if value was same or write succeeded.
- **uint16_t updateBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** write a buffer starting at the specified memory address, but only if changed. - **uint16_t updateBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)**
write a buffer starting at the specified memory address, but only if changed.
Returns bytes written. Returns bytes written.
### Read functions ### Read functions
- **uint8_t readByte(uint16_t memoryAddress)** read a single byte from a given address - **uint8_t readByte(uint16_t memoryAddress)** read a single byte from a given address.
- **uint16_t readBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** read length bytes into buffer starting at specified memory address. - **uint16_t readBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)**
read length bytes into buffer starting at specified memory address.
Returns the number of bytes read, which should be length. Returns the number of bytes read, which should be length.
@@ -99,7 +112,7 @@ Same as write and update functions above. Returns true if successful, false indi
- **uint32_t determineSize(bool debug = false)** - **uint32_t determineSize(bool debug = false)**
function that determines the size of the EEPROM by detecting when a memory address is folded upon memory address 0. function that determines the size of the EEPROM by detecting when a memory address is folded upon memory address 0.
It is based upon the observation that memory wraps around. It is based upon the observation that memory wraps around.
The debug flag gives some output to Serial. The debug flag prints some output to Serial.
**Warning**: this function has changed (again) in 1.4.0 **Warning**: this function has changed (again) in 1.4.0
@@ -108,16 +121,16 @@ Test results
| Type | returns | Memory | Page Size | Notes | | Type | returns | Memory | Page Size | Notes |
|:--------|:--------|:---------|:---------:|:------| |:--------|:--------|:---------|:---------:|:------|
| - | 0 | | | connect error, check device address / wiring | | - | 0 | | | connect error, check device address / wiring |
| 24LC512 | 65536 | 64 KB | 128 | | | 24LC512 | 65536 | 64 KB | 128 | |
| 24LC256 | 32768 | 32 KB | 64 | | | 24LC256 | 32768 | 32 KB | 64 | |
| 24LC128 | 16384 | 16 KB | 64 | | | 24LC128 | 16384 | 16 KB | 64 | |
| 24LC64 | 8192 | 8 KB | 32 | | | 24LC64 | 8192 | 8 KB | 32 | |
| 24LC32 | 4096 | 4 KB | 32 | not tested with hardware | | 24LC32 | 4096 | 4 KB | 32 | not tested with hardware |
| 24LC16 | 2048 | 2 KB | 16 | | | 24LC16 | 2048 | 2 KB | 16 | |
| 24LC08 | 1024 | 1 KB | 16 | | | 24LC08 | 1024 | 1 KB | 16 | |
| 24LC04 | 512 | 512 b | 16 | | | 24LC04 | 512 | 512 b | 16 | |
| 24LC02 | 256 | 256 b | 8 | | | 24LC02 | 256 | 256 b | 8 | |
| 24LC01 | 128 | 128 b | 8 | | | 24LC01 | 128 | 128 b | 8 | |
The function cannot detect smaller than 128 bit EEPROMS. The function cannot detect smaller than 128 bit EEPROMS.
@@ -139,8 +152,9 @@ So you should verify if your sketch can make use of the advantages of **updateBl
#### ExtraWriteCycleTime (experimental) #### ExtraWriteCycleTime (experimental)
To improve support older I2C EEPROMs e.g. IS24C16 two functions were added to increase To improve support older I2C EEPROMs e.g. IS24C16 two functions were
the waiting time before a read and/or write as some older devices have a larger timeout added to increase the waiting time before a read and/or write as some
older devices have a larger timeout
than 5 milliseconds which is the minimum. than 5 milliseconds which is the minimum.
- **void setExtraWriteCycleTime(uint8_t ms)** idem - **void setExtraWriteCycleTime(uint8_t ms)** idem
@@ -152,22 +166,27 @@ than 5 milliseconds which is the minimum.
The library does not offer multiple EEPROMS as one continuous storage device. The library does not offer multiple EEPROMS as one continuous storage device.
## Future
- improve error handling, write functions should return bytes written or so.
- investigate the print interface?
- circular buffer?
- investigate multi-EEPROM storage
- wrapper class?
- investigate smarter strategy for **updateBlock()**
=> find first and last changed position could possibly result in less writes.
- can **setBlock()** use strategies from **updateBlock()**
- Add changelog
- internals
- **\_waitEEReady();** can return bool and could use isConnected() internally.
## Operation ## Operation
See examples See examples
## Future
#### must
- improve documentation
#### should
- investigate multi-EEPROM storage
- wrapper class?
- improve error handling, write functions should return bytes written or so.
#### could
- investigate smarter strategy for **updateBlock()**
=> find first and last changed position could possibly result in less writes.
- can **setBlock()** use strategies from **updateBlock()**
- **\_waitEEReady();** can return bool and could use isConnected() internally.
- added value?
- investigate the print interface?
- circular buffer? (see FRAM library)
- dump function?
+1 -1
View File
@@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/I2C_EEPROM.git" "url": "https://github.com/RobTillaart/I2C_EEPROM.git"
}, },
"version": "1.6.1", "version": "1.6.2",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*", "platforms": "*",
+1 -1
View File
@@ -1,5 +1,5 @@
name=I2C_EEPROM name=I2C_EEPROM
version=1.6.1 version=1.6.2
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for I2C EEPROMS sentence=Library for I2C EEPROMS