try to fix submodule
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
|
||||
#include "./CAT24I2CFlashSettingsStorage.h"
|
||||
|
||||
|
||||
CAT24I2CFlashSettingsStorage::CAT24I2CFlashSettingsStorage(uint8_t address, uint16_t offset) {
|
||||
_address = address;
|
||||
_offset = offset;
|
||||
};
|
||||
|
||||
|
||||
|
||||
CAT24I2CFlashSettingsStorage::~CAT24I2CFlashSettingsStorage() {};
|
||||
|
||||
|
||||
|
||||
void CAT24I2CFlashSettingsStorage::init(TwoWire* wire) {
|
||||
SettingsStorage::init();
|
||||
_wire = wire;
|
||||
reset();
|
||||
};
|
||||
|
||||
|
||||
|
||||
uint8_t CAT24I2CFlashSettingsStorage::readByte(uint8_t* valueToSet) {
|
||||
return readBytes(valueToSet, 1);
|
||||
};
|
||||
|
||||
|
||||
|
||||
uint8_t CAT24I2CFlashSettingsStorage::readFloat(float* valueToSet) {
|
||||
return readBytes(valueToSet, 4);
|
||||
};
|
||||
|
||||
|
||||
|
||||
uint8_t CAT24I2CFlashSettingsStorage::readInt(uint32_t* valueToSet) {
|
||||
return readBytes(valueToSet, 4);
|
||||
};
|
||||
|
||||
|
||||
|
||||
uint8_t CAT24I2CFlashSettingsStorage::writeByte(uint8_t value) {
|
||||
return writeBytes(&value, 1);
|
||||
};
|
||||
|
||||
|
||||
|
||||
uint8_t CAT24I2CFlashSettingsStorage::writeFloat(float value) {
|
||||
return writeBytes(&value, 4);
|
||||
};
|
||||
|
||||
|
||||
|
||||
uint8_t CAT24I2CFlashSettingsStorage::writeInt(uint32_t value) {
|
||||
return writeBytes(&value, 4);
|
||||
};
|
||||
|
||||
|
||||
|
||||
void CAT24I2CFlashSettingsStorage::beforeSave() {
|
||||
reset();
|
||||
};
|
||||
|
||||
|
||||
void CAT24I2CFlashSettingsStorage::beforeLoad() {
|
||||
reset();
|
||||
_wire->beginTransmission(_address);
|
||||
_wire->write(_currptr >> 8);
|
||||
_wire->write(_currptr & 0xFF);
|
||||
_wire->endTransmission(false);
|
||||
};
|
||||
|
||||
|
||||
|
||||
void CAT24I2CFlashSettingsStorage::reset() {
|
||||
_currptr = _offset;
|
||||
};
|
||||
|
||||
|
||||
int CAT24I2CFlashSettingsStorage::readBytes(void* valueToSet, int numBytes) {
|
||||
int read = _wire->requestFrom((uint8_t)_address, (uint8_t)numBytes, (uint8_t)true);
|
||||
_currptr += read;
|
||||
if (read==numBytes)
|
||||
_wire->readBytes((uint8_t*)valueToSet, numBytes);
|
||||
return read;
|
||||
};
|
||||
|
||||
|
||||
int CAT24I2CFlashSettingsStorage::writeBytes(void* value, int numBytes) {
|
||||
_wire->beginTransmission(_address);
|
||||
_wire->write(_currptr >> 8);
|
||||
_wire->write(_currptr & 0xFF);
|
||||
size_t written = _wire->write((uint8_t*)value, numBytes);
|
||||
_wire->endTransmission(true);
|
||||
_currptr += written;
|
||||
delay(5); // write-cycle time
|
||||
return written;
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../SettingsStorage.h"
|
||||
#include "Wire.h"
|
||||
|
||||
class CAT24I2CFlashSettingsStorage : public SettingsStorage {
|
||||
public:
|
||||
CAT24I2CFlashSettingsStorage(uint8_t address = 0xA0, uint16_t offset = 0x0);
|
||||
~CAT24I2CFlashSettingsStorage();
|
||||
|
||||
void init(TwoWire* wire = &Wire);
|
||||
|
||||
protected:
|
||||
uint8_t readByte(uint8_t* valueToSet) override;
|
||||
uint8_t readFloat(float* valueToSet) override;
|
||||
uint8_t readInt(uint32_t* valueToSet) override;
|
||||
|
||||
uint8_t writeByte(uint8_t value) override;
|
||||
uint8_t writeFloat(float value) override;
|
||||
uint8_t writeInt(uint32_t value) override;
|
||||
|
||||
void beforeSave() override;
|
||||
void beforeLoad() override;
|
||||
|
||||
void reset();
|
||||
int readBytes(void* valueToSet, int numBytes);
|
||||
int writeBytes(void* value, int numBytes);
|
||||
|
||||
TwoWire* _wire;
|
||||
uint8_t _address; // i2c address
|
||||
uint16_t _offset; // offset into NVRAM to store settings
|
||||
uint16_t _currptr = 0; // pointer to current location in NVRAM
|
||||
|
||||
};
|
||||
26
firmware/lib/Arduino-FOC-drivers/src/settings/i2c/README.md
Normal file
26
firmware/lib/Arduino-FOC-drivers/src/settings/i2c/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
# I2C memories settings drivers
|
||||
|
||||
Store settings to I2C EEPROMs.
|
||||
|
||||
## CAT24C64 I2C EEPROMs
|
||||
|
||||
:warning: not yet finished or tested!
|
||||
|
||||
Datasheet describes the CAT24C64 as: _The CAT24C64 is a 64 Kb CMOS Serial EEPROM device, internally organized as 8192 words of 8 bits each._
|
||||
|
||||
Provide I2C address in constructor:
|
||||
|
||||
`CAT24I2CFlashSettingsStorage settings = CAT24I2CFlashSettingsStorage(0xA0);`
|
||||
|
||||
If you want to use a different I2C bus than the default, you can pass it to the constructor:
|
||||
|
||||
`settings.init(&Wire2);`
|
||||
|
||||
You can use multiple settings objects in the same EEPROM, by providing an offset to the constructor:
|
||||
|
||||
```c++
|
||||
CAT24I2CFlashSettingsStorage settings = CAT24I2CFlashSettingsStorage(0xA0);
|
||||
CAT24I2CFlashSettingsStorage settings = CAT24I2CFlashSettingsStorage(0xA0, 80);
|
||||
CAT24I2CFlashSettingsStorage settings = CAT24I2CFlashSettingsStorage(0xA0, 160);
|
||||
```
|
||||
Reference in New Issue
Block a user