File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -521,6 +521,28 @@ uint16 EEPROMClass::write(uint16 Address, uint16 Data)
521
521
return status;
522
522
}
523
523
524
+ /* *
525
+ * @brief Writes/upadtes variable data in EEPROM.
526
+ The value is written only if differs from the one already saved at the same address.
527
+ * @param VirtAddress: Variable virtual address
528
+ * @param Data: 16 bit data to be written
529
+ * @retval Success or error status:
530
+ * - EEPROM_SAME_VALUE: If new Data matches existing EEPROM Data
531
+ * - FLASH_COMPLETE: on success
532
+ * - EEPROM_BAD_ADDRESS: if address = 0xFFFF
533
+ * - EEPROM_PAGE_FULL: if valid page is full
534
+ * - EEPROM_NO_VALID_PAGE: if no valid page was found
535
+ * - EEPROM_OUT_SIZE: if no empty EEPROM variables
536
+ * - Flash error code: on write Flash error
537
+ */
538
+ uint16 EEPROMClass::update (uint16 Address, uint16 Data)
539
+ {
540
+ if (read (Address) == Data)
541
+ return EEPROM_SAME_VALUE;
542
+ else
543
+ return write (Address, Data);
544
+ }
545
+
524
546
/* *
525
547
* @brief Return number of variable
526
548
* @retval Number of variables
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ enum : uint16
47
47
EEPROM_BAD_ADDRESS = ((uint16)0x0082 ),
48
48
EEPROM_BAD_FLASH = ((uint16)0x0083 ),
49
49
EEPROM_NOT_INIT = ((uint16)0x0084 ),
50
+ EEPROM_SAME_VALUE = ((uint16)0x0085 ),
50
51
EEPROM_NO_VALID_PAGE = ((uint16)0x00AB )
51
52
};
52
53
@@ -67,6 +68,7 @@ class EEPROMClass
67
68
uint16 read (uint16 address);
68
69
uint16 read (uint16 address, uint16 *data);
69
70
uint16 write (uint16 address, uint16 data);
71
+ uint16 update (uint16 address, uint16 data);
70
72
uint16 count (uint16 *);
71
73
uint16 maxcount (void );
72
74
You can’t perform that action at this time.
0 commit comments