From 577aeb4aa91c2f9ebc9b7e44cde23da647893a32 Mon Sep 17 00:00:00 2001 From: Nils Hasenbanck Date: Sun, 12 Aug 2018 09:50:39 +0200 Subject: [PATCH] All EEPROM access uses persistentStore --- Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp | 10 +++++-- Marlin/src/module/printcounter.cpp | 32 +++++++++++++++------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index b2de3c96bb..e1771c91f7 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -29,6 +29,7 @@ #include "ubl.h" #include "../../../Marlin.h" + #include "../../../HAL/persistent_store_api.h" #include "../../../libs/hex_print_routines.h" #include "../../../module/configuration_store.h" #include "../../../lcd/ultralcd.h" @@ -1167,24 +1168,27 @@ * right now, it is good to have the extra information. Soon... we prune this. */ void unified_bed_leveling::g29_eeprom_dump() { - unsigned char cccc; - unsigned int kkkk; // Needs to be of unspecfied size to compile clean on all platforms + uint8_t cccc; + int kkkk; + uint16_t crc = 0; SERIAL_ECHO_START(); SERIAL_ECHOLNPGM("EEPROM Dump:"); + persistentStore.access_start(); for (uint16_t i = 0; i < persistentStore.capacity(); i += 16) { if (!(i & 0x3)) idle(); print_hex_word(i); SERIAL_ECHOPGM(": "); for (uint16_t j = 0; j < 16; j++) { kkkk = i + j; - eeprom_read_block(&cccc, (const void *)kkkk, sizeof(unsigned char)); + persistentStore.read_data(kkkk, &cccc, sizeof(uint8_t), &crc); print_hex_byte(cccc); SERIAL_ECHO(' '); } SERIAL_EOL(); } SERIAL_EOL(); + persistentStore.access_finish(); } /** diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 44adcf45f2..ea1b7f61f9 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -31,6 +31,7 @@ Stopwatch print_job_timer; // Global Print Job Timer instance #include "printcounter.h" #include "../Marlin.h" +#include "../HAL/persistent_store_api.h" PrintCounter print_job_timer; // Global Print Job Timer instance @@ -73,7 +74,12 @@ void PrintCounter::initStats() { data = { 0, 0, 0, 0, 0.0 }; saveStats(); - eeprom_write_byte((uint8_t*)address, 0x16); + + uint16_t crc = 0; + int a = address; + persistentStore.access_start(); + persistentStore.write_data(a, (uint8_t*)0x16, sizeof(uint8_t), &crc); + persistentStore.access_finish(); } void PrintCounter::loadStats() { @@ -81,11 +87,18 @@ void PrintCounter::loadStats() { debug(PSTR("loadStats")); #endif - // Checks if the EEPROM block is initialized - if (eeprom_read_byte((uint8_t*)address) != 0x16) initStats(); - else eeprom_read_block(&data, - (void*)(address + sizeof(uint8_t)), sizeof(printStatistics)); - + // Check if the EEPROM block is initialized + uint16_t crc = 0; + int a = address; + uint8_t value; + persistentStore.access_start(); + persistentStore.read_data(a, &value, sizeof(uint8_t), &crc); + if (value != 0x16) initStats(); + else { + a = address + sizeof(uint8_t); + persistentStore.read_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc); + } + persistentStore.access_finish(); loaded = true; } @@ -98,8 +111,11 @@ void PrintCounter::saveStats() { if (!isLoaded()) return; // Saves the struct to EEPROM - eeprom_update_block(&data, - (void*)(address + sizeof(uint8_t)), sizeof(printStatistics)); + uint16_t crc = 0; + int a = (address + sizeof(uint8_t)); + persistentStore.access_start(); + persistentStore.write_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc); + persistentStore.access_finish(); } void PrintCounter::showStats() {