|
|
@ -19,92 +19,84 @@
|
|
|
|
#include <Kaleidoscope-EEPROM-Settings.h>
|
|
|
|
#include <Kaleidoscope-EEPROM-Settings.h>
|
|
|
|
#include "crc.h"
|
|
|
|
#include "crc.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
namespace kaleidoscope {
|
|
|
|
struct EEPROMSettings::settings EEPROMSettings::settings;
|
|
|
|
|
|
|
|
bool EEPROMSettings::_isValid;
|
|
|
|
struct EEPROMSettings::settings EEPROMSettings::settings_;
|
|
|
|
bool EEPROMSettings::sealed;
|
|
|
|
bool EEPROMSettings::is_valid_;
|
|
|
|
uint16_t EEPROMSettings::nextStart = sizeof(EEPROMSettings::settings);
|
|
|
|
bool EEPROMSettings::sealed_;
|
|
|
|
|
|
|
|
uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings);
|
|
|
|
|
|
|
|
|
|
|
|
EEPROMSettings::EEPROMSettings(void) {
|
|
|
|
EEPROMSettings::EEPROMSettings(void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void EEPROMSettings::begin(void) {
|
|
|
|
EEPROMSettings::begin(void) {
|
|
|
|
EEPROM.get(0, settings_);
|
|
|
|
EEPROM.get(0, settings);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool EEPROMSettings::isValid(void) {
|
|
|
|
EEPROMSettings::isValid(void) {
|
|
|
|
return is_valid_;
|
|
|
|
return _isValid;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
uint16_t EEPROMSettings::crc(void) {
|
|
|
|
EEPROMSettings::crc(void) {
|
|
|
|
if (sealed_)
|
|
|
|
if (sealed)
|
|
|
|
return settings_.crc;
|
|
|
|
return settings.crc;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void EEPROMSettings::seal(void) {
|
|
|
|
EEPROMSettings::seal(void) {
|
|
|
|
sealed_ = true;
|
|
|
|
sealed = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CRC.finalize();
|
|
|
|
CRC.finalize();
|
|
|
|
|
|
|
|
|
|
|
|
if (settings.magic[0] != 'K' || settings.magic[1] != 'S') {
|
|
|
|
if (settings_.magic[0] != 'K' || settings_.magic[1] != 'S') {
|
|
|
|
settings.magic[0] = 'K';
|
|
|
|
settings_.magic[0] = 'K';
|
|
|
|
settings.magic[1] = 'S';
|
|
|
|
settings_.magic[1] = 'S';
|
|
|
|
settings.version = 0;
|
|
|
|
settings_.version = 0;
|
|
|
|
settings.crc = CRC.crc;
|
|
|
|
settings_.crc = CRC.crc;
|
|
|
|
|
|
|
|
|
|
|
|
return update();
|
|
|
|
return update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (settings.crc != CRC.crc)
|
|
|
|
if (settings_.crc != CRC.crc)
|
|
|
|
_isValid = false;
|
|
|
|
is_valid_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
uint16_t EEPROMSettings::requestSlice(uint16_t size) {
|
|
|
|
EEPROMSettings::requestSlice(uint16_t size) {
|
|
|
|
if (sealed_)
|
|
|
|
if (sealed)
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t start = nextStart;
|
|
|
|
uint16_t start = next_start_;
|
|
|
|
nextStart += size;
|
|
|
|
next_start_ += size;
|
|
|
|
|
|
|
|
|
|
|
|
CRC.update((const void *)&size, sizeof(size));
|
|
|
|
CRC.update((const void *)&size, sizeof(size));
|
|
|
|
|
|
|
|
|
|
|
|
return start;
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void EEPROMSettings::invalidate(void) {
|
|
|
|
EEPROMSettings::invalidate(void) {
|
|
|
|
is_valid_ = false;
|
|
|
|
_isValid = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
uint16_t EEPROMSettings::used(void) {
|
|
|
|
EEPROMSettings::used(void) {
|
|
|
|
return next_start_;
|
|
|
|
return nextStart;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void EEPROMSettings::update(void) {
|
|
|
|
EEPROMSettings::update(void) {
|
|
|
|
settings_.crc = CRC.crc;
|
|
|
|
settings.crc = CRC.crc;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EEPROM.put(0, settings);
|
|
|
|
EEPROM.put(0, settings_);
|
|
|
|
_isValid = true;
|
|
|
|
is_valid_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
uint8_t EEPROMSettings::version(void) {
|
|
|
|
EEPROMSettings::version(void) {
|
|
|
|
return settings_.version;
|
|
|
|
return settings.version;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void EEPROMSettings::version(uint8_t ver) {
|
|
|
|
EEPROMSettings::version(uint8_t ver) {
|
|
|
|
settings_.version = ver;
|
|
|
|
settings.version = ver;
|
|
|
|
|
|
|
|
update();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KaleidoscopePlugins::EEPROMSettings EEPROMSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kaleidoscope::EEPROMSettings EEPROMSettings;
|
|
|
|