From afe39794bdfc1ca70716c182b16d6f73baae8f54 Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Mon, 31 Oct 2022 16:53:19 +0100 Subject: [PATCH] 1.6.2 I2C_EEPROM --- libraries/I2C_EEPROM/.arduino-ci.yml | 21 +++- libraries/I2C_EEPROM/CHANGELOG.md | 138 ++++++++++++++++++++++++ libraries/I2C_EEPROM/I2C_eeprom.cpp | 74 ++++--------- libraries/I2C_EEPROM/I2C_eeprom.h | 6 +- libraries/I2C_EEPROM/library.json | 2 +- libraries/I2C_EEPROM/library.properties | 2 +- libraries/I2C_EEPROM/readme.md | 97 ++++++++++------- 7 files changed, 239 insertions(+), 101 deletions(-) create mode 100644 libraries/I2C_EEPROM/CHANGELOG.md diff --git a/libraries/I2C_EEPROM/.arduino-ci.yml b/libraries/I2C_EEPROM/.arduino-ci.yml index e7cb4633..77a333f9 100644 --- a/libraries/I2C_EEPROM/.arduino-ci.yml +++ b/libraries/I2C_EEPROM/.arduino-ci.yml @@ -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: # Choosing to run compilation tests on 2 different Arduino platforms platforms: @@ -7,5 +22,7 @@ compile: # - leonardo - m4 - esp32 - # - esp8266 - # - mega2560 \ No newline at end of file + - esp8266 + # - mega2560 + - rpipico + diff --git a/libraries/I2C_EEPROM/CHANGELOG.md b/libraries/I2C_EEPROM/CHANGELOG.md new file mode 100644 index 00000000..87a9bc48 --- /dev/null +++ b/libraries/I2C_EEPROM/CHANGELOG.md @@ -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 diff --git a/libraries/I2C_EEPROM/I2C_eeprom.cpp b/libraries/I2C_EEPROM/I2C_eeprom.cpp index 7850e1fb..391a4e6e 100644 --- a/libraries/I2C_EEPROM/I2C_eeprom.cpp +++ b/libraries/I2C_EEPROM/I2C_eeprom.cpp @@ -1,54 +1,17 @@ // // FILE: I2C_eeprom.cpp // AUTHOR: Rob Tillaart -// VERSION: 1.6.1 +// VERSION: 1.6.2 // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // URL: https://github.com/RobTillaart/I2C_EEPROM.git // -// HISTORY: -// 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 +// HISTORY: see changelog.md #include "I2C_eeprom.h" -// Not used directly + +// Not used directly #define I2C_PAGESIZE_24LC512 128 #define I2C_PAGESIZE_24LC256 64 #define I2C_PAGESIZE_24LC128 64 @@ -72,7 +35,7 @@ //////////////////////////////////////////////////////////////////// // -// PUBLIC FUNCTIONS +// PUBLIC FUNCTIONS // 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); _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; } @@ -186,7 +149,6 @@ uint16_t I2C_eeprom::readBlock(const uint16_t memoryAddress, uint8_t * buffer, c addr += cnt; buffer += cnt; len -= cnt; - yield(); // For OS scheduling } return rv; } @@ -225,7 +187,6 @@ uint16_t I2C_eeprom::updateBlock(const uint16_t memoryAddress, const uint8_t * b addr += cnt; buffer += cnt; len -= cnt; - yield(); // For OS scheduling } return rv; } @@ -292,8 +253,8 @@ bool I2C_eeprom::updateBlockVerify(const uint16_t memoryAddress, const uint8_t * // METADATA SECTION // -// returns size in bytes -// returns 0 if not connected +// returns size in bytes +// returns 0 if not connected // // tested for // 2 byte address @@ -321,12 +282,12 @@ uint32_t I2C_eeprom::determineSize(const bool debug) { bool folded = false; - // store old values + // store old values bool addressSize = _isAddressSizeTwoWords; _isAddressSizeTwoWords = size > I2C_DEVICESIZE_24LC16; // 2048 uint8_t buf = readByte(size); - // test folding + // test folding uint8_t cnt = 0; writeByte(size, pat55); if (readByte(0) == pat55) cnt++; @@ -340,7 +301,7 @@ uint32_t I2C_eeprom::determineSize(const bool debug) Serial.println(readByte(size), HEX); } - // restore old values + // restore old values writeByte(size, buf); _isAddressSizeTwoWords = addressSize; @@ -352,19 +313,20 @@ uint32_t I2C_eeprom::determineSize(const bool debug) 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_24LC16) return 16; if (deviceSize <= I2C_DEVICESIZE_24LC64) return 32; if (deviceSize <= I2C_DEVICESIZE_24LC256) return 64; - // I2C_DEVICESIZE_24LC512 + // I2C_DEVICESIZE_24LC512 return 128; } //////////////////////////////////////////////////////////////////// // -// PRIVATE +// PRIVATE // // _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(); _lastWrite = micros(); - yield(); + yield(); // For OS scheduling // 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); readBytes = _wire->requestFrom(addr, length); } + yield(); // For OS scheduling uint8_t cnt = 0; while (cnt < readBytes) { buffer[cnt++] = _wire->read(); - yield(); } return readBytes; } @@ -494,7 +456,7 @@ void I2C_eeprom::_waitEEReady() _wire->beginTransmission(_deviceAddress); int x = _wire->endTransmission(); if (x == 0) return; - yield(); + yield(); // For OS scheduling } return; } diff --git a/libraries/I2C_EEPROM/I2C_eeprom.h b/libraries/I2C_EEPROM/I2C_eeprom.h index 744b58ab..38239399 100644 --- a/libraries/I2C_EEPROM/I2C_eeprom.h +++ b/libraries/I2C_EEPROM/I2C_eeprom.h @@ -2,7 +2,7 @@ // // FILE: I2C_eeprom.h // AUTHOR: Rob Tillaart -// VERSION: 1.6.1 +// VERSION: 1.6.2 // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // URL: https://github.com/RobTillaart/I2C_EEPROM.git // @@ -13,7 +13,7 @@ #include "Wire.h" -#define I2C_EEPROM_VERSION (F("1.6.1")) +#define I2C_EEPROM_VERSION (F("1.6.2")) #define I2C_DEVICESIZE_24LC512 65536 @@ -53,8 +53,10 @@ public: I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, TwoWire *wire = &Wire); #if defined (ESP8266) || defined(ESP32) + // set the I2C pins explicitly (overrule) bool begin(uint8_t sda, uint8_t scl); #endif + // use default I2C pins. bool begin(); bool isConnected(); diff --git a/libraries/I2C_EEPROM/library.json b/libraries/I2C_EEPROM/library.json index 4ecdbf72..c1297fd7 100644 --- a/libraries/I2C_EEPROM/library.json +++ b/libraries/I2C_EEPROM/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/I2C_EEPROM.git" }, - "version": "1.6.1", + "version": "1.6.2", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/libraries/I2C_EEPROM/library.properties b/libraries/I2C_EEPROM/library.properties index bc8ac521..68ec417a 100644 --- a/libraries/I2C_EEPROM/library.properties +++ b/libraries/I2C_EEPROM/library.properties @@ -1,5 +1,5 @@ name=I2C_EEPROM -version=1.6.1 +version=1.6.2 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library for I2C EEPROMS diff --git a/libraries/I2C_EEPROM/readme.md b/libraries/I2C_EEPROM/readme.md index 8a50d843..d70c1cef 100644 --- a/libraries/I2C_EEPROM/readme.md +++ b/libraries/I2C_EEPROM/readme.md @@ -45,35 +45,48 @@ Most important change is 32 bit memory addresses. ### Constructor -- **I2C_eeprom(uint8_t deviceAddress, TwoWire \*wire = &Wire)** constructor, optional Wire interface. -- **I2C_eeprom(uint8_t deviceAddress, uint32_t deviceSize, TwoWire \*wire = &Wire)** constructor, with optional Wire interface. -- **bool begin()** initializes the I2C bus and checks if the device is available on the I2C bus. -- **bool begin(uint8_t sda, uint8_t scl)** idem for ESP32 / ESP8266 and alike. +- **I2C_eeprom(uint8_t deviceAddress, TwoWire \*wire = &Wire)** constructor, +optional Wire interface. +- **I2C_eeprom(uint8_t deviceAddress, uint32_t deviceSize, TwoWire \*wire = &Wire)** +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. ### 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. -- **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. -- **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. ### 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. -- **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. ### Read functions -- **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. +- **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. 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)** 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. -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 @@ -108,16 +121,16 @@ Test results | Type | returns | Memory | Page Size | Notes | |:--------|:--------|:---------|:---------:|:------| | - | 0 | | | connect error, check device address / wiring | -| 24LC512 | 65536 | 64 KB | 128 | | -| 24LC256 | 32768 | 32 KB | 64 | | -| 24LC128 | 16384 | 16 KB | 64 | | -| 24LC64 | 8192 | 8 KB | 32 | | -| 24LC32 | 4096 | 4 KB | 32 | not tested with hardware | -| 24LC16 | 2048 | 2 KB | 16 | | -| 24LC08 | 1024 | 1 KB | 16 | | -| 24LC04 | 512 | 512 b | 16 | | -| 24LC02 | 256 | 256 b | 8 | | -| 24LC01 | 128 | 128 b | 8 | | +| 24LC512 | 65536 | 64 KB | 128 | | +| 24LC256 | 32768 | 32 KB | 64 | | +| 24LC128 | 16384 | 16 KB | 64 | | +| 24LC64 | 8192 | 8 KB | 32 | | +| 24LC32 | 4096 | 4 KB | 32 | not tested with hardware | +| 24LC16 | 2048 | 2 KB | 16 | | +| 24LC08 | 1024 | 1 KB | 16 | | +| 24LC04 | 512 | 512 b | 16 | | +| 24LC02 | 256 | 256 b | 8 | | +| 24LC01 | 128 | 128 b | 8 | | 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) -To improve support older I2C EEPROMs e.g. IS24C16 two functions were added to increase -the waiting time before a read and/or write as some older devices have a larger timeout +To improve support older I2C EEPROMs e.g. IS24C16 two functions were +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. - **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. -## 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 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? +