mirror of
https://github.com/RobTillaart/I2C_EEPROM.git
synced 2026-07-27 20:06:07 +00:00
update GitHub actions
This commit is contained in:
@@ -6,7 +6,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: arduino/arduino-lint-action@v2
|
||||
with:
|
||||
library-manager: update
|
||||
|
||||
@@ -6,9 +6,8 @@ jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v2
|
||||
with:
|
||||
|
||||
+3
-1
@@ -7,9 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [1.9.5] - 2025-11-19
|
||||
- update documentation
|
||||
- update GitHub actions
|
||||
- add examples
|
||||
- improve build efficiency (only one example with 5 boards)
|
||||
|
||||
- minor edits
|
||||
|
||||
## [1.9.4] - 2025-08-27
|
||||
- fix #83, update readme.md (thanks to TonyRiddiough)
|
||||
|
||||
+39
-7
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: I2C_eeprom.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 1.9.3
|
||||
// VERSION: 1.9.5
|
||||
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
|
||||
// URL: https://github.com/RobTillaart/I2C_EEPROM
|
||||
|
||||
@@ -81,6 +81,17 @@ uint8_t I2C_eeprom::getAddress()
|
||||
}
|
||||
|
||||
|
||||
uint16_t I2C_eeprom::partition(uint16_t offset, uint16_t size)
|
||||
{
|
||||
// issue #86
|
||||
// TODO verify within range
|
||||
// else error
|
||||
_partitionOffset = offset;
|
||||
_partitionSize = size;
|
||||
return offset + size;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// WRITE SECTION
|
||||
@@ -606,13 +617,19 @@ void I2C_eeprom::_beginTransmission(const uint16_t memoryAddress)
|
||||
// returns 0 = OK otherwise error
|
||||
int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
|
||||
{
|
||||
// #86 - check range
|
||||
// if (_partitionSize && ((memoryAddress + length) > _partitionSize))
|
||||
// {
|
||||
// return ERROR
|
||||
// }
|
||||
_waitEEReady();
|
||||
if (_autoWriteProtect)
|
||||
{
|
||||
digitalWrite(_writeProtectPin, LOW);
|
||||
}
|
||||
|
||||
this->_beginTransmission(memoryAddress);
|
||||
// #86
|
||||
this->_beginTransmission(memoryAddress + _partitionOffset);
|
||||
_wire->write(buffer, length);
|
||||
int rv = _wire->endTransmission();
|
||||
|
||||
@@ -644,9 +661,15 @@ int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer
|
||||
// returns bytes read
|
||||
uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint16_t length)
|
||||
{
|
||||
// #86 - check range
|
||||
// if (_partitionSize && ((memoryAddress + length) > _partitionSize))
|
||||
// {
|
||||
// return ERROR
|
||||
// }
|
||||
_waitEEReady();
|
||||
|
||||
this->_beginTransmission(memoryAddress);
|
||||
// #86
|
||||
this->_beginTransmission(memoryAddress + _partitionOffset);
|
||||
int rv = _wire->endTransmission();
|
||||
if (rv != 0)
|
||||
{
|
||||
@@ -668,7 +691,9 @@ uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, c
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t address = _deviceAddress | ((memoryAddress >> 8) & 0x07);
|
||||
// #86
|
||||
// uint8_t partialAddr =
|
||||
uint8_t address = _deviceAddress | (((memoryAddress + _partitionOffset)>> 8) & 0x07);
|
||||
readBytes = _wire->requestFrom((int)address, (int)length);
|
||||
}
|
||||
yield(); // For OS scheduling
|
||||
@@ -685,9 +710,14 @@ uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, c
|
||||
// returns true if equal.
|
||||
bool I2C_eeprom::_verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
|
||||
{
|
||||
// #86 - check range
|
||||
// if (_partitionSize && ((memoryAddress + length) > _partitionSize))
|
||||
// {
|
||||
// return ERROR
|
||||
// }
|
||||
_waitEEReady();
|
||||
|
||||
this->_beginTransmission(memoryAddress);
|
||||
// #86
|
||||
this->_beginTransmission(memoryAddress + _partitionOffset);
|
||||
int rv = _wire->endTransmission();
|
||||
if (rv != 0)
|
||||
{
|
||||
@@ -709,7 +739,9 @@ bool I2C_eeprom::_verifyBlock(const uint16_t memoryAddress, const uint8_t * buff
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t address = _deviceAddress | ((memoryAddress >> 8) & 0x07);
|
||||
// #86
|
||||
// uint8_t partialAddr =
|
||||
uint8_t address = _deviceAddress | (((memoryAddress + _partitionOffset)>> 8) & 0x07);
|
||||
readBytes = _wire->requestFrom((int)address, (int)length);
|
||||
}
|
||||
yield(); // For OS scheduling
|
||||
|
||||
+8
-3
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: I2C_eeprom.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 1.9.4
|
||||
// VERSION: 1.9.5
|
||||
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
|
||||
// URL: https://github.com/RobTillaart/I2C_EEPROM
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define I2C_EEPROM_VERSION (F("1.9.4"))
|
||||
#define I2C_EEPROM_VERSION (F("1.9.5"))
|
||||
|
||||
#define I2C_DEVICESIZE_24LC512 65536
|
||||
#define I2C_DEVICESIZE_24LC256 32768
|
||||
@@ -34,7 +34,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
// set the flag EN_AUTO_WRITE_PROTECT to 1 to enable the Write Control at compile time
|
||||
// set the flag EN_AUTO_WRITE_PROTECT to 1 to enable the Write Control at compile time
|
||||
// used if the write_protect pin is explicitly set in the begin() function.
|
||||
// the flag can be set as command line option.
|
||||
#ifndef EN_AUTO_WRITE_PROTECT
|
||||
@@ -83,6 +83,8 @@ public:
|
||||
bool isConnected();
|
||||
uint8_t getAddress();
|
||||
|
||||
uint16_t partition(uint16_t offset, uint16_t size);
|
||||
|
||||
|
||||
// user is responsible that address is in range of the EEPROM used.
|
||||
// writes a byte to memoryAddress
|
||||
@@ -162,6 +164,9 @@ private:
|
||||
uint8_t _pageSize = 0;
|
||||
uint8_t _extraTWR = 0; // milliseconds
|
||||
|
||||
uint16_t _partitionOffset = 0;
|
||||
uint16_t _partitionSize = 0;
|
||||
|
||||
|
||||
// 24LC32..24LC512 use two bytes for memory address
|
||||
// 24LC01..24LC16 use one-byte addresses + part of device address
|
||||
|
||||
+22
-22
@@ -11,10 +11,10 @@
|
||||
#include <I2C_eeprom.h>
|
||||
|
||||
/**
|
||||
* @brief This is a utility class for using an eeprom to store a simple
|
||||
* @brief This is a utility class for using an EEPROM to store a simple
|
||||
* data structure.
|
||||
*
|
||||
* The purpose of the utility is to extend the life of an eeprom memory by
|
||||
* The purpose of the utility is to extend the life of an EEPROM memory by
|
||||
* rotating the writes over different pages to reduce the number of writes
|
||||
* to any individual page.
|
||||
* It does this by partitioning the memory into slots (of continuous pages)
|
||||
@@ -27,11 +27,11 @@
|
||||
* slot in sequence is used (or the first slot if going past the end).
|
||||
*
|
||||
* Note that the data is stored in binary form which means it should not be
|
||||
* expected that the eeprom can be moved between architectures. Data stored
|
||||
* in an eeprom will also become invalid if the data structure is changed
|
||||
* expected that the EEPROM can be moved between architectures. Data stored
|
||||
* in an EEPROM will also become invalid if the data structure is changed
|
||||
* either manually or due to changed optimization settings.
|
||||
*
|
||||
* If the data structure has changed or if the eeprom contains other data it
|
||||
* If the data structure has changed or if the EEPROM contains other data it
|
||||
* must first be formatted with a call to format().
|
||||
*
|
||||
* Finally, since the version number is a long word, this class will
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
/**
|
||||
* @brief Initializes the instance
|
||||
*
|
||||
* This call searches the eeprom for the latest written version and
|
||||
* This call searches the EEPROM for the latest written version and
|
||||
* sets the current slot accordingly.
|
||||
*
|
||||
* @param eeprom The instance of I2C_eeprom to use.
|
||||
@@ -70,15 +70,15 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Formats the eeprom
|
||||
* @brief Formats the EEPROM
|
||||
*
|
||||
* This must be done if the eeprom already contains data or if the
|
||||
* This must be done if the EEPROM already contains data or if the
|
||||
* structure of the data stored changes.
|
||||
*
|
||||
* Formatting is done by writing the max version number to each slot,
|
||||
* thus it performs a write cycle to the first write page of each slot.
|
||||
*
|
||||
* @return True if successful or false if unable to write to eeprom.
|
||||
* @return True if successful or false if unable to write to EEPROM.
|
||||
*/
|
||||
bool format()
|
||||
{
|
||||
@@ -99,9 +99,9 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read data from the eeprom into a buffer.
|
||||
* @brief Read data from the EEPROM into a buffer.
|
||||
*
|
||||
* The data is read from the current slot of the eeprom.
|
||||
* The data is read from the current slot of the EEPROM.
|
||||
*
|
||||
* @param buffer A reference to the buffer to read data into.
|
||||
* @return True if data was read successfully, false otherwise.
|
||||
@@ -109,11 +109,11 @@ public:
|
||||
bool read(T &buffer) const { return read(&buffer); }
|
||||
|
||||
/**
|
||||
* @brief Read data from the eeprom into a buffer.
|
||||
* @brief Read data from the EEPROM into a buffer.
|
||||
*
|
||||
* The data is read from the current slot of the eeprom.
|
||||
* The data is read from the current slot of the EEPROM.
|
||||
*
|
||||
* @param buffer A pointet to the buffer to read data into.
|
||||
* @param buffer A pointer to the buffer to read data into.
|
||||
* @return True if data was read successfully, false otherwise.
|
||||
*/
|
||||
bool read(T *buffer) const
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write a buffer to the next slot in the eeprom.
|
||||
* @brief Write a buffer to the next slot in the EEPROM.
|
||||
*
|
||||
* This updates the current slot of this instance.
|
||||
*
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
bool write(T &buffer) { return write(&buffer); }
|
||||
|
||||
/**
|
||||
* Write data of object to the next slot in the eeprom. This updates
|
||||
* Write data of object to the next slot in the EEPROM. This updates
|
||||
* the current slot of the instance.
|
||||
*
|
||||
* @param buffer A pointer to the buffer to write data from.
|
||||
@@ -161,7 +161,7 @@ public:
|
||||
_currentSlot++;
|
||||
_currentVersion++;
|
||||
|
||||
// Wrap around to start if going past end of alotted region
|
||||
// Wrap around to start if going past end of allocated region
|
||||
uint16_t maxSlots = _totalPages / _bufferPages;
|
||||
if (_currentSlot >= maxSlots)
|
||||
_currentSlot = 0;
|
||||
@@ -182,14 +182,14 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns metrics for the eeprom usage.
|
||||
* @brief Returns metrics for the EEPROM usage.
|
||||
*
|
||||
* Dividing the returned values of \p writeCounter with \p slots yields the average number of
|
||||
* writes to the individual write pages of the eeprom. This can be used to estimate the remaining
|
||||
* writes to the individual write pages of the EEPROM. This can be used to estimate the remaining
|
||||
* number of possible writes.
|
||||
*
|
||||
* @param[out] slots The number of slots used to write the data buffer.
|
||||
* @param[out] writeCounter The total number of write to the eeprom since the last format (or first use).
|
||||
* @param[out] writeCounter The total number of write to the EEPROM since the last format (or first use).
|
||||
* @return True if the instance is initialized, false otherwise.
|
||||
*/
|
||||
bool getMetrics(uint16_t &slots, uint32_t &writeCounter)
|
||||
@@ -220,8 +220,8 @@ private:
|
||||
auto slotSize = _pageSize * _bufferPages;
|
||||
|
||||
startSlot = 0;
|
||||
endSlot = (_totalPages / _bufferPages) - 1; // Index of last slot
|
||||
probeSlot = startSlot + ((endSlot - startSlot) / 2); // Midway between start and end
|
||||
endSlot = (_totalPages / _bufferPages) - 1; // Index of last slot
|
||||
probeSlot = startSlot + ((endSlot - startSlot) / 2); // Midway between start and end
|
||||
|
||||
if(_eeprom->readBlock(0, (uint8_t *)¤t, sizeof(current)) != sizeof(current))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2011-2025 Rob Tillaart
|
||||
Copyright (c) 2011-2026 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
+14
-14
@@ -9,44 +9,44 @@
|
||||
[](https://registry.platformio.org/libraries/robtillaart/I2C_EEPROM)
|
||||
|
||||
|
||||
# I2C_eeprom_cyclic_store
|
||||
# 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,
|
||||
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.
|
||||
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
|
||||
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
|
||||
As it reaches the end of the allocated 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
|
||||
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
|
||||
|
||||
- **begin(eeprom, pageSize, totalPages)** initialization
|
||||
- **format()** erase data from eeprom
|
||||
- **begin(EEPROM, pageSize, totalPages)** initialization
|
||||
- **format()** erase data from EEPROM
|
||||
- **read(buffer)** read buffer from last location prom
|
||||
- **write(buffer)** write buffer to next location on eeprom
|
||||
- **write(buffer)** write buffer to next location on EEPROM
|
||||
- **getMetrics(slots, writeCounter)** get usage metrics
|
||||
|
||||
|
||||
## 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.
|
||||
it detect an EEPROM that has data that wasn't written using the class.
|
||||
|
||||
|
||||
## Operational
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/I2C_EEPROM.git"
|
||||
},
|
||||
"version": "1.9.4",
|
||||
"version": "1.9.5",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name=I2C_EEPROM
|
||||
version=1.9.4
|
||||
version=1.9.5
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for I2C EEPROMS
|
||||
|
||||
Reference in New Issue
Block a user