|
@@ -32,6 +32,7 @@
|
32
|
32
|
#if ENABLED(SDCARD_EEPROM_EMULATION)
|
33
|
33
|
|
34
|
34
|
#include "../shared/eeprom_api.h"
|
|
35
|
+#include "../../sd/cardreader.h"
|
35
|
36
|
|
36
|
37
|
#ifndef E2END
|
37
|
38
|
#define E2END 0xFFF // 4KB
|
|
@@ -41,44 +42,34 @@
|
41
|
42
|
#define _ALIGN(x) __attribute__ ((aligned(x))) // SDIO uint32_t* compat.
|
42
|
43
|
static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
|
43
|
44
|
|
44
|
|
-#if ENABLED(SDSUPPORT)
|
|
45
|
+#define EEPROM_FILENAME "eeprom.dat"
|
45
|
46
|
|
46
|
|
- #include "../../sd/cardreader.h"
|
|
47
|
+bool PersistentStore::access_start() {
|
|
48
|
+ if (!card.isMounted()) return false;
|
47
|
49
|
|
48
|
|
- #define EEPROM_FILENAME "eeprom.dat"
|
|
50
|
+ SdFile file, root = card.getroot();
|
|
51
|
+ if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
|
|
52
|
+ return true; // false aborts the save
|
49
|
53
|
|
50
|
|
- bool PersistentStore::access_start() {
|
51
|
|
- if (!card.isMounted()) return false;
|
|
54
|
+ int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE);
|
|
55
|
+ if (bytes_read < 0) return false;
|
|
56
|
+ for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++)
|
|
57
|
+ HAL_eeprom_data[bytes_read] = 0xFF;
|
|
58
|
+ file.close();
|
|
59
|
+ return true;
|
|
60
|
+}
|
52
|
61
|
|
53
|
|
- SdFile file, root = card.getroot();
|
54
|
|
- if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
|
55
|
|
- return true; // false aborts the save
|
|
62
|
+bool PersistentStore::access_finish() {
|
|
63
|
+ if (!card.isMounted()) return false;
|
56
|
64
|
|
57
|
|
- int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE);
|
58
|
|
- if (bytes_read < 0) return false;
|
59
|
|
- for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++)
|
60
|
|
- HAL_eeprom_data[bytes_read] = 0xFF;
|
|
65
|
+ SdFile file, root = card.getroot();
|
|
66
|
+ int bytes_written = 0;
|
|
67
|
+ if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
|
|
68
|
+ bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE);
|
61
|
69
|
file.close();
|
62
|
|
- return true;
|
63
|
|
- }
|
64
|
|
-
|
65
|
|
- bool PersistentStore::access_finish() {
|
66
|
|
- if (!card.isMounted()) return false;
|
67
|
|
-
|
68
|
|
- SdFile file, root = card.getroot();
|
69
|
|
- int bytes_written = 0;
|
70
|
|
- if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
|
71
|
|
- bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE);
|
72
|
|
- file.close();
|
73
|
|
- }
|
74
|
|
- return (bytes_written == HAL_EEPROM_SIZE);
|
75
|
70
|
}
|
76
|
|
-
|
77
|
|
-#else // !SDSUPPORT
|
78
|
|
-
|
79
|
|
- #error "Please define SPI_EEPROM (in Configuration.h) or disable EEPROM_SETTINGS."
|
80
|
|
-
|
81
|
|
-#endif // !SDSUPPORT
|
|
71
|
+ return (bytes_written == HAL_EEPROM_SIZE);
|
|
72
|
+}
|
82
|
73
|
|
83
|
74
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
84
|
75
|
for (size_t i = 0; i < size; i++)
|