Add MarlinSettings::validate()
This commit is contained in:
@ -38,10 +38,10 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||
do {
|
||||
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
||||
*value = c;
|
||||
if (writing) *value = c;
|
||||
crc16(crc, &c, 1);
|
||||
pos++;
|
||||
value++;
|
||||
|
@ -43,10 +43,10 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||
do {
|
||||
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
||||
*value = c;
|
||||
if (writing) *value = c;
|
||||
crc16(crc, &c, 1);
|
||||
pos++;
|
||||
value++;
|
||||
|
@ -128,7 +128,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||
return (bytes_written != size); // return true for any error
|
||||
}
|
||||
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||
UINT bytes_read = 0;
|
||||
FRESULT s;
|
||||
s = f_lseek(&eeprom_file, pos);
|
||||
@ -140,7 +140,15 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
||||
SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
|
||||
return true;
|
||||
}
|
||||
s = f_read(&eeprom_file, (void *)value, size, &bytes_read);
|
||||
if (writing) {
|
||||
s = f_read(&eeprom_file, (void *)value, size, &bytes_read);
|
||||
crc16(crc, value, size);
|
||||
}
|
||||
else {
|
||||
uint8_t temp[size];
|
||||
s = f_read(&eeprom_file, (void *)temp, size, &bytes_read);
|
||||
crc16(crc, temp, size);
|
||||
}
|
||||
if (s) {
|
||||
SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful
|
||||
SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the
|
||||
@ -151,7 +159,6 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
||||
SERIAL_PROTOCOLLNPAIR("\n bytes_read=", bytes_read);
|
||||
return true;
|
||||
}
|
||||
crc16(crc, value, size);
|
||||
pos = pos + size;
|
||||
return bytes_read != size; // return true for any error
|
||||
}
|
||||
|
@ -93,13 +93,13 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
||||
void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||
for (uint16_t i = 0; i < size; i++) {
|
||||
byte* accessPoint = (byte*)(pageBase + pos + i);
|
||||
value[i] = *accessPoint;
|
||||
uint8_t c = *accessPoint;
|
||||
if (writing) value[i] = c;
|
||||
crc16(crc, &c, 1);
|
||||
}
|
||||
|
||||
crc16(crc, value, size);
|
||||
pos += ((size + 1) & ~1);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,6 @@ bool access_start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool access_finish(){
|
||||
if (!card.cardOK) return false;
|
||||
int16_t bytes_written = 0;
|
||||
@ -81,11 +80,12 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
value[i] = HAL_STM32F1_eeprom_content [pos + i];
|
||||
uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
|
||||
if (writing) value[i] = c`;
|
||||
crc16(crc, &c, 1);
|
||||
}
|
||||
crc16(crc, value, size);
|
||||
pos += size;
|
||||
return false;
|
||||
}
|
||||
|
@ -38,10 +38,10 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||
do {
|
||||
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
||||
*value = c;
|
||||
if (writing) *value = c;
|
||||
crc16(crc, &c, 1);
|
||||
pos++;
|
||||
value++;
|
||||
|
@ -10,7 +10,7 @@ namespace PersistentStore {
|
||||
bool access_start();
|
||||
bool access_finish();
|
||||
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc);
|
||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing=true);
|
||||
|
||||
} // PersistentStore
|
||||
} // HAL
|
||||
|
Reference in New Issue
Block a user