28 lines
762 B
C++
28 lines
762 B
C++
|
/*
|
||
|
* ESP8266 RTC Memory Access library
|
||
|
*
|
||
|
* copyright: Jannik Beyerstedt | http://jannikbeyerstedt.de | code@jannikbeyerstedt.de
|
||
|
* license: http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 License
|
||
|
*/
|
||
|
|
||
|
#include "rtc-helpers.hpp"
|
||
|
|
||
|
#include <ESP.h>
|
||
|
|
||
|
#define RTC_MEMCHECK_MAGIC 0xAABBCCDD // cheap input validation by using a magic constant
|
||
|
|
||
|
bool rtcMemoryLoad(rtcStore_t* rtcStore_ptr) {
|
||
|
if (ESP.rtcUserMemoryRead(0, (uint32_t*)rtcStore_ptr, sizeof(*rtcStore_ptr))) {
|
||
|
return (RTC_MEMCHECK_MAGIC == rtcStore_ptr->magic);
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool rtcMemoryStore(rtcStore_t* rtcStore_ptr) {
|
||
|
rtcStore_ptr->magic = RTC_MEMCHECK_MAGIC;
|
||
|
if (ESP.rtcUserMemoryWrite(0, (uint32_t*)rtcStore_ptr, sizeof(*rtcStore_ptr))) {
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|