77#define _APOLLO3_LIBRARIES_EEPROM_H_
88
99#include " Arduino.h"
10+ #include " FlashIAPBlockDevice.h"
1011
1112#define EEPROM_DEFAULT_SRAM_USAGE (1024 )
1213
1314typedef struct _eeprom_config_t {
1415 mbed::bd_size_t sram_bytes = EEPROM_DEFAULT_SRAM_USAGE;
1516} eeprom_config_t ;
1617
17- class EEPROMClass : protected FlashIAPBlockDevice {
18+ class EEPROMClass : public FlashIAPBlockDevice {
1819private:
1920 eeprom_config_t _cfg;
2021
@@ -35,17 +36,17 @@ class EEPROMClass : protected FlashIAPBlockDevice {
3536 }
3637 uint8_t read (int idx){
3738 uint8_t val = 0x00 ;
38- read (&val, idx , 1 );
39+ read (idx, &val , 1 );
3940 return val;
4041 }
4142 void write (int idx, uint8_t * data, uint32_t size){
4243 mbed::bd_size_t scratch_size = (_cfg.sram_bytes +3 )/4 ;
4344 uint32_t scratch[scratch_size];
4445 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)
4647 erase ();
48+ memcpy (scratch, data, size);
4749 int result = FlashIAPBlockDevice::program ((uint8_t *)scratch, 0 , 4 *scratch_size);
48- printf (" updating flash. result: %d\n " , result);
4950 return ;
5051 }
5152 printf (" contents already match\n " );
@@ -66,7 +67,7 @@ class EEPROMClass : protected FlashIAPBlockDevice {
6667 }
6768
6869 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 ));
7071 return t;
7172 }
7273
0 commit comments