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)
521521 return status;
522522}
523523
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+
524546/* *
525547 * @brief Return number of variable
526548 * @retval Number of variables
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ enum : uint16
4747 EEPROM_BAD_ADDRESS = ((uint16)0x0082 ),
4848 EEPROM_BAD_FLASH = ((uint16)0x0083 ),
4949 EEPROM_NOT_INIT = ((uint16)0x0084 ),
50+ EEPROM_SAME_VALUE = ((uint16)0x0085 ),
5051 EEPROM_NO_VALID_PAGE = ((uint16)0x00AB )
5152 };
5253
@@ -67,6 +68,7 @@ class EEPROMClass
6768 uint16 read (uint16 address);
6869 uint16 read (uint16 address, uint16 *data);
6970 uint16 write (uint16 address, uint16 data);
71+ uint16 update (uint16 address, uint16 data);
7072 uint16 count (uint16 *);
7173 uint16 maxcount (void );
7274
You can’t perform that action at this time.
0 commit comments