7
7
#define _APOLLO3_LIBRARIES_EEPROM_H_
8
8
9
9
#include " Arduino.h"
10
+ #include " FlashIAPBlockDevice.h"
10
11
11
12
#define EEPROM_DEFAULT_SRAM_USAGE (1024 )
12
13
13
14
typedef struct _eeprom_config_t {
14
15
mbed::bd_size_t sram_bytes = EEPROM_DEFAULT_SRAM_USAGE;
15
16
} eeprom_config_t ;
16
17
17
- class EEPROMClass : protected FlashIAPBlockDevice {
18
+ class EEPROMClass : public FlashIAPBlockDevice {
18
19
private:
19
20
eeprom_config_t _cfg;
20
21
@@ -35,17 +36,17 @@ class EEPROMClass : protected FlashIAPBlockDevice {
35
36
}
36
37
uint8_t read (int idx){
37
38
uint8_t val = 0x00 ;
38
- read (&val, idx , 1 );
39
+ read (idx, &val , 1 );
39
40
return val;
40
41
}
41
42
void write (int idx, uint8_t * data, uint32_t size){
42
43
mbed::bd_size_t scratch_size = (_cfg.sram_bytes +3 )/4 ;
43
44
uint32_t scratch[scratch_size];
44
45
FlashIAPBlockDevice::read ((uint8_t *)scratch, 0 , _cfg.sram_bytes ); // keep all of flash in sram in case we need to erase
45
- if (memcmp ((void *)(((uint8_t *)scratch) + idx), data, size)){ // compare desired data (data) to existing information in flash (scratch)
46
+ if (memcmp ((void *)(((uint8_t *)scratch) + idx), data, size)){ // compare desired data (data) to existing information in flash (scratch)
46
47
erase ();
48
+ memcpy (scratch, data, size);
47
49
int result = FlashIAPBlockDevice::program ((uint8_t *)scratch, 0 , 4 *scratch_size);
48
- printf (" updating flash. result: %d\n " , result);
49
50
return ;
50
51
}
51
52
printf (" contents already match\n " );
@@ -66,7 +67,7 @@ class EEPROMClass : protected FlashIAPBlockDevice {
66
67
}
67
68
68
69
template <typename T> T &get (int idx, T &t){
69
- read ((uint8_t *)&t, idx , sizeof (T)/sizeof (uint8_t ));
70
+ read (idx, (uint8_t *)&t, sizeof (T)/sizeof (uint8_t ));
70
71
return t;
71
72
}
72
73
0 commit comments