update library.json, license, minor edits (#37)

This commit is contained in:
Rob Tillaart
2021-12-19 20:01:34 +01:00
committed by GitHub
parent 7eae2b7ba2
commit 1a6461a7dd
20 changed files with 169 additions and 118 deletions
+15 -12
View File
@@ -1,7 +1,7 @@
//
// FILE: I2C_eeprom.cpp
// AUTHOR: Rob Tillaart
// VERSION: 1.5.1
// VERSION: 1.5.2
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
//
@@ -40,7 +40,8 @@
// 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
#include <I2C_eeprom.h>
@@ -62,7 +63,7 @@
#if defined(ESP32) || defined(ESP8266)
#define I2C_BUFFERSIZE 128
#else
#define I2C_BUFFERSIZE 30 // AVR, STM
#define I2C_BUFFERSIZE 30 // AVR, STM
#endif
@@ -184,7 +185,7 @@ int I2C_eeprom::updateBlock(const uint16_t memoryAddress, const uint8_t* buffer,
{
uint8_t buf[I2C_BUFFERSIZE];
uint8_t cnt = I2C_BUFFERSIZE;
if (cnt > len) cnt = len;
rv += _ReadBlock(addr, buf, cnt);
if (memcmp(buffer, buf, cnt) != 0)
@@ -275,9 +276,9 @@ uint8_t I2C_eeprom::getPageSize(uint32_t deviceSize)
// PRIVATE
//
// _pageBlock aligns buffer to page boundaries for writing.
// and to I2C buffer size
// returns 0 = OK otherwise error
// _pageBlock aligns buffer to page boundaries for writing.
// and to I2C buffer size
// returns 0 = OK otherwise error
int I2C_eeprom::_pageBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length, const bool incrBuffer)
{
uint16_t addr = memoryAddress;
@@ -301,7 +302,7 @@ int I2C_eeprom::_pageBlock(const uint16_t memoryAddress, const uint8_t* buffer,
}
// supports one and two bytes addresses
// supports one and two bytes addresses
void I2C_eeprom::_beginTransmission(const uint16_t memoryAddress)
{
if (this->_isAddressSizeTwoWords)
@@ -321,8 +322,8 @@ void I2C_eeprom::_beginTransmission(const uint16_t memoryAddress)
}
// pre: length <= this->_pageSize && length <= I2C_BUFFERSIZE;
// returns 0 = OK otherwise error
// pre: length <= this->_pageSize && length <= I2C_BUFFERSIZE;
// returns 0 = OK otherwise error
int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint8_t length)
{
_waitEEReady();
@@ -337,8 +338,8 @@ int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t* buffer,
}
// pre: buffer is large enough to hold length bytes
// returns bytes read
// pre: buffer is large enough to hold length bytes
// returns bytes read
uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t* buffer, const uint8_t length)
{
_waitEEReady();
@@ -386,4 +387,6 @@ void I2C_eeprom::_waitEEReady()
return;
}
// -- END OF FILE --
+17 -15
View File
@@ -2,7 +2,7 @@
//
// FILE: I2C_eeprom.h
// AUTHOR: Rob Tillaart
// VERSION: 1.5.1
// VERSION: 1.5.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.5.1"))
#define I2C_EEPROM_VERSION (F("1.5.2"))
#define I2C_DEVICESIZE_24LC512 65536
@@ -59,26 +59,26 @@ public:
bool isConnected();
// writes a byte to memoryAddress
// writes a byte to memoryAddress
int writeByte(const uint16_t memoryAddress, const uint8_t value);
// writes length bytes from buffer to EEPROM
// writes length bytes from buffer to EEPROM
int writeBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length);
// set length bytes in the EEPROM to the same value.
// set length bytes in the EEPROM to the same value.
int setBlock(const uint16_t memoryAddress, const uint8_t value, const uint16_t length);
// returns the value stored in memoryAddress
// returns the value stored in memoryAddress
uint8_t readByte(const uint16_t memoryAddress);
// reads length bytes into buffer
// reads length bytes into buffer
uint16_t readBlock(const uint16_t memoryAddress, uint8_t* buffer, const uint16_t length);
// updates a byte at memoryAddress, writes only if there is a new value.
// return 0 if data is same or written OK, error code otherwise.
// updates a byte at memoryAddress, writes only if there is a new value.
// return 0 if data is same or written OK, error code otherwise.
int updateByte(const uint16_t memoryAddress, const uint8_t value);
// updates a block in memory, writes only if there is a new value.
// only to be used when you expect to write same buffer multiple times.
// test your performance gains!
// updates a block in memory, writes only if there is a new value.
// only to be used when you expect to write same buffer multiple times.
// test your performance gains!
int updateBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length);
uint32_t determineSize(const bool debug = false);
@@ -100,8 +100,8 @@ private:
uint8_t _pageSize;
uint8_t _extraTWR = 0; // milliseconds
// 24LC32..24LC512 use two bytes for memory address
// 24LC01..24LC16 use one-byte addresses + part of device address
// 24LC32..24LC512 use two bytes for memory address
// 24LC01..24LC16 use one-byte addresses + part of device address
bool _isAddressSizeTwoWords;
@@ -116,7 +116,7 @@ private:
int _WriteBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint8_t length);
uint8_t _ReadBlock(const uint16_t memoryAddress, uint8_t* buffer, const uint8_t length);
// to optimize the write latency of the EEPROM
// to optimize the write latency of the EEPROM
void _waitEEReady();
TwoWire * _wire;
@@ -124,4 +124,6 @@ private:
UNIT_TEST_FRIEND;
};
// -- END OF FILE --
+20 -19
View File
@@ -6,12 +6,13 @@
// PURPOSE: Supplemental utility class for I2C_EEPROM library
//
#include <I2C_eeprom.h>
/**
* @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
* rotating the writes over different pages to reduce the number of writes
* to any individual page.
@@ -23,7 +24,7 @@
* version number which is then used for subsequent reads.
* Whenever data is written the version number is incremented and the next
* 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
@@ -31,10 +32,10 @@
*
* 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
* *derail and fail* to add new versions past 4294967295 writes.
*
*
* @tparam T the type of the data structure to store, should only contain
* **value** members and no constructor/destructor nor other
* methods/functions - e g a pure DTO.
@@ -45,10 +46,10 @@ class I2C_eeprom_cyclic_store
public:
/**
* @brief Initializes the instance
*
*
* 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.
* @param pageSize The number of bytes in each write page.
* @param totalPages Specifies the total number of pages to use.
@@ -69,12 +70,12 @@ public:
/**
* @brief Formats the eeprom
*
*
* This must be done if the eeprom already contains data or if the
* structure of the data stored changes.
*
* 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.
* 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.
*/
@@ -93,14 +94,14 @@ public:
_currentSlot = 0;
_isInitialized = true;
return true;
return true;
}
/**
* @brief Read data from the eeprom into a buffer.
*
*
* 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.
*/
@@ -108,9 +109,9 @@ public:
/**
* @brief Read data from the eeprom into a buffer.
*
*
* The data is read from the current slot of the eeprom.
*
*
* @param buffer A pointet to the buffer to read data into.
* @return True if data was read successfully, false otherwise.
*/
@@ -127,9 +128,9 @@ public:
/**
* @brief Write a buffer to the next slot in the eeprom.
*
*
* This updates the current slot of this instance.
*
*
* @param buffer A reference to the buffer to write data from.
* @return True if data was written successfully, false otherwise.
*/
@@ -181,11 +182,11 @@ public:
/**
* @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
* 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).
* @return True if the instance is initialized, false otherwise.
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2011-2021 Rob Tillaart
Copyright (c) 2011-2022 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
+21 -16
View File
@@ -5,9 +5,11 @@
[![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)
# I2C_EEPROM
Arduino Library for external I2C EEPROM - 24LC512, 24LC256, 24LC64/32/16/08/04/02/01
Arduino Library for external I2C EEPROM - 24LC512, 24LC256, 24LC64/32/16/08/04/02/01.
## Description
@@ -22,7 +24,7 @@ The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_sto
### Constructor
- **I2C_eeprom(uint8_t deviceAddress, TwoWire \*wire = &Wire)** constructor, optional Wire interface
- **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.
@@ -32,12 +34,14 @@ The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_sto
### Core functions
- **int writeByte(uint16_t memoryAddress, uint8_t value)** write a single byte to the specified memory address.
- **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.
- **int writeBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** write a buffer starting at the specified memory address.
- **int updateBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** write a buffer starting at the specified memory address, 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.
- **int writeBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** write a buffer starting at the specified memory address.
- **int updateBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** write a buffer starting at the specified memory address, but only if changed.
- **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 0 if OK.
- **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.
- **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.
### Other
@@ -46,14 +50,14 @@ The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_sto
- **uint8_t getPageSize()** idem
- **uint8_t getPageSize(uint32_t deviceSize)** idem
- **uint32_t getLastWrite()** idem
- **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.
- **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.
**Warning**: this function has changed (again) in 1.4.0
**Warning**: this function has changed (again) in 1.4.0
Test results
Test results
| Type | returns | Memory | Page Size | Notes |
|:--------|:--------|:---------|:---------:|:------|
@@ -79,8 +83,8 @@ The function cannot detect smaller than 128 bit EEPROMS.
The function **updateBlock()** reads the block of data and compares it with the new values to see if it needs rewriting.
As the function reads/writes the data in blocks with a maximum length of **I2C_BUFFERSIZE** (== 30 on AVR limitation).
It does this comparison in chunks if the length exceeds this number.
The result is that an **updateBlock()** call can result e.g. in 4 reads and only 2 writes under the hood.
It does this comparison in chunks if the length exceeds this number.
The result is that an **updateBlock()** call can result e.g. in 4 reads and only 2 writes under the hood.
If data is changed often between writes, **updateBlock()** is slower than **writeBlock()**.
So you should verify if your sketch can make use of the advantages of **updateBlock()**
@@ -90,7 +94,7 @@ So you should verify if your sketch can make use of the advantages of **updateBl
(new since 1.5.1)
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 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.
@@ -107,8 +111,9 @@ The library does not offer multiple EEPROMS as one continuous storage device.
- improve error handling, write functions should return bytes written or so.
- what can we do with the print interface? (investigate)
- investigate multi-EEPROM storage,
- investigate smarter strategy for updateBlock() => find first and last changed position could possibly result in less writes.
- investigate multi-EEPROM storage,
- investigate smarter strategy for updateBlock() => find first and last changed position could possibly result in less writes.
- can setBlock use strategies from update
## Operational
+6
View File
@@ -1,12 +1,16 @@
[![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)
[![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)
# I2C_eeprom_cyclic_store
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.
@@ -25,10 +29,12 @@ The interface is pretty straightforward
- **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.
## Operational
See examples
@@ -5,12 +5,14 @@
// PURPOSE: Simple example of how to use cyclic storage.
//
#include <I2C_eeprom.h>
#include <I2C_eeprom_cyclic_store.h>
#define MEMORY_SIZE 0x2000 // Total capacity of the EEPROM
#define PAGE_SIZE 64 // Size of write page of device, use datasheet to find!
struct SampleData {
public:
uint32_t counter;
@@ -18,11 +20,13 @@ public:
char message[32];
};
SampleData data;
I2C_eeprom ee(0x50, MEMORY_SIZE);
I2C_eeprom_cyclic_store<SampleData> cs;
void setup()
{
Serial.begin(115200);
@@ -39,7 +43,7 @@ void setup()
sprintf(data.message, "Initialized to %x", data.counter);
cs.write(data);
}
}
void loop()
@@ -2,7 +2,6 @@
// FILE: I2C_eeprom_determineSize.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test determinSize() function
//
#include "Wire.h"
@@ -67,4 +66,6 @@ void loop()
{
}
// -- END OF FILE --
@@ -2,7 +2,6 @@
// FILE: I2C_eeprom_format.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo format EEPROM
//
#include "Wire.h"
@@ -82,4 +81,5 @@ void loop()
{
}
// -- END OF FILE --
@@ -3,10 +3,9 @@
// AUTHOR: Rob Tillaart
// PURPOSE: demo I2C_EEPROM library store /retrieve struct
//
// uses a 24LC256 (32KB) EEPROM
// as this test writes a lot it might wear out EEPROMs eventually.
//
//
#include "Wire.h"
@@ -15,7 +14,6 @@
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
uint32_t start, duration;
struct
@@ -53,7 +51,7 @@ void setup()
measurement.temperature = 22.5;
measurement.humidity = 53.1;
measurement.pressure = 1000.9;
// store it in EEPROM
start = micros();
ee.writeBlock(0, (uint8_t *) &measurement, sizeof(measurement));
@@ -85,8 +83,11 @@ void setup()
Serial.println("\ndone...");
}
void loop()
{
}
// -- END OF FILE
+5 -3
View File
@@ -3,10 +3,10 @@
// AUTHOR: Rob Tillaart
// PURPOSE: show/test I2C_EEPROM library
//
// uses a 24LC256 (32KB) EEPROM
// might need adaptions for other EEPROMS (page size etc)
#include "Wire.h"
#include "I2C_eeprom.h"
@@ -209,7 +209,7 @@ void loop()
void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
{
const int BLOCK_TO_LENGTH = 10;
SERIAL_OUT.print("\t ");
for (int x = 0; x < 10; x++)
{
@@ -241,4 +241,6 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
SERIAL_OUT.println();
}
// END OF FILE
// -- END OF FILE --
@@ -2,7 +2,6 @@
// FILE: I2C_eeprom_test_performance.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test I2C_EEPROM library
//
#include "Wire.h"
@@ -53,8 +52,8 @@ void loop()
void test()
{
char data2[] = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999A";
char data2[] = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999A";
totals = 0;
Serial.print("\nTEST: timing writeByte()\t");
uint32_t start = micros();
@@ -145,7 +144,7 @@ void test()
void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
{
const int BLOCK_TO_LENGTH = 10;
Serial.print("\t ");
for (int x = 0; x < 10; x++)
{
@@ -177,4 +176,6 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
Serial.println();
}
// END OF FILE
// -- END OF FILE --
@@ -3,9 +3,9 @@
// AUTHOR: Rob Tillaart
// PURPOSE: demo I2C_EEPROM library - updateByte
//
// uses a 24LC256 (32KB) EEPROM
#include "Wire.h"
#include "I2C_eeprom.h"
@@ -15,9 +15,9 @@ I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
uint32_t start, dur1, dur2;
void setup()
void setup()
{
Serial.begin(115200);
Serial.begin(115200);
while (!Serial); // wait for SERIAL_OUT port to connect. Needed for Leonardo only
Serial.println(__FILE__);
@@ -38,7 +38,7 @@ void setup()
Serial.print("SIZE: ");
Serial.print(size);
Serial.println(" KB");
}
}
else if (size == 0)
{
Serial.println("WARNING: Can't determine eeprom size");
@@ -61,7 +61,7 @@ void setup()
Serial.print("DUR1: ");
Serial.println(dur1);
delay(10);
Serial.println("\nTEST: 100x updateByte()");
ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros();
@@ -73,12 +73,15 @@ void setup()
Serial.print("DUR2: ");
Serial.println(dur2);
delay(10);
Serial.println("done...");
}
void loop()
void loop()
{
}
// -- END OF FILE
// -- END OF FILE --
@@ -3,10 +3,9 @@
// AUTHOR: Rob Tillaart
// PURPOSE: demo I2C_EEPROM library - performance gain updateBlock
//
// uses a 24LC256 (32KB) EEPROM
// as this test writes a lot it might wear out EEPROMs eventually.
//
#include "Wire.h"
#include "I2C_eeprom.h"
@@ -18,6 +17,7 @@ uint32_t start, dur1, dur2;
uint8_t ar[100];
void setup()
{
Serial.begin(115200);
@@ -47,10 +47,12 @@ void setup()
Serial.println("\ndone...");
}
void loop()
{
}
void test_1(int n)
{
Serial.println(n);
@@ -85,6 +87,7 @@ void test_1(int n)
Serial.println();
}
void test_2()
{
Serial.println("\nTEST: 100x writeBlock()");
@@ -136,4 +139,5 @@ void dump(uint32_t from, uint32_t to)
}
// -- END OF FILE
// -- END OF FILE --
@@ -7,6 +7,7 @@
// 0.1.0 2014-05-xx initial version
// 0.1.1 2020-07-14 fix #1 compile for ESP; fix author
#include <Wire.h>
#include <I2C_eeprom.h>
@@ -38,11 +39,12 @@
I2C_eeprom eeprom(DEVICEADDRESS, EE24LC01MAXBYTES);
void readAndWriteVar() {
SERIAL_DEBUG.println("----------------------------------------------");
void readAndWriteVar() {
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.print("SINGLE BYTE: writing and retreiving EEPROM on I2C at address ");
SERIAL_DEBUG.println(DEVICEADDRESS);
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.println("----------------------------------------------");
byte curval = eeprom.readByte(TEST_ADDR);
@@ -59,11 +61,11 @@ void readAndWriteVar() {
curval = eeprom.readByte(TEST_ADDR);
SERIAL_DEBUG.print("new value: ");
SERIAL_DEBUG.println(curval);
SERIAL_DEBUG.println(curval);
}
void readAndWritePage(unsigned int pageAddress, int bufferLen) {
void readAndWritePage(unsigned int pageAddress, int bufferLen) {
// always make the maximum size, just don't use all of it.
byte testBuffer[LONG_BUFFER_LEN + 1];
@@ -91,54 +93,54 @@ void readAndWritePage(unsigned int pageAddress, int bufferLen) {
eeprom.readBlock(pageAddress, testBuffer, bufferLen);
SERIAL_DEBUG.print("new value: ");
SERIAL_DEBUG.println((char*)testBuffer);
SERIAL_DEBUG.println((char*)testBuffer);
}
void setup()
{
SERIAL_DEBUG.begin(57600);
SERIAL_DEBUG.begin(57600);
while (!SERIAL_DEBUG); // wait for SERIAL_DEBUG port to connect. Needed for Leonardo only
SERIAL_DEBUG.println("IT IS BEGINNING");
SERIAL_DEBUG.println("WAIT FOR IT");
SERIAL_DEBUG.println("IT IS BEGINNING");
SERIAL_DEBUG.println("WAIT FOR IT");
eeprom.begin();
readAndWriteVar();
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.println("PAGE:");
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.println("PAGE:");
SERIAL_DEBUG.print(" writing and retrieving EEPROM Page on I2C at address ");
SERIAL_DEBUG.println(DEVICEADDRESS);
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.println("----------------------------------------------");
readAndWritePage(TEST_PAGE_ADDR, SHORT_BUFFER_LEN);
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.println("MULTI-PAGE:");
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.println("MULTI-PAGE:");
SERIAL_DEBUG.print("writing and retrieving EEPROM Pages on I2C at address ");
SERIAL_DEBUG.println(DEVICEADDRESS);
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.println("----------------------------------------------");
readAndWritePage(LONG_TEST_PAGE_ADDR, LONG_BUFFER_LEN);
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.println("MULTI-PAGE UNALINGED: ");
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.println("MULTI-PAGE UNALINGED: ");
SERIAL_DEBUG.print("writing and retrieving EEPROM Pages on I2C at address ");
SERIAL_DEBUG.println(DEVICEADDRESS);
SERIAL_DEBUG.println("----------------------------------------------");
SERIAL_DEBUG.println("----------------------------------------------");
readAndWritePage(UNALIGNED_TEST_PAGE_ADDR, UNALIGNED_BUFFER_LEN);
SERIAL_DEBUG.println("\nDone...");
}
void loop()
{
// Nothing to do during loop
}
+2 -2
View File
@@ -1,7 +1,7 @@
# Syntax Coloring Map For I2C_EEPROM
# Syntax Colouring Map For I2C_EEPROM
# Datatypes (KEYWORD1)
# Data types (KEYWORD1)
I2C_eeprom KEYWORD1
I2C_eeprom_cyclic_store KEYWORD1
+1 -1
View File
@@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/I2C_EEPROM.git"
},
"version": "1.5.1",
"version": "1.5.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
+1 -1
View File
@@ -1,5 +1,5 @@
name=I2C_EEPROM
version=1.5.1
version=1.5.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for I2C EEPROMS
+2
View File
@@ -38,12 +38,14 @@
unittest_setup()
{
fprintf(stderr, "I2C_EEPROM_VERSION: %s\n", ( char * ) I2C_EEPROM_VERSION);
}
unittest_teardown()
{
}
/*
unittest(test_new_operator)
{
+14
View File
@@ -8,6 +8,7 @@
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
#include <ArduinoUnitTests.h>
#include "Arduino.h"
@@ -17,6 +18,7 @@ class I2C_eeprom_wrapper;
#include "I2C_eeprom.h"
class I2C_eeprom_wrapper {
public:
static uint8_t pageSize(I2C_eeprom &eeprom) { return eeprom._pageSize; }
@@ -25,6 +27,7 @@ class I2C_eeprom_wrapper {
#define I2C_EEPROM_ADDR 0x50
unittest_setup()
{
}
@@ -33,6 +36,7 @@ unittest_teardown()
{
}
/**
* Verify that an instance gets the default page size
* when the constructor without device size is used.
@@ -49,6 +53,7 @@ unittest(i2c_eeprom_default_page_size)
// assertEqual(false, I2C_eeprom_wrapper::isAddressSizeTwoWords(eeprom));
}
/**
* Verify that the constructor calculates the correct
* page size and addressing for a 1K eeprom (e g AT24C01).
@@ -63,6 +68,7 @@ unittest(i2c_eeprom_1k_page_size)
assertEqual(false, I2C_eeprom_wrapper::isAddressSizeTwoWords(eeprom));
}
/**
* Verify that the constructor calculates the correct
* page size and addressing for a 2K eeprom (e g AT24C02).
@@ -77,6 +83,7 @@ unittest(i2c_eeprom_2k_page_size)
assertEqual(false, I2C_eeprom_wrapper::isAddressSizeTwoWords(eeprom));
}
/**
* Verify that the constructor calculates the correct
* page size and addressing for a 4K eeprom (e g AT24C04).
@@ -91,6 +98,7 @@ unittest(i2c_eeprom_4k_page_size)
assertEqual(false, I2C_eeprom_wrapper::isAddressSizeTwoWords(eeprom));
}
/**
* Verify that the constructor calculates the correct
* page size and addressing for a 8K eeprom (e g AT24C08).
@@ -105,6 +113,7 @@ unittest(i2c_eeprom_8k_page_size)
assertEqual(false, I2C_eeprom_wrapper::isAddressSizeTwoWords(eeprom));
}
/**
* Verify that the constructor calculates the correct
* page size and addressing for a 16K eeprom (e g AT24C16).
@@ -119,6 +128,7 @@ unittest(i2c_eeprom_16k_page_size)
assertEqual(false, I2C_eeprom_wrapper::isAddressSizeTwoWords(eeprom));
}
/**
* Verify that the constructor calculates the correct
* page size and addressing for a 32K eeprom (e g AT24C32).
@@ -133,6 +143,7 @@ unittest(i2c_eeprom_32k_page_size)
assertEqual(true, I2C_eeprom_wrapper::isAddressSizeTwoWords(eeprom));
}
/**
* Verify that the constructor calculates the correct
* page size and addressing for a 64K eeprom (e g AT24C64).
@@ -147,6 +158,7 @@ unittest(i2c_eeprom_64k_page_size)
assertEqual(true, I2C_eeprom_wrapper::isAddressSizeTwoWords(eeprom));
}
/**
* Verify that the constructor calculates the correct
* page size and addressing for a 128K eeprom (e g AT24C128).
@@ -161,6 +173,7 @@ unittest(i2c_eeprom_128k_page_size)
assertEqual(true, I2C_eeprom_wrapper::isAddressSizeTwoWords(eeprom));
}
/**
* Verify that the constructor calculates the correct
* page size and addressing for a 256K eeprom (e g AT24C256).
@@ -175,6 +188,7 @@ unittest(i2c_eeprom_256k_page_size)
assertEqual(true, I2C_eeprom_wrapper::isAddressSizeTwoWords(eeprom));
}
unittest_main()
// ------------------