0.2.3 I2C_24LC1025

This commit is contained in:
Rob Tillaart 2023-05-02 13:37:13 +02:00
parent 3df5eef2c1
commit 97a88265da
6 changed files with 99 additions and 31 deletions

View File

@ -5,21 +5,28 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.3] - 2023-05-02
- improve support for RP2040
- move code from .h to .cpp
- update readme.md
- minor edits
## [0.2.2]
- add changelog.md
- add RP2040 to build-CI
- minor edits
## [0.2.0] - 2022-06-08
- add verify functions
- improve documentation / comments
## [0.2.1] - 2022-06-11
- update documentation
- minor edits
- minor improvements / bug fixes
- add get/setExtraWriteCycleTime()
## [0.2.0] - 2022-06-08
- add verify functions
- improve documentation / comments
----
## [0.1.5] - 2021-08-30

View File

@ -1,11 +1,9 @@
//
// FILE: I2C_24LC1025.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// VERSION: 0.2.3
// PURPOSE: I2C_24LC1025 library for Arduino with EEPROM I2C_24LC1025 et al.
// URL: https://github.com/RobTillaart/I2C_24LC1025
//
// HISTORY: See changelog.md
#include "I2C_24LC1025.h"
@ -33,7 +31,7 @@ I2C_24LC1025::I2C_24LC1025(uint8_t deviceAddress, TwoWire * wire)
}
#if defined (ESP8266) || defined(ESP32)
#if defined(ESP8266) || defined(ESP32)
bool I2C_24LC1025::begin(uint8_t sda, uint8_t scl)
{
if ((sda < 255) && (scl < 255))
@ -50,6 +48,20 @@ bool I2C_24LC1025::begin(uint8_t sda, uint8_t scl)
#endif
#if defined(PICO_RP2040)
bool I2C_24LC1025::begin(uint8_t sda, uint8_t scl)
{
if ((sda < 255) && (scl < 255))
{
_wire->setSCL(scl);
_wire->setSDA(sda);
_wire->begin();
}
_lastWrite = 0;
return isConnected();
}
#endif
bool I2C_24LC1025::begin()
{
_wire->begin();
@ -238,6 +250,41 @@ bool I2C_24LC1025::updateBlockVerify(const uint32_t memoryAddress, const uint8_t
}
////////////////////////////////////////////////////////////////////
//
// METADATA SECTION
//
uint32_t I2C_24LC1025::getDeviceSize()
{
return _deviceSize;
}
uint8_t I2C_24LC1025::getPageSize()
{
return _pageSize;
}
uint32_t I2C_24LC1025::getLastWrite()
{
return _lastWrite;
}
void I2C_24LC1025::setExtraWriteCycleTime(uint8_t ms)
{
_extraTWR = ms;
}
uint8_t I2C_24LC1025::getExtraWriteCycleTime()
{
return _extraTWR;
}
////////////////////////////////////////////////////////////////////
//
// PRIVATE
@ -275,8 +322,6 @@ void I2C_24LC1025::_beginTransmission(uint32_t memoryAddress)
_actualAddress = _deviceAddress;
if (memoryAddress >= 0x10000) _actualAddress |= 0x04; // addresbit 16
#define I2C_WRITEDELAY 5000
// Wait until EEPROM gives ACK again.
// this is a bit faster than the hardcoded 5 milliSeconds // chapter 7
@ -360,11 +405,10 @@ uint8_t I2C_24LC1025::_ReadBlock(uint32_t memoryAddress, uint8_t * buffer, const
void I2C_24LC1025::_waitEEReady()
{
#define I2C_WRITEDELAY 5000
// Wait until EEPROM gives ACK again.
// this is a bit faster than the hardcoded 5 milliSeconds
// TWR = WriteCycleTime
uint32_t waitTime = I2C_WRITEDELAY + _extraTWR * 1000UL; // do the math once.
uint32_t waitTime = I2C_WRITEDELAY + _extraTWR * 1000UL;
while ((micros() - _lastWrite) <= waitTime)
{
_wire->beginTransmission(_deviceAddress);

View File

@ -2,31 +2,36 @@
//
// FILE: I2C_24LC1025.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.2
// VERSION: 0.2.3
// PURPOSE: I2C_24LC1025 library for Arduino with EEPROM 24LC1025 et al.
// URL: https://github.com/RobTillaart/I2C_24LC1025
//
// HISTORY: See changelog.md
#include "Arduino.h"
#include "Wire.h"
#define I2C_24LC1025_VERSION (F("0.2.2"))
#define I2C_24LC1025_VERSION (F("0.2.3"))
#define I2C_DEVICESIZE_24LC1025 131072
#define I2C_PAGESIZE_24LC1025 128
// to adjust low level timing (use with care)
// can also be done on command line.
#ifndef I2C_WRITEDELAY
#define I2C_WRITEDELAY 5000
#endif
class I2C_24LC1025
{
public:
I2C_24LC1025(uint8_t deviceAddress, TwoWire *wire = &Wire);
#if defined (ESP8266) || defined(ESP32)
#if defined(ESP8266) || defined(ESP32) || defined(PICO_RP2040)
bool begin(uint8_t sda, uint8_t scl);
#endif
bool begin();
@ -71,14 +76,15 @@ public:
// Meta data functions
uint32_t getDeviceSize() { return _deviceSize; };
uint8_t getPageSize() { return _pageSize; };
uint32_t getLastWrite() { return _lastWrite; };
uint32_t getDeviceSize();
uint8_t getPageSize();
uint32_t getLastWrite();
// 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; };
uint8_t getExtraWriteCycleTime() { return _extraTWR; };
void setExtraWriteCycleTime(uint8_t ms);
uint8_t getExtraWriteCycleTime();
private:
uint8_t _deviceAddress;

View File

@ -21,9 +21,20 @@ A2 = Non-Configurable Chip Select.
This pin must be connected to VCC (+5V).
The device will **NOT** work when this pin floats or is connected to GND (0V).
This library follows the I2C_EEPROM library, see links below.
#### Links
- https://github.com/RobTillaart/I2C_EEPROM
## Interface
```cpp
#include "I2C_24LC1025.h"
```
The interface is kept quite identical to the I2C_EEPROM library.
https://github.com/RobTillaart/I2C_EEPROM
@ -34,7 +45,7 @@ Most important change is 32 bit memory addresses.
- **I2C_24LC1025(uint8_t deviceAddress, TwoWire \*wire = &Wire)** constructor, 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.
- **bool begin(uint8_t sda, uint8_t scl)** idem for ESP32 / ESP8266 / RP2040 and alike.
- **bool isConnected()** test to see if deviceAddress is found on the bus.

View File

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

View File

@ -1,5 +1,5 @@
name=I2C_24LC1025
version=0.2.2
version=0.2.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for 24FC1025 I2C EEPROM