1.7.1 I2C_EEPROM

This commit is contained in:
rob tillaart 2023-01-12 17:52:04 +01:00
parent 76fcd8e3f8
commit 889ee24e55
11 changed files with 123 additions and 19 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

View File

@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -6,10 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [1.7.1] - 2023-01-12
- add setDeviceSize()
- add setPageSize()
- use setDeviceSize() in constructor to force power of 2.
- update unit test
- update GitHub actions
- update license
- update readme.md
- minor edits
## [1.7.0] - 2022-12-02
- fix #48 rewrote constructor.
## [1.6.2] - 2022-10-30
- Add RP2040 support to build-CI.
- Add CHANGELOG.md
@ -17,7 +27,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
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

View File

@ -1,11 +1,9 @@
//
// FILE: I2C_eeprom.cpp
// AUTHOR: Rob Tillaart
// VERSION: 1.7.0
// VERSION: 1.7.1
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
//
// HISTORY: see changelog.md
#include "I2C_eeprom.h"
@ -46,11 +44,11 @@ I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, TwoWire * wire) :
I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, TwoWire * wire)
{
_deviceAddress = deviceAddress;
_deviceSize = deviceSize;
_deviceSize = setDeviceSize(deviceSize);
_pageSize = getPageSize(_deviceSize);
_wire = wire;
// Chips 16Kbit (2048 Bytes) or smaller only have one-word addresses.
// Chips 16 Kbit (2048 Bytes) or smaller only have one-word addresses.
this->_isAddressSizeTwoWords = deviceSize > I2C_DEVICESIZE_24LC16;
}
@ -326,6 +324,35 @@ uint8_t I2C_eeprom::getPageSize(uint32_t deviceSize)
}
uint32_t I2C_eeprom::setDeviceSize(uint32_t deviceSize)
{
uint32_t size = 128;
// force power of 2.
while ((size <= 65536) && ( size <= deviceSize))
{
_deviceSize = size;
size *= 2;
}
// Chips 16 Kbit (2048 Bytes) or smaller only have one-word addresses.
this->_isAddressSizeTwoWords = _deviceSize > I2C_DEVICESIZE_24LC16;
return _deviceSize;
}
uint8_t I2C_eeprom::setPageSize(uint8_t pageSize)
{
uint8_t size = 8;
// force power of 2.
while ((size <= 128) && ( size <= pageSize))
{
_pageSize = size;
size *= 2;
}
return _pageSize;
}
////////////////////////////////////////////////////////////////////
//
// PRIVATE

View File

@ -2,18 +2,16 @@
//
// FILE: I2C_eeprom.h
// AUTHOR: Rob Tillaart
// VERSION: 1.7.0
// VERSION: 1.7.1
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
//
// HISTORY: See I2C_eeprom.cpp
#include "Arduino.h"
#include "Wire.h"
#define I2C_EEPROM_VERSION (F("1.7.0"))
#define I2C_EEPROM_VERSION (F("1.7.1"))
#define I2C_DEVICESIZE_24LC512 65536
@ -105,6 +103,12 @@ public:
uint8_t getPageSize(uint32_t deviceSize);
uint32_t getLastWrite() { return _lastWrite; };
// for overruling and debugging.
// forces a power of 2
uint32_t setDeviceSize(uint32_t deviceSize); // returns set size
uint8_t setPageSize(uint8_t pageSize); // returns set size
// TWR = WriteCycleTime
// 5 ms is minimum, one can add extra ms here to adjust timing of both read() and write()
void setExtraWriteCycleTime(uint8_t ms) { _extraTWR = ms; };

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2011-2022 Rob Tillaart
Copyright (c) 2011-2023 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

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/I2C_EEPROM.git"
},
"version": "1.7.0",
"version": "1.7.1",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=I2C_EEPROM
version=1.7.0
version=1.7.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for I2C EEPROMS

View File

@ -40,7 +40,7 @@ default address = 0x50 .. 0x57 depending on three address lines
The interface is kept quite identical to the I2C_24LC1025 library.
https://github.com/RobTillaart/I2C_24LC1025
Most important change is 32 bit memory addresses.
Most important difference is 32 bit memory addresses.
### Constructor
@ -135,6 +135,14 @@ Test results
The function cannot detect smaller than 128 bit EEPROMS.
Experimental since 1.7.1 can be used for debugging and overruling constructor.
- **uint32_t setDeviceSize(uint32_t deviceSize)** overrules constructor setting.
returns set size == 128, 256, ... 32768, 65536
- **uint8_t setPageSize(uint8_t pageSize)** overrules constructor setting.
returns set size == 8, 16, 32, 64, 128.
#### UpdateBlock()
(new since 1.4.2)
@ -179,6 +187,10 @@ See examples
- investigate multi-EEPROM storage
- wrapper class?
- improve error handling, write functions should return bytes written or so.
- move code from .h to .cpp?
- make deviceSize explicit in examples?
- AT24C32 has a WriteCycle Time of max 20 ms
- make a define of the 5000 ?
#### could
- investigate smarter strategy for **updateBlock()**

View File

@ -88,7 +88,6 @@ unittest(test_constants)
assertEqual(I2C_DEVICESIZE_24LC04, 512);
assertEqual(I2C_DEVICESIZE_24LC02, 256);
assertEqual(I2C_DEVICESIZE_24LC01, 128);
}
@ -106,9 +105,62 @@ 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);
}
unittest(test_setDeviceSize)
{
I2C_eeprom EE(0x50, 0x8000);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC512), I2C_DEVICESIZE_24LC512);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC256), I2C_DEVICESIZE_24LC256);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC128), I2C_DEVICESIZE_24LC128);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC64), I2C_DEVICESIZE_24LC64);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC32), I2C_DEVICESIZE_24LC32);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC16), I2C_DEVICESIZE_24LC16);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC08), I2C_DEVICESIZE_24LC08);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC04), I2C_DEVICESIZE_24LC04);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC02), I2C_DEVICESIZE_24LC02);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC01), I2C_DEVICESIZE_24LC01);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC512 + 1), I2C_DEVICESIZE_24LC512);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC256 + 1), I2C_DEVICESIZE_24LC256);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC128 + 1), I2C_DEVICESIZE_24LC128);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC64 + 1), I2C_DEVICESIZE_24LC64);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC32 + 1), I2C_DEVICESIZE_24LC32);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC16 + 1), I2C_DEVICESIZE_24LC16);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC08 + 1), I2C_DEVICESIZE_24LC08);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC04 + 1), I2C_DEVICESIZE_24LC04);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC02 + 1), I2C_DEVICESIZE_24LC02);
assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC01 + 1), I2C_DEVICESIZE_24LC01);
}
/*
unittest(test_setPageSize)
{
I2C_eeprom EE(0x50, 0x8000);
assertEqual(EE.setPageSize(129), 128);
assertEqual(EE.setPageSize(128), 128);
assertEqual(EE.setPageSize(127), 64);
assertEqual(EE.setPageSize(65), 64);
assertEqual(EE.setPageSize(64), 64);
assertEqual(EE.setPageSize(63), 32);
assertEqual(EE.setPageSize(33), 32);
assertEqual(EE.setPageSize(32), 32);
assertEqual(EE.setPageSize(31), 16);
assertEqual(EE.setPageSize(17), 16);
assertEqual(EE.setPageSize(16), 16);
assertEqual(EE.setPageSize(9), 8);
assertEqual(EE.setPageSize(8), 8);
}
*/
unittest_main()
// --------