diff --git a/CHANGELOG.md b/CHANGELOG.md index 1602ed2..1a81de9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.8.0] - 2023-11-24 (breaking change) +- simplify **begin()**, remove setting Wire pins from library. +- add **getAddress()** +- update readme.md + + ## [1.7.4] - 2023-09-06 - solve #57 add support for WriteProtectPin - add writeProtectPin as optional parameter in **begin()** @@ -18,7 +24,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - update keywords.txt - update readme.md - ## [1.7.3] - 2023-05-10 - fix #55 ==> redo fix #53 - add test to detect **MBED** and **RP2040** diff --git a/I2C_eeprom.cpp b/I2C_eeprom.cpp index ef045f0..7704d80 100644 --- a/I2C_eeprom.cpp +++ b/I2C_eeprom.cpp @@ -1,7 +1,7 @@ // // FILE: I2C_eeprom.cpp // AUTHOR: Rob Tillaart -// VERSION: 1.7.4 +// VERSION: 1.8.0 // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // URL: https://github.com/RobTillaart/I2C_EEPROM.git @@ -53,56 +53,9 @@ I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, T } -#if defined(ESP8266) || defined(ESP32) - -bool I2C_eeprom::begin(uint8_t sda, uint8_t scl, int8_t writeProtectPin) -{ - // if (_wire == 0) Serial.println("zero"); // test #48 - if ((sda < 255) && (scl < 255)) - { - _wire->begin(sda, scl); - } - else - { - _wire->begin(); - } - _lastWrite = 0; - _writeProtectPin = writeProtectPin; - if (_writeProtectPin >= 0) - { - pinMode(_writeProtectPin, OUTPUT); - preventWrite(); - } - return isConnected(); -} - -#elif defined(ARDUINO_ARCH_RP2040) && !defined(__MBED__) - -bool I2C_eeprom::begin(uint8_t sda, uint8_t scl, int8_t writeProtectPin) -{ - if ((sda < 255) && (scl < 255)) - { - _wire->setSCL(scl); - _wire->setSDA(sda); - _wire->begin(); - } - _lastWrite = 0; - _writeProtectPin = writeProtectPin; - if (_writeProtectPin >= 0) - { - pinMode(_writeProtectPin, OUTPUT); - preventWrite(); - } - return isConnected(); -} - -#endif - - bool I2C_eeprom::begin(int8_t writeProtectPin) { // if (_wire == 0) Serial.println("zero"); // test #48 - _wire->begin(); _lastWrite = 0; _writeProtectPin = writeProtectPin; if (_writeProtectPin >= 0) @@ -121,6 +74,12 @@ bool I2C_eeprom::isConnected() } +uint8_t I2C_eeprom::getAddress() +{ + return _deviceAddress; +} + + ///////////////////////////////////////////////////////////// // // WRITE SECTION diff --git a/I2C_eeprom.h b/I2C_eeprom.h index f8914f6..8934264 100644 --- a/I2C_eeprom.h +++ b/I2C_eeprom.h @@ -2,7 +2,7 @@ // // FILE: I2C_eeprom.h // AUTHOR: Rob Tillaart -// VERSION: 1.7.4 +// VERSION: 1.8.0 // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // URL: https://github.com/RobTillaart/I2C_EEPROM.git @@ -11,7 +11,7 @@ #include "Wire.h" -#define I2C_EEPROM_VERSION (F("1.7.4")) +#define I2C_EEPROM_VERSION (F("1.8.0")) #define I2C_DEVICESIZE_24LC512 65536 @@ -59,15 +59,10 @@ class I2C_eeprom */ I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, TwoWire *wire = &Wire); - -// MBED test ==> see #55, #53 -#if defined(ESP8266) || defined(ESP32) || (defined(ARDUINO_ARCH_RP2040) && !defined(__MBED__)) - // set the I2C pins explicitly (overrule) - bool begin(uint8_t sda, uint8_t scl, int8_t writeProtectPin = -1); -#endif // use default I2C pins. bool begin(int8_t writeProtectPin = -1); bool isConnected(); + uint8_t getAddress(); // writes a byte to memoryAddress diff --git a/README.md b/README.md index 4cd233f..3558a68 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,16 @@ One from "Earle F. Philhower" and an "MBED" one. See issues #53 and #55 for deta In 1.7.3 defines are checked to select between these two and as far as tested this seems to solve the issue #53 while being backwards compatible. -If a better solution is found, it will be implemented. +If a better solution is found, it will be implemented. + + +#### Breaking change + +Version 1.8.0 introduced a breaking change. +You cannot set the pins in **begin()** any more. +This reduces the dependency of processor dependent Wire implementations. +The user has to call **Wire.begin()** and can optionally set the Wire pins +before calling **I2C_eeprom.begin()**. #### Links @@ -76,13 +85,8 @@ Furthermore it checks if the deviceAddress is available on the I2C bus. Returns true if deviceAddress is found on the bus, false otherwise. Optionally one can set the **WP** writeProtect pin. (see section below). If the **WP** pin is defined the default will be to **not** allow writing. -- **bool begin(uint8_t sda, uint8_t scl, uint8_t writeProtectPin = -1)** for ESP32 / ESP8266 / RP2040 and alike. -Initializes the I2C bus with the specified pins, thereby 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. -Optionally one can set the **WP** writeProtect pin. (see section below). -If the **WP** pin is defined the default will be to **not** allow writing. - **bool isConnected()** test to see if deviceAddress is found on the bus. +- **uint8_t getAddress()** returns device address set in the constructor. ### Write functions @@ -195,7 +199,7 @@ than 5 milliseconds which is the minimum. - **void setExtraWriteCycleTime(uint8_t ms)** idem - **uint8_t getExtraWriteCycleTime()** idem -Since 1.7.2 it is also possible to adjust the **I2C_WRITEDELAY** in the .h file +It is also possible to adjust the **I2C_WRITEDELAY** in the .h file or overrule the define on the command line. @@ -252,21 +256,18 @@ See examples - write functions should return bytes written or so. - make deviceSize explicit in examples? - #### Could - investigate smarter strategy for **updateBlock()** => find first and last changed position could possibly result in less writes. - can **setBlock()** use strategies from **updateBlock()** - #### Wont - investigate the print interface? - circular buffer? (see FRAM library) - dump function? - ## Support If you appreciate my libraries, you can support the development and maintenance. diff --git a/README_cyclic_store.md b/README_cyclic_store.md index 6532be9..bc43791 100644 --- a/README_cyclic_store.md +++ b/README_cyclic_store.md @@ -2,24 +2,37 @@ [![Arduino CI](https://github.com/RobTillaart/I2C_EEPROM/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) [![Arduino-lint](https://github.com/RobTillaart/I2C_EEPROM/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/I2C_EEPROM/actions/workflows/arduino-lint.yml) [![JSON check](https://github.com/RobTillaart/I2C_EEPROM/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/I2C_EEPROM/actions/workflows/jsoncheck.yml) +[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/I2C_EEPROM.svg)](https://github.com/RobTillaart/I2C_EEPROM/issues) + [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/I2C_EEPROM/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/I2C_EEPROM.svg?maxAge=3600)](https://github.com/RobTillaart/I2C_EEPROM/releases) +[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/I2C_EEPROM.svg)](https://registry.platformio.org/libraries/robtillaart/I2C_EEPROM) # I2C_eeprom_cyclic_store -Utility class for storing data using cyclic writes to eeprom memory +Utility class for storing data using cyclic writes to eeprom memory. ## Description -In order to maximize the life expectancy of an eeprom this class implements a method to spread the write operations across as much of the eeprom as possible, rather than writing to the same fixed location. +In order to maximize the life expectancy of an eeprom this class implements +a method to spread the write operations across as much of the eeprom as possible, +rather than writing to the same fixed location. -This is suitable for a situation where a single data structure (buffer), such as settings, configuration or metric data, is written to the eeprom. +This is suitable for a situation where a single data structure (buffer), +such as settings, configuration or metric data, is written to the eeprom. -It operates by partitioning the eeprom into slots large enough to hold the declared buffer (and header) and then writing each new version of the data to the next slot, overwriting any older version already in there. As it reaches the end of the alotted region of the eeprom it wraps around and starts writing from the start of the memory again. When initializing an instance it scans the eeprom to find the last written version and continues from that. +It operates by partitioning the eeprom into slots large enough to hold the +declared buffer (and header) and then writing each new version of the data +to the next slot, overwriting any older version already in there. +As it reaches the end of the alotted region of the eeprom it wraps around +and starts writing from the start of the memory again. +When initializing an instance it scans the eeprom to find the last written +version and continues from that. -In order to use an eeprom that already has data (and if the structure of the buffer changes) the eeprom has to be prepared by formatting the indexes. +In order to use an eeprom that already has data (and if the structure of the + buffer changes) the eeprom has to be prepared by formatting the indexes. The interface is pretty straightforward @@ -32,7 +45,8 @@ The interface is pretty straightforward ## Limitation -The class does not handle changes in buffer size or structure, nor does it detect an eeprom that has data that wasn't written using the class. +The class does not handle changes in buffer size or structure, nor does +it detect an eeprom that has data that wasn't written using the class. ## Operational diff --git a/library.json b/library.json index 34ce909..c311c75 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/I2C_EEPROM.git" }, - "version": "1.7.4", + "version": "1.8.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 8797c4a..b17864c 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=I2C_EEPROM -version=1.7.4 +version=1.8.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library for I2C EEPROMS