|
|
@ -32,6 +32,7 @@
|
|
|
|
#if ENABLED(SDCARD_EEPROM_EMULATION)
|
|
|
|
#if ENABLED(SDCARD_EEPROM_EMULATION)
|
|
|
|
|
|
|
|
|
|
|
|
#include "../shared/eeprom_api.h"
|
|
|
|
#include "../shared/eeprom_api.h"
|
|
|
|
|
|
|
|
#include "../../sd/cardreader.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef E2END
|
|
|
|
#ifndef E2END
|
|
|
|
#define E2END 0xFFF // 4KB
|
|
|
|
#define E2END 0xFFF // 4KB
|
|
|
@ -41,44 +42,34 @@
|
|
|
|
#define _ALIGN(x) __attribute__ ((aligned(x))) // SDIO uint32_t* compat.
|
|
|
|
#define _ALIGN(x) __attribute__ ((aligned(x))) // SDIO uint32_t* compat.
|
|
|
|
static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
|
|
|
|
static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
#define EEPROM_FILENAME "eeprom.dat"
|
|
|
|
|
|
|
|
|
|
|
|
#include "../../sd/cardreader.h"
|
|
|
|
bool PersistentStore::access_start() {
|
|
|
|
|
|
|
|
if (!card.isMounted()) return false;
|
|
|
|
|
|
|
|
|
|
|
|
#define EEPROM_FILENAME "eeprom.dat"
|
|
|
|
SdFile file, root = card.getroot();
|
|
|
|
|
|
|
|
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
|
|
|
|
|
|
|
|
return true; // false aborts the save
|
|
|
|
|
|
|
|
|
|
|
|
bool PersistentStore::access_start() {
|
|
|
|
int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE);
|
|
|
|
if (!card.isMounted()) return false;
|
|
|
|
if (bytes_read < 0) return false;
|
|
|
|
|
|
|
|
for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++)
|
|
|
|
|
|
|
|
HAL_eeprom_data[bytes_read] = 0xFF;
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SdFile file, root = card.getroot();
|
|
|
|
bool PersistentStore::access_finish() {
|
|
|
|
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
|
|
|
|
if (!card.isMounted()) return false;
|
|
|
|
return true; // false aborts the save
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE);
|
|
|
|
SdFile file, root = card.getroot();
|
|
|
|
if (bytes_read < 0) return false;
|
|
|
|
int bytes_written = 0;
|
|
|
|
for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++)
|
|
|
|
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
|
|
|
|
HAL_eeprom_data[bytes_read] = 0xFF;
|
|
|
|
bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE);
|
|
|
|
file.close();
|
|
|
|
file.close();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (bytes_written == HAL_EEPROM_SIZE);
|
|
|
|
bool PersistentStore::access_finish() {
|
|
|
|
}
|
|
|
|
if (!card.isMounted()) return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SdFile file, root = card.getroot();
|
|
|
|
|
|
|
|
int bytes_written = 0;
|
|
|
|
|
|
|
|
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
|
|
|
|
|
|
|
|
bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE);
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return (bytes_written == HAL_EEPROM_SIZE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else // !SDSUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#error "Please define SPI_EEPROM (in Configuration.h) or disable EEPROM_SETTINGS."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // !SDSUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
|
|
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|