From ff21bd6cdc790e3103241a74339f2216ccecf54e Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Sat, 25 Nov 2023 13:19:42 +0100 Subject: [PATCH] simplify begin() (#60) - simplify **begin()**, remove setting Wire pins from library. - add **getAddress()** - update readme.md - update examples --- CHANGELOG.md | 8 ++- I2C_eeprom.cpp | 55 +++---------------- I2C_eeprom.h | 11 +--- README.md | 23 ++++---- README_cyclic_store.md | 26 +++++++-- .../I2C_eeprom_cyclic_store.ino | 2 + .../I2C_eeprom_determineSize.ino | 3 + .../I2C_eeprom_format/I2C_eeprom_format.ino | 3 + .../I2C_eeprom_struct/I2C_eeprom_struct.ino | 8 +-- examples/I2C_eeprom_test/I2C_eeprom_test.ino | 6 +- .../I2C_eeprom_test_performance.ino | 6 +- .../I2C_eeprom_update/I2C_eeprom_update.ino | 7 ++- .../I2C_eeprom_updateBlock.ino | 8 +-- .../I2C_eeprom_verify/I2C_eeprom_verify.ino | 7 ++- .../I2C_small_eeprom_test.ino | 2 + library.json | 2 +- library.properties | 2 +- test/unit_test_001.cpp | 22 ++++++-- test/unit_test_cyclic_store.cpp | 41 ++++++++++---- test/unit_test_page_size.cpp | 16 +++++- 20 files changed, 147 insertions(+), 111 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1602ed2..7d6da9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ 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 +- update examples + + ## [1.7.4] - 2023-09-06 - solve #57 add support for WriteProtectPin - add writeProtectPin as optional parameter in **begin()** @@ -18,7 +25,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 @@ public: */ 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/examples/I2C_eeprom_cyclic_store/I2C_eeprom_cyclic_store.ino b/examples/I2C_eeprom_cyclic_store/I2C_eeprom_cyclic_store.ino index d32e8b7..66d41fe 100644 --- a/examples/I2C_eeprom_cyclic_store/I2C_eeprom_cyclic_store.ino +++ b/examples/I2C_eeprom_cyclic_store/I2C_eeprom_cyclic_store.ino @@ -32,6 +32,8 @@ void setup() Serial.begin(115200); while(!Serial); + Wire.begin(); + ee.begin(); cs.begin(ee, PAGE_SIZE, MEMORY_SIZE/PAGE_SIZE); diff --git a/examples/I2C_eeprom_determineSize/I2C_eeprom_determineSize.ino b/examples/I2C_eeprom_determineSize/I2C_eeprom_determineSize.ino index 345e58c..8abcb28 100644 --- a/examples/I2C_eeprom_determineSize/I2C_eeprom_determineSize.ino +++ b/examples/I2C_eeprom_determineSize/I2C_eeprom_determineSize.ino @@ -16,10 +16,13 @@ uint32_t start, diff; void setup() { Serial.begin(115200); + while (!Serial); // wait for Serial port to connect. Needed for Leonardo only Serial.println(__FILE__); Serial.print("I2C_EEPROM_VERSION: "); Serial.println(I2C_EEPROM_VERSION); + Wire.begin(); + ee.begin(); if (! ee.isConnected()) { diff --git a/examples/I2C_eeprom_format/I2C_eeprom_format.ino b/examples/I2C_eeprom_format/I2C_eeprom_format.ino index 55613aa..a3cac78 100644 --- a/examples/I2C_eeprom_format/I2C_eeprom_format.ino +++ b/examples/I2C_eeprom_format/I2C_eeprom_format.ino @@ -16,10 +16,13 @@ uint32_t start, diff; void setup() { Serial.begin(115200); + while (!Serial); // wait for Serial port to connect. Needed for Leonardo only Serial.println(__FILE__); Serial.print("I2C_EEPROM_VERSION: "); Serial.println(I2C_EEPROM_VERSION); + Wire.begin(); + ee.begin(); if (! ee.isConnected()) { diff --git a/examples/I2C_eeprom_struct/I2C_eeprom_struct.ino b/examples/I2C_eeprom_struct/I2C_eeprom_struct.ino index 81a39ce..707c207 100644 --- a/examples/I2C_eeprom_struct/I2C_eeprom_struct.ino +++ b/examples/I2C_eeprom_struct/I2C_eeprom_struct.ino @@ -27,12 +27,12 @@ struct void setup() { Serial.begin(115200); - while (!Serial); // wait for Serial to connect. - + while (!Serial); // wait for Serial port to connect. Needed for Leonardo only Serial.println(__FILE__); - Serial.print("VERSION: "); + Serial.print("I2C_EEPROM_VERSION: "); Serial.println(I2C_EEPROM_VERSION); - Serial.println(); + + Wire.begin(); ee.begin(); if (! ee.isConnected()) diff --git a/examples/I2C_eeprom_test/I2C_eeprom_test.ino b/examples/I2C_eeprom_test/I2C_eeprom_test.ino index 1bae78b..5bed50a 100644 --- a/examples/I2C_eeprom_test/I2C_eeprom_test.ino +++ b/examples/I2C_eeprom_test/I2C_eeprom_test.ino @@ -26,8 +26,12 @@ uint32_t start, diff, totals = 0; void setup() { SERIAL_OUT.begin(115200); - while (!SERIAL_OUT); // wait for SERIAL_OUT port to connect. Needed for Leonardo only + while (!SERIAL_OUT); // wait for SERIAL_OUT port to connect. Needed for Leonardo only SERIAL_OUT.println(__FILE__); + SERIAL_OUT.print("I2C_EEPROM_VERSION: "); + SERIAL_OUT.println(I2C_EEPROM_VERSION); + + Wire.begin(); ee.begin(); if (! ee.isConnected()) diff --git a/examples/I2C_eeprom_test_performance/I2C_eeprom_test_performance.ino b/examples/I2C_eeprom_test_performance/I2C_eeprom_test_performance.ino index 500d005..e3c8cc1 100644 --- a/examples/I2C_eeprom_test_performance/I2C_eeprom_test_performance.ino +++ b/examples/I2C_eeprom_test_performance/I2C_eeprom_test_performance.ino @@ -16,11 +16,13 @@ uint32_t start, diff, totals = 0; void setup() { Serial.begin(115200); - while (!Serial); // wait for Serial port to connect. Needed for Leonardo only + while (!Serial); // wait for Serial port to connect. Needed for Leonardo only Serial.println(__FILE__); - Serial.print("VERSION: "); + Serial.print("I2C_EEPROM_VERSION: "); Serial.println(I2C_EEPROM_VERSION); + Wire.begin(); + ee.begin(); if (! ee.isConnected()) { diff --git a/examples/I2C_eeprom_update/I2C_eeprom_update.ino b/examples/I2C_eeprom_update/I2C_eeprom_update.ino index e95be1d..bd775b2 100644 --- a/examples/I2C_eeprom_update/I2C_eeprom_update.ino +++ b/examples/I2C_eeprom_update/I2C_eeprom_update.ino @@ -18,12 +18,13 @@ uint32_t start, dur1, dur2; void setup() { Serial.begin(115200); - while (!Serial); // wait for SERIAL_OUT port to connect. Needed for Leonardo only - + while (!Serial); // wait for Serial port to connect. Needed for Leonardo only Serial.println(__FILE__); - Serial.print("VERSION: "); + Serial.print("I2C_EEPROM_VERSION: "); Serial.println(I2C_EEPROM_VERSION); + Wire.begin(); + ee.begin(); if (! ee.isConnected()) { diff --git a/examples/I2C_eeprom_updateBlock/I2C_eeprom_updateBlock.ino b/examples/I2C_eeprom_updateBlock/I2C_eeprom_updateBlock.ino index 8426b5e..626cda5 100644 --- a/examples/I2C_eeprom_updateBlock/I2C_eeprom_updateBlock.ino +++ b/examples/I2C_eeprom_updateBlock/I2C_eeprom_updateBlock.ino @@ -21,12 +21,12 @@ uint8_t ar[100]; void setup() { Serial.begin(115200); - while (!Serial); // wait for SERIAL_OUT port to connect. Needed for Leonardo only - + while (!Serial); // wait for Serial port to connect. Needed for Leonardo only Serial.println(__FILE__); - Serial.print("VERSION: "); + Serial.print("I2C_EEPROM_VERSION: "); Serial.println(I2C_EEPROM_VERSION); - Serial.println(); + + Wire.begin(); ee.begin(); if (! ee.isConnected()) diff --git a/examples/I2C_eeprom_verify/I2C_eeprom_verify.ino b/examples/I2C_eeprom_verify/I2C_eeprom_verify.ino index 58ddcc8..5a05d82 100644 --- a/examples/I2C_eeprom_verify/I2C_eeprom_verify.ino +++ b/examples/I2C_eeprom_verify/I2C_eeprom_verify.ino @@ -19,12 +19,13 @@ uint32_t start, dur1, dur2; void setup() { Serial.begin(115200); - while (!Serial); // wait for SERIAL_OUT port to connect. Needed for Leonardo only - + while (!Serial); // wait for Serial port to connect. Needed for Leonardo only Serial.println(__FILE__); - Serial.print("VERSION: "); + Serial.print("I2C_EEPROM_VERSION: "); Serial.println(I2C_EEPROM_VERSION); + Wire.begin(); + ee.begin(); if (! ee.isConnected()) { diff --git a/examples/I2C_small_eeprom_test/I2C_small_eeprom_test.ino b/examples/I2C_small_eeprom_test/I2C_small_eeprom_test.ino index 2ea5078..2141e64 100644 --- a/examples/I2C_small_eeprom_test/I2C_small_eeprom_test.ino +++ b/examples/I2C_small_eeprom_test/I2C_small_eeprom_test.ino @@ -105,6 +105,8 @@ void setup() SERIAL_DEBUG.println("IT IS BEGINNING"); SERIAL_DEBUG.println("WAIT FOR IT"); + Wire.begin(); + eeprom.begin(); readAndWriteVar(); 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 diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index 0201106..124b0f1 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -52,7 +52,7 @@ unittest(test_new_operator) assertEqualINF(exp(800)); assertEqualINF(0.0/0.0); assertEqualINF(42); - + assertEqualNAN(INFINITY - INFINITY); assertEqualNAN(0.0/0.0); assertEqualNAN(42); @@ -63,7 +63,7 @@ unittest(test_new_operator) unittest(test_constructor) { Wire.resetMocks(); - + Wire.begin(); I2C_eeprom EE(0x50, 0x8000); assertTrue(EE.begin()); @@ -76,6 +76,8 @@ unittest(test_constructor) unittest(test_constants) { + Wire.resetMocks(); + Wire.begin(); I2C_eeprom EE(0x50, 0x8000); assertEqual(I2C_DEVICESIZE_24LC512, 65536); @@ -93,6 +95,8 @@ unittest(test_constants) unittest(test_getPageSize) { + Wire.resetMocks(); + Wire.begin(); I2C_eeprom EE(0x50, 0x8000); assertEqual(EE.getPageSize(I2C_DEVICESIZE_24LC512), 128); @@ -105,7 +109,7 @@ unittest(test_getPageSize) assertEqual(EE.getPageSize(I2C_DEVICESIZE_24LC04), 16); assertEqual(EE.getPageSize(I2C_DEVICESIZE_24LC02), 8); assertEqual(EE.getPageSize(I2C_DEVICESIZE_24LC01), 8); - + I2C_eeprom prom(0x50, 0x8123); assertEqual(prom.getDeviceSize(), 0x8000); assertEqual(prom.getPageSize(), 64); @@ -114,6 +118,8 @@ unittest(test_getPageSize) unittest(test_setDeviceSize) { + Wire.resetMocks(); + Wire.begin(); I2C_eeprom EE(0x50, 0x8000); assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC512), I2C_DEVICESIZE_24LC512); @@ -140,9 +146,11 @@ unittest(test_setDeviceSize) } -/* + unittest(test_setPageSize) { + Wire.resetMocks(); + Wire.begin(); I2C_eeprom EE(0x50, 0x8000); assertEqual(EE.setPageSize(129), 128); @@ -159,8 +167,10 @@ unittest(test_setPageSize) assertEqual(EE.setPageSize(9), 8); assertEqual(EE.setPageSize(8), 8); } -*/ + unittest_main() -// -------- + +// -- END OF FILE -- + diff --git a/test/unit_test_cyclic_store.cpp b/test/unit_test_cyclic_store.cpp index e76f451..83ccbef 100644 --- a/test/unit_test_cyclic_store.cpp +++ b/test/unit_test_cyclic_store.cpp @@ -9,12 +9,12 @@ // Note: The implementation of the I2C_eeprom_cyclic_store should have been // made injactable so that a mock or fake for I2C_eeprom could have been used // instead of having to rely on a test implementation of the Wire singleton. -// +// // This could have been done by changing the class to take two template // parameters, the first being one for I2C_eeprom or it's mock and the second // being the data type to store. For simplicity an alias could have been // introduced so that users wouldn't have to specify I2C_eeprom but that made -// the editor lose track of the intellisense comments. :-/ +// the editor lose track of the intellisense comments. :-/ // // Thus this remains until someone comes up with a brighter idea. @@ -40,12 +40,13 @@ unittest_teardown() } /** - * Verify that I2C_eeprom_cyclic_store fails to + * Verify that I2C_eeprom_cyclic_store fails to * initialize when unable to read from eeprom. */ unittest(cyclic_store_fails_begin) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -57,12 +58,13 @@ unittest(cyclic_store_fails_begin) } /** - * Verify that I2C_eeprom_cyclic_store successfully + * Verify that I2C_eeprom_cyclic_store successfully * initializes on empty eeprom. */ unittest(cyclic_store_empty_begin) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -87,6 +89,7 @@ unittest(cyclic_store_empty_begin) unittest(cyclic_store_double_page_buffer) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -117,6 +120,7 @@ unittest(cyclic_store_double_page_buffer) unittest(cyclic_store_finds_single_stored_version) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -155,6 +159,7 @@ unittest(cyclic_store_finds_single_stored_version) unittest(cyclic_store_finds_last_half_filled_eeprom) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -205,6 +210,7 @@ unittest(cyclic_store_finds_last_half_filled_eeprom) unittest(cyclic_store_finds_version_if_last_slot) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -256,6 +262,7 @@ unittest(cyclic_store_finds_version_if_last_slot) unittest(cyclic_store_finds_last_wrapped_eeprom) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -304,12 +311,13 @@ unittest(cyclic_store_finds_last_wrapped_eeprom) * Verify that I2C_eeprom_cyclic_store successfully finds the last * entry after writes have wrapped around the end of the eeprom * when using a buffer that spans two pages. And that it does so - * even if the number of pages is not evenly divisable by the + * even if the number of pages is not evenly divisable by the * number of pages the buffer span. */ unittest(cyclic_store_finds_last_wrapped_eeprom_double_page_buffer) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -361,6 +369,7 @@ unittest(cyclic_store_finds_last_wrapped_eeprom_double_page_buffer) unittest(cyclic_store_fails_init_on_too_large_buffer) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE); EE.begin(); @@ -376,6 +385,7 @@ unittest(cyclic_store_fails_init_on_too_large_buffer) unittest(cyclic_store_empty_metrics) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -407,6 +417,7 @@ unittest(cyclic_store_empty_metrics) unittest(cyclic_store_fails_metrics_when_failed_initialize) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE); EE.begin(); @@ -427,6 +438,7 @@ unittest(cyclic_store_fails_metrics_when_failed_initialize) unittest(cyclic_store_fails_metrics_when_not_initialized) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE); EE.begin(); @@ -440,13 +452,14 @@ unittest(cyclic_store_fails_metrics_when_not_initialized) } /** - * Verify that I2C_eeprom_cyclic_store correctly + * Verify that I2C_eeprom_cyclic_store correctly * increments the number of writes when saving * new versions. */ unittest(cyclic_store_increments_write_counter) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -489,6 +502,7 @@ unittest(cyclic_store_increments_write_counter) unittest(cyclic_store_format_single_page) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -522,6 +536,7 @@ unittest(cyclic_store_format_single_page) unittest(cyclic_store_format_double_page) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -556,6 +571,7 @@ unittest(cyclic_store_format_double_page) unittest(cyclic_store_format_double_page_odd_space) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); @@ -590,12 +606,13 @@ unittest(cyclic_store_format_double_page_odd_space) unittest(cyclic_store_wrapping_single_page) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE); EE.begin(); - + auto miso = Wire.getMiso(I2C_EEPROM_ADDR); miso->push_back(0xff); miso->push_back(0xff); @@ -635,12 +652,13 @@ unittest(cyclic_store_wrapping_single_page) unittest(cyclic_store_wrapping_double_page) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE); EE.begin(); - + auto miso = Wire.getMiso(I2C_EEPROM_ADDR); miso->push_back(0xff); miso->push_back(0xff); @@ -677,12 +695,13 @@ unittest(cyclic_store_wrapping_double_page) unittest(cyclic_store_wrapping_double_page_odd_space) { Wire.resetMocks(); + Wire.begin(); auto mosi = Wire.getMosi(I2C_EEPROM_ADDR); I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE); EE.begin(); - + auto miso = Wire.getMiso(I2C_EEPROM_ADDR); miso->push_back(0xff); miso->push_back(0xff); @@ -713,4 +732,6 @@ unittest(cyclic_store_wrapping_double_page_odd_space) unittest_main() -// -------- + +// -- END OF FILE -- + diff --git a/test/unit_test_page_size.cpp b/test/unit_test_page_size.cpp index 7fddc0c..1558aa9 100644 --- a/test/unit_test_page_size.cpp +++ b/test/unit_test_page_size.cpp @@ -40,11 +40,12 @@ unittest_teardown() /** * Verify that an instance gets the default page size * when the constructor without device size is used. - * The expected outcome is I2C_EEPROM_PAGESIZE + * The expected outcome is I2C_EEPROM_PAGESIZE */ unittest(i2c_eeprom_default_page_size) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom eeprom(I2C_EEPROM_ADDR); @@ -61,6 +62,7 @@ unittest(i2c_eeprom_default_page_size) unittest(i2c_eeprom_1k_page_size) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x80); @@ -76,6 +78,7 @@ unittest(i2c_eeprom_1k_page_size) unittest(i2c_eeprom_2k_page_size) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x100); @@ -91,6 +94,7 @@ unittest(i2c_eeprom_2k_page_size) unittest(i2c_eeprom_4k_page_size) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x200); @@ -106,6 +110,7 @@ unittest(i2c_eeprom_4k_page_size) unittest(i2c_eeprom_8k_page_size) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x400); @@ -121,6 +126,7 @@ unittest(i2c_eeprom_8k_page_size) unittest(i2c_eeprom_16k_page_size) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x800); @@ -136,6 +142,7 @@ unittest(i2c_eeprom_16k_page_size) unittest(i2c_eeprom_32k_page_size) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x1000); @@ -151,6 +158,7 @@ unittest(i2c_eeprom_32k_page_size) unittest(i2c_eeprom_64k_page_size) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x2000); @@ -166,6 +174,7 @@ unittest(i2c_eeprom_64k_page_size) unittest(i2c_eeprom_128k_page_size) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x4000); @@ -181,6 +190,7 @@ unittest(i2c_eeprom_128k_page_size) unittest(i2c_eeprom_256k_page_size) { Wire.resetMocks(); + Wire.begin(); I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x8000); @@ -191,4 +201,6 @@ unittest(i2c_eeprom_256k_page_size) unittest_main() -// ------------------ + +// -- END OF FILE -- +