-
Notifications
You must be signed in to change notification settings - Fork 9
/
Eeprom_ESP.cpp
56 lines (48 loc) · 1.19 KB
/
Eeprom_ESP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <Arduino.h>
#include <EEPROM.h>
#include "EEPROM_ESP.h"
#ifdef EEPROM_ESP
unsigned char eeprom_read_byte(
unsigned char * pos)
{
return EEPROM.read(int(pos));
}
int eeprom_read_word(
const unsigned int * pointer) {
return EEPROM.read(int(pointer++)) << 8 + EEPROM.read(int(pointer));
}
void eeprom_write_byte(
unsigned char * pointer,
unsigned char value)
{
//Serial.println(int(pointer));
EEPROM.write(int(pointer), value);
EEPROM.commit();
//#define EEPROM_VER
#ifdef EEPROM_VER
DEBUG_PRINT("Ep.W");DEBUG_PRINTLN( EEPROM.read(int(pointer)));
#endif
}
void eeprom_read_block(
void * __dst,
const void * __src,
unsigned int __n)//Read a block of __n bytes from EEPROM address __src to SRAM __dst.
{
for (int i = 0; i < __n; i++) {
*((char *)__dst + i) = eeprom_read_byte((uint8_t *)__src + i);
}
}
void eeprom_write_block(
const void * src,
void * dst,
unsigned int num) //Write a block of __n bytes to EEPROM address __dst from __src.
{
int pos = int(dst);
for (int i = 0; i < num; i++) {
byte data = *((unsigned char*)src + i);
//Serial.print(pos + i);
EEPROM.write(pos + i, data);
}
EEPROM.commit();
}
#endif