Skip to content

Commit 7de4155

Browse files
Merge pull request #249 from noisymime/master
Add EEPROM.update() function
2 parents d3058d3 + 7c32077 commit 7de4155

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

STM32F1/libraries/EEPROM/EEPROM.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff 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

STM32F1/libraries/EEPROM/EEPROM.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)